|
|
@@ -0,0 +1,333 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import {ref, computed} from "vue"
|
|
|
+import {ElTable} from "element-plus"
|
|
|
+import {deliverOrder, getOrder, getOrderById, payOrder, commentOrder, calculateOrder} from "../api/order"
|
|
|
+import {parseOrderType, parseTime} from "../utils";
|
|
|
+
|
|
|
+const props = defineProps({
|
|
|
+ orderId: {
|
|
|
+ type: Number,
|
|
|
+ required: true
|
|
|
+ }
|
|
|
+})
|
|
|
+
|
|
|
+const role = sessionStorage.getItem("role")
|
|
|
+
|
|
|
+const orderDialogVisible = ref(false)
|
|
|
+const commentDialogVisible = ref(false)
|
|
|
+
|
|
|
+const userId = ref(0)
|
|
|
+const productId = ref(0)
|
|
|
+const productName = ref('')
|
|
|
+const price = ref(0)
|
|
|
+const amount = ref(0)
|
|
|
+const paid = ref(0)
|
|
|
+const type = ref('')
|
|
|
+const content = ref('')
|
|
|
+const rating = ref(0)
|
|
|
+const status = ref('')
|
|
|
+const createTime = ref('')
|
|
|
+const finishTime = ref('')
|
|
|
+const storeId = ref(0)
|
|
|
+
|
|
|
+const totalPrice = ref(0)
|
|
|
+const discountPrice = ref(0)
|
|
|
+
|
|
|
+getOrderDetail()
|
|
|
+
|
|
|
+function getOrderDetail() {
|
|
|
+ getOrderById(props.orderId).then(res => {
|
|
|
+ userId.value = res.data.result.userId
|
|
|
+ productId.value = res.data.result.productId
|
|
|
+ productName.value = res.data.result.productName
|
|
|
+ amount.value = res.data.result.amount
|
|
|
+ price.value = res.data.result.price
|
|
|
+ paid.value = res.data.result.paid
|
|
|
+ type.value = res.data.result.type
|
|
|
+ content.value = res.data.result.content
|
|
|
+ rating.value = res.data.result.rating
|
|
|
+ status.value = res.data.result.status
|
|
|
+ createTime.value = res.data.result.createTime
|
|
|
+ finishTime.value = res.data.result.finishTime
|
|
|
+ storeId.value = res.data.result.storeId
|
|
|
+
|
|
|
+ totalPrice.value = amount.value * price.value
|
|
|
+ discountPrice.value = totalPrice.value
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function handlePay() {
|
|
|
+ orderDialogVisible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+function handleConfirmOrder() {
|
|
|
+ payOrder(props.orderId).then(res => {
|
|
|
+ if (res.data.code === '000') {
|
|
|
+ ElMessage({
|
|
|
+ message: '订单提交成功!',
|
|
|
+ type: 'success',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ getOrderDetail()
|
|
|
+ } else if (res.data.code === '400') {
|
|
|
+ ElMessage({
|
|
|
+ message: res.data.msg,
|
|
|
+ type: 'error',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function handlePayDialogClose() {
|
|
|
+ orderDialogVisible.value = false
|
|
|
+}
|
|
|
+
|
|
|
+function handleDeliver() {
|
|
|
+ deliverOrder(props.orderId).then(res => {
|
|
|
+ if (res.data.code === '000') {
|
|
|
+ ElMessage({
|
|
|
+ message: '订单发货成功!',
|
|
|
+ type: 'success',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ getOrderDetail()
|
|
|
+ } else if (res.data.code === '400') {
|
|
|
+ ElMessage({
|
|
|
+ message: res.data.msg,
|
|
|
+ type: 'error',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function handleGet() {
|
|
|
+ getOrder(props.orderId).then(res => {
|
|
|
+ if (res.data.code === '000') {
|
|
|
+ ElMessage({
|
|
|
+ message: '订单收货成功!',
|
|
|
+ type: 'success',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ getOrderDetail()
|
|
|
+ } else if (res.data.code === '400') {
|
|
|
+ ElMessage({
|
|
|
+ message: res.data.msg,
|
|
|
+ type: 'error',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function handleComment() {
|
|
|
+ commentDialogVisible.value = true
|
|
|
+}
|
|
|
+
|
|
|
+function handleSendComment() {
|
|
|
+
|
|
|
+ const payload = {
|
|
|
+ orderId: props.orderId,
|
|
|
+ comment: content.value,
|
|
|
+ rating: rating.value
|
|
|
+ }
|
|
|
+
|
|
|
+ commentOrder(payload).then(res => {
|
|
|
+ if (res.data.code === '000') {
|
|
|
+ ElMessage({
|
|
|
+ message: '评价成功!',
|
|
|
+ type: 'success',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ getOrderDetail()
|
|
|
+ commentDialogVisible.value = false
|
|
|
+ } else {
|
|
|
+ ElMessage({
|
|
|
+ message: res.data.msg,
|
|
|
+ type: 'error',
|
|
|
+ center: true,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+function parsePaid() {
|
|
|
+ if (paid.value === null) {
|
|
|
+ return "暂未支付"
|
|
|
+ } else {
|
|
|
+ return paid.value + " 元"
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// 对于变化的内容使用计算属性返回响应式结果
|
|
|
+const statusText = computed(() => {
|
|
|
+ switch (status.value) {
|
|
|
+ case 'UNPAID':
|
|
|
+ return "待顾客支付"
|
|
|
+ case 'UNSEND':
|
|
|
+ return "待商家发货"
|
|
|
+ case 'UNGET':
|
|
|
+ return "待顾客收货"
|
|
|
+ case 'UNCOMMENT':
|
|
|
+ return "待顾客评价"
|
|
|
+ case 'DONE':
|
|
|
+ return "已完成"
|
|
|
+ default:
|
|
|
+ return "状态标签"
|
|
|
+ }
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|
|
|
+
|
|
|
+<template>
|
|
|
+ <el-card class="order-item-card" shadow="hover">
|
|
|
+
|
|
|
+ <template #header>
|
|
|
+ <div class="card-header">
|
|
|
+ <div>
|
|
|
+ <span> 订单号 {{ props.orderId }}</span>
|
|
|
+ <el-tag style="margin-left: 8px" v-if="status!=='DONE'" type="info"> {{ statusText }}</el-tag>
|
|
|
+ <el-tag style="margin-left: 8px" v-if="status==='DONE'" type="success"> {{ statusText }}</el-tag>
|
|
|
+ </div>
|
|
|
+ <el-button @click="handlePay" v-if="status==='UNPAID' && role==='CUSTOMER'"
|
|
|
+ class="status-change-button" size="small" type="primary">
|
|
|
+ 支付
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="handleDeliver" v-if="status==='UNSEND' && role==='STAFF'"
|
|
|
+ class="status-change-button" size="small" type="primary">
|
|
|
+ 发货
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="handleGet" v-if="status==='UNGET' && role==='CUSTOMER'"
|
|
|
+ class="status-change-button" size="small" type="primary">
|
|
|
+ 收货
|
|
|
+ </el-button>
|
|
|
+ <el-button @click="handleComment" v-if="status==='UNCOMMENT'&& role==='CUSTOMER'"
|
|
|
+ class="status-change-button" size="small" type="primary">
|
|
|
+ 评价
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <el-descriptions
|
|
|
+ :column="1"
|
|
|
+ >
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="商品">
|
|
|
+ {{ productName }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="数量">
|
|
|
+ {{ amount }} 件
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="订单原价">
|
|
|
+ {{ totalPrice }} 元
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="实付金额">
|
|
|
+ {{ parsePaid() }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="取货类型">
|
|
|
+ <el-tag> {{ parseOrderType(type) }}</el-tag>
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="创建时间">
|
|
|
+ {{ parseTime(createTime) }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="完成时间">
|
|
|
+ {{ parseTime(finishTime) }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="评分" v-if="status==='DONE'">
|
|
|
+ <el-rate
|
|
|
+ v-model="rating"
|
|
|
+ disabled
|
|
|
+ show-score
|
|
|
+ text-color="#ff9900"
|
|
|
+ score-template="{value} 分"
|
|
|
+ size="small"
|
|
|
+ />
|
|
|
+ </el-descriptions-item>
|
|
|
+ <el-descriptions-item style="font-size: 15px" label="评价内容" v-if="status==='DONE'">
|
|
|
+ {{ content }}
|
|
|
+ </el-descriptions-item>
|
|
|
+ </el-descriptions>
|
|
|
+ </el-card>
|
|
|
+
|
|
|
+ <el-dialog v-model="orderDialogVisible" :before-close="handlePayDialogClose">
|
|
|
+ <el-row>
|
|
|
+ <span class="pay-dialog-title">订单支付</span>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <div>
|
|
|
+ <el-form>
|
|
|
+ <el-form-item>
|
|
|
+ <label>购买数量:</label>
|
|
|
+ {{ amount }} 件
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label>折扣前总价:</label>
|
|
|
+ {{ totalPrice }} 元
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label>提货方式:</label>
|
|
|
+ {{ parseOrderType(type) }}
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <label>折扣后金额:</label>
|
|
|
+ {{ discountPrice }} 元
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <el-button @click="handleConfirmOrder" type="primary" plain>
|
|
|
+ 确认支付
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
+ <el-dialog
|
|
|
+ v-model="commentDialogVisible"
|
|
|
+ title="发起评价"
|
|
|
+ >
|
|
|
+ <el-form>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <span style="margin-right: 30px">商品满意度</span>
|
|
|
+ <el-rate v-model="rating" clearable
|
|
|
+ :texts="['非常差', '差', '普通', '好', '非常好']"
|
|
|
+ show-text/>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <label>文字评价</label>
|
|
|
+ <el-input v-model="content" type="textarea" rows="10" placeholder="说点什么吧">
|
|
|
+
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" @click="handleSendComment">评价</el-button>
|
|
|
+ <el-button @click="commentDialogVisible = false">取消</el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ </el-dialog>
|
|
|
+
|
|
|
+</template>
|
|
|
+
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+.order-item-card {
|
|
|
+ margin: 20px;
|
|
|
+ border-radius: 8px;
|
|
|
+ min-width: max-content;
|
|
|
+}
|
|
|
+
|
|
|
+.card-header {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: space-between;
|
|
|
+}
|
|
|
+
|
|
|
+.status-change-button {
|
|
|
+ margin-left: 10px;
|
|
|
+}
|
|
|
+
|
|
|
+.pay-dialog-title {
|
|
|
+ font-size: 30px;
|
|
|
+ margin-bottom: 20px;
|
|
|
+}
|
|
|
+</style>
|