//index.js //获取应用实例 const app = getApp() const config = require('../../../utils/config.js'); const util = require("../../../utils/util.js"); Page({ data: { startdate: new Date(), date: "请输入您的预产期", datecss: 'dateinput1', phone: '', gxShow: false, name: '', objectArray: [], promotionShow: '', promotionID: '', imgpath: '', dcphone: '', pd_title: null, pd_imgurl: null }, phoneInput: function (e) { this.setData({ phone: e.detail.value }) }, nameInput: function (e) { this.setData({ name: e.detail.value }) }, bindDateChange: function (e) { if (e.detail.value != "请输入您的预产期") { this.setData({ datecss: 'dateinput2', date: e.detail.value }) } }, onLoad: function (options) { if (app.globalData.userphone != "" && app.globalData.userphone != null && app.globalData.userphone != 'undefined' && app.globalData.userphone != '') { 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 + '/getBranches', method: 'get', success: function (res) { that.setData({ objectArray: res.data }) }, fail() { app.timeOut() } }) wx.request({ url: app.globalData.url + '/getPromotionDCByID', method: 'get', data: { id: options.prx_id }, success: function (res) { that.setData({ pd_title: res.data.pd_title, pd_imgurl: res.data.pd_imgurl, promotionID: res.data.id, imgpath: res.data.pd_result_imgurl }) 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() } }) }, bindPickerChange: function (e) { var that = this var obj = that.data.objectArray[e.detail.value] that.setData({ promotionShow: e.detail.value }) }, onShareAppMessage: function () { return { title: this.data.pd_title, path: '/pages/index/index?share=promotion&url=/pages/testpromotion/testpromotion&id=' + this.data.prx_id + '', // path: '/pages/testpromotion/testpromotion?id=' + this.data.prx_id, imageUrl: this.data.pd_imgurl } }, hrefIndex: function() { util.goHome(); }, 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_prom_id: this.data.promotionID, 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_dc_phone: this.data.dcphone }, success: function (res) { wx.hideLoading() if (res.data == 1) { that.setData({ gxShow: true }) } else { wx.showToast({ title: '亲,您今天已经预约过了', icon: 'none', duration: 1500 }) } }, fail() { app.timeOut() } }) this.setData({ date: "请输入您的预产期", phone: app.globalData.userphone, name: null }) } } //事件处理函数 })