//index.js //获取应用实例 const app = getApp() const config = require('../../utils/config.js'); Page({ data: { startdate: new Date(), date: "请输入您的预产期", phone: '', name: '', objectArray: [], promotionShow: '', promotionID: '', imgpath: '', dcphone: '' }, phoneInput: function (e) { this.setData({ phone: e.detail.value }) }, nameInput: function (e) { this.setData({ name: e.detail.value }) }, bindDateChange: function (e) { this.setData({ date: e.detail.value }) }, onLoad: function (options) { if (options.phone != null) { this.setData({ dcphone: options.phone }) } var that = this wx.request({ url: app.globalData.url + '/getBranches', method: 'get', success: function (res) { that.setData({ objectArray: res.data }) },fail() { app.timeOut() } }) wx.request({ url: app.globalData.url + '/getPromotionDC', method: 'get', success: function (res) { that.setData({ imgpath: res.data.pd_headimg, promotionID: res.data.id }) wx.getLocation({ type: 'wgs84', success: function (res) { let latitude = res.latitude let longitude = res.longitude // let latitude = '31.314453' // let longitude = '120.654302' wx.request({ url: `https://apis.map.qq.com/ws/geocoder/v1/?location=${latitude},${longitude}&key=${config.key}`, success: res => { wx.request({ url: app.globalData.url + '/checkMkt', method: 'get', data: { branche_code: res.data.result.ad_info.city_code.substring(3, 6) + '000' }, success: function (res) { if (res.data.length == 1) { var obj = that.data.objectArray.find(function (obj) { return obj.branche_code === res.data[0].branche_code }) that.setData({ promotionShow: that.data.objectArray.indexOf(obj) }) } else { that.setData({ promotionShow: 1 }) } }, fail() { app.timeOut() } }) }, fail: (res) => { //获取城市失败 } }) }, fail: (res) => { // 获取位置失败 } }) }, fail() { app.timeOut() } }) let _this = this; _this.setData({ navH: app.globalData.navHeight }) }, bindPickerChange: function (e) { var that = this var obj = that.data.objectArray[e.detail.value] that.setData({ promotionShow: e.detail.value }) }, confirm: function (e) { var that = this var myphone = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/; var mydate = /^(\d+)-(\d{1,2})-(\d{1,2})$/; if (!myphone.test(this.data.phone)) { wx.showToast({ title: '手机号输入错误', icon: 'none', duration: 1500 }) } else if (!mydate.test(this.data.date)) { wx.showToast({ title: '预产期输入错误', icon: 'none', duration: 1500 }) } else if (this.data.objectArray[this.data.promotionShow].branche_code == null || this.data.objectArray[this.data.promotionShow].branche_code == '') { wx.showToast({ title: '请选择您参加的活动', icon: 'none', duration: 1500 }) } else { var duedate = new Date(); var year = duedate.getFullYear(); var month = duedate.getMonth() + 1; var strDate = duedate.getDate(); var seperator1 = "-"; var hours = ("0" + (duedate.getHours())).slice(-2); var minutes = ("0" + (duedate.getMinutes())).slice(-2); var seconds = ("0" + (duedate.getSeconds())).slice(-2); wx.showLoading({ title: '保存中......', icon: 'loading', duration: 5500 }) wx.request({ url: app.globalData.url + '/insertPromotionDCUserInfo', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { pd_phone: this.data.phone, pd_duedate: this.data.date, pd_city: this.data.objectArray[this.data.promotionShow].branche_code, pd_date: year + seperator1 + month + seperator1 + strDate + ' ' + hours + ':' + minutes + ':' + seconds, pd_prom_id: this.data.promotionID, pd_dc_phone: this.data.dcphone }, success: function (res) { wx.hideLoading() if (res.data == 1) { wx.navigateTo({ url: '/pages/dcpromotion/dcpresult/dcpresult' }) } else { wx.showToast({ title: '亲,您今天已经预约过了', icon: 'none', duration: 1500 }) } }, fail() { app.timeOut() } }) this.setData({ date: "请输入您的预产期", phone: app.globalData.userphone, name: null }) } } //事件处理函数 })