优化代码

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>
<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">
<text>立即支付</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S2">
<block v-if="order.state == 1">
<view class="btn" @click.stop="cancelOrder">
<text>取消订单</text>
</view>
</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">
<text>取消订单</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S2">
<block v-if="order.state == 1">
<view class="btn" @click.stop="payOrder">
<text>立即支付</text>
</view>
</block>
</block>
<!-- T1T2公共操作 -->
<block v-if="order.listType == listType.T1 || order.listType == listType.T2">
<block
v-if="
order.state == state[order.listType].S3 ||
order.state == state[order.listType].S4 ||
order.state == state[order.listType].S5
"
>
<!-- 购买/议价公共操作 -->
<block v-if="order.listType == 't1' || order.listType == 't2'">
<block v-if="order.state == 2 || order.state == 4 || order.state == 5">
<view class="btn" @click.stop="refundOrder">
<text>申请退款</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S4">
<block v-if="order.state == 4">
<view class="btn" @click.stop="payRetainage">
<text>支付尾款</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S5">
<block v-if="order.state == 5">
<view class="btn" @click.stop="confirmOrder">
<text>确认完成</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S6">
<block v-if="order.state == 6">
<view class="btn" @click.stop="appraiseOrder">
<text>评价师傅</text>
</view>
@ -56,19 +52,32 @@
</view>
</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.state == state[order.listType].S1">
<block v-if="order.listType == 't4'">
<block v-if="order.state == 0">
<view class="btn" @click.stop="cancelRefund">
<text>取消申请</text>
</view>
</block>
<block v-if="order.state == state[order.listType].S3">
<block v-if="order.state == 2">
<view class="btn" @click.stop="showReason">
<text>查看未通过原因</text>
</view>
</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">
<text class="iconfont icon-shanchu"></text>
</view>
@ -81,10 +90,7 @@
export default {
name: "component-order-action",
data() {
return {
listType: this.$models.order.listType,
state: this.$models.order.state,
};
return {};
},
props: {
order: {
@ -101,7 +107,9 @@ export default {
* 支付
*/
payOrder() {
this.$emit("payOrder");
this.$models.order.payOrder(this.order.id).then(() => {
this.$emit("afterPay");
});
},
/**
* 支付尾款
@ -109,6 +117,11 @@ export default {
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>
</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">
<!-- 报价订单未选择师傅 展示师傅列表 -->
<block
v-if="order.listType == listType.T2 && order.orderType == 2 && order.state == state[order.listType].S1"
>
<block v-if="order.listType == 't2' && order.orderType == 1 && order.state == 0">
<view class="worker-list-group">
<view class="list-group">
<view class="list-item" v-for="(item, index) in previewWorkerList" :key="index">
@ -54,10 +52,8 @@
<!-- 购买订单|/议价订单已选择师傅 展示师傅简介 -->
<block
v-if="
(order.listType == listType.T1 &&
order.state != state[order.listType].S1 &&
order.state != state[order.listType].S2) ||
(order.listType == listType.T2 && order.state != state[order.listType].S1)
(order.listType == 't1' && order.state != 0 && order.state != 1) ||
(order.listType == 't2' && order.state != 0)
"
>
<view class="worker-item-box">
@ -79,8 +75,6 @@ export default {
name: "component-order-item",
data() {
return {
listType: this.$models.order.listType,
state: this.$models.order.state,
stateText: "",
stateDesc: "",
previewWorkerList: [],

View File

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

View File

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

View File

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

View File

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

View File

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