// c:\Users\Holy-Knight-IX\Desktop\Working Space\4.TikTok-MiniPro\ttc\package2\pages\appointment\appointment.js let config = require("../../../config/config.js"); let util = require("../../../utils/util"); let Http = require("../../../utils/HttpBasics"); let app = getApp(); const imgurl = require("../../../utils/imgurl"); Page({ data: { appointmentText: "确认预约", id: "", orderId: "", startTime: "", endTime: "", mallTenantId: "", pickedAddress: "请选择地址", pickedDate: "请选择日期", pickedStartTime: "请选择", pickedEndTime: "请选择", describeStr: "", status: "", isShowBtns: false }, onLoad(options) { console.log(options, 'options'); this.setData({ id: options.id || '', orderId: options.orderId || '', startTime: options.startTime || '', endTime: options.endTime || '' }) const mallTenantId = tt.getStorageSync('mallTenantId'); if (mallTenantId) { this.setData({ mallTenantId }) } if (this.data.id) { this.getDetail(this.data.id) } }, chooseAddress() { if (!this.data.isShowBtns) return let that = this; tt.chooseLocation({ success: function (res) { that.setData({ pickedAddress: res.address, }) }, fail: function (error) { console.log(error) }, complete: function (data) {} }) }, chooseDate(e) { console.log(e.detail.value, 'e'); this.setData({ pickedDate: e.detail.value }) }, chooseStartTime(e) { console.log(e.detail.value, 'e'); this.setData({ pickedStartTime: e.detail.value }) }, chooseEndTime(e) { console.log(e.detail.value, 'e'); this.setData({ pickedEndTime: e.detail.value }) }, describing(e) { this.setData({ describeStr: e.detail.value }) }, confirm() { const tempData = this.data if (tempData.pickedAddress == '请选择地址') { tt.showToast({ title: '请选择地址!', icon: 'fail' }); return } if (tempData.pickedDate == '请选择日期') { tt.showToast({ title: '请请选择日期!', icon: 'fail' }); return } if (tempData.pickedStartTime == '请选择') { tt.showToast({ title: '请起始时间!', icon: 'fail' }); return } if (tempData.pickedEndTime == '请选择') { tt.showToast({ title: '请结束时间!', icon: 'fail' }); return } const data = { couponOrderId: tempData.orderId, userAddress: tempData.pickedAddress, startDate: tempData.pickedDate + " " + tempData.pickedStartTime + ":00", endDate: tempData.pickedDate + " " + tempData.pickedEndTime + ":00", describeStr: tempData.describeStr, mallTenantId: tempData.mallTenantId || '' } if (this.data.id) { data.id = this.data.id } if (this.data.status == 1) { data.status = 0 } console.log(data, 'data'); this.saveOrderReservation(data) }, cancel() { tt.showModal({ title: "取消预约", content: "确定要取消预约吗?", showCancel: true, success: (res) => { if (res.confirm) { this.cancelReservation(this.data.id) } if (res.cancel) { return } }, fail: (res) => { }, }); }, cancelReservation(id) { const that = this Http.post({ url: config.api.cancelReservation, data: { id, mallTenantId: this.data.mallTenantId || '' } }).then(res => { console.log(res, 'cancelReservation'); tt.showToast({ title: '取消成功!', icon: 'success', duration: 2000, success: (res) => { setTimeout(() => { tt.navigateBack(); }, 1500); }, fail: (res) => { }, }); }).catch(err => { console.log(err, 'cancelReservation'); tt.showToast({ title: err.message, icon: 'none' }); }) }, saveOrderReservation(data) { Http.post({ url: config.api.saveOrderReservation, data }).then(res => { console.log(res, 'saveOrderReservation'); tt.showToast({ title: '预约成功!', icon: 'success', duration: 2000, success: (res) => { setTimeout(() => { tt.navigateBack(); }, 1500); }, fail: (res) => { }, }); }).catch(err => { console.log(err, 'saveOrderReservation'); tt.showToast({ title: err.message, icon: 'none' }); }) }, getDetail(id) { const that = this Http.get({ url: config.api.getOrderReservationDetail, data: { id, mallTenantId: this.data.mallTenantId || '' } }).then(res => { console.log(res, 'getOrderReservationDetail'); const status = res.data.status that.setData({ pickedAddress: res.data.userAddress || '请选择地址', pickedDate: util.timestampToTime(res.data.startDate, 'YYYY-MM-DD'), pickedStartTime: util.timestampToTime(res.data.startDate, 'hh:mm'), pickedEndTime: util.timestampToTime(res.data.endDate, 'hh:mm'), describeStr: res.data.describeStr, status, appointmentText: res.data.status == 1 ? "重新预约" : "修改预约" }) if (status == 0 || status == 1 || status == 2 || status == 3) { that.setData({ isShowBtns: true }) } }).catch(err => { console.log(err, 'getOrderReservationDetail'); }) } })