You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
6.7 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// pages/order/reason/reason.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
reasonItems: [{
name: "改主意了",
select: false
}, {
name: "重复下单",
select: false
},
{
name: "产品缺货",
select: false
}, {
name: "等待时间过长",
select: false
},
{
name: "店员态度不好",
select: false
}, {
name: "添加或删除产品",
select: false
},
{
name: "无法支付订单",
select: false
}, {
name: "找不到餐厅",
select: false
},
],
storeId: "",
ticketId: "",
ticketNo: "",
type: "",
reason: ""
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
if (options.type == 'cancel') {
wx.setNavigationBarTitle({
title: '取消订单',
});
} else if (options.type == 'refund') {
wx.setNavigationBarTitle({
title: '申请退款',
});
}
this.setData({
type: options.type,
storeId: options.storeId,
ticketId: options.ticketId,
ticketNo: options.ticketNo
});
},
/**
* 取消/退款操作
* 1:查询订单
* 2:校验订单状态
* 3:根据type执行相应操作
*/
bindCancelOrder: function() {
var that = this;
// 查询订单信息
var params = {
"method": "wxdc.sales.order.info",
"wxStoreId": that.data.storeId,
"memberId": app.userId,
"ticketId": that.data.ticketId,
"ticketNo": that.data.ticketNo
}
var ignores = [];
wx.showLoading({
title: '加载中...'
});
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores,
function(json) {
console.log("订单取消", json);
wx.hideLoading();
var result = json.data;
if (result.status == 1) {
var order = result.data;
// 执行取消/退款操作
if (undefined != order && null != order) {
var type = that.data.type;
if (type == "cancel") {
that.cancelOrder(order);
} else if (type == "refund") {
that.refundOrder(order);
} else {
app.msg.showMsg("提示", "操作类型不存在");
}
} else {
app.msg.showMsg("提示", "订单不存在");
}
} else {
app.msg.showMsg("提示", "操作失败:" + result.message);
}
},
function(error) {
console.log(error);
app.msg.showMsg("提示", "网络中断,操作失败");
}
);
},
/**
* 取消订单
*/
cancelOrder: function(order) {
var that = this;
// 0-等待付款;1-已支付;2-已退单;3-已取消;4-商家已确认;5-已完成;
if (order.status != 1) {
if (order.status == 3) {
wx.showModal({
title: '提示',
content: '订单已取消,是否返回上一级页面',
success: function(res) {
console.log(res);
if (res.confirm) {
that.returnBack();
}
}
})
} else {
app.msg.showMsg("提示", "订单状态非法");
}
return;
}
var params = {
"method": "wxdc.sales.order.cancel",
"storeId": order.storeId,
"memberId": app.userId,
"ticketId": order.ticketId,
"cancelReason": that.getReason()
}
// 不签名参数
var ignores = [];
ignores.push("cancelReason");
wx.showLoading({
title: '加载中...'
});
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores,
function(json) {
wx.hideLoading();
var result = json.data;
if (result.status == 1) {
that.returnBack();
} else {
var msg = result.message;
if (msg.indexOf('已取消') > -1) {
that.returnBack();
} else {
app.msg.showMsg("提示", "操作失败:" + msg);
}
}
},
function(error) {
console.log(error);
app.msg.showMsg("提示", "网络中断,操作失败");
}
);
},
/**
* 退单
*/
refundOrder: function(order) {
var that = this;
// 0-等待付款;1-已支付;2-已退单;3-已取消;4-商家已确认;5-已完成;
if (order.status != 4) {
if (order.status == 2) {
wx.showModal({
title: '提示',
content: '订单已退款,是否返回上一级页面',
success: function(res) {
if (res.confirm) {
that.returnBack();
}
}
});
} else {
app.msg.showMsg("提示", "订单状态非法");
}
return;
}
var params = {
"method": "wxdc.order.refund.user.apply",
"wxStoreId": order.storeId,
"memberId": app.userId,
"ticketId": order.ticketId,
"refundReason": that.getReason()
}
// 不签名参数
var ignores = [];
ignores.push("refundReason");
wx.showLoading({
title: '加载中...'
});
app.jsapi.api(app.globalData.appKey, app.globalData.appSecret, app.globalData.serverUrl).ajax(params, ignores,
function(json) {
wx.hideLoading();
var result = json.data;
if (result.status == 1) {
that.returnBack();
} else {
var msg = result.message;
if (msg.indexOf('已退单') > -1) {
that.returnBack();
} else {
app.msg.showMsg("提示", "操作失败:" + msg);
}
}
},
function(error) {
console.log(error);
app.msg.showMsg("提示", "网络中断,操作失败");
}
);
},
/**
* 返回上一个页面
*/
returnBack: function() {
var pages = getCurrentPages();
var sourcePage = pages[pages.length - 2];
sourcePage.loadOrderInfo();
wx.navigateBack({
delta: 1
});
},
/**
* 原因选中
*/
bindSelect: function(e) {
var index = e.currentTarget.dataset.index;
var reasonItems = this.data.reasonItems;
reasonItems[index].select = !reasonItems[index].select;
this.setData({
reasonItems: reasonItems
});
},
/**
* 输入原因
*/
inputReason: function(e) {
this.setData({
reason: e.detail.value
});
},
/**
* 获取取消/退款原因
*/
getReason: function() {
var reason = "";
var reasonItems = this.data.reasonItems;
reasonItems.forEach(function(item, index) {
if (item.select) {
reason = reason.length > 0 ? reason + "" + item.name : item.name;
}
});
return reason += this.data.reason;
}
})