优化代码

This commit is contained in:
TOP糯米 2023-03-14 22:13:22 +08:00
parent 7d3cbde1af
commit ab92a5a2ee
7 changed files with 106 additions and 124 deletions

View File

@ -1,53 +1,49 @@
<template> <template>
<view class="component-order-action"> <view class="component-order-action">
<block v-if="order.listType == listType.T1"> <!-- 购买 -->
<block v-if="order.state == state[order.listType].S1"> <block v-if="order.listType == 't1'">
<block v-if="order.state == 0">
<view class="btn" @click.stop="payOrder"> <view class="btn" @click.stop="payOrder">
<text>立即支付</text> <text>立即支付</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S2"> <block v-if="order.state == 1">
<view class="btn" @click.stop="cancelOrder"> <view class="btn" @click.stop="cancelOrder">
<text>取消订单</text> <text>取消订单</text>
</view> </view>
</block> </block>
</block> </block>
<block v-if="order.listType == listType.T2"> <!-- /议价 -->
<block v-if="order.state == state[order.listType].S1"> <block v-if="order.listType == 't2'">
<block v-if="order.state == 0">
<view class="btn" @click.stop="cancelOrder"> <view class="btn" @click.stop="cancelOrder">
<text>取消订单</text> <text>取消订单</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S2"> <block v-if="order.state == 1">
<view class="btn" @click.stop="payOrder"> <view class="btn" @click.stop="payOrder">
<text>立即支付</text> <text>立即支付</text>
</view> </view>
</block> </block>
</block> </block>
<!-- T1T2公共操作 --> <!-- 购买/议价公共操作 -->
<block v-if="order.listType == listType.T1 || order.listType == listType.T2"> <block v-if="order.listType == 't1' || order.listType == 't2'">
<block <block v-if="order.state == 2 || order.state == 4 || order.state == 5">
v-if="
order.state == state[order.listType].S3 ||
order.state == state[order.listType].S4 ||
order.state == state[order.listType].S5
"
>
<view class="btn" @click.stop="refundOrder"> <view class="btn" @click.stop="refundOrder">
<text>申请退款</text> <text>申请退款</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S4"> <block v-if="order.state == 4">
<view class="btn" @click.stop="payRetainage"> <view class="btn" @click.stop="payRetainage">
<text>支付尾款</text> <text>支付尾款</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S5"> <block v-if="order.state == 5">
<view class="btn" @click.stop="confirmOrder"> <view class="btn" @click.stop="confirmOrder">
<text>确认完成</text> <text>确认完成</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S6"> <block v-if="order.state == 6">
<view class="btn" @click.stop="appraiseOrder"> <view class="btn" @click.stop="appraiseOrder">
<text>评价师傅</text> <text>评价师傅</text>
</view> </view>
@ -56,19 +52,32 @@
</view> </view>
</block> </block>
</block> </block>
<!-- 货运 -->
<block v-if="order.listType == 't3'">
<block v-if="order.state == 0">
<view class="btn" @click.stop="payDistributionOrder">
<text>立即支付</text>
</view>
</block>
<block v-if="order.state == 1 || order.state == 2">
<view class="btn" @click.stop="">
<text>确认完成</text>
</view>
</block>
</block>
<!-- 退款 --> <!-- 退款 -->
<block v-if="order.listType == listType.T4"> <block v-if="order.listType == 't4'">
<block v-if="order.state == state[order.listType].S1"> <block v-if="order.state == 0">
<view class="btn" @click.stop="cancelRefund"> <view class="btn" @click.stop="cancelRefund">
<text>取消申请</text> <text>取消申请</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S3"> <block v-if="order.state == 2">
<view class="btn" @click.stop="showReason"> <view class="btn" @click.stop="showReason">
<text>查看未通过原因</text> <text>查看未通过原因</text>
</view> </view>
</block> </block>
<block v-if="order.state == state[order.listType].S2 || order.state == state[order.listType].S3"> <block v-if="order.state == 1 || order.state == 2">
<view class="del" @click.stop="delOrder"> <view class="del" @click.stop="delOrder">
<text class="iconfont icon-shanchu"></text> <text class="iconfont icon-shanchu"></text>
</view> </view>
@ -81,10 +90,7 @@
export default { export default {
name: "component-order-action", name: "component-order-action",
data() { data() {
return { return {};
listType: this.$models.order.listType,
state: this.$models.order.state,
};
}, },
props: { props: {
order: { order: {
@ -101,7 +107,9 @@ export default {
* 支付 * 支付
*/ */
payOrder() { payOrder() {
this.$emit("payOrder"); this.$models.order.payOrder(this.order.id).then(() => {
this.$emit("afterPay");
});
}, },
/** /**
* 支付尾款 * 支付尾款
@ -109,6 +117,11 @@ export default {
payRetainage() { payRetainage() {
this.$emit("payRetainage"); this.$emit("payRetainage");
}, },
payDistributionOrder() {
this.$models.service.payDistributionOrder(this.order.id).then(() => {
this.$emit("afterPay");
});
},
/** /**
* 取消 * 取消
*/ */

View File

@ -32,12 +32,10 @@
<text class="text">{{ order.serviceTime }}</text> <text class="text">{{ order.serviceTime }}</text>
</view> </view>
<!-- 购买订单|/议价订单|货运订单 可展示师傅信息 --> <!-- 购买订单|/议价订单|货运订单 可展示师傅信息 -->
<block v-if="order.listType == listType.T1 || order.listType == listType.T2 || order.listType == listType.T3"> <block v-if="order.listType == 't1' || order.listType == 't2' || 't3'">
<view class="order-worker-box"> <view class="order-worker-box">
<!-- 报价订单未选择师傅 展示师傅列表 --> <!-- 报价订单未选择师傅 展示师傅列表 -->
<block <block v-if="order.listType == 't2' && order.orderType == 1 && order.state == 0">
v-if="order.listType == listType.T2 && order.orderType == 2 && order.state == state[order.listType].S1"
>
<view class="worker-list-group"> <view class="worker-list-group">
<view class="list-group"> <view class="list-group">
<view class="list-item" v-for="(item, index) in previewWorkerList" :key="index"> <view class="list-item" v-for="(item, index) in previewWorkerList" :key="index">
@ -54,10 +52,8 @@
<!-- 购买订单|/议价订单已选择师傅 展示师傅简介 --> <!-- 购买订单|/议价订单已选择师傅 展示师傅简介 -->
<block <block
v-if=" v-if="
(order.listType == listType.T1 && (order.listType == 't1' && order.state != 0 && order.state != 1) ||
order.state != state[order.listType].S1 && (order.listType == 't2' && order.state != 0)
order.state != state[order.listType].S2) ||
(order.listType == listType.T2 && order.state != state[order.listType].S1)
" "
> >
<view class="worker-item-box"> <view class="worker-item-box">
@ -79,8 +75,6 @@ export default {
name: "component-order-item", name: "component-order-item",
data() { data() {
return { return {
listType: this.$models.order.listType,
state: this.$models.order.state,
stateText: "", stateText: "",
stateDesc: "", stateDesc: "",
previewWorkerList: [], previewWorkerList: [],

View File

@ -2,40 +2,6 @@ import Vue from "vue"
let prototype = Vue.prototype; let prototype = Vue.prototype;
export default { export default {
listType: {
// 普通订单
T1: 't1',
// 一口价/报价订单
T2: 't2',
// 货运订单
T3: 't3',
// 退款订单
T4: 't4',
},
state: {
t1: {
S1: 0,
S2: 1,
S3: 2,
S4: 4,
S5: 5,
S6: 6,
},
t2: {
S1: 0,
S2: 1,
S3: 2,
S4: 4,
S5: 5,
S6: 6,
},
t3: {},
t4: {
S1: 7,
S2: 8,
S3: 9,
},
},
stateTextColor(listType, orderType, state) { stateTextColor(listType, orderType, state) {
switch (state) { switch (state) {
default: default:
@ -43,40 +9,44 @@ export default {
} }
}, },
stateText(listType, orderType, state) { stateText(listType, orderType, state) {
let current = this.state[listType]; if (listType == 't1') {
if (listType == this.listType.T1) {
switch (state) { switch (state) {
case current.S1: return ['待支付', '为保证师傅按时上门,建议尽快选择师傅并完成支付']; case 0: return ['待支付', '为保证师傅按时上门,建议尽快选择师傅并完成支付'];
case current.S2: return ['待师傅接单']; case 1: return ['待师傅接单'];
case current.S3: return ['服务中']; case 2: return ['服务中'];
case current.S4: return ['待支付尾款']; case 4: return ['待支付尾款'];
case current.S5: return ['服务已完成,待确认']; case 5: return ['服务已完成,待确认'];
case current.S6: return ['订单已完成']; case 6: return ['订单已完成'];
} }
} else if (listType == this.listType.T2) { } else if (listType == 't2') {
switch (state) { switch (state) {
case current.S1: case 0:
if (orderType == 1) { if (orderType == 2) {
return ['待师傅接单']; return ['待师傅接单'];
} }
return ['待选择师傅']; return ['待选择师傅'];
case current.S2: case 1:
if (orderType == 1) { if (orderType == 2) {
return ['师傅已接单,待支付']; return ['师傅已接单,待支付'];
} }
return ['已选择师傅,待支付']; return ['已选择师傅,待支付'];
case current.S3: return ['服务中']; case 2: return ['服务中'];
case current.S4: return ['待支付尾款']; case 4: return ['待支付尾款'];
case current.S5: return ['服务已完成,待确认']; case 5: return ['服务已完成,待确认'];
case current.S6: return ['订单已完成']; case 6: return ['订单已完成'];
} }
} else if (listType == this.listType.T3) { } else if (listType == 't3') {
return ['未知状态'];
} else if (listType == this.listType.T4) {
switch (state) { switch (state) {
case current.S1: return ['退款申请审核中']; case 0: return ['待支付'];
case current.S2: return ['已退款']; case 1: return ['待接单'];
case current.S3: return ['退款未通过']; case 2: return ['进行中'];
case 3: return ['已完成'];
}
} else if (listType == 't4') {
switch (state) {
case 0: return ['退款申请审核中'];
case 1: return ['已退款'];
case 2: return ['退款未通过'];
} }
} }
@ -88,7 +58,7 @@ export default {
createOrder(order) { createOrder(order) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
prototype.$request({ prototype.$request({
api: "order.createOrder", api: "order.create.t1",
data: order, data: order,
}).then((response) => { }).then((response) => {
if (response.code == 1) { if (response.code == 1) {
@ -104,7 +74,7 @@ export default {
payOrder(id) { payOrder(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
prototype.$request({ prototype.$request({
api: "order.pay", api: "order.pay.t1",
data: { data: {
id: id id: id
} }
@ -113,12 +83,13 @@ export default {
uni.requestPayment({ uni.requestPayment({
...response.data, ...response.data,
provider: "wxpay", provider: "wxpay",
success(res) { success() {
return resolve(); resolve();
} },
fail() {
reject();
},
}); });
} else {
return reject(response.msg);
} }
}).catch(e => { }).catch(e => {
throw e throw e
@ -179,5 +150,5 @@ export default {
return reject(response.msg); return reject(response.msg);
}).catch(e => { }); }).catch(e => { });
}); });
} },
} }

View File

@ -147,7 +147,7 @@ export default {
createDemandOrder(data) { createDemandOrder(data) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
prototype.$request({ prototype.$request({
api: "order.createDemandOrder", api: "order.create.t2",
data: data, data: data,
}).then(response => { }).then(response => {
if (response.code == 1) { if (response.code == 1) {

View File

@ -284,8 +284,8 @@ export default {
* 选择分类 * 选择分类
*/ */
selectCate(e) { selectCate(e) {
this.cateId = this.cateList[this.cateId].id; this.cateId = this.cateList[e.detail.value].id;
this.cateText = this.cateList[this.cateId].name; this.cateText = this.cateList[e.detail.value].name;
}, },
/** /**
* 上传图片 * 上传图片
@ -370,10 +370,10 @@ export default {
baoxian: this.insurance ? 1 : 0, baoxian: this.insurance ? 1 : 0,
money: this.price, money: this.price,
}) })
.then((orderData) => { .then((response) => {
if (this.type == 2) { this.$utils.toast(response.msg).then(() => {
this.$models.order.payOrder(orderData.oid); this.$utils.toPage("/pages/order/order", {}, "switch");
} });
}); });
}, },
}, },

View File

@ -113,7 +113,7 @@
<text class="text">客服</text> <text class="text">客服</text>
</view> </view>
<view class="action"> <view class="action">
<order-action :order="order" /> <order-action :order="order" @afterPay="afterPay" />
</view> </view>
</view> </view>
</app-layout> </app-layout>
@ -225,6 +225,9 @@ export default {
}, },
}); });
}, },
/**
* 加载详情
*/
loadDetail() { loadDetail() {
this.$models.order this.$models.order
.orderDetail({ .orderDetail({
@ -255,6 +258,9 @@ export default {
}); });
}); });
}, },
afterPay() {
this.loadDetail();
},
}, },
}; };
</script> </script>

View File

@ -31,7 +31,7 @@
> >
<order-item :order="item" :index="index"> <order-item :order="item" :index="index">
<view class="action-group"> <view class="action-group">
<order-action :order="item" @payOrder="payOrder(item.id)" /> <order-action :order="item" @afterPay="afterPay" />
</view> </view>
</order-item> </order-item>
</view> </view>
@ -60,7 +60,7 @@ export default {
tabHeight: 0, tabHeight: 0,
tabList: [ tabList: [
{ {
listType: this.$models.order.listType.T1, listType: "t1",
name: "购买订单", name: "购买订单",
api: "order.list.t1", api: "order.list.t1",
status: -1, status: -1,
@ -69,7 +69,7 @@ export default {
list: [], list: [],
}, },
{ {
listType: this.$models.order.listType.T2, listType: "t2",
name: "报/议价订单", name: "报/议价订单",
api: "order.list.t2", api: "order.list.t2",
status: -1, status: -1,
@ -78,7 +78,7 @@ export default {
list: [], list: [],
}, },
{ {
listType: this.$models.order.listType.T3, listType: "t3",
name: "货运订单", name: "货运订单",
api: "order.list.t3", api: "order.list.t3",
status: -1, status: -1,
@ -87,7 +87,7 @@ export default {
list: [], list: [],
}, },
{ {
listType: this.$models.order.listType.T4, listType: "t4",
name: "退款记录", name: "退款记录",
api: "order.list.t4", api: "order.list.t4",
status: 1, status: 1,
@ -104,10 +104,10 @@ export default {
OrderAction, OrderAction,
WidgetLoadMore, WidgetLoadMore,
}, },
onLoad() { onLoad() {},
this.switchTab(0); onShow() {
this.switchTab(this.tabIndex);
}, },
onShow() {},
onReady() {}, onReady() {},
onReachBottom() { onReachBottom() {
this.loadData(); this.loadData();
@ -181,18 +181,16 @@ export default {
toDetail(id, state, listType, orderType) { toDetail(id, state, listType, orderType) {
let tab = "detail"; let tab = "detail";
// //
if (listType == this.$models.order.listType.T2 && orderType == 2 && state == this.$models.order.state[listType].T1) { if (listType == "t2" && orderType == 2 && state == 0) {
tab = "worker"; tab = "worker";
} }
this.$utils.toPage("/pages/order/detail?list=" + listType + "&tab=" + tab + "&id=" + id); this.$utils.toPage("/pages/order/detail?list=" + listType + "&tab=" + tab + "&id=" + id);
}, },
/** /**
* 支付订单 * 支付后操作
*/ */
payOrder(id) { afterPay() {
this.$models.order.payOrder(id).then(() => { this.switchTab(this.tabIndex);
console.log("支付成功");
});
}, },
}, },
}; };