personal.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. hasUserInfo:false
  19. },
  20. onChooseAvatar(e) {
  21. console.log(e.detail)
  22. this.setData({
  23. avatarUrl: e.detail.avatarUrl
  24. })
  25. },
  26. /**
  27. * 生命周期函数--监听页面加载
  28. */
  29. onLoad: function (options) {
  30. },
  31. getCountNum: async function(){
  32. /**
  33. * 福利社
  34. */
  35. let resBuy = await WelfareMall.getUserCouponSnNum({
  36. mobile: getMobileCache(),
  37. });
  38. return Number(resBuy.data.num)
  39. },
  40. // 授权手机号
  41. getPhoneNumber(e) {
  42. getPhoneNumberSync(e, async () => {
  43. let nums = await this.getCountNum();
  44. this.setData({
  45. isLogin: true,
  46. mobileTop: getMobileCache(),
  47. countNum: nums,
  48. })
  49. })
  50. },
  51. // 授权手机号--跳转导航栏
  52. getPhoneNav(e) {
  53. getPhoneNumberSync(e, async () => {
  54. let nums = await this.getCountNum();
  55. this.setData({
  56. isLogin: true,
  57. mobileTop: getMobileCache(),
  58. countNum: nums,
  59. });
  60. this.goToCoupon(e);
  61. })
  62. },
  63. // 授权手机号--跳转导航栏
  64. getPathCoupon(e) {
  65. console.log(e)
  66. getPhoneNumberSync(e, async () => {
  67. let nums = await this.getCountNum();
  68. console.log(nums)
  69. this.setData({
  70. isLogin: true,
  71. mobileTop: getMobileCache(),
  72. countNum: nums,
  73. });
  74. this.getCouponPath(e);
  75. })
  76. },
  77. // 员工通道
  78. getStaff(e) {
  79. console.log(e)
  80. getPhoneNumberSync(e, async () => {
  81. let nums = await this.getCountNum();
  82. console.log(nums)
  83. this.setData({
  84. isLogin: true,
  85. mobileTop: getMobileCache(),
  86. countNum: nums,
  87. });
  88. this.toStaff(e);
  89. })
  90. },
  91. // 动态获取导航栏
  92. async getIndexList(){
  93. let res = await WelfareMall.getPersonalData();
  94. await this.getPath(res.data.navigationList);
  95. this.setData({
  96. navigationList:res.data.navigationList,
  97. })
  98. },
  99. // 导航栏地址链接跳转
  100. goToCoupon:function(e){
  101. var appId = e.currentTarget.dataset.appid;
  102. var path = e.currentTarget.dataset.path;
  103. if(appId && path){
  104. wx.navigateToMiniProgram({
  105. appId: appId,
  106. path: path,
  107. success(res) {
  108. // 打开成功
  109. }
  110. })
  111. }
  112. if(!appId && path){
  113. wx.navigateTo({
  114. url: path,
  115. })
  116. }
  117. },
  118. /**
  119. * 活动列表我的券包路径
  120. * @param {*} nums
  121. */
  122. getPath: async function(res){
  123. if(res != null && res.length > 0){
  124. for(var i = 0;i<res.length;i++){
  125. if("/pages/welfareMall/coupon/coupon" == res[i].path){
  126. this.setData({
  127. couponPath: true,
  128. })
  129. return;
  130. }
  131. }
  132. }
  133. },
  134. /**
  135. * 生命周期函数--监听页面初次渲染完成
  136. */
  137. onReady: function () {
  138. },
  139. /**
  140. * 生命周期函数--监听页面显示
  141. */
  142. onShow: async function () {
  143. this.setData({
  144. grayTheme: app.globalData.grayTheme
  145. })
  146. this.getIndexList();
  147. let userMobile = await activity.getMobileCache();
  148. if (userMobile.length !== 0) {
  149. this.setData({
  150. isLogin: true,
  151. mobileTop: userMobile,
  152. })
  153. }
  154. var userInfo = wx.getStorageSync("userInfo");
  155. if (userInfo.avatarUrl && userInfo.nickName) {
  156. this.setData({
  157. userInfo: userInfo,
  158. hasUserInfo:true
  159. })
  160. }
  161. if(this.data.isLogin){
  162. let nums = await this.getCountNum();
  163. this.setData({
  164. countNum: nums,
  165. })
  166. }
  167. },
  168. getCouponPath(e) {
  169. const url = "/pages/welfareMall/coupon/coupon"
  170. wx.navigateTo({
  171. url
  172. })
  173. },
  174. toStaff(e) {
  175. const url = "/pages/welfareMall/staff/distinguish"
  176. wx.navigateTo({
  177. url
  178. })
  179. },
  180. logout(){
  181. wx.removeStorageSync('userInfo');
  182. this.setData({
  183. isLogin:false,
  184. countNum:0,
  185. hasUserInfo:false
  186. })
  187. },
  188. getUserProfile: function(e){
  189. wx.getUserProfile({
  190. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  191. success: (res) => {
  192. console.log(res);
  193. var openId = wx.getStorageSync('loginInfo').openId;
  194. var mobile = getMobileCache();
  195. if(openId && mobile){
  196. activity.saveUser(openId,mobile,res.userInfo.avatarUrl,res.userInfo.nickName);
  197. var userInfo = {
  198. mobile:mobile,
  199. avatarUrl:res.userInfo.avatarUrl,
  200. nickName:res.userInfo.nickName,
  201. }
  202. wx.setStorageSync('userInfo',userInfo);
  203. }
  204. this.setData({
  205. userInfo: res.userInfo,
  206. hasUserInfo: true
  207. })
  208. // this.userRecruitInfo(res.userInfo.openId)
  209. }
  210. })
  211. },
  212. handlePageSizes(e) {
  213. this.setData({
  214. bodyImageHeight: e.detail.bodyImageHeight
  215. })
  216. },
  217. /**
  218. * 生命周期函数--监听页面隐藏
  219. */
  220. onHide: function () {
  221. },
  222. /**
  223. * 生命周期函数--监听页面卸载
  224. */
  225. onUnload: function () {
  226. },
  227. /**
  228. * 页面相关事件处理函数--监听用户下拉动作
  229. */
  230. onPullDownRefresh: function () {
  231. },
  232. /**
  233. * 页面上拉触底事件的处理函数
  234. */
  235. onReachBottom: function () {
  236. },
  237. /**
  238. * 用户点击右上角分享
  239. */
  240. onShareAppMessage: function () {
  241. }
  242. })