// pages/creatAgent/index.js const app = getApp(); const commonUtil = require('../../utils/commonUtil.js'); const dateUtil = require('../../utils/util.js'); var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js'); var qqmapsdk; Page({ /** * 页面的初始数据 */ data: { array3: ['中国', '美国', '英国'], value3: 0, files: [], loading: false, phoneNumber: '', sendTime: '获取验证码', sendColor: '#027AFF', snsMsgWait:60, showMsgCode: true, msgCode: '', disabled: 1, //0不可点 region:["河南省", "许昌市", "襄城县"], customItem: '全部', lat: '', lng: '', detailAddress:"", city:'',//地址解析用 pmdUserId: '', agencyStatus: 0, fromMiniApp: 0, }, bindRegionChange: function (e) { console.log('picker发送选择改变,携带值为', e.detail.value) this.setData({ region: e.detail.value }) }, bindPicker3Change: function (e) { this.setData({ value3: e.detail.value }) }, inputBlur: function (e) { var that = this; var myreg = /^[1][3456789][0-9]{9}$/; if (myreg.test(e.detail.value)) { that.setData({ phoneNumber: e.detail.value }); } else { wx.showToast({ duration: 2000, title: '手机号格式不正确', icon: 'none', mask: true }) } }, getCode: function (e) { var that = this; setTimeout(function() { var myreg = /^[1][3456789][0-9]{9}$/; if (myreg.test(that.data.phoneNumber)) { that.setData({ msgCode: '', sendColor: '#ccc', sendTime: '60秒', snsMsgWait:60, smsFlag: false }); that.sendCode(); } else { wx.showToast({ duration: 2000, title: '手机号格式不正确', icon: 'none', mask: true }) } }, 100); }, sendCode: function () { var that = this; // 60秒后重新获取验证码 wx.request({ url: app.globalData.ip + '/commons/sendMsgCode', data: { // tel: that.data.phoneNumber tel: that.data.phoneNumber }, header: app.globalData.header, method: "GET", success: function (res) { console.log("发送短信验证码"); console.log(res); if (res.data.status == 200) { that.setData({ smsFlag: true, sendColor: '#cccccc', sendTime: that.data.snsMsgWait + '秒', snsMsgWait: that.data.snsMsgWait - 1, disabled: 0, }); let inter = setInterval(function () { that.setData({ smsFlag: true, sendColor: '#cccccc', sendTime: that.data.snsMsgWait + '秒', snsMsgWait: that.data.snsMsgWait - 1 }); if (that.data.snsMsgWait < 0) { clearInterval(inter) that.setData({ sendColor: '#027AFF', sendTime: '重新获取', snsMsgWait: 60, smsFlag: false, disabled: 1, }); } }.bind(that), 1000); } else { wx.showToast({ icon: "none", title: res.data.msg, duration: 2000 }); } } }) }, formSubmit(e) { var that = this; that.setData({ loading:true }) console.log('form发生了submit事件,携带数据为:', e.detail.value) let values = e.detail.value; if(app.isEmptyCheck(e.detail.value.userName)){ wx.showToast({ duration: 2000, title: '请输入代理姓名', icon: 'none', mask: true }) that.setData({ loading:false }) } else if(app.isEmptyCheck(e.detail.value.tel)){ wx.showToast({ duration: 2000, title: '请输入代理人手机号', icon: 'none', mask: true }) that.setData({ loading:false }) } else if(app.isEmptyCheck(e.detail.value.msgCode)){ wx.showToast({ duration: 2000, title: '请输入验证码', icon: 'none', mask: true }) that.setData({ loading:false }) } else { values['pmdUserId'] = that.data.pmdUserId; console.log(values); wx.request({ url: app.globalData.ip + '/agency/add', data: values, header: { 'content-type': 'application/json' }, // method: "POST", success: function (res) { console.log(res); if (res.data.status == 200) { /*app.globalData.sessionId = res.data.data.sessionId; app.globalData.headers.Cookie = 'JSESSIONID=' + res.data.data.sessionId; app.globalData.headers2.Cookie = 'JSESSIONID=' + res.data.data.sessionId; app.globalData.isLogin = true; app.globalData.agencyStatus = res.data.data.agencyStatus; app.globalData.loginUserInfo = res.data.data; //登录设置缓存 app.globalData.userLoginTokenInfo.tel = res.data.data.tel; app.globalData.userLoginTokenInfo.token = null; wx.setStorageSync('loginUserTokenInfo', app.globalData.userLoginTokenInfo);*/ wx.redirectTo({ url: '/pages/creatSuccess/index', }) /*if (res.data.data.createNewAgency == 0) { that.setData({ agencyStatus: app.globalData.agencyStatus }); } else { wx.redirectTo({ url: '/pages/creatSuccess/index', }) }*/ } else { wx.showToast({ icon: "none", title: res.data.msg, duration: 2000 }); } that.setData({ loading:false }) }, fail: function () { wx.showToast({ icon: "none", title: '创建代理失败,请联系管理员', duration: 2000 }); that.setData({ loading:false }) } }) /*that.validateTelCode(e.detail.value.tel, e.detail.value.msgCode).then(res => { if(res.data.status == 200) { values['userId'] = res.data.data.userId; values['lng'] = that.data.lng; values['lat'] = that.data.lat; if(that.data.region != null && that.data.region.length == 3) { values['province'] = that.data.region[0]; values['city'] = that.data.region[1]; values['district'] = that.data.region[2]; } if(that.data.files != null && that.data.files.length != 0) { values['images'] = that.data.files.join(','); } } else { wx.showToast({ icon: "none", title: res.data.msg, duration: 2000 }); that.setData({ loading:false }) } });*/ } }, validateTelCode: function(tel, code) { return new Promise(function(reslove, reject) { var that = this; // 60秒后重新获取验证码 wx.request({ url: app.globalData.ip + '/commons/validateMsgCode', data: { tel: tel, code: code, checkAgency: 'checkAgency', sessionId: app.globalData.sessionId, }, header: app.globalData.header, method: "GET", success: function (res) { reslove(res); }, fail: function (res) { reject({ data: { code: 500, msg: '验证失败,请联系管理员', } }); } }) }) }, chooseImage: function (e) { var that = this; wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths; var formData = {}; wx.uploadFile({ url: app.globalData.ip + '/user/uploadImage', filePath: res.tempFilePaths[0], name: 'uploadFile', header: app.globalData.header2, // 设置请求的 header formData: formData, // HTTP 请求中其他额外的 form data success: function (res1) { console.log(res1); if (res1.statusCode == 200) { var result = JSON.parse(res1.data) if (result.status == 200) { that.setData({ files: that.data.files.concat(result.data.url) }); } else { app.showTips(that, '上传失败'); } } }, fail: function (res2) { } }) } }) }, previewImage: function (e) { wx.previewImage({ current: e.currentTarget.id, // 当前显示图片的http链接 urls: this.data.files // 需要预览的图片http链接列表 }) }, getLocation: function() { var that = this; // var url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" + lat + "," + lng + "&key=7P6BZ-S2OC2-NH3UK-CT2DU-QO5FS-J7FVS"; wx.getLocation({ type: 'wgs84', success (res) { const latitude = res.latitude const longitude = res.longitude const speed = res.speed const accuracy = res.accuracy that.setData({ lat: latitude, lng: longitude, }); } }) }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // this.getLocation(); console.log(options); if (app.isNotEmptyCheck(options.pmdUserId)) { this.data.pmdUserId = options.pmdUserId; } if (app.isNotEmptyCheck(options.fromMiniApp)) { this.data.fromMiniApp = options.fromMiniApp; } this.setData({ pmdUserId: this.data.pmdUserId, fromMiniApp: this.data.fromMiniApp, }) qqmapsdk = new QQMapWX({ key: '5PTBZ-YI7C6-MZGS3-ES7QN-4T5O2-EJFVR' }); //登录=================================start if (app.globalData.isLogin) { this.setData({ agencyStatus: app.globalData.agencyStatus, loginUserInfo: app.globalData.loginUserInfo, }); } else { // 由于 userLogin 是网络请求,可能会在 Page.onLoad 之后才返回 // 所以此处加入 callback 以防止这种情况 app.userLoginCallback = res => { this.setData({ agencyStatus: app.globalData.agencyStatus, loginUserInfo: app.globalData.loginUserInfo, }); } } //登录=================================end }, getAddress:function(){ var that = this; qqmapsdk.reverseGeocoder({ location: { latitude: that.data.lat, longitude: that.data.lng }, success: function (res) { console.log(res); that.data.region = []; that.data.region.push(res.result.address_component.province); that.data.region.push(res.result.address_component.city); that.data.region.push(res.result.address_component.district); console.log(that.data.region); that.setData({ city:res.result.address_component.city, detailAddress:res.result.address, region:that.data.region }); }, fail: function (res) { console.log(res); }, complete: function (res) { // console.log(res); } }) }, addressBlur:function(e){ var that = this; qqmapsdk.geocoder({ address: e.detail.value, region: that.data.city, success: function (res) { console.log(res); that.setData({ lat: res.result.location.latitude, lng: res.result.location.longitude, }); }, fail: function (res) { console.log(res); }, complete: function (res) { // console.log(res); } }); }, goWithdraw:function(){ wx.switchTab({ url: '/pages/index/index', }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { var that = this; return { title: '邀请成为代理', // imageUrl: that.data.channel.channelPoster, path: '/pages/creatAgent/index?pmdUserId=' + that.data.pmdUserId } } })