// pages/kids_information/kids_information.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber,curatorName,formatEncrypt } from '../../utils/util.js' import { StudentDetail,ModifyStudentInfo,BindLibAudit} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp() Page({ /** * 页面的初始数据 */ data: { options: {}, baseImgUrl, isShowPickerModel: false, phone:'', patriarchName:'', homeAddress:'', studyPlanName:'', isAddChild:0, studentImg:'', isAdd:false, imgUrl:'', school: '', childName: '', parentName: '', sex: 0, grade: '', parentRole:'', isReview:0, refuseModel:false, pickerData: [ { actIndex: 0, list: ['一年级', '二年级', '三年级', '四年级', '五年级', '六年级'] }, { actIndex: 0, list: ['语文', '数学', '英文'] }, { actIndex: 0, list: ['男', '女'] } ], pickerIndex: null }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData(options) if (options.isReview==1){ wx.setNavigationBarTitle({ title: '详情', }) } const {isReview}=this.data if(isReview==0){ this.getInformation() } }, /** * 生命周期函数--监听页面初次渲染完成 */ 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 () { }, /** * 路由跳转 */ redirectCtl: app.redirectCtl, /** * 路由跳转 */ navigateCtl: app.navigateCtl, /** * 提示框隐藏 */ allShowModel: function () { this.setData({refuseModel:false }) }, /** * 拒绝审核弹框 */ refuseShow: function (e) { const { type } = e.currentTarget.dataset; this.setData({ refuseType: Number(type)}) if(type==2){ this.setData({ refuseModel: true}) }else{ this.selectRefuse() } }, /** * 通过拒绝审核 */ selectRefuse: function (cb) { const continuousFn = { fn: this.selectRefuse, param: { ...arguments } } const { vipId,refuseType} = this.data; BindLibAudit({ data:{vipId,type:refuseType}, continuousFn }).then(res => { if(refuseType==1){ wx.showToast({ title: '通过审核', icon: 'none' }) }else{ wx.showToast({ title: '拒绝成功', icon: 'none' }) } this.allShowModel() setTimeout(function(){ wx.navigateBack({}) },1500) if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, /** * 上传头像 */ uploadHeadIconCtl: function () { wx.chooseImage({ count: 1, success: res => { this.uploadImage(res.tempFilePaths[0]) }, fail: res => { // wx.showToast({ // title: '选择拍照或者相册失败', // icon: 'none' // }) } }) }, /** * 上传头像接口 */ uploadImage: function (file) { app.uploadFile('/api/common/common/uploadForm', file, {}).then(res => { let { filePath } = JSON.parse(res).data.pics[0]; console.log(filePath); this.setData({ imgUrl: filePath}) // this.updateInfor({ // imageKey: filePath // }, 1) }) }, /** * input */ inputCtl: function (e) { const mobileExp = /^1[0-9]{10}$/; const { temp = {}, type } = e.currentTarget.dataset const { value } = e.detail temp[type] = value; const { parentName, family,phone,childName } = temp; // console.log(parentName) if (type == 'phone') { if (value != '') { if (!mobileExp.test(value)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 2000 }) return this.setData({ phone}) } else { return this.setData({ phone }) } } } else if (type == 'childName') { return this.setData({ childName }) } }, /** * picker */ pickerCtl: function (e) { const { temp = {}, type, index } = e.currentTarget.dataset console.log(index) this.setData({ pickerIndex: index, isShowPickerModel: true }) }, /** * 取消 */ cancel:function(){ wx.navigateBack({}) }, /** * picker选择列 */ checkPickerModel: function (e) { const { index } = e.currentTarget.dataset let { temp = {}, pickerIndex, pickerData } = this.data let { actIndex, list } = pickerData[pickerIndex] let str = `pickerData[${pickerIndex}].actIndex`; console.log(index, pickerIndex) // if (index < 0) { if (pickerIndex == 0) { // if (this.data['grade'] != list[actIndex]) { temp['grade'] = list[index] // } } else if (pickerIndex == 1) { if (this.data['courseName'] != list[actIndex]) { temp['courseName'] = list[index] } } else if (pickerIndex == 2) { temp['sex'] = Number(index) + 1 } else if (pickerIndex == 3) { if (this.data['studyPlan'] != list[actIndex]) { temp['studyPlan'] = list[index] } } else if (pickerIndex == 4) { if (this.data['parentRole'] != list[actIndex]) { temp['parentRole'] = list[index] } } temp['isShowPickerModel'] = false this.setData(temp) }, /** * 获取个人信息 */ getInformation: function (cb) { const continuousFn = { fn: this.getInformation, param: { ...arguments } } const { vipId, school } = this.data StudentDetail({ data: {vipId}, continuousFn }).then(res => { const listTemp = (res => { if(res.school.length>10){ res.school=res.school.slice(0,10)+'...' } return res })(res.data) this.setData({ ...res.data }) if (school && school != '' && res.data.school != school) { this.setData({ school:school }) } if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, /** * 修改信息 */ amendChildren:function(cb){ const continuousFn = { fn: this.amendChildren, param: { ...arguments } } var that = this; const { childName,grade, school, imgUrl, sex,vipId } = this.data; // console.log(childName,grade, school, imgUrl, sex,vipId); if (!childName) { wx.showToast({ title: '请输入学生姓名', icon: 'none' }) return } if (!grade) { wx.showToast({ title: '请输入年级', icon: 'none' }) return } if (!school) { wx.showToast({ title: '请输入在读学校', icon: 'none' }) return } ModifyStudentInfo({ data: { childName:formatEncrypt(childName), grade, school:formatEncrypt(school), imgUrl, sex:Number(sex), vipId }, continuousFn }).then(res => { wx.showToast({ title: '修改成功', duration: 1000 }) this.getInformation() // setTimeout((function callback() { // wx.navigateBack({ // delta: 2 // }) // }).bind(this), 1000); if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, })