123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260 |
- // parents/pages/information/information.js
- import { routers, viewImage, sharePage, isFn, getGlobalVal } from '../../../utils/util.js'
- import { GetVipInfo, UploadFile, SaveVipInfo, GetMineInfo } from '../../../utils/api.js'
- const { navigateTo, redirectTo, navigateBack } = routers()
- const { globalData, hasLibraryService, hasVipService } = getApp()
- const { baseImgUrl, qrcodeInvalidToastText, noVipListToastText} = globalData
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- baseImgUrl,
- isLoaded: 0,
- vip: {
- imgUrl: '',
- childName: '',
- sex: '',
- grade: '',
- school: '',
- parentName: '',
- phone: '',
- parentRole: '',
- libId:'',
- league_name:''
- },
- isSchool:false,
- gradeArray: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级', '七年级', '八年级', '九年级'],
- gradeIndex: 0,
- sexArray: ['男', '女'],
- sexIndex: 0,
- parentRoleArray: ['爸爸', '妈妈', '爷爷', '奶奶', '外公', '外婆', '其他'],
- parentRoleIndex: 0,
- footerArray: [
- {
- type: 1,
- text: '取消'
- },
- {
- type: 2,
- text: '保存'
- }
- ]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- if (options.zindex!=3){
- options.vipId = getGlobalVal('vipId', `vipId_${getGlobalVal('userId')}`) || ''
- }
- const {vip}=this.data
- vip.school = options.school || ''
- vip.sex = options.sex || ''
- vip.phone = options.phone || ''
- vip.parentName = options.parentName || ''
- vip.parentRole = options.parentRole || ''
- vip.grade = options.grade || ''
- vip.childName = options.childName || ''
- vip.imgUrl = options.imgUrl || ''
- vip.vipId = options.vipId
- vip.libId = options.libId
- vip.league_name = options.league_name
- // console.log(vip)
- this.setData({ options, vip, isLoaded: 1})
- if (!options.isSchool){
- this.getData()
- }
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- const obj = { navigateTo, redirectTo, navigateBack, viewImage }
- for (const i in obj) {
- this[i] = obj[i]
- }
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- if (isFn(sharePage)) return sharePage()
- },
- /**
- * 获取个人资料
- */
- getData: function (cb) {
- const continuousFn = { fn: this.getData, param: { ...arguments } }
- if (!hasVipService()) {
- cb && cb()
- return
- }
- const { vipId } = this.data.options
- GetVipInfo({ data: { vipId }, continuousFn }).then(res => {
- this.setData({ vip: { ...res.data } })
- cb && cb(res)
- }).catch(res => {
- cb && cb(res)
- })
- },
- /**
- * 上传头像
- */
- uploadImgCtl: function () {
- const continuousFn = { fn: this.uploadImgCtl, param: { ...arguments } }
- const {vip}=this.data;
- wx.chooseImage({
- count: 1,
- success: res => {
- UploadFile({ file: res.tempFilePaths, continuousFn }).then(res => {
- vip.imgUrl = res[0]
- this.setData({ vip})
- })
- }
- })
- },
- /**
- * 保存输入值
- */
- inputCtl: function (e) {
- const { value } = e.detail
- const { type } = e.currentTarget.dataset
- const { vip } = this.data
- vip[type] = value
- this.setData({ vip })
- },
- /**
- * 改变年级
- */
- pickerGradeCtl: function (e) {
- const { value } = e.detail
- const { gradeArray, gradeIndex,vip } = this.data
- // if (value == gradeIndex) {
- // return
- // }
- vip.grade = gradeArray[value]
- this.setData({ vip, gradeIndex: value })
- },
- /**
- * 改变性别
- */
- pickerSexCtl: function (e) {
- const { value } = e.detail
- const { sexArray, sexIndex,vip } = this.data
- vip.sex = ~~value + 1
- this.setData({ vip, sexIndex: value })
- },
- /**
- * 改变角色
- */
- pickerRoleCtl: function (e) {
- console.log(e)
- const { value } = e.detail
- const { parentRoleArray, parentRoleIndex } = this.data
- this.setData({ 'vip.parentRole': parentRoleArray[~~value], parentRoleIndex: value })
- console.log(parentRoleArray[~~value])
- },
- /**
- * 获取会员卡列表
- */
- getVipList: function () {
- const continuousFn = { fn: this.getVipList, param: { ...arguments } }
- const userId = getGlobalVal('userId')
- GetMineInfo({ continuousFn }).then(res => {
- const { vipList = null } = res.data
- if (vipList.length > 0) {
- wx.setStorageSync(`vipList_${userId}`, vipList)
- } else {
- wx.showToast({
- title: noVipListToastText,
- icon: 'none'
- })
- }
- })
- },
- /**
- * 提交按钮
- */
- submitCtl: function (e) {
- const continuousFn = { fn: this.submitCtl, param: { ...arguments } }
- const { type } = e.currentTarget.dataset
- const { vip, options } = this.data
- if (options.zindex == 3) {
- vip.libId = options.libId || ''
- }
- if (type == 1) {
- wx.navigateBack({
- delta: 1
- })
- } else if (type == 2) {
- if (!vip['childName']) {
- wx.showToast({
- title: '请填写姓名',
- icon: 'none'
- })
- return
- }
- SaveVipInfo({ data: { ...vip }, continuousFn }).then(res => {
- if (options.zindex == 3){
- this.getVipList()
- wx.showToast({
- title: '添加成功',
- })
- }else{
- wx.showToast({
- title: '保存成功',
- })
- }
- setTimeout(() => {
- navigateBack({
- delta:3
- })
- }, 2000)
- })
- }
- }
- })
|