<template>
|
<div class="table-list">
|
<!-- 搜索相关 -->
|
<el-form ref="searchForm" :model="searchForm" class="search-form" inline>
|
<el-form-item label="订单号">
|
<el-input v-model="searchForm.order_no" placeholder="请输入订单号" />
|
</el-form-item>
|
<el-form-item label="团购商品">
|
<el-input v-model="searchForm.product_name" placeholder="请输入团购商品名称" />
|
</el-form-item>
|
<el-form-item label="用户昵称">
|
<el-input v-model="searchForm.nickName" placeholder="请输入用户昵称" />
|
</el-form-item>
|
<el-form-item label="状态">
|
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
<el-option label="待支付" :value="0"></el-option>
|
<el-option label="团购中" :value="1"></el-option>
|
<el-option label="已完成" :value="2"></el-option>
|
<el-option label="已取消" :value="-1"></el-option>
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" @click="onSearch">查询</el-button>
|
<el-button @click="onReset">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<!-- 表格 -->
|
<el-table
|
:data="list"
|
v-loading="loading"
|
style="width: 100%">
|
<el-table-column prop="groupbuy_bill_id" label="ID" width="100" />
|
<el-table-column prop="order_no" label="订单号" width="200" />
|
<el-table-column prop="product.product.product_name" label="团购商品" min-width="200" />
|
<el-table-column prop="user.nickName" label="用户" width="120" />
|
<el-table-column prop="actual_people" label="当前人数" width="100" />
|
<el-table-column prop="groupbuy_num" label="成团人数" width="100" />
|
<el-table-column prop="total_price" label="总价" width="100">
|
<template slot-scope="scope">
|
¥{{ scope.row.total_price }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="actual_price" label="实付" width="100">
|
<template slot-scope="scope">
|
¥{{ scope.row.actual_price }}
|
</template>
|
</el-table-column>
|
<el-table-column prop="status" label="状态" width="100">
|
<template slot-scope="scope">
|
<el-tag :type="getStatusTagType(scope.row.status)">
|
{{ getStatusText(scope.row.status) }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="创建时间" width="160">
|
<template slot-scope="scope">
|
{{ formatDate(scope.row.create_time) }}
|
</template>
|
</el-table-column>
|
<el-table-column label="操作" width="150">
|
<template slot-scope="scope">
|
<el-button size="mini" @click="onView(scope.row)">查看</el-button>
|
<el-button size="mini" type="success" @click="onUpdateStatus(scope.row)" v-if="canUpdateStatus(scope.row)">
|
{{ getStatusButtonText(scope.row) }}
|
</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 分页 -->
|
<div class="pagination">
|
<el-pagination
|
@size-change="handleSizeChange"
|
@current-change="handleCurrentChange"
|
:current-page="pageInfo.page"
|
:page-size="pageInfo.limit"
|
layout="total, prev, pager, next, jumper"
|
:total="pageInfo.total">
|
</el-pagination>
|
</div>
|
|
<!-- 订单详情弹窗 -->
|
<el-dialog title="订单详情" :visible.sync="dialogVisible" width="60%">
|
<div v-if="currentOrder">
|
<el-descriptions :column="2" border>
|
<el-descriptions-item label="订单号">{{ currentOrder.order_no }}</el-descriptions-item>
|
<el-descriptions-item label="团购商品">{{ currentOrder.product.product.product_name }}</el-descriptions-item>
|
<el-descriptions-item label="用户">{{ currentOrder.user.nickName }}</el-descriptions-item>
|
<el-descriptions-item label="团购活动">{{ currentOrder.active.active_name }}</el-descriptions-item>
|
<el-descriptions-item label="团购价格">¥{{ currentOrder.actual_price }}</el-descriptions-item>
|
<el-descriptions-item label="团购人数">{{ currentOrder.actual_people }}/{{ currentOrder.groupbuy_num }}</el-descriptions-item>
|
<el-descriptions-item label="订单状态">{{ getStatusText(currentOrder.status) }}</el-descriptions-item>
|
<el-descriptions-item label="创建时间">{{ formatDate(currentOrder.create_time) }}</el-descriptions-item>
|
</el-descriptions>
|
|
<div class="mt20">
|
<h4>参团用户列表</h4>
|
<el-table :data="currentOrder.billUser" style="width: 100%" size="small">
|
<el-table-column prop="user.nickName" label="用户名" />
|
<el-table-column prop="is_creator" label="是否团长" width="100">
|
<template slot-scope="scope">
|
<el-tag :type="scope.row.is_creator ? 'success' : 'info'">
|
{{ scope.row.is_creator ? '是' : '否' }}
|
</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column label="参团时间">
|
<template slot-scope="scope">
|
{{ formatDate(scope.row.create_time) }}
|
</template>
|
</el-table-column>
|
</el-table>
|
</div>
|
</div>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script>
|
import PlusApi from '@/api/plus/groupbuy'
|
|
export default {
|
name: 'GroupbuyOrder',
|
data() {
|
return {
|
loading: false,
|
list: [],
|
searchForm: {
|
order_no: '',
|
product_name: '',
|
nickName: '',
|
status: ''
|
},
|
pageInfo: {
|
page: 1,
|
limit: 20,
|
total: 0
|
},
|
dialogVisible: false,
|
currentOrder: null
|
}
|
},
|
created() {
|
this.getList()
|
},
|
methods: {
|
// 获取列表
|
getList() {
|
this.loading = true
|
const params = {
|
page: this.pageInfo.page,
|
list_rows: this.pageInfo.limit,
|
...this.searchForm
|
}
|
PlusApi.orderList(params).then(res => {
|
this.list = res.data.list.data
|
this.pageInfo.total = res.data.list.total
|
}).finally(() => {
|
this.loading = false
|
})
|
},
|
// 搜索
|
onSearch() {
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 重置
|
onReset() {
|
this.searchForm = {
|
order_no: '',
|
product_name: '',
|
nickName: '',
|
status: ''
|
}
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
// 查看订单
|
onView(row) {
|
this.currentOrder = row
|
this.dialogVisible = true
|
},
|
// 更新订单状态
|
onUpdateStatus(row) {
|
let newStatus;
|
if (row.status === 0) {
|
newStatus = 1; // 从待支付改为团购中
|
} else if (row.status === 1) {
|
// 询问是成功还是失败
|
this.$prompt('请输入操作备注(成功/失败)', '操作确认', {
|
confirmButtonText: '成功',
|
cancelButtonText: '失败',
|
inputPlaceholder: '输入成功或失败'
|
}).then(({ value }) => {
|
if (value === '成功') {
|
newStatus = 2; // 成功
|
} else if (value === '失败') {
|
newStatus = -1; // 失败
|
} else {
|
this.$message.error('请输入成功或失败');
|
return;
|
}
|
this.updateOrderStatus(row.groupbuy_bill_id, newStatus);
|
}).catch(() => {
|
// 取消操作
|
});
|
return;
|
}
|
|
this.updateOrderStatus(row.groupbuy_bill_id, newStatus);
|
},
|
// 更新订单状态请求
|
updateOrderStatus(orderId, status) {
|
PlusApi.updateOrderStatus({
|
groupbuy_bill_id: orderId,
|
status: status
|
}).then(res => {
|
this.$message.success('状态更新成功');
|
this.getList();
|
this.dialogVisible = false;
|
});
|
},
|
// 格式化日期
|
formatDate(timestamp) {
|
if (!timestamp) return '';
|
const date = new Date(timestamp * 1000);
|
return date.toLocaleString('zh-CN');
|
},
|
// 获取状态文本
|
getStatusText(status) {
|
const statusMap = {
|
'-1': '已取消',
|
'0': '待支付',
|
'1': '团购中',
|
'2': '已完成'
|
};
|
return statusMap[status] || '未知';
|
},
|
// 获取状态标签类型
|
getStatusTagType(status) {
|
const typeMap = {
|
'-1': 'danger',
|
'0': 'warning',
|
'1': 'primary',
|
'2': 'success'
|
};
|
return typeMap[status] || 'info';
|
},
|
// 是否可以更新状态
|
canUpdateStatus(row) {
|
return row.status === 0 || row.status === 1; // 只有待支付和团购中的订单可以更新状态
|
},
|
// 获取状态按钮文本
|
getStatusButtonText(row) {
|
if (row.status === 0) {
|
return '标记为团购中';
|
} else if (row.status === 1) {
|
return '更新状态';
|
}
|
return '';
|
},
|
// 分页相关
|
handleSizeChange(val) {
|
this.pageInfo.limit = val
|
this.pageInfo.page = 1
|
this.getList()
|
},
|
handleCurrentChange(val) {
|
this.pageInfo.page = val
|
this.getList()
|
}
|
}
|
}
|
</script>
|