personal.js 4.6 KB

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