index.js 6.0 KB

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