personal.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. // pages/welfareMall/personal/personal.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import activity from '../../../api/activity'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. const app = getApp();
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. isLogin: false,
  12. mobileTop: 'TONY WU',
  13. countNum: 0,
  14. grayTheme:false,
  15. navigationList:[],
  16. couponPath: false,
  17. },
  18. /**
  19. * 生命周期函数--监听页面加载
  20. */
  21. onLoad: function (options) {
  22. },
  23. getCountNum: async function(){
  24. /**
  25. * 福利社
  26. */
  27. let resBuy = await WelfareMall.getUserCouponSnNum({
  28. mobile: getMobileCache(),
  29. });
  30. return Number(resBuy.data.num)
  31. },
  32. // 授权手机号
  33. getPhoneNumber(e) {
  34. getPhoneNumberSync(e, async () => {
  35. let nums = await this.getCountNum();
  36. this.setData({
  37. isLogin: true,
  38. mobileTop: getMobileCache(),
  39. countNum: nums,
  40. })
  41. })
  42. },
  43. // 授权手机号--跳转导航栏
  44. getPhoneNav(e) {
  45. getPhoneNumberSync(e, async () => {
  46. let nums = await this.getCountNum();
  47. this.setData({
  48. isLogin: true,
  49. mobileTop: getMobileCache(),
  50. countNum: nums,
  51. });
  52. this.goToCoupon(e);
  53. })
  54. },
  55. // 授权手机号--跳转导航栏
  56. getPathCoupon(e) {
  57. console.log(e)
  58. getPhoneNumberSync(e, async () => {
  59. let nums = await this.getCountNum();
  60. console.log(nums)
  61. this.setData({
  62. isLogin: true,
  63. mobileTop: getMobileCache(),
  64. countNum: nums,
  65. });
  66. this.getCouponPath(e);
  67. })
  68. },
  69. // 员工通道
  70. getStaff(e) {
  71. console.log(e)
  72. getPhoneNumberSync(e, async () => {
  73. let nums = await this.getCountNum();
  74. console.log(nums)
  75. this.setData({
  76. isLogin: true,
  77. mobileTop: getMobileCache(),
  78. countNum: nums,
  79. });
  80. this.toStaff(e);
  81. })
  82. },
  83. // 动态获取导航栏
  84. async getIndexList(){
  85. let res = await WelfareMall.getPersonalData();
  86. await this.getPath(res.data.navigationList);
  87. this.setData({
  88. navigationList:res.data.navigationList,
  89. })
  90. },
  91. // 导航栏地址链接跳转
  92. goToCoupon:function(e){
  93. var appId = e.currentTarget.dataset.appid;
  94. var path = e.currentTarget.dataset.path;
  95. if(appId && path){
  96. wx.navigateToMiniProgram({
  97. appId: appId,
  98. path: path,
  99. success(res) {
  100. // 打开成功
  101. }
  102. })
  103. }
  104. if(!appId && path){
  105. wx.navigateTo({
  106. url: path,
  107. })
  108. }
  109. },
  110. /**
  111. * 活动列表我的券包路径
  112. * @param {*} nums
  113. */
  114. getPath: async function(res){
  115. if(res != null && res.length > 0){
  116. for(var i = 0;i<res.length;i++){
  117. if("/pages/welfareMall/coupon/coupon" == res[i].path){
  118. this.setData({
  119. couponPath: true,
  120. })
  121. return;
  122. }
  123. }
  124. }
  125. },
  126. /**
  127. * 生命周期函数--监听页面初次渲染完成
  128. */
  129. onReady: function () {
  130. },
  131. /**
  132. * 生命周期函数--监听页面显示
  133. */
  134. onShow: async function () {
  135. this.setData({
  136. grayTheme: app.globalData.grayTheme
  137. })
  138. this.getIndexList();
  139. let userMobile = await activity.getMobileCache();
  140. // console.log(userMobile)
  141. if (userMobile.length !== 0) {
  142. this.setData({
  143. isLogin: true,
  144. mobileTop: userMobile,
  145. })
  146. }
  147. if(this.data.isLogin){
  148. let nums = await this.getCountNum();
  149. this.setData({
  150. countNum: nums,
  151. })
  152. }
  153. },
  154. getCouponPath(e) {
  155. const url = "/pages/welfareMall/coupon/coupon"
  156. wx.navigateTo({
  157. url
  158. })
  159. },
  160. toStaff(e) {
  161. const url = "/pages/welfareMall/staff/distinguish"
  162. wx.navigateTo({
  163. url
  164. })
  165. },
  166. logout(){
  167. wx.removeStorageSync('userInfo');
  168. this.setData({
  169. isLogin:false,
  170. countNum:0
  171. })
  172. },
  173. /**
  174. * 生命周期函数--监听页面隐藏
  175. */
  176. onHide: function () {
  177. },
  178. /**
  179. * 生命周期函数--监听页面卸载
  180. */
  181. onUnload: function () {
  182. },
  183. /**
  184. * 页面相关事件处理函数--监听用户下拉动作
  185. */
  186. onPullDownRefresh: function () {
  187. },
  188. /**
  189. * 页面上拉触底事件的处理函数
  190. */
  191. onReachBottom: function () {
  192. },
  193. /**
  194. * 用户点击右上角分享
  195. */
  196. onShareAppMessage: function () {
  197. }
  198. })