me.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  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/qiehuan_icon.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. console.log(options)
  124. this.setData({ options, isLoaded: 1 })
  125. getWxloginCode(code => {
  126. this.setData({ code })
  127. })
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady: function () {
  133. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  134. for (const i in obj) {
  135. this[i] = obj[i]
  136. }
  137. },
  138. /**
  139. * 生命周期函数--监听页面显示
  140. */
  141. onShow: function () {
  142. // wx.hideHomeButton()
  143. this.getVipList()
  144. this.getCheckRole()
  145. },
  146. /**
  147. * 生命周期函数--监听页面隐藏
  148. */
  149. onHide: function () {
  150. },
  151. /**
  152. * 生命周期函数--监听页面卸载
  153. */
  154. onUnload: function () {
  155. },
  156. /**
  157. * 页面相关事件处理函数--监听用户下拉动作
  158. */
  159. onPullDownRefresh: function () {
  160. },
  161. /**
  162. * 页面上拉触底事件的处理函数
  163. */
  164. onReachBottom: function () {
  165. },
  166. /**
  167. * 选择角色
  168. */
  169. pickerRoleCtl:function(e){
  170. const {value}=e.detail
  171. const {list=[]}=this.data;
  172. if (list[value].type==0){
  173. redirectTo({ url: 'parents/pages/me/me', paras: {} })
  174. }else{
  175. wx.setStorageSync('list', [list[value]])
  176. redirectTo({ url: 'president/pages/home/home', paras: { libId: list[value].libId } })
  177. }
  178. },
  179. /**
  180. * 获取角色列表
  181. */
  182. getCheckRole: function () {
  183. const continuousFn = { fn: this.getCheckRole, param: { ...arguments } }
  184. CheckRole({ continuousFn }).then(res => {
  185. const { list = null } = res.data
  186. const data = (res => {
  187. const arr = []
  188. for (const i in res) {
  189. arr.push(res[i].msg)
  190. }
  191. return arr
  192. })(list)
  193. this.setData({ roleList:data,list })
  194. })
  195. },
  196. /**
  197. * 用户点击右上角分享
  198. */
  199. onShareAppMessage: function () {
  200. if (isFn(sharePage)) return sharePage()
  201. },
  202. /**
  203. * 获取会员卡列表
  204. */
  205. getVipList: function () {
  206. const continuousFn = { fn: this.getVipList, param: { ...arguments } }
  207. const userId = getGlobalVal('userId')
  208. const { options}=this.data
  209. const fn = (i, v) => {
  210. globalData['vip'] = v
  211. wx.setStorageSync(`vip_${userId}`, v)
  212. var obj={"league_name":v.lname,"id":v.lib_id,"type":v.type}
  213. wx.setStorageSync('library', obj)
  214. globalData['vipIndex'] = i
  215. wx.setStorageSync(`vipIndex_${userId}`, i)
  216. globalData['vipId'] = v['vip_id']
  217. wx.setStorageSync(`vipId_${userId}`, v['vip_id'])
  218. }
  219. GetMineInfo({ continuousFn }).then(res => {
  220. const { vipList = null } = res.data
  221. if (vipList.length > 0) {
  222. for (var i in vipList){
  223. if (options.vipId == vipList[i].vip_id){
  224. options.vipIndex = i
  225. getApp().globalData['vipIndex'] = i
  226. wx.setStorageSync(`vipIndex_${userId}`, i)
  227. fn(i, vipList[i])
  228. break
  229. }
  230. }
  231. this.setData({ vipList, options})
  232. } else {
  233. wx.showToast({
  234. title: noVipListToastText,
  235. icon: 'none'
  236. })
  237. }
  238. })
  239. },
  240. /**
  241. * 选择跳转进入页
  242. */
  243. selectRouteCtl: function (e) {
  244. const { index } = e.currentTarget.dataset
  245. const { routerTwo } = this.data
  246. const { url, zindex } = routerTwo[index]
  247. if (index==2){
  248. navigateTo({ url, zindex })
  249. }else{
  250. if (!hasVipService()) return
  251. navigateTo({ url, zindex,isAdd:0 })
  252. }
  253. },
  254. /**
  255. * 显示学员切换框
  256. */
  257. toggleSelectVipCtl: function () {
  258. const { vipList } = this.data.options
  259. // if (!vipList || vipList.length < 2) return
  260. this.setData({ isShowVipModal: !this.data.isShowVipModal })
  261. },
  262. /**
  263. * 添加孩子跳转
  264. */
  265. addchildPage: function () {
  266. const { routerTwo } = this.data
  267. const { url, zindex } = routerTwo[0]
  268. // if (!hasVipService()) return
  269. wx.scanCode({
  270. success: res => {
  271. const webUrl = res.result
  272. const vipId = webUrl.split('_')[1].split('.')[0]
  273. if (!vipId) {
  274. wx.showToast({
  275. title: qrcodeInvalidToastText,
  276. icon: 'none'
  277. })
  278. return
  279. }
  280. // console.log(vipId)
  281. navigateTo({ url, paras: { vipId, zindex: 3, isAdd: 1} })
  282. }
  283. })
  284. //
  285. },
  286. /**
  287. * 学员切换
  288. */
  289. selectVipCtl: function (e) {
  290. const { index } = e.currentTarget.dataset
  291. const { options, vipList} = this.data
  292. const { vipIndex, userId } = options
  293. // if (index == vipIndex) {
  294. // return
  295. // }
  296. const { vip_id } = vipList[index]
  297. if (vip_id) {
  298. options.vip = vipList[index]
  299. getApp().globalData['vip'] = vipList[index]
  300. wx.setStorageSync(`vip_${userId}`, vipList[index])
  301. options.vipIndex = index
  302. getApp().globalData['vipIndex'] = index
  303. wx.setStorageSync(`vipIndex_${userId}`, index)
  304. var obj={"league_name":vipList[index].lname,"id":vipList[index].lib_id,"type":vipList[index].type}
  305. wx.setStorageSync('library', obj)
  306. options.vipId = vip_id
  307. getApp().globalData['vipId'] = vip_id
  308. wx.setStorageSync(`vipId_${userId}`, vip_id)
  309. // wx.removeStorageSync('library')
  310. }
  311. this.setData({ options, isShowVipModal: 0 })
  312. },
  313. /**
  314. * 获取微信用户信息
  315. */
  316. getUserInfoCtl: function (e) {
  317. const { detail } = e
  318. const { userInfo, errMsg = '触发获取微信用户信息失败' } = detail
  319. if (userInfo) {
  320. if (isFn(saveUserInfo)) saveUserInfo(detail, this.data.code)
  321. } else {
  322. wx.showToast({
  323. title: '触发微信授权失败',
  324. icon: 'none'
  325. })
  326. }
  327. }
  328. })