//index.js //获取应用实例 const app = getApp() const config = require('../../../utils/config.js'); Page({ data: { startdate: new Date(), date: "请输入您的预产期", phone: '', name: '', objectArray: [], promotionShow: '', promotionID: '', imgpath: '' }, 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 () { if (app.globalData.userphone == "" || app.globalData.userphone == null || app.globalData.userphone == undefined) { app.ifAuthorization(); } else { if (app.globalData.userphone.split(" ").join("").length != 0) { this.setData({ phone: app.globalData.userphone }) } else { this.setData({ phone: "请输入您的手机号" }) } } var that = this wx.request({ url: app.globalData.url + '/getWxPosition', method: 'get', success: function (res) { const temp = [] for(var i = 0;i { wx.request({ url: app.globalData.url + '/getValidPosition', method: 'get', data: { po_mkt: res.data.result.ad_info.adcode }, success: function (res) { if (res.data.status == 1) { var obj = that.data.objectArray.find(function (obj) { return obj.id === res.data.data.id }) that.setData({ promotionShow: that.data.objectArray.indexOf(obj), imgpath: res.data.data.po_headimg }) } }, 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, imgpath: obj.po_headimg }) }, 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.name == null || this.data.name == ''){ wx.showToast({ title: '请输入您的姓名', icon: 'none', duration: 1500 }) } else if (this.data.objectArray[this.data.promotionShow].id == null || this.data.objectArray[this.data.promotionShow].id == ''){ 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 + '/insertPromotionUserInfo', method: 'post', header: { "Content-Type": "application/x-www-form-urlencoded" }, data: { pu_username: this.data.name, pu_phone: this.data.phone, pu_duedate: this.data.date, pu_promotionid: this.data.objectArray[this.data.promotionShow].id, pu_date: year + seperator1 + month + seperator1 + strDate + ' ' + hours + ':' + minutes + ':' + seconds }, success: function (res) { wx.hideLoading() if (res.data == 1) { wx.navigateTo({ url: '/pages/promotion/promotionofflineresult/promotionofflineresult?status=yes' }) } else { wx.navigateTo({ url: '/pages/promotion/promotionofflineresult/promotionofflineresult?status=none' }) } }, fail() { app.timeOut() } }) this.setData({ date: "请输入您的预产期", phone: app.globalData.userphone, name: null }) } } //事件处理函数 })