personal.js 6.0 KB

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