//获取应用实例 var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); var check = require('../../../utils/check.js'); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { // serviceId:'ea11209c0e', // cusId:'931400', serviceId: '', cusId: '', gender: '2', address: { id: 0, areaCode: 0, address: '', name: '', tel: '', isDefault: 0, province: '', city: '', county: '', latitude: '', longitude: '', addressDetail: '', detail: '', addressname: '', }, addressIdSave: '', //新增地址保存 orderInfo: { }, addressId: '', checkedAddress: { }, addressList: [], addressShow: false, remark: '', remarkPopupShow: false, remarkList: [ '上门前提前电话联系', '请准时到达', '请自带打扫工具', '主要打扫厨房&卫生间', '家里有宠物' ], remarkActive: '', message: '', remarkShow: false, addressId: '', addressName: '', noAppoint: '', aftersaleStatus: '', orderId: '', order: '', bookId: '', bookCount: 0, orderStatusText: '订单服务中', activeTab: 1, orderBook: { status: '' }, orderChannel: 0, jzOrderBookDetails: [], unusedSerList: [], usedSerList: [], serList: [], choosePopup: false, timeList: [], // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 30), dateList: [], timeIndex: '', //选中的时间段 dateIndex: 0, //选中的日期 appointDate: '', //显示信息 isHide: false, product: { serviceTimes: '', price: '' }, noonType: 1, selectTimeValue: '', goodsTip:{ remark:null } }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options); // if (options.serviceId) { // this.setData({ // serviceId: options.serviceId // }); // } // if (options.orderId) { // this.setData({ // orderId: options.orderId // }); // } if (options.scene) { var scene = decodeURIComponent(options.scene); // scene='id,221e10b7ae;cid,931400: ""'; console.log(scene); // id,46dd84a816;cid,931400 id,221e10b7ae;cid,931400: "" let sceneStr = scene.split(';'); if (scene.indexOf(':') > 0) { let validStr = scene.split(':')[0]; sceneStr = validStr.split(';'); } if (scene.indexOf('cid') >= 0) { this.setData({ serviceId: sceneStr[0].split(",")[1], cusId: sceneStr[1].split(",")[1] }); this.getOrderDetail(); } }else{ //url解析 var scene =Object.keys(options)[0];//[id,d7a4b23bad;cid,356539] console.log(Object.keys(options)); // id,46dd84a816;cid,931400 id,221e10b7ae;cid,931400: "" let sceneStr = scene.split(';'); if (scene.indexOf(':') > 0) { let validStr = scene.split(':')[0]; sceneStr = validStr.split(';'); } if (scene.indexOf('cid') >= 0) { this.setData({ serviceId: sceneStr[0].split(",")[1], cusId: sceneStr[1].split(",")[1] }); this.getOrderDetail(); } } app.globalData.mapSelectFinish = false; // this.getOrderDetail(); }, getOrderDetail: function () { wx.showLoading({ title: '加载中' }); util.request(api.getOrderInfo, { serviceId: this.data.serviceId, cusId: this.data.cusId }).then(res => { wx.hideLoading(); if (res.errno === 0) { console.log(res.data); this.setData({ orderInfo: res.data, goodsTip:res.data.goodsTip, addressId: res.data.addressId, dyDetails: res.data.dyDetails, afterSale: res.data.afterSale, payOverTime: res.data.payOverTime, remainTimes: res.data.serviceTimes - res.data.servedTimes, // orderGoods: res.data.orderGoods, // handleOption: res.data.orderInfo.handleOption, // expressInfo: res.data.expressInfo }); if (res.data.addressId) { this.getAddressList(); } } else { util.showErrorToast(res.errmsg); } }).catch(err => { wx.hideLoading(); }); }, getAddressList() { util.request(api.getCusAddressList, { cusId: this.data.cusId }).then(res => { if (res.errno === 0) { this.setData({ addressList: res.data.list, }); let current = this.data.addressList.filter(item => { return item.id == this.data.addressId }); if (current.length > 0) { this.setData({ checkedAddress: current[0] }); } } }); }, onShow: function () { // this.getOrderDetail(); if (app.globalData.mapSelectFinish) { let poi = app.globalData.mapSelectPoi; let location = poi.location; let address = this.data.address; address.lng = location.split(',')[0]; address.lat = location.split(',')[1]; address.addressname = poi.address; this.setData({ address: address, // selectAddress:poi.address }); console.log(this.data.address); this.getAreaCode(); } }, getServiceDetail: function () { let that = this; if (that.data.orderId == null || that.data.orderId === undefined) { util.showErrorToast('页面已过期,请刷新页面重新查看'); return; } util.request(api.ServiceDetail, { order_id: this.data.orderId }).then(res => { if (res.errno === 0) { let jzOrderBookDetails = res.data.jzOrderBookDetails; let unusedSerList = jzOrderBookDetails.filter(item => { return item.status === 0 || item.status == 1; }); let usedSerList = jzOrderBookDetails.filter(item => { return item.status == 3 || item.status == 4; }); this.setData({ aftersaleStatus: res.data.order ? res.data.order.aftersaleStatus : '', noAppoint: res.data.noAppoint, goods: res.data.goods, orderBook: res.data.orderBook, jzOrderBookDetails: jzOrderBookDetails, activeTab: 1, unusedSerList: unusedSerList, usedSerList: usedSerList, serList: unusedSerList, orderChannel: res.data.orderChannel, addressId: res.data.order.addressId, addressName: res.data.order.address, mobile: res.data.order.mobile, product: res.data.product }); } }); }, showAppoint(e) { // let status = e.currentTarget.dataset.status; // if (status == 1) { // let time = e.currentTarget.dataset.time; // let str = time.substr(0, 16).replace(/-/g, '/'); // let isNear = new Date(str).getTime() - new Date().getTime() - 2 * 60 * 60 * 1000; // console.log(isNear); // if (isNear < 0) { // wx.showToast({ // title: '服务时间小于2小时,不能修改预约', // icon: 'none', // duration: 2000 // }); // return false; // } // } // if (this.data.order.aftersaleStatus == 1 || this.data.order.aftersaleStatus == 2) { // util.showErrorToast("退款中,无法预约"); // return; // } // console.info(this.data.addressName) // if (this.data.addressId == 0||this.data.addressName==null||this.data.addressName=='') { // util.showErrorToast("请输入服务地址"); // return; // } if (this.data.appointDate != '') { this.setData({ choosePopup: true, }); return false; } else { this.setData({ choosePopup: true, noonType: 1, timeIndex: 0 }); let params = { days: 30, // orderBookId:this.data.bookId, bookId: this.data.serviceId, goodsId: this.data.orderInfo.goodsId, serviceDuration: this.data.orderInfo.serviceDuration } this.getDayTime(params); } }, getTimeList() { let timeList = util.getBeginTimeList(this.data.orderInfo.serviceDuration, this.data.noonType, this.data.dateList[this.data.dateIndex].name); this.setData({ timeList: timeList, selectTimeValue: timeList.length == 0 ? '' : timeList[0].value }); if (this.data.timeList.length == 0) { this.setData({ timeIndex: '' }); } }, getDayStock() { if (this.data.dateIndex < 0) { return false; } let params = { day: this.data.dateList[this.data.dateIndex].date, goodsId: this.data.orderInfo.goodsId, addressId: this.data.addressId == 0 ? this.data.addressIdSave : this.data.checkedAddress.id, productId: this.data.orderInfo.productId, orderId: this.data.orderInfo.id, serviceDuration: this.data.orderInfo.serviceDuration }; wx.showLoading({ title: '加载中' }); util.request(api.EveryDayStock, params, "GET").then(res => { wx.hideLoading(); if (res.errno == 0) { this.setData({ timeList: res.data }); let validList = this.data.timeList.filter(item => { return item.stock > 0; }); if (validList.length > 0) { this.setData({ timeIndex: validList[0].id - 1 }); } else { this.setData({ timeIndex: '' }); } } else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); this.setData({ timeList: [], timeIndex: '' }); } }).catch(err => { console.log(err); wx.hideLoading(); wx.showToast({ title: err.errMsg, icon: 'none' }); this.setData({ timeList: [], timeIndex: '' }); }); }, onClose() { this.setData({ choosePopup: false }); }, getDayTime(params) { wx.showLoading({ title: '加载中', }); util.request(api.everyDayTime, params, "GET") .then(res => { wx.hideLoading(); if (res.errno == 0) { this.setData({ dateList: res.data, dateIndex: 0, timeIndex: -1, noonType: 1 }); let period = res.data[0].period; let list = period.filter(item => { return item.ofTime == '上午'; }); this.setData({ timeList: list }); } else { wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); this.setData({ timeList: [], timeIndex: '' }); } }).catch(err => { console.log(err); wx.hideLoading(); wx.showToast({ title: err.errMsg, icon: 'none' }); this.setData({ timeList: [], timeIndex: '' }); }); }, dateCheck(e) { let index = e.currentTarget.dataset.index; let date = e.currentTarget.dataset.date; let week = e.currentTarget.dataset.week; let isbook = e.currentTarget.dataset.isbook; this.setData({ dateIndex: index }); let period = this.data.dateList[this.data.dateIndex].period; let current = (this.data.noonType == 1 ? '上午' : '下午'); let list = period.filter(item => { return item.ofTime == current; }); this.setData({ timeList: list }); let isNoTime = list.every(item => { return item.timeMsg && item.timeMsg != null; }); if (isNoTime) { this.setData({ timeIndex: -1, selectTimeValue: '' }); } // let dateName = this.data.dateList[this.data.dateIndex].name; // this.setData({ // dateIndex: index // }); // let curDateName = this.data.dateList[this.data.dateIndex].name; // if ((curDateName == '今天') || ((new Date()).getHours() >18&&curDateName == "明天")) { // this.setData({ // noonType: 2 // }) // } // this.getTimeList(); }, timeCheck(e) { let index = e.currentTarget.dataset.index; // if (e.currentTarget.dataset.stock == 0) { // wx.showToast({ // title: '所选时间无库存,请选择其他时间', // icon: 'none', // duration: 2000 // }); // return; // } let msg = e.currentTarget.dataset.msg; if (msg == null || msg == '') { let time = (this.data.timeList[index].begin).split(':')[0]; this.setData({ timeIndex: index, selectTimeValue: Number(time) }); } // this.setData({ // timeIndex: index, // selectTimeValue: this.data.timeList[index].value // }); }, submitBook() { //提交预约 if (this.data.addressId == '' && this.data.addressIdSave == '') { util.showErrorToast("请输入服务地址"); return; } if (this.data.timeIndex === '' || this.data.timeIndex < 0) { util.showErrorToast("请选择服务时间"); return false; } // if (this.data.mobile == null || this.data.mobile.length != 11) { // util.showErrorToast("请填写手机号码"); // return; // } let date = this.data.dateList[this.data.dateIndex].bookdate; let week = this.data.dateList[this.data.dateIndex].weekOfDay; let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end; console.log(date, week, time); let params = { cusId: this.data.cusId, serviceId: this.data.serviceId, date: date, startTime: time.split('-')[0], endTime: time.split('-')[1], addressId: (this.data.addressId == 0 || this.data.addressId == null) ? this.data.addressIdSave : this.data.checkedAddress.id, remark: this.data.remark + this.data.message }; console.info(params); wx.showLoading({ title: '加载中...' }); util.request(api.customerBook, params, "POST").then(res => { if (res.errno == 0) { wx.hideLoading(); this.setData({ isHide: true }); wx.showToast({ title: '预约成功', icon: 'none', duration: 2000 }); // setTimeout(() => { // wx.navigateTo({ // url: "/pages/ucenter/orderDetail/orderDetail?id=" + this.data.orderId // }); // }, 2000); } else { wx.showToast({ title: res.errmsg, icon: 'none' }); // util.showErrorToast(res.errmsg); } }); }, confirmTime() { if (this.data.timeIndex === '' || this.data.timeIndex < 0) { util.showErrorToast('请选择服务时间'); return false; } let date = this.data.dateList[this.data.dateIndex].bookdate; let week = this.data.dateList[this.data.dateIndex].weekOfDay; let time = this.data.timeList[this.data.timeIndex].begin + '-' + this.data.timeList[this.data.timeIndex].end; this.setData({ choosePopup: false, appointDate: date + ' ' + week + ' ' + time }); }, selectAddress() { //已经输入过地址的订单 不允许再次选择地址 if (this.data.order.addressId > 0) return; wx.navigateTo({ url: '/pages/ucenter/address/address' }); }, showRemark() { this.setData({ remarkShow: true }); }, onRemarkClose() { this.setData({ remarkShow: false }); }, confirmRemark() { this.setData({ remarkShow: false }); }, bindMessageInput: function (e) { this.setData({ message: e.detail.value }); }, bindPhone(e) { this.setData({ mobile: e.detail.value }) }, copyOrder() { wx.setClipboardData({ data: this.data.orderInfo.orderSn, success: function (res) { wx.getClipboardData({ success: function (res) { wx.showToast({ title: '订单编号复制成功', icon: 'success', duration: 2000 }); } }); } }); }, onAddressClose() { this.setData({ addressShow: false }) }, onAddressClick() { //阻止事件冒泡,不要删 }, addressConfirm(e) { let address = e.currentTarget.dataset.address; this.setData({ checkedAddress: address, addressShow: false }); }, addressSelect() { this.setData({ addressShow: true }); }, showRemarkSelect() { this.setData({ remarkPopupShow: true }); }, onRemarkPopupClose() { this.setData({ remarkPopupShow: false }) }, onRemarkClick() { //阻止事件冒泡,不要删 }, remarkItemSelect(e) { let remark = e.currentTarget.dataset.remark; this.setData({ remark: remark, remarkActive: remark, }); }, remarkItemConfirm() { if (this.data.remarkActive === '') { util.showErrorToast("请选择备注"); return false; } this.setData({ remarkPopupShow: false }); }, bindinputMobile(event) { let address = this.data.address; address.tel = event.detail.value; this.setData({ address: address }); }, bindinputName(event) { let address = this.data.address; address.name = event.detail.value; this.setData({ address: address }); }, bindinputAddress(event) { let address = this.data.address; address.detail = event.detail.value.replace(/[,,]/g, ''); this.setData({ address: address }); // return value.replace(/[,,]/g,''); }, bindAddressDetail(event) { let address = this.data.address; address.addressname = event.detail.value.replace(/[,,]/g, ''); this.setData({ address: address }); }, submitAll() { if ((this.data.addressId == '' || this.data.addressId == null) && this.data.addressIdSave == '') { this.saveAddress(); } else { this.submitBook(); } }, async saveAddress() { console.log(this.data.address); let address = this.data.address; // if (address.addressname == 0) { // util.showErrorToast('请选择服务地址'); // return false; // } if (address.addressname == '') { util.showErrorToast('请选择服务地址'); return false; } if (address.name == '') { util.showErrorToast('请输入姓名'); return false; } if (address.detail == '') { util.showErrorToast('请输入门牌号'); return false; } if (this.data.gender == null || this.data.gender == '') { util.showErrorToast('请选择性别'); return false; } if (address.tel == '') { util.showErrorToast('请输入手机号码'); return false; } if (!check.isValidPhone(address.tel)) { util.showErrorToast('手机号不正确'); return false; } let that = this; let addressString = address.detail == '' ? address.addressname : address.addressname + ',' + address.detail; wx.showLoading({ title: '加载中...' }); let res = await util.request(api.addCusAddress, { gender: this.data.gender, addressId: address.id, name: address.name, tel: address.tel, province: address.province, city: address.city, county: address.county, areaCode: address.areaCode, addressDetail: addressString, isDefault: address.isDefault, lat: Number(address.lat).toFixed(5), lng: Number(address.lng).toFixed(5), cusId: this.data.cusId }, 'POST'); wx.hideLoading(); if (res.errno === 0) { that.setData({ addressIdSave: res.data }) that.submitBook(); } else { wx.showModal({ title: '提醒', showCancel: false, content: res.errmsg }); } }, goMap() { // const key = "JA2BZ-XGOEU-UNZVD-46G64-S6MYJ-6BBF4"; //使用在腾讯位置服务申请的key // const key = '6TRBZ-XXC6F-BWWJB-N75ME-BQNOF-YKFQY'; // const referer = '鲸致生活LifePlus'; // const category = '小区,生活服务,娱乐休闲'; // wx.navigateTo({ // url: 'plugin://chooseLocation/index?key=' + key + '&referer=' + referer + '&category=' + category // }); let that = this; // wx.authorize({ // scope: "scope.userLocation", // success: (res) => { // console.log("authorize", res); wx.chooseLocation({ success: (location) => { console.log("chooseLocation success: ", location); console.log(`经度${location.longitude},维度${location.latitude}`); console.log(location); if (location != null) { let address = that.data.address; address.lat = location.latitude; address.lng = location.longitude; address.addressname = location.address; that.setData({ address: address, // selectAddress:location.address }); console.log(that.data.address); that.getAreaCode(); } }, fail: (err) => { console.log("chooseLocation fail: " + err.errMsg); }, }); // }, // fail: () => { // wx.openSetting({}); // }, // }); }, goMap() { console.log('gomap'); app.globalData.mapSelectFinish = false; // wx.navigateTo({ // url: '/pages/map/mapContent/mapContent', // }); if (this.data.address.lng && this.data.address.lat) { let city = (this.data.address.city == '市辖区' ? this.data.address.province : this.data.address.city) wx.navigateTo({ url: '/pages/map/mapContent/mapContent?lng=' + this.data.address.lng + '&lat=' + this.data.address.lat + '&addressname=' + this.data.address.addressname + '&city=' + city, }); } else { wx.navigateTo({ url: '/pages/map/mapContent/mapContent', }); } }, maleSelect() { this.setData({ gender: 1 }); }, femaleSelect() { this.setData({ gender: 2 }); }, getAreaCode() { let param = { location: this.data.address.lng + ',' + this.data.address.lat, extensions: 'all', key: api.gdKey, radius: 3000, }; wx.request({ url: api.gdUrl, data: param, method: 'GET', header: { 'Content-Type': 'application/json' }, success: res => { console.log(res); if (res.data.infocode == "10000") { if (res.data.info == "OK") { // let ad_info = res.data.result.ad_info; // let areaCode = res.data.result.ad_info.adcode; let regeocode = res.data.regeocode.addressComponent; let cityName = (regeocode.city == null || regeocode.city.length == 0) ? regeocode.province : regeocode.city; let district = (regeocode.district == null || regeocode.district.length == 0) ? '' : regeocode.district; this.setData({ ['address.areaCode']: regeocode.adcode, ['address.province']: regeocode.province, ['address.city']: cityName, ['address.county']: district, // ['address.addressname']:res.data.result.address }); } else { wx.showToast({ title: '获取地区码失败', icon: 'none', duration: 3000 }); } } else { wx.showToast({ title: '获取地区码失败', icon: 'none', duration: 3000 }); } }, fail: function (err) { reject(err); } }); }, goAddAddress() { wx.navigateTo({ url: '/pages/ucenter/addressAdd/addressAdd?id=' + 0 }); }, noonTab(e) { let noon = e.currentTarget.dataset.noon; this.setData({ timeIndex: -1, noonType: noon, selectTimeValue: '', }); let period = this.data.dateList[this.data.dateIndex].period; let current = (this.data.noonType == 1 ? '上午' : '下午'); let list = period.filter(item => { return item.ofTime == current; }); this.setData({ timeList: list }); } });