index.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. const CONFIG = require('../../config.js')
  2. const WXAPI = require('apifm-wxapi')
  3. const AUTH = require('../../utils/auth')
  4. const TOOLS = require('../../utils/tools.js')
  5. const APP = getApp()
  6. // fixed首次打开不显示标题的bug
  7. APP.configLoadOK = () => {
  8. }
  9. Page({
  10. data: {
  11. balance:0.00,
  12. freeze:0,
  13. score:0,
  14. growth:0,
  15. score_sign_continuous:0,
  16. rechargeOpen: false, // 是否开启充值[预存]功能
  17. // 用户订单统计数据
  18. count_id_no_confirm: 0,
  19. count_id_no_pay: 0,
  20. count_id_no_reputation: 0,
  21. count_id_no_transfer: 0,
  22. // 判断有没有用户详细资料
  23. userInfoStatus: 0 // 0 未读取 1 没有详细信息 2 有详细信息
  24. },
  25. onLoad() {
  26. },
  27. onShow() {
  28. const _this = this
  29. const order_hx_uids = wx.getStorageSync('order_hx_uids')
  30. this.setData({
  31. version: CONFIG.version,
  32. order_hx_uids
  33. })
  34. AUTH.checkHasLogined().then(isLogined => {
  35. if (isLogined) {
  36. _this.getUserApiInfo();
  37. _this.getUserAmount();
  38. _this.orderStatistics();
  39. TOOLS.showTabBarBadge();
  40. } else {
  41. AUTH.authorize().then(res => {
  42. _this.getUserApiInfo();
  43. _this.getUserAmount();
  44. _this.orderStatistics();
  45. TOOLS.showTabBarBadge();
  46. })
  47. }
  48. })
  49. AUTH.wxaCode().then(code => {
  50. this.data.code = code
  51. })
  52. },
  53. async getUserApiInfo() {
  54. const res = await WXAPI.userDetail(wx.getStorageSync('token'))
  55. if (res.code == 0) {
  56. let _data = {}
  57. _data.apiUserInfoMap = res.data
  58. if (res.data.base.mobile) {
  59. _data.userMobile = res.data.base.mobile
  60. }
  61. if (res.data.base.nick && res.data.base.avatarUrl) {
  62. _data.userInfoStatus = 2
  63. } else {
  64. _data.userInfoStatus = 1
  65. }
  66. if (this.data.order_hx_uids && this.data.order_hx_uids.indexOf(res.data.base.id) != -1) {
  67. _data.canHX = true // 具有扫码核销的权限
  68. }
  69. const adminUserIds = wx.getStorageSync('adminUserIds')
  70. if (adminUserIds && adminUserIds.indexOf(res.data.base.id) != -1) {
  71. _data.isAdmin = true
  72. }
  73. if (res.data.peisongMember && res.data.peisongMember.status == 1) {
  74. _data.memberChecked = false
  75. } else {
  76. _data.memberChecked = true
  77. }
  78. this.setData(_data);
  79. }
  80. },
  81. async memberCheckedChange() {
  82. const res = await WXAPI.peisongMemberChangeWorkStatus(wx.getStorageSync('token'))
  83. if (res.code != 0) {
  84. wx.showToast({
  85. title: res.msg,
  86. icon: 'none'
  87. })
  88. } else {
  89. this.getUserApiInfo()
  90. }
  91. },
  92. getUserAmount: function () {
  93. var that = this;
  94. WXAPI.userAmount(wx.getStorageSync('token')).then(function (res) {
  95. if (res.code == 0) {
  96. that.setData({
  97. balance: res.data.balance.toFixed(2),
  98. freeze: res.data.freeze.toFixed(2),
  99. score: res.data.score,
  100. growth: res.data.growth
  101. });
  102. }
  103. })
  104. },
  105. handleOrderCount: function (count) {
  106. return count > 99 ? '99+' : count;
  107. },
  108. orderStatistics: function () {
  109. WXAPI.orderStatistics(wx.getStorageSync('token')).then((res) => {
  110. if (res.code == 0) {
  111. const {
  112. count_id_no_confirm,
  113. count_id_no_pay,
  114. count_id_no_reputation,
  115. count_id_no_transfer,
  116. } = res.data || {}
  117. this.setData({
  118. count_id_no_confirm: this.handleOrderCount(count_id_no_confirm),
  119. count_id_no_pay: this.handleOrderCount(count_id_no_pay),
  120. count_id_no_reputation: this.handleOrderCount(count_id_no_reputation),
  121. count_id_no_transfer: this.handleOrderCount(count_id_no_transfer),
  122. })
  123. }
  124. })
  125. },
  126. goAsset: function () {
  127. wx.navigateTo({
  128. url: "/pages/asset/index"
  129. })
  130. },
  131. goScore: function () {
  132. wx.navigateTo({
  133. url: "/pages/score/index"
  134. })
  135. },
  136. goOrder: function (e) {
  137. wx.navigateTo({
  138. url: "/pages/order-list/index?type=" + e.currentTarget.dataset.type
  139. })
  140. },
  141. scanOrderCode(){
  142. wx.scanCode({
  143. onlyFromCamera: true,
  144. success(res) {
  145. wx.navigateTo({
  146. url: '/pages/order-details/scan-result?hxNumber=' + res.result,
  147. })
  148. },
  149. fail(err) {
  150. console.error(err)
  151. wx.showToast({
  152. title: err.errMsg,
  153. icon: 'none'
  154. })
  155. }
  156. })
  157. },
  158. async updateUserInfo(e) {
  159. if (!e.detail.errMsg || e.detail.errMsg != "getUserInfo:ok") {
  160. wx.showModal({
  161. title: '提示',
  162. content: e.detail.errMsg,
  163. showCancel: false
  164. })
  165. return;
  166. }
  167. wx.showLoading({
  168. title: '',
  169. })
  170. const res = await WXAPI.encryptedData(this.data.code, e.detail.encryptedData, e.detail.iv)
  171. wx.hideLoading({
  172. success: (res) => {},
  173. })
  174. AUTH.wxaCode().then(code => {
  175. this.data.code = code
  176. })
  177. if (res.code == 0) {
  178. // 更新用户资料
  179. await WXAPI.modifyUserInfo({
  180. token: wx.getStorageSync('token'),
  181. avatarUrl: res.data.avatarUrl,
  182. nick: res.data.nickName,
  183. province: res.data.province,
  184. city: res.data.city,
  185. gender: res.data.gender,
  186. })
  187. this.getUserApiInfo();
  188. } else {
  189. wx.showModal({
  190. title: '错误',
  191. content: res.msg,
  192. showCancel: false
  193. })
  194. }
  195. },
  196. })