import Dialog from '@vant/weapp/dialog/dialog'; const util = require('../../../utils/util'); const check = require('../../../utils/check'); const api = require('../../../config/api'); const app = getApp(); Page({ /** * 页面的初始数据 */ data: { infoGoods: app.globalData.infoGoods, customerName: '', customerTel: '', address: '', addressId: '', serviceModelText: '请选择', serviceModel: '', // startServiceTime:'请选择', typePickerShow: false, timePickerShow: false, serviceModelList: [{ id: '1', name: '钟点工' }, { id: '2', name: '白班保姆' }, { id: '3', name: '住家保姆' }, // {id:'4',name:'月嫂'}, // {id:'5',name:'代班保姆-钟点工'}, // {id:'6',name:'代班保姆-保姆'}, ], // typeColumns:['钟点工','白班保姆','住家保姆','月嫂','代班保姆-钟点工','代班保姆-保姆'], typeColumns: ['钟点工', '白班保姆', '住家保姆'], currentDate: new Date().getTime(), minDate: new Date().getTime(), recommender: '', //推荐人 recommenderName: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { }, selectAddress() { wx.navigateTo({ url: '/pages/ucenter/address/address', }) }, formatterDate(type, value) { if (type === 'year') { return `${value}年`; } if (type === 'month') { return `${value}月`; } return value; }, onTimeCancel() { this.setData({ timePickerShow: false, }); }, onTimeConfirm(event) { console.log(event); this.setData({ startServiceTime: util.formetdate(new Date(event.detail)), timePickerShow: false, }); }, showServicePicker() { this.setData({ typePickerShow: true, }); }, showTimePicker() { this.setData({ timePickerShow: true, }); }, onTypeCancel: function () { this.setData({ typePickerShow: false, }); }, onTypeConfirm: function (event) { this.setData({ serviceModel: this.data.serviceModelList[event.detail.index].id, serviceModelText: event.detail.value, typePickerShow: false, }); }, recommendChange() { if (this.data.recommender.length == 6) { util.request(api.addClueRecommender, { recCode: this.data.recommender }).then(res => { if (res.errno === 0) this.setData({ recommenderName: res.data }) else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); this.setData({ recommenderName: "不存在" }) } }) } }, confirmSubmit() { if (this.data.customerName == '') { wx.showToast({ title: '请输入客户名称', icon: 'none', duration: 2000 }); return false; } if (this.data.customerTel == '') { wx.showToast({ title: '请输入手机号', icon: 'none', duration: 2000 }); return false; } if (!check.isValidPhone(this.data.customerTel)) { // util.showErrorToast('请输入正确的手机号码'); wx.showToast({ title: '输入正确的手机号码', icon: 'none', duration: 2000 }); return false; } if (this.data.address ==''||this.data.address == '请填写服务住址') { wx.showToast({ title: '请选择住址', icon: 'none', duration: 2000 }); return false; } console.info(this.data.address) console.info(this.data.address.indexOf("市")) if(this.data.address.indexOf("市")<0){ wx.showToast({ title: '请填写所在的城市', icon: 'none', duration: 2000 }); return false; } if (this.data.serviceModelText == '请选择') { wx.showToast({ title: '请选择服务类型', icon: 'none', duration: 2000 }); return false; } // if(this.data.startServiceTime=='请选择'){ // wx.showToast({ // title: '请选择服务时间', // icon: 'none', // duration: 2000 // }); // return false; // } console.log('校验成功'); let userInfo = wx.getStorageSync('userInfo'); wx.showLoading({ title: '提交中...', mask: true, }); util.request(api.addClue, { "customerName": this.data.customerName, "customerTel": this.data.customerTel, "mallAddressId": this.data.addressId, "serviceModel": this.data.serviceModel, "address":this.data.address, // "startServiceTime": this.data.startServiceTime, "userId": userInfo.id, "recommmender":this.data.recommender, "recommmenderName":this.data.recommenderName }, "POST") .then((res) => { wx.hideLoading(); if (res.errno == 0) { app.globalData.infoGoods.type = '2'; wx.navigateTo({ url: '/pages/checkout/payResult/payResult', }) } else { util.showErrorToast(res.errmsg); } }).catch(() => { wx.hideLoading(); }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { // let addressId = wx.getStorageSync('addressId'); // if (addressId === "") { // addressId = 0; // } let addressId = app.globalData.infoAddress.addressId; if (addressId != '') { this.setData({ addressId: addressId, address: app.globalData.infoAddress.addressDetail }) } }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })