var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); var check = require('../../../utils/check.js'); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { orderId: '', serviceId: '', bookCount: 0, orderStatusText: '订单服务中', activeTab: 1, noAppoint: '', aftersaleStatus: '', orderBook: { status: '', }, orderChannel: 0, jzOrderBookDetails: [], unusedSerList: [], usedSerList: [], serList: [], choosePopup: false, // timeList: check.getTimeList(1), timeList: [], // dateList: util.getDateList(new Date(new Date().getTime() + 60 * 60 * 1000 * 24 * 0), 1, 21), dateList:[], timeIndex: '', //选中的时间段 dateIndex: 0, // checkedAddress: { addressId: 0 }, //选中的地址信息 isHaveAddress: false, noonType: 1, selectTimeValue: '', bookId:'', }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { this.setData({ orderId: options.orderId }); // this.getServiceDetail(); }, getServiceDetail: function () { // wx.showLoading({ // title: '加载中', // }); // setTimeout(function() { // wx.hideLoading(); // }, 2000); util.request(api.ServiceDetail, { order_id: this.data.orderId // order_id: '1342922' }).then(res => { // wx.hideLoading(); if (res.errno === 0) { let jzOrderBookDetails = res.data.jzOrderBookDetails; let unusedSerList = jzOrderBookDetails.filter(item => { return item.status === 0 || item.status == 1 || item.status == 7 }); let usedSerList = jzOrderBookDetails.filter(item => { return item.status == 3 || item.status == 4 }); // let timeList = check.getTimeList(res.data.goods.serviceDuration); this.setData({ aftersaleStatus: res.data.order.aftersaleStatus, goods: res.data.goods, noAppoint: res.data.noAppoint, orderBook: res.data.orderBook, jzOrderBookDetails: jzOrderBookDetails, // activeTab: 1, unusedSerList: unusedSerList, usedSerList: usedSerList, serList: (this.data.activeTab == 1 ? unusedSerList : usedSerList), // timeList: timeList, orderChannel: res.data.orderChannel, isHaveAddress: res.data.order.addressId != null && res.data.order.addressId > 0 && res.data.order.address ? true : false }); console.log(res.data.order.addressId); if (res.data.order.addressId) { console.info("set address") this.setData({ checkedAddress: { addressId: res.data.order.addressId, address: res.data.order.address, tel: res.data.order.mobile, name: res.data.order.consignee } }) console.info(this.data.checkedAddress) } } }); }, selectAddress() { wx.navigateTo({ url: '/pages/ucenter/address/address', }) }, onTabChange(e) { this.setData({ activeTab: e.detail.name, }); if (this.data.activeTab == 1) { this.setData({ serList: this.data.unusedSerList }); } else { this.setData({ serList: this.data.usedSerList }) } }, showAppoint(e) { //是否有地址 如果没有地址 必须先选择地址 console.info(this.data.checkedAddress) if (this.data.checkedAddress.addressId == null ||this.data.checkedAddress.addressId =='') { wx.showToast({ title: '请先选择服务地址', icon: 'none', duration: 2000 }); return false; } 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; } } this.setData({ choosePopup: true, serviceId: e.currentTarget.dataset.id, bookId:e.currentTarget.dataset.bookid }); // this.getDayStock(); this.getDayTime(); }, getDayStock() { if (this.data.dateIndex < 0) { return false; } if( this.data.checkedAddress.addressId==null|| this.data.checkedAddress.addressId==0){ wx.showToast({ title: '请选择地址', icon:'none' }) return false } let params = { day: this.data.dateList[this.data.dateIndex].date, goodsId: this.data.orderBook.goodsId, lng: this.data.orderBook.lng, lat: this.data.orderBook.lat, addressId: this.data.checkedAddress.addressId, productId: this.data.orderBook.productId, serviceDuration: this.data.orderBook.serviceDuration } wx.showLoading({ title: '加载中', }); util.request(api.EveryDayStock, params, "GET") .then(res => { wx.hideLoading(); if (res.errno == 0) { this.setData({ timeList: res.data, timeIndex: 0 }); // 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(function (err) { console.log(err); wx.hideLoading(); wx.showToast({ title: err.errMsg, icon: 'none' }); this.setData({ timeList: [], timeIndex: '' }); }); }, onClose() { this.setData({ choosePopup: false }); }, getDayTime() { let params = { days:30, orderBookId:this.data.bookId, bookId:this.data.serviceId } 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(function (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; // if (index >= 7 || (index >= 2 && index < 7 && (week != '周六' && week != '周日'))) { // this.setData({ // dateIndex: index // }); // } 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:'' }); } }, 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) }); } }, 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 }); }, confirmTime() { if (this.data.timeIndex === ''||this.data.timeIndex<0) { wx.showToast({ title: '请选择服务时间', icon: 'none', duration: 2000 }); 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; console.log(date, week, time); let params = { detail_id: this.data.serviceId, date: date, startTime: time.split('-')[0], endTime: time.split('-')[1], addressId: this.data.checkedAddress.addressId ? this.data.checkedAddress.addressId : 0 }; util.request(api.ServiceOrderBook, params, "GET") .then(res => { console.log(res); if (res.errno == 0) { wx.showToast({ title: '预约成功', icon: 'none', duration: 2000 }); // this.setData({ // // oneTimeAppoint:date+' '+week+' '+time, // choosePopup: false, // }); // this.getServiceDetail(); wx.navigateTo({ url: '/pages/checkout/appointResult/appointResult?id=' + this.data.orderId, }); } else { //util.showErrorToast(res.errmsg); wx.showToast({ title: res.errmsg, icon: 'none', duration: 2000 }); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function (options) { let that = this; var addressInfo = wx.getStorageSync('addressInfo'); if (addressInfo === "") { addressInfo = {}; } that.setData({ checkedAddress: addressInfo }) console.info(this.data.checkedAddress) if (this.data.orderId) { this.getServiceDetail(); } }, goReVisit(e) { let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/extra/newRevisit/newRevisit?id=' + id, success: (res) => { }, fail: (res) => { }, }); }, goDiff(e){ let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/diffOrder/diffOrder?id='+ id, }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })