personal.js 6.0 KB

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