var util = require('../../../utils/util.js'); var api = require('../../../config/api.js'); Page({ data: { excludeAxb: '', //订单不包含安心包,才可以退款 orderId: 0, payOverTime: 0, timer: '', remainTimes: '', orderInfo: {}, dyDetails: [], afterSale: null, orderGoods: [], expressInfo: {}, flag: false, handleOption: {}, orderType: 0, //如果是1表示从引荐人的订单列表过来的,需要隐藏操作按钮 shopPhone: '', complainTips: false, ticketTips: false, //投诉工单 处理结果回收 ticketId: '', //投诉id satisfaction: 0, //投诉处理满意度 satisfactionTips: {}, satisfactionLow: { tips: '非常抱歉,我们会立即安排专属客服跟进了解具体问题!', notice: '您的评价是对我们最大的鼓励和鞭策,感谢您的评价。' }, satisfactionMid: { tips: '我们会持续了解问题,为您提供更好的服务', notice: '感谢您的评价,我们会持续收集顾客的建议,优化服务!' }, satisfactionHigh: { tips: '感谢您的认可,我们将为您持续提供优质服务', notice: '感谢您的认可,我们将持续为您提供更加优质的服务!' }, star: '/static/images/new/star.png', starYellow: '/static/images/new/star_yellow.png', starRed: '/static/images/new/star_red.png', msgShow: false, //客户追加备注 message: '', //备注信息 cancelList: [{ id: 19, value: "临时有事,暂时不预约" }, { id: 20, value: "先屯着后面预约" }, { id: 21, value: "服务商原因,保洁师无法上门" } ], //取消页面 cancelShow: false, cancelDetailId: '', cancelReason: '', //选中的取消原因项 isShowPL: false //是否台数的商品 直接显示上门时间和服务内容 }, cancelItemConfirm() { let that = this; if (that.data.cancelReason == '') { util.showErrorToast("请选择取消原因"); return; } wx.showLoading({ title: '提交中' }); util.request(api.OrderBookCancel, { detailId: that.data.cancelDetailId, cancelReason: that.data.cancelReason }, "POST").then(res => { wx.hideLoading(); if (res.errno === 0) { wx.showToast({ title: "提交成功" }); let items = that.data.dyDetails; items.forEach(item => { if (item.id == that.data.cancelDetailId) { item.isCancel = false; item.statusVal = "已取消"; item.status = 6; } }) this.setData({ cancelShow: false, dyDetails: items, 'orderInfo.handleOption.book': true, 'orderInfo.detailId': res.data }) }else{ util.showErrorToast(res.errmsg); } }) }, goCancelBook(e) { //取消工单预约 this.setData({ cancelDetailId: e.currentTarget.dataset.id, cancelShow: true }) }, cancelItemSelect(e) { this.setData({ cancelReason: e.currentTarget.dataset.id }) }, onCancelPopupClose() { this.setData({ cancelShow: false }) }, onCancelClick() { //无实际意义 防止冒泡 }, cancelTicketTips() { this.setData({ ticketTips: false, }) }, showMsg() { this.setData({ msgShow: true }) }, onMsgClose() { this.setData({ msgShow: false }) }, confirmMsg() { if (this.data.message == '') { util.showErrorToast("请输入备注"); return; } let that = this; wx.showLoading({ title: '提交中' }); util.request(api.OrderMsg, { orderId: that.data.orderId, message: that.data.message }, "POST").then(function (res) { wx.hideLoading(); if (res.errno === 0) { wx.showToast({ title: "提交成功" }); //赋值给所有工单 let dyDetails = that.data.dyDetails; dyDetails.forEach(item => { item.customerRemark = that.data.message }) that.setData({ msgShow: false, dyDetails: dyDetails }) } }) }, bindMsgInput(e) { this.setData({ message: e.detail.value }); }, showTicketTips(e) { let ticketId = parseInt(e.currentTarget.dataset.id); this.setData({ ticketTips: true, ticketId: ticketId }) }, selectTicketValue(e) { //点击星号 let id = parseInt(e.currentTarget.dataset.id); this.setData({ satisfaction: id }) let tips = this.data.satisfactionLow; if (id >= 3 && id < 5) tips = this.data.satisfactionMid else if (id == 5) tips = this.data.satisfactionHigh this.setData({ satisfactionTips: tips }) }, confTicketTips() { if (this.data.satisfaction == 0) { util.showErrorToast("请选择满意度"); return; } let that = this; wx.showLoading({ title: '提交中' }); util.request(api.TicketSatisfaction, { id: that.data.ticketId, satisfaction: that.data.satisfaction }, "POST").then(function (res) { if (res.errno === 0) { wx.hideLoading(); //隐藏弹框并设置工单为已评论过 let dyDetails = that.data.dyDetails; dyDetails.forEach(detail => { if (detail.ticketVo && detail.ticketVo.ticketId == that.data.ticketId) { detail.ticketVo.isSatisfaction = false; console.info("进入") console.info(detail) } }); that.setData({ ticketTips: false, dyDetails: dyDetails }); wx.showToast({ title: that.data.satisfactionTips.notice, icon: 'none', duration: 2000 }); } }); }, onLoad: function (options) { // 页面初始化 options为页面跳转所带来的参数 this.setData({ orderId: options.id, orderType: options.orderType }); // this.getOrderDetail(); }, onShow: function () { // 页面显示 this.getOrderDetail(); }, onPullDownRefresh() { wx.showNavigationBarLoading(); //在标题栏中显示加载 this.getOrderDetail(); wx.hideNavigationBarLoading(); //完成停止加载 wx.stopPullDownRefresh(); //停止下拉刷新 }, expandDetail: function () { let that = this; this.setData({ flag: !that.data.flag }); }, getOrderDetail: function () { wx.showLoading({ title: '加载中' }); setTimeout(function () { wx.hideLoading(); }, 2000); let that = this; util.request(api.OrderDetail, { orderId: that.data.orderId }).then(function (res) { if (res.errno === 0) { wx.hideLoading(); console.log(11) //获取预约开始时间 res.data.dyDetails.forEach(item => { if (item.bookTime) item.bookStartTime = item.bookTime.substring(0, 16); }); that.setData({ orderInfo: res.data, dyDetails: res.data.dyDetails, afterSale: res.data.afterSale, payOverTime: res.data.payOverTime, remainTimes: res.data.serviceTimes - res.data.servedTimes, message: res.data.message // orderGoods: res.data.orderGoods, // handleOption: res.data.orderInfo.handleOption, // expressInfo: res.data.expressInfo }); //是否为按台服务的商品--按台服务商品 展示服务内容 通过关键字:空调、油烟机、洗衣机、冰箱 if (res.data.goodsName.indexOf('空调') >= 0 || res.data.goodsName.indexOf('油烟机') >= 0 || res.data.goodsName.indexOf('洗衣机') >= 0 || res.data.goodsName.indexOf('冰箱') >= 0) { that.setData({ isShowPL: true }) } if (that.data.payOverTime > 0) { let timer = setInterval(() => { let newTime = that.data.payOverTime - 1; if (newTime >= 0) { that.setData({ payOverTime: newTime }); } else { clearInterval(that.data.timer); } }, 1000); that.setData({ timer: timer }); } } // let excludeAxb = res.data.orderGoods.every(item => { // return item.goodsSn != '1036016'; // }); // that.setData({ // excludeAxb: excludeAxb // }); }); }, // “去付款”按钮点击效果 payOrder: function () { let that = this; util.request(api.OrderPayCheck, { orderId: that.data.orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { const outOrderNo = res.data; console.log(res); wx.continueToPay({ // orderId: this.data.orderId, // 内部订单号 outOrderNo: outOrderNo, // 外部订单号 2个订单号必填一个 success: res => { console.log(res); const { orderId, outOrderNo } = res; console.log('success res', res); console.log('orderId', orderId, 'outOrderNo', outOrderNo); wx.redirectTo({ url: '/pages/ucenter/order/order' }); }, fail: res => { console.log(res); const { orderId, outOrderNo, errNo, errMsg, errLogId } = res; if (errLogId) { console.log('查询订单信息失败', errNo, errMsg, errLogId); } if (orderId || outOrderNo) { console.log('支付失败', errNo, errMsg, orderId, outOrderNo); } util.showErrorToast('支付失败'); }, }); } }); }, payOrder() { let that = this; util.request(api.OrderPrepay, { orderId: this.data.orderId }, 'POST').then(function (res) { if (res.errno === 0) { const payParam = res.data; console.log("支付过程开始") wx.requestPayment({ 'timeStamp': payParam.timeStamp, 'nonceStr': payParam.nonceStr, 'package': payParam.packageValue, 'signType': payParam.signType, 'paySign': payParam.paySign, 'success': function (res) { console.log("支付过程成功") that.getOrderDetail(); }, 'fail': function (res) { console.log("支付过程失败") util.showErrorToast('支付失败'); }, 'complete': function (res) { console.log("支付过程结束") } }); }else{ wx.showToast({ title: res.errmsg, icon: 'none' }); } }); }, // “取消订单”点击效果 cancelOrder: function () { let that = this; let orderInfo = that.data.orderInfo; wx.showModal({ title: '', content: '确定要取消此订单?', success: function (res) { if (res.confirm) { util.request(api.OrderCancel, { orderId: orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { wx.showToast({ title: '取消订单成功' }); util.redirect('/pages/ucenter/order/order'); } else { util.showErrorToast(res.errmsg); } }); } } }); }, // “取消订单并退款”点击效果 refundOrder: function () { let that = this; let orderInfo = that.data.orderInfo; wx.showModal({ title: '', content: '确定要取消此订单?', success: function (res) { if (res.confirm) { util.request(api.OrderRefund, { orderId: orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { wx.showToast({ title: '取消订单成功' }); util.redirect('/pages/ucenter/order/order'); } else { util.showErrorToast(res.errmsg); } }); } } }); }, // “删除”点击效果 deleteOrder: function () { let that = this; let orderInfo = that.data.orderInfo; wx.showModal({ title: '', content: '确定要删除此订单?', success: function (res) { if (res.confirm) { util.request(api.OrderDelete, { orderId: orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { wx.showToast({ title: '删除订单成功' }); util.redirect('/pages/ucenter/order/order'); } else { util.showErrorToast(res.errmsg); } }); } } }); }, // “待上门”点击效果 confirmOrder: function () { let that = this; let orderInfo = that.data.orderInfo; wx.showModal({ title: '', content: '确认上门服务?', success: function (res) { if (res.confirm) { util.request(api.OrderConfirm, { orderId: orderInfo.id }, 'POST').then(function (res) { if (res.errno === 0) { wx.showToast({ title: '确认上门成功!' }); util.redirect('/pages/ucenter/order/order'); } else { util.showErrorToast(res.errmsg); } }); } } }); }, // “申请售后”点击效果 aftersaleOrder: function () { wx.navigateTo({ url: '/pages/ucenter/applyRefund/applyRefund?id=' + this.data.orderId, }); // 0没申请 1申请没审核 2 客服审核通过 3 退款成功 4审核拒绝 5 用户取消 6退款中 // util.redirect('/pages/ucenter/aftersale/aftersale?id=' + this.data.orderId); // if (this.data.orderInfo.afterSaleStatus === 0||this.data.orderInfo.afterSaleStatus === 4) { // wx.navigateTo({ // url:'/pages/ucenter/applyRefund/applyRefund?id=' + this.data.orderId , // }); // } else { // util.redirect('/pages/ucenter/aftersaleDetail/aftersaleDetail?id=' + this.data.orderId); // } }, viewService() { wx.navigateTo({ url: '../serviceDetail/serviceDetail?orderId=' + this.data.orderId }); }, buyAgain(e) { let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/goods/goods?id=' + id, }); }, copyOrder() { wx.setClipboardData({ data: this.data.orderInfo.orderSn, success: function (res) { wx.getClipboardData({ success: function (res) { wx.showToast({ title: '订单编号复制成功', icon: 'success', duration: 2000 }); } }); } }); }, onReady: function () { // 页面渲染完成 }, onHide: function () { console.log('onHide'); // clearInterval(this.data.timer); }, onUnload: function () { console.log('onunload'); clearInterval(this.data.timer); }, cancelRefund() { let that = this; let afterSale = that.data.afterSale; wx.showModal({ title: '', content: '确认取消退款?', success: function (res) { if (res.confirm) { util.request(api.AftersaleCancel, { orderId: afterSale.orderId, id: afterSale.id }, 'POST').then(function (res) { if (res.errno === 0) { wx.showToast({ title: '操作成功!' }); that.getOrderDetail(); } else { util.showErrorToast(res.errmsg); } }); } } }); }, goReVisit(e) { let id = e.currentTarget.dataset.id; wx.navigateTo({ url: '/pages/extra/newRevisit/newRevisit?id=' + id, success: (res) => { }, fail: (res) => { }, }); }, goComplain(e) { let phone = e.currentTarget.dataset.phone; this.setData({ shopPhone: phone, complainTips: true }) }, cancelComplain() { this.setData({ complainTips: false }) }, confComplain() { wx.makePhoneCall({ phoneNumber: this.data.shopPhone }); }, goEditAppoint(e) { let id = e.currentTarget.dataset.id; 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; // } // } wx.navigateTo({ url: '/pages/ucenter/appointOrder/appointOrder?serviceId=' + id + '&orderId=' + this.data.orderInfo.id, success: (res) => { }, fail: (res) => { }, }); }, // goAppoint() { // console.log(this.data.orderId ); // wx.navigateTo({ // url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + this.data.orderId + '&serviceId=' + this.data.orderId, // }); // }, makeStorePhone(e) { wx.makePhoneCall({ phoneNumber: e.currentTarget.dataset.phone }); }, goAppoint(e) { let id = e.currentTarget.dataset.id; let detailId = e.currentTarget.dataset.detail; wx.navigateTo({ url: '/pages/ucenter/appointOrder/appointOrder?orderId=' + this.data.orderId + '&serviceId=' + detailId }) }, goIm(){ wx.navigateTo({ url: '/pages/im/im' }); }, });