index.js 4.5 KB

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