app.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. //app.js
  2. var JMessage = require('./libs/jmessage-wxapplet-sdk-1.4.2.min.js')
  3. App({
  4. onLaunch: function () {
  5. // 展示本地存储能力
  6. let _this = this;
  7. let logs = wx.getStorageSync('logs') || []
  8. const updateManager = wx.getUpdateManager()
  9. updateManager.onCheckForUpdate(function (res) {
  10. // 请求完新版本信息的回调
  11. if (res.hasUpdate) {
  12. updateManager.onUpdateReady(function () {
  13. wx.showModal({
  14. title: '更新提示',
  15. content: '新版本已经准备好,是否重启应用?',
  16. success(res) {
  17. if (res.confirm) {
  18. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  19. updateManager.applyUpdate()
  20. }
  21. }
  22. })
  23. })
  24. };
  25. })
  26. logs.unshift(Date.now());
  27. wx.setStorageSync('logs', logs);
  28. wx.login({
  29. success: loginCode => {
  30. wx.setStorageSync('key', { 'code': loginCode.code });
  31. wx.request({
  32. url: _this.globalData.prodUrl + 'web-sso/get_open_id',
  33. data: {
  34. code: loginCode.code
  35. },
  36. success: function (data) {
  37. _this.globalData.requestStatus = true;
  38. wx.setStorageSync('key', { 'openid': data.data.data.openid, 'ydw_token': data.data.ydw_token, 'persionid': data.data.persion.kid});
  39. wx.setStorageSync('persion', { 'persion': data.data.persion });
  40. // 去支付提醒
  41. _this.payRemind();
  42. if(data.data.is_first) {
  43. _this.globalData.is_first = true;
  44. };
  45. if(data.data.red_pack_msg.length>0) {
  46. _this.globalData.red_pack_msg = data.data.red_pack_msg.length
  47. }
  48. }
  49. })
  50. // 发送 res.code 到后台换取 openId, sessionKey, unionId
  51. }
  52. })
  53. //获取openID
  54. // _this.getLogs(_this);
  55. // 获取用户信息
  56. // wx.getSetting({
  57. // success: res => {
  58. // if (res.authSetting['scope.userInfo']) {
  59. // // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
  60. // wx.getUserInfo({
  61. // success: res => {
  62. // // 可以将 res 发送给后台解码出 unionId
  63. // this.globalData.userInfo = res.userInfo
  64. // console.log(this.globalData.userInfo)
  65. // // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  66. // // 所以此处加入 callback 以防止这种情况
  67. // if (this.userInfoReadyCallback) {
  68. // this.userInfoReadyCallback(res)
  69. // }
  70. // }
  71. // })
  72. // }
  73. // }
  74. // });
  75. },
  76. globalData: {
  77. userInfo: null,
  78. requestStatus: false,
  79. prodUrl: 'https://www.eqbidding.com/',
  80. is_first: false,
  81. awardsConfig: {},
  82. red_pack_msg:0
  83. },
  84. getLogs: function (obj) {
  85. return new Promise((resolve, reject) => {
  86. let _this = obj;
  87. wx.login({
  88. success: loginCode => {
  89. wx.setStorageSync('key', { 'code': loginCode.code });
  90. wx.request({
  91. url: _this.globalData.prodUrl + 'web-sso/get_open_id',
  92. data: {
  93. code: loginCode.code
  94. },
  95. success: function (data) {
  96. _this.globalData.requestStatus = true;
  97. wx.setStorageSync('key', { 'openid': data.data.data.openid, 'ydw_token': data.data.ydw_token });
  98. wx.setStorageSync('persion', { 'persion': data.data.persion });
  99. resolve();
  100. if (data.data.is_first) {
  101. _this.globalData.is_first = true;
  102. };
  103. if (data.data.red_pack_msg.length > 0) {
  104. _this.globalData.red_pack_msg = data.data.red_pack_msg.length
  105. };
  106. },
  107. fail: reject
  108. })
  109. }
  110. })
  111. })
  112. },
  113. payRemind : function () {
  114. let _this = this;
  115. wx.request({
  116. url: _this.globalData.prodUrl + 'web-pm/wx/pm/wait_pay_money',
  117. header: {
  118. 'ydw-token': wx.getStorageSync('key').ydw_token
  119. },
  120. success: function (data) {
  121. if (data.data.status!=500){
  122. if (data.data.data.length > 0) {
  123. wx.showModal({
  124. title: '温馨提示',
  125. content: '您有' + data.data.data.length + '件商品未付款',
  126. confirmText: '去支付',
  127. showCancel: false,
  128. success(res) {
  129. if (res.confirm) {
  130. wx.navigateTo({
  131. url: '/pages/mine/wxml/beingphotographed/beingphotographed'
  132. })
  133. }
  134. }
  135. })
  136. }
  137. }
  138. },
  139. });
  140. },
  141. update: function (userinfo) {
  142. var _this = this;
  143. wx.request({
  144. url: _this.globalData.prodUrl + 'web-pm/wx/pm/update_userinfo',
  145. data: {
  146. userinfo
  147. },
  148. header: { 'ydw-token': wx.getStorageSync('key').ydw_token },
  149. method: 'GET',
  150. dataType: 'json',
  151. responseType: 'text',
  152. success: function (data) {
  153. wx.setStorageSync('persion', { 'persion': data.data.persion });
  154. _this.globalData.userInfo = true
  155. },
  156. fail: function (res) { }
  157. })
  158. },
  159. smalltoBIG(n){
  160. var fraction = ['角', '分'];
  161. var digit = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖'];
  162. var unit = [['元', '万', '亿'], ['', '拾', '佰', '仟']];
  163. var head = n < 0 ? '欠' : '';
  164. n = Math.abs(n);
  165. var s = '';
  166. for(var i = 0; i<fraction.length; i++){
  167. s += (digit[Math.floor(n * 10 * Math.pow(10, i)) % 10] + fraction[i]).replace(/零./, '');
  168. }
  169. s = s || '整';
  170. n = Math.floor(n);
  171. for (var i = 0; i < unit[0].length && n > 0; i++) {
  172. var p = '';
  173. for (var j = 0; j < unit[1].length && n > 0; j++) {
  174. p = digit[n % 10] + unit[1][j] + p;
  175. n = Math.floor(n / 10);
  176. }
  177. s = p.replace(/(零.)*零$/, '').replace(/^$/, '零') + unit[0][i] + s;
  178. }
  179. return head + s.replace(/(零.)*零元/, '元').replace(/(零.)+/g, '零').replace(/^整$/, '零元整');
  180. }
  181. })