personal.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. async getIndexList(){
  71. let res = await WelfareMall.getPersonalData();
  72. await this.getPath(res.data.navigationList);
  73. this.setData({
  74. navigationList:res.data.navigationList,
  75. })
  76. },
  77. // 导航栏地址链接跳转
  78. goToCoupon:function(e){
  79. var appId = e.currentTarget.dataset.appid;
  80. var path = e.currentTarget.dataset.path;
  81. if(appId && path){
  82. wx.navigateToMiniProgram({
  83. appId: appId,
  84. path: path,
  85. success(res) {
  86. // 打开成功
  87. }
  88. })
  89. }
  90. if(!appId && path){
  91. wx.navigateTo({
  92. url: path,
  93. })
  94. }
  95. },
  96. /**
  97. * 活动列表我的券包路径
  98. * @param {*} nums
  99. */
  100. getPath: async function(res){
  101. if(res != null && res.length > 0){
  102. for(var i = 0;i<res.length;i++){
  103. if("/pages/welfareMall/coupon/coupon" == res[i].path){
  104. this.setData({
  105. couponPath: true,
  106. })
  107. return;
  108. }
  109. }
  110. }
  111. },
  112. /**
  113. * 生命周期函数--监听页面初次渲染完成
  114. */
  115. onReady: function () {
  116. },
  117. /**
  118. * 生命周期函数--监听页面显示
  119. */
  120. onShow: async function () {
  121. this.setData({
  122. grayTheme: app.globalData.grayTheme
  123. })
  124. this.getIndexList();
  125. let userMobile = await activity.getMobileCache();
  126. // console.log(userMobile)
  127. if (userMobile.length !== 0) {
  128. this.setData({
  129. isLogin: true,
  130. mobileTop: userMobile,
  131. })
  132. }
  133. if(this.data.isLogin){
  134. let nums = await this.getCountNum();
  135. this.setData({
  136. countNum: nums,
  137. })
  138. }
  139. },
  140. getCouponPath(e) {
  141. const url = "/pages/welfareMall/coupon/coupon"
  142. wx.navigateTo({
  143. url
  144. })
  145. },
  146. toStaff(e) {
  147. const url = "/pages/welfareMall/staff/distinguish"
  148. wx.navigateTo({
  149. url
  150. })
  151. },
  152. /**
  153. * 生命周期函数--监听页面隐藏
  154. */
  155. onHide: function () {
  156. },
  157. /**
  158. * 生命周期函数--监听页面卸载
  159. */
  160. onUnload: function () {
  161. },
  162. /**
  163. * 页面相关事件处理函数--监听用户下拉动作
  164. */
  165. onPullDownRefresh: function () {
  166. },
  167. /**
  168. * 页面上拉触底事件的处理函数
  169. */
  170. onReachBottom: function () {
  171. },
  172. /**
  173. * 用户点击右上角分享
  174. */
  175. onShareAppMessage: function () {
  176. }
  177. })