me.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. // parents/pages/me/me.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { GetMineInfo, CheckRole} from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService, saveUserInfo, getWxloginCode} = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText, isIphoneX, noVipListToastText} = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 0,
  14. isShowVipModal: 0,
  15. canIUseGetUserInfo: wx.canIUse('button.open-type.getUserInfo'),
  16. routerOne: [
  17. {
  18. icon: '../../../assets/vip.png',
  19. text: '会员服务',
  20. time: '',
  21. paras: {},
  22. url: '',
  23. zindex: 3
  24. },
  25. ],
  26. routerTwo: [
  27. {
  28. icon: '../../../assets/personal_info.png',
  29. text: '个人资料',
  30. time: '',
  31. paras: {
  32. type: 1
  33. },
  34. url: 'parents/pages/information/information',
  35. zindex: 3
  36. },
  37. {
  38. icon: '../../../assets/apply_pages.png',
  39. text: '申请书单记录',
  40. time: '',
  41. paras: {},
  42. url: 'parents/pages/apply_bookLists/apply_bookLists',
  43. zindex: 3
  44. },
  45. // {
  46. // icon: '../../../assets/qie_huan_jue_se.png',
  47. // text: '角色切换',
  48. // time: '',
  49. // paras: {},
  50. // url: '',
  51. // zindex: 3
  52. // },
  53. // {
  54. // icon: '../../../assets/problem_icon.png',
  55. // text: '常见问题',
  56. // time: '',
  57. // paras: {},
  58. // url: 'pages/question/question',
  59. // zindex: 3
  60. // },
  61. // {
  62. // icon: '../../../assets/aijia_icon.png',
  63. // text: '关于私塾家',
  64. // time: '',
  65. // paras: {},
  66. // url: 'pages/about_aijia/about_aijia',
  67. // zindex: 3
  68. // },
  69. ],
  70. routerThree: [
  71. {
  72. icon: '../../../assets/aijia_icon.png',
  73. text: '关于私塾家',
  74. time: '',
  75. paras: {
  76. type: 1
  77. },
  78. url: 'pages/about_aijia/about_aijia',
  79. zindex: 3
  80. },
  81. ],
  82. roleList: [],
  83. footerData: {
  84. isIphoneX,
  85. actIndex: 2,
  86. list: [
  87. {
  88. text: '找好书',
  89. icon: '../../../assets/book_gray.png',
  90. actIcon: '../../../assets/book_blue.png',
  91. url: 'parents/pages/main/main',
  92. zindex: 3,
  93. },
  94. {
  95. text: '好书推荐',
  96. icon: '../../../assets/wish_gray.png',
  97. actIcon: '../../../assets/wish_blue.png',
  98. url: 'parents/pages/growth_track/growth_track',
  99. zindex: 3,
  100. },
  101. {
  102. text: '我的',
  103. icon: '../../../assets/me_gray.png',
  104. actIcon: '../../../assets/me_blue.png',
  105. url: 'parents/pages/me/me',
  106. zindex: 3,
  107. }
  108. ]
  109. }
  110. },
  111. /**
  112. * 生命周期函数--监听页面加载
  113. */
  114. onLoad: function (options) {
  115. const userId = getGlobalVal('userId')
  116. options.library = getGlobalVal('library')
  117. options.vipList = getGlobalVal('vipList', `vipList_${userId}`)
  118. options.vipIndex = getGlobalVal('vipIndex', `vipIndex_${userId}`)
  119. options.vipId = getGlobalVal('vipId', `vipId_${userId}`)
  120. options.vip = getGlobalVal('vip', `vip_${userId}`)
  121. options.userId = userId
  122. options.userInfo = getGlobalVal('userInfo')
  123. this.setData({ options, isLoaded: 1 })
  124. getWxloginCode(code => {
  125. this.setData({ code })
  126. })
  127. },
  128. /**
  129. * 生命周期函数--监听页面初次渲染完成
  130. */
  131. onReady: function () {
  132. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  133. for (const i in obj) {
  134. this[i] = obj[i]
  135. }
  136. },
  137. /**
  138. * 生命周期函数--监听页面显示
  139. */
  140. onShow: function () {
  141. this.getVipList()
  142. this.getCheckRole()
  143. },
  144. /**
  145. * 生命周期函数--监听页面隐藏
  146. */
  147. onHide: function () {
  148. },
  149. /**
  150. * 生命周期函数--监听页面卸载
  151. */
  152. onUnload: function () {
  153. },
  154. /**
  155. * 页面相关事件处理函数--监听用户下拉动作
  156. */
  157. onPullDownRefresh: function () {
  158. },
  159. /**
  160. * 页面上拉触底事件的处理函数
  161. */
  162. onReachBottom: function () {
  163. },
  164. /**
  165. * 选择角色
  166. */
  167. pickerRoleCtl:function(e){
  168. const {value}=e.detail
  169. const {list=[]}=this.data;
  170. if (list[value].type==0){
  171. wx.setStorageSync('library', { id: list[value].libId, league_name: list[value].libName})
  172. redirectTo({ url: 'parents/pages/main/main', paras: { libId:list[value].libId } })
  173. }else{
  174. wx.setStorageSync('list', [list[value]])
  175. redirectTo({ url: 'president/pages/home/home', paras: { libId: list[value].libId } })
  176. }
  177. },
  178. /**
  179. * 获取角色列表
  180. */
  181. getCheckRole: function () {
  182. const continuousFn = { fn: this.getCheckRole, param: { ...arguments } }
  183. CheckRole({ continuousFn }).then(res => {
  184. const { list = null } = res.data
  185. const data = (res => {
  186. const arr = []
  187. for (const i in res) {
  188. arr.push(res[i].msg)
  189. }
  190. return arr
  191. })(list)
  192. this.setData({ roleList:data,list })
  193. })
  194. },
  195. /**
  196. * 用户点击右上角分享
  197. */
  198. onShareAppMessage: function () {
  199. if (isFn(sharePage)) return sharePage()
  200. },
  201. /**
  202. * 获取会员卡列表
  203. */
  204. getVipList: function () {
  205. const continuousFn = { fn: this.getVipList, param: { ...arguments } }
  206. const userId = getGlobalVal('userId')
  207. const { options}=this.data
  208. GetMineInfo({ continuousFn }).then(res => {
  209. const { vipList = null } = res.data
  210. if (vipList.length > 0) {
  211. for (var i in vipList){
  212. if (options.vipId == vipList[i].vip_id){
  213. options.vipIndex = i
  214. getApp().globalData['vipIndex'] = i
  215. wx.setStorageSync(`vipIndex_${userId}`, i)
  216. }
  217. }
  218. this.setData({ vipList, options})
  219. } else {
  220. wx.showToast({
  221. title: noVipListToastText,
  222. icon: 'none'
  223. })
  224. }
  225. })
  226. },
  227. /**
  228. * 选择跳转进入页
  229. */
  230. selectRouteCtl: function (e) {
  231. const { index } = e.currentTarget.dataset
  232. const { routerTwo } = this.data
  233. const { url, zindex } = routerTwo[index]
  234. if (index==2){
  235. navigateTo({ url, zindex })
  236. }else{
  237. if (!hasVipService()) return
  238. navigateTo({ url, zindex })
  239. }
  240. },
  241. /**
  242. * 显示学员切换框
  243. */
  244. toggleSelectVipCtl: function () {
  245. const { vipList } = this.data.options
  246. // if (!vipList || vipList.length < 2) return
  247. this.setData({ isShowVipModal: !this.data.isShowVipModal })
  248. },
  249. /**
  250. * 添加孩子跳转
  251. */
  252. addchildPage: function () {
  253. const { routerTwo } = this.data
  254. const { url, zindex } = routerTwo[0]
  255. if (!hasVipService()) return
  256. wx.scanCode({
  257. success: res => {
  258. const webUrl = res.result
  259. const vipId = webUrl.split('_')[1].split('.')[0]
  260. if (!vipId) {
  261. wx.showToast({
  262. title: qrcodeInvalidToastText,
  263. icon: 'none'
  264. })
  265. return
  266. }
  267. // console.log(vipId)
  268. navigateTo({ url, paras: { vipId, zindex: 3} })
  269. }
  270. })
  271. //
  272. },
  273. /**
  274. * 学员切换
  275. */
  276. selectVipCtl: function (e) {
  277. const { index } = e.currentTarget.dataset
  278. const { options, vipList} = this.data
  279. const { vipIndex, userId } = options
  280. if (index == vipIndex) {
  281. return
  282. }
  283. const { vip_id } = vipList[index]
  284. if (vip_id) {
  285. options.vip = vipList[index]
  286. getApp().globalData['vip'] = vipList[index]
  287. wx.setStorageSync(`vip_${userId}`, vipList[index])
  288. options.vipIndex = index
  289. getApp().globalData['vipIndex'] = index
  290. wx.setStorageSync(`vipIndex_${userId}`, index)
  291. options.vipId = vip_id
  292. getApp().globalData['vipId'] = vip_id
  293. wx.setStorageSync(`vipId_${userId}`, vip_id)
  294. wx.removeStorageSync('library')
  295. }
  296. this.setData({ options, isShowVipModal: 0 })
  297. },
  298. /**
  299. * 获取微信用户信息
  300. */
  301. getUserInfoCtl: function (e) {
  302. const { detail } = e
  303. const { userInfo, errMsg = '触发获取微信用户信息失败' } = detail
  304. if (userInfo) {
  305. if (isFn(saveUserInfo)) saveUserInfo(detail, this.data.code)
  306. } else {
  307. wx.showToast({
  308. title: '触发微信授权失败',
  309. icon: 'none'
  310. })
  311. }
  312. }
  313. })