123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- const app = getApp()
- Page({
- data: {
- startdate: new Date(),
- userInfo: {},
- consultanturl: undefined,
- date: "请输入您的预产期",
- datecss: 'dateinput1',
- phone: '',
- hasUserInfo: false,
- canIUse: wx.canIUse('button.open-type.getUserInfo'),
- consultants: ''
- },
- //事件处理函数
- bindViewTap: function() {
- wx.navigateTo({
- url: '../logs/logs'
- })
- },
- onLoad: function() {
- console.log(app.globalData.userphone)
- 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 + '/getConsultant',
- method: 'get',
- success: function(res) {
- that.setData({
- consultanturl: res.data.wi_url
- })
- },
- fail() {
- app.timeOut()
- }
- })
- if (app.globalData.userInfo) {
- this.setData({
- userInfo: app.globalData.userInfo,
- hasUserInfo: true
- })
- } else if (this.data.canIUse) {
- // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
- // 所以此处加入 callback 以防止这种情况
- app.userInfoReadyCallback = res => {
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- }
- } else {
- // 在没有 open-type=getUserInfo 版本的兼容处理
- wx.getUserInfo({
- success: res => {
- app.globalData.userInfo = res.userInfo
- this.setData({
- userInfo: res.userInfo,
- hasUserInfo: true
- })
- },
- fail() {
- app.timeOut()
- }
- })
- }
- let _this = this;
- _this.setData({
- navH: app.globalData.navHeight
- })
- },
- getUserInfo: function(e) {
- app.globalData.userInfo = e.detail.userInfo
- this.setData({
- userInfo: e.detail.userInfo,
- hasUserInfo: true
- })
- },
- bindDateChange: function(e) {
- if (e.detail.value != "请输入您的预产期") {
- this.setData({
- date: e.detail.value,
- datecss: 'dateinput2'
- })
- }
- },
- phoneInput: function(e) {
- this.setData({
- phone: 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 {
- var duedate = new Date();
- var year = duedate.getFullYear();
- var month = duedate.getMonth() + 1;
- var strDate = duedate.getDate();
- var seperator1 = "-";
- var bookingdate = this.data.date;
- wx.showLoading({
- title: '保存中......',
- icon: 'loading',
- duration: 5500
- })
- wx.request({
- url: app.globalData.url + '/getDcIntroducerConsultants',
- method: 'get',
- data: {
- dig_introducer_phone: app.globalData.introducer
- },
- success: function(res) {
- if (res.data != null) {
- that.setData({
- consultants: res.data
- })
- }
- wx.request({
- url: app.globalData.url + '/insertCustomerBooking',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- bk_phone: that.data.phone,
- bk_duedate: that.data.date,
- bk_date: year + seperator1 + month + seperator1 + strDate,
- bk_type: 4,
- bk_introducer_phone: app.globalData.introducer,
- bk_introducer_consultant: that.data.consultants
- },
- success: function(res) {
- var date = new Date();
- var year = date.getFullYear();
- var month = ("0" + (date.getMonth() + 1)).slice(-2);;
- var strDate = ("0" + (date.getDate())).slice(-2);
- var hours = ("0" + (date.getHours())).slice(-2);
- var minutes = ("0" + (date.getMinutes())).slice(-2);
- var seconds = ("0" + (date.getSeconds())).slice(-2);
- var eh_time = year + '-' + month + '-' + strDate + ' ' + hours + ':' + minutes + ':' + seconds;
- if (res.data > 1) {
- wx.hideLoading()
- wx.showToast({
- title: '亲,您今天已经预约过了',
- icon: 'none',
- duration: 1500
- })
- } else {
- wx.showToast({
- title: '预约成功!',
- icon: 'success',
- duration: 1500
- })
- // 发送消息
- wx.request({
- url: app.globalData.url + '/WXSendBookingMessage',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- bk_phone: that.data.phone,
- bk_type: 4,
- bk_date: eh_time,
- bk_duedate: bookingdate,
- bk_introducer_phone: app.globalData.introducer,
- bk_introducer_consultant: that.data.consultants
- }
- })
- wx.request({
- url: app.globalData.url + '/insertDcIntroduceLog',
- method: 'post',
- header: {
- "Content-Type": "application/x-www-form-urlencoded"
- },
- data: {
- xul_openid: app.globalData.openid,
- xul_phone: app.globalData.userphone,
- xul_event: 3,
- xul_introducer_phone: app.globalData.introducer
- }
- })
- }
- that.setData({
- date: "请输入您的预产期",
- phone: that.data.phone
- })
- },
- fail() {
- app.timeOut()
- }
- })
- },
- fail() {
- app.timeOut()
- }
- })
- }
- },
- onShareAppMessage: function() {
- return {
- title: '悦所-专属顾问',
- path: '/pages/index/index?skip=1&path=/pages/consultant/consultant'
- }
- }
- })
|