// pages/tasks/tasks.js import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber,formatEncrypt } from '../../utils/util.js' import { Register, LibList, MyInfo,GetVerificationCode,BindPhone,RegisterV2,CheckStatus} from '../../utils/api.js' const { navigateTo, redirectTo, navigateBack } = routers() const { globalData } = getApp() const { baseImgUrl, thumbnail } = globalData const app = getApp(); Page({ /** * 页面的初始数据 */ data: { hiddenModel:false, isLook: false, phone:'', curatorName: '', libId: '', areaIndex:0, libIndex:0, isBtn:1, isPhone:0, times:60, tips:'获取验证码', isCode:true, code:'', cityList: [ // { // city: "广州", // libList: [ // { // libId: "dahioubrbiuwnirtbirwubribsbfgb", // libName: "私塾家星伯乐共享图书馆GZ151safsa", // status:'' // }, // { // libId: "dahioubrbiuwnirtbirwubribsbfgb", // libName: "私塾家星伯乐共享图书馆GZ15144", // status: '' // }, // { // libId: "dahioubrbiuwnirtbirwubribsbfgb", // libName: "私塾家星伯乐共享图书馆GZ151", // status: '' // }, // ] // }, // { // city: "深圳", // libList: [ // { // libId: "dahioubrbiuwnirtbirwubribsbfgb", // libName: "私塾家星伯乐共享图书馆GZ151444", // status: '' // } // ] // }, // { // city: "佛山", // libList: [ // { // libId: "dahioubrbiuwnirtbirwubribsbfgb", // libName: "私塾家星伯乐共享图书馆GZ151222", // status: 'active' // } // ] // }, ] }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // console.log(options) this.setData(options); const userInfo = wx.getStorageSync('userInfo') this.setData({ userInfo}); const {isBtn,phone,isSlect} = options if (isBtn==0){ this.getInfo(); } this.checkStatus() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { const obj = { navigateTo, redirectTo, navigateBack, viewImage } for (const i in obj) { this[i] = obj[i] } }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // this.getLibList(); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { if (app.sharePageDefaultCtl) { return app.sharePageDefaultCtl() } }, //查看图片 viewImageCtl: app.viewImageCtl, /** * 跳转 */ navigateCtl: app.navigateCtl, /** * 底部导航跳转 */ redirectCtl: app.redirectCtl, /** * 提示框隐藏 */ allShowModel: function () { this.setData({ hiddenModel: false }) }, /** * 选择地区 */ selectArea: function () { console.log('55555') this.setData({ hiddenModel: true}) }, /** * 选择城市 */ selectCity:function(e){ const { index } = e.currentTarget.dataset; this.setData({ areaIndex: index }) }, /** * 选择馆名 */ setLibName:function(e){ const { item,idx } = e.currentTarget.dataset; const { libId, libName}=item; const { areaIndex, libIndex,cityList } = this.data; console.log(areaIndex, libIndex, cityList) var temp = {}; for (var i in cityList) { for (var j in cityList[i].libList) { temp[`cityList[${i}].libList[${j}].status`] = '' } } temp[`cityList[${areaIndex}].libList[${idx}].status`] = cityList[areaIndex].libList[idx].status == '' ? 'active' : ''; this.setData(temp) console.log(cityList) this.setData({ libId, libName,hiddenModel: false,libIndex:idx }) }, /** * 上传头像 */ 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 }) }) }, /** * input */ inputCtl: function (e) { const mobileExp = /^1[0-9]{10}$/; const { temp = {}, type } = e.currentTarget.dataset const { value } = e.detail temp[type] = value; const { curatorName, phone,code} = temp; // console.log(phone) if (type == 'phone') { this.setData({ 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 == 'curatorName') { return this.setData({ curatorName }) } else if(type == 'code'){ this.setData({ code }) } }, /** * 点击馆 */ getLibList:function(cb){ const continuousFn = { fn: this.getLibList, param: { ...arguments } } const { areaIndex,libIndex}=this.data; LibList({ data: {}, continuousFn }).then(res => { const { cityList}=res.data; var temp = {}; for (var i in cityList) { for (var j in cityList[i].libList){ temp[`cityList[${i}].libList[${j}].libId`] = cityList[i].libList[j].libId temp[`cityList[${i}].libList[${j}].libName`] = cityList[i].libList[j].libName temp[`cityList[${i}].city`] = cityList[i].city temp[`cityList[${i}].libList[${j}].status`] = '' } } this.setData(temp) if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, /** * 提交数据 */ getData: function (cb) { const mobileExp = /^1[0-9]{10}$/; const continuousFn = { fn: this.getData, param: { ...arguments } } const { phone, curatorName, libId,code} = this.data; console.log(phone, curatorName, libId,code) if (!curatorName) { wx.showToast({ title: '请输入姓名', icon: 'none' }) return } if (!mobileExp.test(phone)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 2000 }) return } else if (!phone) { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 2000 }) return } if (!code) { wx.showToast({ title: '请输入验证码', icon: 'none' }) return } if (!libId) { wx.showToast({ title: '请选择馆', icon: 'none' }) return } // console.log(phone, curatorName, libId) RegisterV2({ data: { phone:formatEncrypt(phone), curatorName:formatEncrypt(curatorName), libId,vCode:formatEncrypt(code)}, continuousFn }).then(res => { if (libId =='6b308989-0988-45a0-853d-537a923ba2e7'){ this.redirectCtl({ url: 'child_list', method: {} }, true) }else{ this.redirectCtl({ url: 'check_status', method: { isCheck: 1, curatorName } }, true) } if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, /** * 审核结果 * */ checkStatus: function () { const continuousFn = { fn: this.checkStatus, param: { ...arguments } } CheckStatus({ data: {},continuousFn}).then(res => { const {phone} = res.data if(phone){ this.setData({ isCode:false}); } }) }, /** * 获取数据 */ getInfo: function (cb) { const continuousFn = { fn: this.getInfo, param: { ...arguments } } const { isType } = this.data; MyInfo({ data: { type:isType}, continuousFn }).then(res => { const { curatorName, phone, libId, libName } = res.data; this.setData({ curatorName, phone, libId, libName }) if (isFn(cb)) cb() }).catch(res => { this.setData({ isLoaded: true }) if (isFn(cb)) cb() }) }, /** * 绑定手机号 */ bindCuratorPhone: function (cb) { const continuousFn = { fn: this.bindCuratorPhone, param: { ...arguments } } const { code,phone } = this.data; const mobileExp = /^1[0-9]{10}$/; if (!mobileExp.test(phone)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 2000 }) return } else if (!phone) { wx.showToast({ title: '手机号不能为空', icon: 'none', duration: 2000 }) return } if (!code) { wx.showToast({ title: '请输入验证码', icon: 'none' }) return } BindPhone({ data: { vCode:formatEncrypt(code),phone:formatEncrypt(phone)}, continuousFn }).then(res => { wx.showToast({ title: '绑定成功', duration: 1000 }) this.redirectCtl({ url: 'main', method: {} }, true) if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) }, /** * 再次获取验证码 */ setStime:function(){ const mobileExp = /^1[0-9]{10}$/; const { times, phone}=this.data; // console.log(phone) if (!phone) { wx.showToast({ title: '手机号码不能为空', icon: 'none' }) return } else if (!mobileExp.test(phone)) { wx.showToast({ title: '手机号码位数不对', icon: 'none', duration: 1000 }) return } if (times == 60 || times ==0){ this.getPhoneCode() } if(times>0){ this.startSetInter() }else if(times==0){ this.setData({times:60}) this.startSetInter() } }, /** * 开始计时 */ startSetInter: function () { var that = this; const {phone, tips, times} = that.data; // console.log(phone, tips, times) if (times == 0) { that.setData({ tips: "获取验证码"}); return ; } else { var numVal =that.data.times--; that.setData({ tips: "重新发送(" + numVal + ")"}); } this.myTime=setTimeout(function () { that.startSetInter(); }, 1000); }, /** * 获取手机验证码(加密) */ getPhoneCode: function (cb) { const continuousFn = { fn: this.getPhoneCode, param: { ...arguments } } const { phone } = this.data; console.log(phone) GetVerificationCode({ data: { phone:formatEncrypt(phone)}, continuousFn }).then(res => { if (isFn(cb)) cb() }).catch(res => { if (isFn(cb)) cb() }) } })