| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- // 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()
- })
- }
- })
|