wangzhibo
6 天以前 da0230346106bc810664488a2b152bc24f853a44
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
<template>
    <div class="logistics-item">
        <div class="row">
            <span>联系电话:</span>
 
            <span>{{ scope.address.phone }}({{ scope.address.contact }})</span>
        </div>
 
        <div class="row">
            <span>所在地区:</span>
 
            <span>
                {{ scope.address.province }}{{ scope.address.city }}{{ scope.address.district }}
            </span>
        </div>
 
        <div class="row">
            <span>详细地址:</span>
 
            <span>
                {{ scope.address.address }}
            </span>
        </div>
 
        <div class="btns" v-if="scope.status != 0">
            <el-button size="small" @click="toDeliver()" v-if="[1, 2].includes(scope.status!)">{{
                scope.status == 1 ? "发货" : "编辑"
            }}</el-button>
 
            <el-button size="small" @click="open" v-if="scope.logistics">查看物流</el-button>
        </div>
 
        <!-- 发货 -->
        <cl-form ref="Form" />
 
        <!-- 物流信息 -->
        <cl-dialog v-model="visible" title="物流信息" height="60vh">
            <div class="info" v-loading="loading">
                <template v-if="info?.expName">
                    <el-descriptions :column="1" :style="{ marginBottom: '10px' }">
                        <el-descriptions-item label="快递名称:">{{
                            info?.expName
                        }}</el-descriptions-item>
                        <el-descriptions-item label="物流单号:">{{
                            info?.number
                        }}</el-descriptions-item>
                    </el-descriptions>
 
                    <el-timeline>
                        <el-timeline-item
                            v-for="(item, index) in info?.list"
                            :key="index"
                            hollow
                            :timestamp="item.time"
                        >
                            {{ item.status }}
                        </el-timeline-item>
                    </el-timeline>
                </template>
 
                <el-empty :image-size="80" description="暂无物流信息" v-else />
            </div>
        </cl-dialog>
    </div>
</template>
 
<script lang="ts" setup name="order-logistics-item">
import { useForm } from "@cool-vue/crud";
import { useCool } from "/@/cool";
import { PropType, ref } from "vue";
import { ElMessage } from "element-plus";
import { useDict } from "/$/dict";
import { isString } from "lodash-es";
 
const props = defineProps({
    scope: {
        type: Object as PropType<Eps.OrderInfoEntity>,
        default: () => ({})
    },
    disabled: Boolean
});
 
const { service } = useCool();
const { dict } = useDict();
const Form = useForm();
 
// 物流信息
const info = ref<{
    expName: string;
    number: string;
    list: {
        time: string;
        status: string;
    }[];
}>();
 
// 是否可见
const visible = ref(false);
 
// 信息加载中
const loading = ref(false);
 
// 查看物流
async function open() {
    visible.value = true;
    loading.value = true;
 
    await service.order.info
        .logistics({
            orderId: props.scope.id
        })
        .then((res) => {
            info.value = undefined;
 
            if (isString(res)) {
                ElMessage.error(res);
            } else {
                info.value = res;
            }
        })
        .catch((err) => {
            ElMessage.error(err.message);
        });
 
    loading.value = false;
}
 
// 发货
function toDeliver() {
    const { num, company } = props.scope.logistics || {};
    const isEdit = props.scope.status != 1;
 
    Form.value?.open({
        title: isEdit ? "编辑单号" : "订单发货",
        width: "500px",
        props: {
            labelPosition: "top"
        },
        form: {
            num,
            company
        },
        items: [
            {
                label: "物流公司",
                prop: "company",
                required: true,
                component: {
                    name: "el-select",
                    options: dict.get("logisticsCompany"),
                    props: {
                        filterable: true
                    }
                }
            },
            {
                label: "物流单号",
                prop: "num",
                required: true,
                component: {
                    name: "el-input",
                    props: {
                        clearable: true
                    }
                }
            }
        ],
        on: {
            submit(data, { close, done }) {
                if (data.company == "sf") {
                    if (!data.num.includes(":")) {
                        data.num += `:${props.scope.address.phone.slice(-4)}`;
                    }
                }
 
                service.order.info[isEdit ? "update" : "deliver"]({
                    [isEdit ? "id" : "orderId"]: props.scope.id,
                    logistics: data
                })
                    .then(() => {
                        ElMessage.success("保存成功");
                        close();
 
                        // 更新状态为待收货
                        props.scope.status = 2;
 
                        // 更新物流信息
                        props.scope.logistics = data;
                    })
                    .catch((err) => {
                        ElMessage.error(err.message);
                        done();
                    });
            }
        }
    });
}
</script>
 
<style lang="scss" scoped>
.logistics-item {
    text-align: left;
    font-size: 12px;
    position: relative;
 
    .icon {
        position: absolute;
        right: -5px;
        top: 0;
        cursor: pointer;
        font-size: 16px;
        color: var(--el-color-danger);
    }
 
    .row {
        display: flex;
 
        & > span {
            &:first-child {
                flex-shrink: 0;
            }
        }
    }
 
    .btns {
        margin-top: 4px;
    }
}
</style>