information.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // parents/pages/information/information.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
  3. import { VipInfo, GetpositionArea,UploadFile, ReadingAaveVipInfo } from '../../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, hasLibraryService, hasVipService } = getApp()
  6. const { baseImgUrl, qrcodeInvalidToastText } = globalData
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. baseImgUrl,
  13. isLoaded: 0,
  14. vip: {
  15. imgUrl: '',
  16. childName: '',
  17. sex: '',
  18. grade: '',
  19. school: '',
  20. parentName:'',
  21. phone:'',
  22. parentRole:''
  23. },
  24. user_vipId:"",
  25. gradeArray: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级', '七年级', '八年级', '九年级'],
  26. gradeIndex: 0,
  27. parentRoleArray: ['爸爸', '妈妈','爷爷','奶奶','外公','外婆','其他'],
  28. parentRoleIndex:0,
  29. sexArray: ['男', '女'],
  30. sexIndex: 0,
  31. footerArray: [
  32. {
  33. type: 1,
  34. text: '取消'
  35. },
  36. {
  37. type: 2,
  38. text: '保存'
  39. }
  40. ]
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. const { vip } = this.data
  47. if (options.zindex == 3) {
  48. vip.school = options.name || ''
  49. vip.sex = options.sex || ''
  50. vip.phone = options.phone || ''
  51. vip.parentName = options.parentName || ''
  52. vip.parentRole = options.parentRole || ''
  53. vip.grade = options.grade || ''
  54. vip.childName = options.childName || ''
  55. vip.imgUrl = options.imgUrl || ''
  56. this.setData({ isLoaded: 1 })
  57. }
  58. const user_vipId = wx.getStorageSync("vipId")
  59. this.setData({
  60. user_vipId: user_vipId
  61. });
  62. options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
  63. wx.setNavigationBarTitle({
  64. title: `个人资料`,
  65. })
  66. this.setData({ options, vip })
  67. console.log(vip)
  68. if (options.zindex != 3) {
  69. this.getData(res => {
  70. this.setData({ isLoaded: 1 })
  71. })
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady: function () {
  78. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  79. for (const i in obj) {
  80. this[i] = obj[i]
  81. }
  82. },
  83. /**
  84. * 生命周期函数--监听页面显示
  85. */
  86. onShow: function () {
  87. },
  88. /**
  89. * 生命周期函数--监听页面隐藏
  90. */
  91. onHide: function () {
  92. },
  93. /**
  94. * 生命周期函数--监听页面卸载
  95. */
  96. onUnload: function () {
  97. },
  98. /**
  99. * 页面相关事件处理函数--监听用户下拉动作
  100. */
  101. onPullDownRefresh: function () {
  102. },
  103. /**
  104. * 页面上拉触底事件的处理函数
  105. */
  106. onReachBottom: function () {
  107. },
  108. /**
  109. * 用户点击右上角分享
  110. */
  111. onShareAppMessage: function () {
  112. if (isFn(sharePage)) return sharePage()
  113. },
  114. /**
  115. * 获取个人资料
  116. */
  117. getData: function (cb) {
  118. const continuousFn = { fn: this.getData, param: { ...arguments } }
  119. const { user_vipId } = this.data
  120. VipInfo({ data: { vipId: user_vipId }, continuousFn }).then(res => {
  121. this.setData({ vip: { ...res.data } })
  122. cb && cb(res)
  123. }).catch(res => {
  124. cb && cb(res)
  125. })
  126. },
  127. /**
  128. * 上传头像
  129. */
  130. uploadImgCtl: function () {
  131. const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
  132. wx.chooseImage({
  133. count: 1,
  134. success: res => {
  135. UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
  136. this.setData({ 'vip.imgUrl': res[0] })
  137. })
  138. }
  139. })
  140. },
  141. /**
  142. * 保存输入值
  143. */
  144. inputCtl: function (e) {
  145. const { value } = e.detail
  146. const { type } = e.currentTarget.dataset
  147. const { vip } = this.data
  148. vip[type] = value
  149. this.setData({ vip })
  150. },
  151. /**
  152. * 改变年级
  153. */
  154. pickerGradeCtl: function (e) {
  155. const { value } = e.detail
  156. const { gradeArray, gradeIndex } = this.data
  157. if (value == gradeIndex) {
  158. return
  159. }
  160. this.setData({ 'vip.grade': gradeArray[value], gradeIndex: value })
  161. },
  162. /**
  163. * 改变性别
  164. */
  165. pickerSexCtl: function (e) {
  166. const { value } = e.detail
  167. const { sexArray, sexIndex } = this.data
  168. this.setData({ 'vip.sex': ~~value + 1, sexIndex: value })
  169. },
  170. /**
  171. * 改变角色
  172. */
  173. pickerRoleCtl: function (e) {
  174. console.log(e)
  175. const { value } = e.detail
  176. const { parentRoleArray, parentRoleIndex } = this.data
  177. this.setData({ 'vip.parentRole': parentRoleArray[~~value], parentRoleIndex: value })
  178. console.log(parentRoleArray[~~value])
  179. },
  180. /**
  181. * 提交按钮
  182. */
  183. submitCtl: function (e) {
  184. const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
  185. const { type } = e.currentTarget.dataset
  186. const { user_vipId, options} = this.data
  187. const { vip } = this.data
  188. vip.school = options.name || ''
  189. this.setData({ options, vip })
  190. console.log(vip)
  191. if (type == 1) {
  192. wx.navigateBack({
  193. delta: 1
  194. })
  195. } else if (type == 2) {
  196. if (!vip['childName']) {
  197. wx.showToast({
  198. title: '请填写完姓名',
  199. icon: 'none'
  200. })
  201. return
  202. }
  203. ReadingAaveVipInfo({ data: { ...vip, vipId: user_vipId }, continuousFn }).then(res => {
  204. wx.showToast({
  205. title: '保存成功',
  206. })
  207. setTimeout(() => {
  208. navigateBack()
  209. }, 2000)
  210. })
  211. }
  212. }
  213. })