index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. import { fetchUserCenter } from '../../services/usercenter/fetchUsercenter';
  2. import { getToPayOrderCount, getToSendOrderCount, getToReceiveOrderCount } from '../../services/order/order';
  3. import { ORDER_STATUS } from '../../services/order/order';
  4. import Toast from 'tdesign-miniprogram/toast/index';
  5. const menuData = [
  6. [
  7. {
  8. title: '收货地址',
  9. tit: '',
  10. url: '',
  11. type: 'address',
  12. },
  13. {
  14. title: '联系客服',
  15. tit: '',
  16. url: '',
  17. type: 'service',
  18. },
  19. ],
  20. ];
  21. const orderTagInfos = [
  22. {
  23. title: '待付款',
  24. iconName: 'wallet',
  25. orderNum: 0,
  26. tabType: ORDER_STATUS.TO_PAY,
  27. status: 1,
  28. },
  29. {
  30. title: '待发货',
  31. iconName: 'deliver',
  32. orderNum: 0,
  33. tabType: ORDER_STATUS.TO_SEND,
  34. status: 1,
  35. },
  36. {
  37. title: '待收货',
  38. iconName: 'package',
  39. orderNum: 0,
  40. tabType: ORDER_STATUS.TO_RECEIVE,
  41. status: 1,
  42. },
  43. {
  44. title: '待评价',
  45. iconName: 'comment',
  46. orderNum: 0,
  47. tabType: ORDER_STATUS.FINISHED,
  48. status: 1,
  49. },
  50. // {
  51. // title: '退款/售后',
  52. // iconName: 'exchang',
  53. // orderNum: 0,
  54. // tabType: 0,
  55. // status: 1,
  56. // },
  57. ];
  58. const getDefaultData = () => ({
  59. showMakePhone: false,
  60. userInfo: {
  61. avatarUrl: '',
  62. nickName: '正在登录...',
  63. phoneNumber: '',
  64. },
  65. menuData,
  66. orderTagInfos,
  67. customerServiceInfo: {},
  68. currAuthStep: 1,
  69. showKefu: true,
  70. versionNo: '',
  71. toPayOrderCount: 0,
  72. toSendOrderCount: 0,
  73. toReceiveOrderCount: 0,
  74. });
  75. Page({
  76. data: getDefaultData(),
  77. onLoad() {
  78. this.getVersionInfo();
  79. },
  80. onShow() {
  81. this.getTabBar().init();
  82. this.init();
  83. },
  84. onPullDownRefresh() {
  85. this.init();
  86. },
  87. init() {
  88. this.fetUseriInfoHandle();
  89. this.initOrderCount();
  90. },
  91. async initOrderCount() {
  92. const [pay, send, receive] = await Promise.all([
  93. getToPayOrderCount(),
  94. getToSendOrderCount(),
  95. getToReceiveOrderCount(),
  96. ]);
  97. this.setData({
  98. 'orderTagInfos[0].orderNum': pay,
  99. 'orderTagInfos[1].orderNum': send,
  100. 'orderTagInfos[2].orderNum': receive,
  101. });
  102. },
  103. fetUseriInfoHandle() {
  104. fetchUserCenter().then(({ userInfo, countsData, customerServiceInfo }) => {
  105. // eslint-disable-next-line no-unused-expressions
  106. menuData?.[0].forEach((v) => {
  107. countsData.forEach((counts) => {
  108. if (counts.type === v.type) {
  109. // eslint-disable-next-line no-param-reassign
  110. v.tit = counts.num;
  111. }
  112. });
  113. });
  114. this.setData({
  115. userInfo,
  116. menuData,
  117. customerServiceInfo,
  118. currAuthStep: 2,
  119. });
  120. wx.stopPullDownRefresh();
  121. });
  122. },
  123. onClickCell({ currentTarget }) {
  124. const { type } = currentTarget.dataset;
  125. switch (type) {
  126. case 'address': {
  127. wx.navigateTo({ url: '/pages/usercenter/address/list/index' });
  128. break;
  129. }
  130. case 'service': {
  131. this.openMakePhone();
  132. break;
  133. }
  134. case 'help-center': {
  135. Toast({
  136. context: this,
  137. selector: '#t-toast',
  138. message: '你点击了帮助中心',
  139. icon: '',
  140. duration: 1000,
  141. });
  142. break;
  143. }
  144. case 'point': {
  145. Toast({
  146. context: this,
  147. selector: '#t-toast',
  148. message: '你点击了积分菜单',
  149. icon: '',
  150. duration: 1000,
  151. });
  152. break;
  153. }
  154. case 'coupon': {
  155. wx.navigateTo({ url: '/pages/coupon/coupon-list/index' });
  156. break;
  157. }
  158. default: {
  159. Toast({
  160. context: this,
  161. selector: '#t-toast',
  162. message: '未知跳转',
  163. icon: '',
  164. duration: 1000,
  165. });
  166. break;
  167. }
  168. }
  169. },
  170. jumpNav(e) {
  171. const status = e.detail.tabType;
  172. if (status === 0) {
  173. wx.navigateTo({ url: '/pages/order/after-service-list/index' });
  174. } else {
  175. wx.navigateTo({ url: `/pages/order/order-list/index?status=${status}` });
  176. }
  177. },
  178. jumpAllOrder() {
  179. wx.navigateTo({ url: '/pages/order/order-list/index' });
  180. },
  181. openMakePhone() {
  182. this.setData({ showMakePhone: true });
  183. },
  184. closeMakePhone() {
  185. this.setData({ showMakePhone: false });
  186. },
  187. call() {
  188. wx.makePhoneCall({
  189. phoneNumber: this.data.customerServiceInfo.servicePhone,
  190. });
  191. },
  192. gotoUserEditPage() {
  193. const { currAuthStep } = this.data;
  194. if (currAuthStep === 2) {
  195. wx.navigateTo({ url: '/pages/usercenter/person-info/index' });
  196. } else {
  197. this.fetUseriInfoHandle();
  198. }
  199. },
  200. getVersionInfo() {
  201. const versionInfo = wx.getAccountInfoSync();
  202. const { version, envVersion = __wxConfig } = versionInfo.miniProgram;
  203. this.setData({
  204. versionNo: envVersion === 'release' ? version : envVersion,
  205. });
  206. },
  207. });