me.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. // parents/pages/me/me.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { CheckRole } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService, saveUserInfo, getWxloginCode} = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 0,
  14. isShowVipModal: 0,
  15. positionArray: ['馆长', '家长'],
  16. positionIndex: 0,
  17. canIUseGetUserInfo: wx.canIUse('button.open-type.getUserInfo'),
  18. vip: {
  19. position: ''
  20. },
  21. routerOne: [
  22. {
  23. icon: '../../../assets/vip.png',
  24. text: '会员服务',
  25. time: '',
  26. paras: {},
  27. url: '',
  28. zindex: 3
  29. },
  30. ],
  31. routerTwo: [
  32. {
  33. icon: '../../../assets/personal_info.png',
  34. text: '调书申请记录',
  35. time: '',
  36. paras: {
  37. type: 1
  38. },
  39. url: 'president/pages/allocate_books_record/allocate_books_record',
  40. zindex: 3
  41. },
  42. {
  43. icon: '../../../assets/apply_pages.png',
  44. text: '申请新书记录',
  45. time: '',
  46. paras: {},
  47. url: 'president/pages/newbooks_apply_record/newbooks_apply_record',
  48. zindex: 3
  49. },
  50. ],
  51. footerData: {
  52. actIndex: 2,
  53. list: [
  54. {
  55. text: '日常事务',
  56. icon: '../../../assets/lock_gary.png',
  57. actIcon: '../../../assets/lock_blue.png',
  58. url: 'president/pages/home/home',
  59. zindex: 3,
  60. },
  61. {
  62. text: '人员管理',
  63. icon: '../../../assets/people_manager_gary.png',
  64. actIcon: '../../../assets/people_manager_blue.png',
  65. url: 'president/pages/Personnel_management/Personnel_management',
  66. zindex: 3,
  67. },
  68. {
  69. text: '我的',
  70. icon: '../../../assets/me_gray.png',
  71. actIcon: '../../../assets/me_blue.png',
  72. url: 'president/pages/me/me',
  73. zindex: 3,
  74. }
  75. ]
  76. }
  77. },
  78. /**
  79. * 生命周期函数--监听页面加载
  80. */
  81. onLoad: function (options) {
  82. const userId = getGlobalVal('userId')
  83. options.library = getGlobalVal('library')
  84. options.vipList = getGlobalVal('vipList', `vipList_${userId}`)
  85. options.vipIndex = getGlobalVal('vipIndex', `vipIndex_${userId}`)
  86. options.vipId = getGlobalVal('vipId', `vipId_${userId}`)
  87. options.vip = getGlobalVal('vip', `vip_${userId}`)
  88. options.userId = userId
  89. options.userInfo = getGlobalVal('userInfo')
  90. options.list = getGlobalVal('list')
  91. console.log(options)
  92. this.setData({ options, isLoaded: 1 })
  93. getWxloginCode(code => {
  94. this.setData({ code })
  95. })
  96. },
  97. /**
  98. * 生命周期函数--监听页面初次渲染完成
  99. */
  100. onReady: function () {
  101. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  102. for (const i in obj) {
  103. this[i] = obj[i]
  104. }
  105. },
  106. /**
  107. * 生命周期函数--监听页面显示
  108. */
  109. onShow: function () {
  110. },
  111. testclick: function () {
  112. navigateTo({
  113. url: 'president/pages/newbooks_apply_record/newbooks_apply_record?id=113f76b8-8d84-4b18-b882-c4098d515067',
  114. })
  115. },
  116. /**
  117. * 生命周期函数--监听页面隐藏
  118. */
  119. onHide: function () {
  120. },
  121. /**
  122. * 生命周期函数--监听页面卸载
  123. */
  124. onUnload: function () {
  125. },
  126. /**
  127. * 页面相关事件处理函数--监听用户下拉动作
  128. */
  129. onPullDownRefresh: function () {
  130. },
  131. /**
  132. * 页面上拉触底事件的处理函数
  133. */
  134. onReachBottom: function () {
  135. },
  136. /**
  137. * 用户点击右上角分享
  138. */
  139. onShareAppMessage: function () {
  140. if (isFn(sharePage)) return sharePage()
  141. },
  142. /**
  143. * 选择跳转进入页
  144. */
  145. selectRouteCtl: function (e) {
  146. const { index } = e.currentTarget.dataset
  147. const { routerTwo } = this.data
  148. const { url, zindex } = routerTwo[index]
  149. // if (index==2){
  150. navigateTo({ url, zindex })
  151. // }else{
  152. // if (!hasVipService()) return
  153. // navigateTo({ url, zindex })
  154. // }
  155. },
  156. /**
  157. * 身份切换
  158. */
  159. pickerpositionCtl: function (e) {
  160. const { value } = e.detail
  161. const { positionArray, positionIndex } = this.data
  162. this.setData({ 'vip.position': ~~value + 1, positionIndex: value })
  163. if (value ==0) {
  164. wx.showToast({
  165. title: '您目前的身份已经是馆长啦',
  166. icon: 'none'
  167. })
  168. return
  169. }
  170. else{
  171. this.toggleSubmit()
  172. }
  173. },
  174. /**
  175. * 身份切换家长
  176. */
  177. toggleSubmit: function () {
  178. const continuousFn = { fn: this.delCtl, param: { ...arguments } }
  179. CheckRole({ data: { }, continuousFn }).then(res => {
  180. wx.showToast({
  181. title: res.msg
  182. })
  183. if (res.code ==999){
  184. redirectTo({ url: 'parents/pages/main/main', paras: { isDirector: 1 } })
  185. }
  186. })
  187. },
  188. /**
  189. * 显示学员切换框
  190. */
  191. toggleSelectVipCtl: function () {
  192. const { vipList } = this.data.options
  193. // if (!vipList || vipList.length < 2) return
  194. this.setData({ isShowVipModal: !this.data.isShowVipModal })
  195. },
  196. /**
  197. * 添加孩子跳转
  198. */
  199. addchildPage: function () {
  200. const { routerTwo } = this.data
  201. const { url, zindex } = routerTwo[0]
  202. if (!hasVipService()) return
  203. navigateTo({ url, zindex })
  204. },
  205. /**
  206. * 学员切换
  207. */
  208. selectVipCtl: function (e) {
  209. const { index } = e.currentTarget.dataset
  210. const { options } = this.data
  211. const { vipIndex, vipList, userId } = options
  212. if (index == vipIndex) {
  213. return
  214. }
  215. const { vip_id } = vipList[index]
  216. if (vip_id) {
  217. options.vip = vipList[index]
  218. getApp().globalData['vip'] = vipList[index]
  219. wx.setStorageSync(`vip_${userId}`, vipList[index])
  220. options.vipIndex = index
  221. getApp().globalData['vipIndex'] = index
  222. wx.setStorageSync(`vipIndex_${userId}`, index)
  223. options.vipId = vip_id
  224. getApp().globalData['vipId'] = vip_id
  225. wx.setStorageSync(`vipId_${userId}`, vip_id)
  226. wx.removeStorageSync('library')
  227. }
  228. this.setData({ options, isShowVipModal: 0 })
  229. },
  230. /**
  231. * 获取微信用户信息
  232. */
  233. getUserInfoCtl: function (e) {
  234. const { detail } = e
  235. const { userInfo, errMsg = '触发获取微信用户信息失败' } = detail
  236. if (userInfo) {
  237. if (isFn(saveUserInfo)) saveUserInfo(detail, this.data.code)
  238. } else {
  239. wx.showToast({
  240. title: '触发微信授权失败',
  241. icon: 'none'
  242. })
  243. }
  244. }
  245. })