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), timeIndex: '', //选中的时间段 dateIndex: 0, // checkedAddress: { addressId: 0 }, //选中的地址信息 isHaveAddress: false }, /** * 生命周期函数--监听页面加载 */ 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 }); 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.address == null || this.data.checkedAddress.address == '') { 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 }); this.getDayStock(); }, getDayStock() { if (this.data.dateIndex < 0) { 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 } 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 }); }, 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 // }); // } if (isbook) { this.setData({ dateIndex: index }); this.getDayStock(); } }, timeCheck(e) { let index = e.currentTarget.dataset.index; // if (e.currentTarget.dataset.stock == 0) { // wx.showToast({ // title: '所选时间无库存,请选择其他时间', // icon: 'none', // duration: 2000 // }); // return; // } this.setData({ timeIndex: index }); }, confirmTime() { if (this.data.timeIndex === '') { wx.showToast({ title: '请选择服务时间', icon: 'none', duration: 2000 }); return false; } let date = this.data.dateList[this.data.dateIndex].date; let week = this.data.dateList[this.data.dateIndex].week; let time = this.data.timeList[this.data.timeIndex].time; 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(); } else { util.showErrorToast(res.errmsg); } }); }, /** * 生命周期函数--监听页面初次渲染完成 */ 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) => { }, }); }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })