childList.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. // pages/childList/childList.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. thumbnail: app.globalData.thumbnail,
  9. baseImgUrl: app.globalData.baseImgUrl,
  10. hiddenModel: false,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: function (options) {
  16. this.setData(options);
  17. console.log(options)
  18. if (!options.vipId) {
  19. const userId = app.globalData.userId || wx.getStorageSync('userId')
  20. const vipId = app.globalData.parentVipId || wx.getStorageSync(`parentVipId-${userId}`)
  21. options.vipId = vipId
  22. options.userId = userId
  23. this.setData(options);
  24. }
  25. },
  26. /**
  27. * 生命周期函数--监听页面初次渲染完成
  28. */
  29. onReady: function () {
  30. },
  31. /**
  32. * 生命周期函数--监听页面显示
  33. */
  34. onShow: function () {
  35. this.getChildInfo();
  36. },
  37. /**
  38. * 生命周期函数--监听页面隐藏
  39. */
  40. onHide: function () {
  41. },
  42. /**
  43. * 生命周期函数--监听页面卸载
  44. */
  45. onUnload: function () {
  46. },
  47. /**
  48. * 页面相关事件处理函数--监听用户下拉动作
  49. */
  50. onPullDownRefresh: function () {
  51. },
  52. /**
  53. * 页面上拉触底事件的处理函数
  54. */
  55. onReachBottom: function () {
  56. },
  57. /**
  58. * 用户点击右上角分享
  59. */
  60. onShareAppMessage: function () {
  61. },
  62. /**
  63. * 用户点击右上角分享
  64. */
  65. onShareAppMessage: function () {
  66. },
  67. /**
  68. * 底部导航跳转
  69. */
  70. redirectCtl: app.redirectCtl,
  71. /**
  72. * 路由跳转
  73. */
  74. // navigateCtl: app.navigateCtl,
  75. navigateCtl: function (e) {
  76. const { add } = e.currentTarget.dataset
  77. console.log(e)
  78. if (add==1) {
  79. wx.removeStorageSync('list')
  80. app.navigateCtl(e);
  81. }else{
  82. app.navigateCtl(e);
  83. }
  84. },
  85. /**
  86. * 我的信息
  87. */
  88. getMyInfo: function () {
  89. const userId = app.globalData.userId || wx.getStorageSync('userId')
  90. if (userId) {
  91. console.log('123')
  92. const parentInfo = app.globalData.parentInfo || wx.getStorageSync(`parentInfo-${userId}`)
  93. const parentVipList = wx.getStorageSync(`parentVipList-${userId}`) || []
  94. const parentVipLiIdx = app.globalData.parentVipLiIdx || wx.getStorageSync(`parentVipLiIdx-${userId}`) || 0
  95. const parentVipId = app.globalData.parentVipId || wx.getStorageSync(`parentVipId-${userId}`) || ''
  96. const parentImg = parentInfo.imgUrl || '';
  97. const { imgUrl } = parentVipList[parentVipLiIdx] ? parentVipList[parentVipLiIdx] : { imgUrl: '' };
  98. this.setData({ userId, parentInfo, parentVipList, parentVipLiIdx, parentVipId, parentImg, childImg: imgUrl })
  99. // console.log(parentVipList);
  100. }
  101. },
  102. // 获取孩子信息
  103. getChildInfo:function(){
  104. wx.showLoading({
  105. title: '加载中',
  106. })
  107. const { userId}=this.data;
  108. if (userId) {
  109. const parentVipLiIdx = app.globalData.parentVipLiIdx || wx.getStorageSync(`parentVipLiIdx-${userId}`) || 0;
  110. this.setData({ parentVipLiIdx })
  111. }
  112. const postData = { fn: this.getChildInfo, param: { ...arguments } }
  113. app.post('/api/parents/parents/V2/getMyInfo', {}, 0, postData).then(res => {
  114. wx.hideLoading();
  115. const { childList}=res.data;
  116. this.setData({ parentVipList: childList})
  117. })
  118. },
  119. /**
  120. * 提示框隐藏
  121. */
  122. allShowModel: function () {
  123. this.setData({ hiddenModel: false })
  124. },
  125. /**
  126. * 切换孩子信息
  127. */
  128. modalInfo: function (e) {
  129. const { index } = e.currentTarget.dataset;
  130. this.setData({ hiddenModel: true, childIndex: index })
  131. },
  132. checkActChildCtl: function (res) {
  133. const { childIndex } = this.data;
  134. const { parentVipLiIdx, parentVipList, userId } = this.data;
  135. this.setData({
  136. parentVipLiIdx: childIndex,
  137. parentVipId: parentVipList[childIndex]['vipId'],
  138. hiddenModel: false
  139. })
  140. getApp().globalData.parentVipLiIdx = childIndex
  141. getApp().globalData.parentVipId = parentVipList[childIndex]['vipId']
  142. wx.setStorageSync(`parentVipLiIdx-${userId}`, childIndex)
  143. wx.setStorageSync(`parentVipId-${userId}`, parentVipList[childIndex]['vipId'])
  144. this.setData({ pageNo: 1 })
  145. // this.getChildInfo();
  146. },
  147. })