jiangchengfeiyi-Web/src/views/Orders/OrderList.vue

216 lines
8.9 KiB
Vue
Raw Normal View History

<template>
2024-11-04 10:30:18 +00:00
<div>
2024-11-05 08:45:53 +00:00
<el-input style="width: 200px; height: 30px; margin-right: 10px;" suffix-icon="Search" placeholder="请输入订单编号"
2024-11-04 11:57:46 +00:00
v-model="name"></el-input>
2024-11-04 10:30:18 +00:00
<el-button class="ml-5" type="primary" @click="load" style="height: 25px;">搜索</el-button>
<el-button type="warning" @click="reset" style="height:25px">重置</el-button>
</div>
<div style="margin: 15px 0">
<el-popconfirm class="ml-5" confirm-button-text='确定' cancel-button-text='取消' icon="InfoFilled" icon-color="red"
title="您确定批量删除这些数据吗?" @confirm="delBatch" width=180>
<template #reference>
<el-button style="height: 25px" class="ml-5" type="danger">批量删除 <el-icon style="margin-left: 5px;">
<Remove />
</el-icon></el-button>
</template>
</el-popconfirm>
</div>
2024-11-05 08:45:53 +00:00
<!-- 数据展示层 -->
2024-11-04 10:30:18 +00:00
<el-table :data="tableData" border stripe header-cell-class-name="headerBg"
:cell-style="{ 'text-align': 'center', 'font-size': '16px' }" @selection-change="handleSelectionChange"
:header-cell-style="{ 'text-align': 'center' }">
2024-11-05 08:45:53 +00:00
<el-table-column type="selection" width="55" fixed="left"></el-table-column>
<el-table-column prop="id" label="订单编号" width="80"></el-table-column>
2024-11-04 10:30:18 +00:00
<el-table-column prop="userId" label="用户id"></el-table-column>
2024-11-05 08:45:53 +00:00
<el-table-column prop="orderNumber" label="订单编号" width="150"></el-table-column>
<!-- 商品信息需要发第二次请求 -->
<el-table-column label="所购买的商品" width="100">
<el-table-column label="展开所有商品" type="expand" width="100">
<el-table :data="orderDetail">
<el-table-column label="商品编号" prop="id" />
<el-table-column label="商品名称" prop="orderDetail[num].type" />
<el-table-column label="商品图片" prop="orderDetail[num].price" />
<el-table-column label="类别" prop="city" />
<el-table-column label="商品单价" prop="address" />
<el-table-column label="是否是限定商品" prop="zip" />
<el-table-column label="数量" prop="address" />
</el-table>
</el-table-column>
</el-table-column>
<el-table-column label="地址信息快照" width="180">
<el-table-column prop="addressSnapshot.name" label="收货人" />
<el-table-column prop="addressSnapshot.phone" label="手机号" />
<el-table-column prop="addressSnapshot.region" label="地区" />
<el-table-column prop="addressSnapshot.detailAddress" label="详细地址" />
</el-table-column>
<el-table-column label="优惠卷信息快照" width="50">
<el-table-column prop="couponSnapshot.name" label="优惠卷名称" />
<el-table-column prop="couponSnapshot.conditionAmount" label="优惠金额" />
</el-table-column>
2024-11-04 10:30:18 +00:00
<el-table-column prop="totalAmount" label="订单总金额"></el-table-column>
<el-table-column prop="orderStatus" label="订单状态"></el-table-column>
2024-11-05 08:45:53 +00:00
<el-table-column label="操作" width="120px" fixed="right">
2024-11-04 10:30:18 +00:00
<template #default="scope">
2024-11-05 08:45:53 +00:00
<el-button size="small" @click="showDetail(scope.$index, scope.row , 0)">
2024-11-04 10:30:18 +00:00
详情
</el-button>
</template>
</el-table-column>
</el-table>
<div style="padding: 10px 0">
2024-11-05 08:45:53 +00:00
<el-pagination @size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="searchParams.current"
:page-size="searchParams.pageSize"
:page-sizes="[5, 10, 15, 20]"
:small="null" :disabled="null"
:background="null"
layout="total, sizes, prev, pager, next, jumper"
2024-11-04 10:30:18 +00:00
:total="total" />
</div>
2024-11-05 08:45:53 +00:00
<!-- <el-dialog title="订单详情信息" v-model="orderList" width="60%">
2024-11-04 10:30:18 +00:00
<el-form label-width="100px" size="default">
<el-form-item label="订单id">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.id" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="用户id">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.userId" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="用户名称">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.addressSnapshot.name" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="订单编号">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.addressSnapshot" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="收货地址">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.addressSnapshot.region" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="详细地址">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.addressSnapshot.detailAddress" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="电话">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.addressSnapshot.phone" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="优惠券名称">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.couponSnapshot.name" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="满减金额">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.couponSnapshot.conditionAmount" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="订单总金额">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.totalAmount" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
<el-form-item label="订单状态">
2024-11-04 11:57:46 +00:00
<el-input v-model="orderList.orderStatus" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="创建时间">
<el-input v-model="orderList.createTime" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="更新时间">
<el-input v-model="orderList.updateTime" autocomplete="off"></el-input>
2024-11-04 10:30:18 +00:00
</el-form-item>
</el-form>
<template #footer>
<div class="dialog-footer">
<el-button style="height: 30px;" @click="dialogFormVisible = false">取消</el-button>
<el-button style="height: 30px" type="primary" @click=save>确认</el-button>
</div>
2024-11-04 10:47:06 +00:00
</template>
2024-11-05 08:45:53 +00:00
</el-dialog> -->
</template>
2024-11-04 10:30:18 +00:00
<script lang="ts" setup>
2024-11-05 08:45:53 +00:00
import {onMounted, ref} from "vue";
2024-11-04 10:30:18 +00:00
import myAxios from "@/api/myAxios";
import {ElMessage} from "element-plus";
2024-11-05 08:45:53 +00:00
const tableData : any= ref([]); //表单展示数据
2024-11-04 10:30:18 +00:00
const total = ref(0);
const title = ref('')
const editForm : any = ref({});
const DialogVisible = ref(true);
2024-11-04 11:57:46 +00:00
const name =ref('')
2024-11-04 10:30:18 +00:00
const searchParams: any = ref({ //封装分页
current: 1, //当前页码
pageSize: 5 //每页显示条数
})
2024-11-05 08:45:53 +00:00
const num = ref(0)
const orderDetail : any = ref([]) //订单中的商品明细,多个商品
//订单列表
const orderList = ref([{}])
onMounted(()=>{
getOrderList() //页面加载获取订单列表
})
2024-11-04 10:30:18 +00:00
const handleSizeChange = (newSize: any) => {
searchParams.value.pageSize = newSize //新的页面数
getOrderList()
}
const handleCurrentChange = (Current: any) => {
searchParams.value.current = Current
getOrderList()
}
const handleSelectionChange = (row: any) => {
2024-11-05 08:45:53 +00:00
// id.value = JSON.parse(JSON.stringify(row));
2024-11-04 10:30:18 +00:00
}
const getOrderList = async () => {
try {
2024-11-04 11:57:46 +00:00
const res = await myAxios.post('/order/list/page', { ...searchParams.value});
2024-11-05 08:45:53 +00:00
console.log('订单信息--->',res.data);
2024-11-04 10:30:18 +00:00
if (res.data.code === 1) {
2024-11-05 08:45:53 +00:00
tableData.value = res.data.data.records;
2024-11-04 10:30:18 +00:00
total.value = parseInt(res.data.data.total)
2024-11-05 08:45:53 +00:00
console.log('tableData-->',tableData.value);
//获取订单记录成功后,获取订单详情记录
console.log('数组长度--->',tableData.value.length);
for(let key in tableData.value) {
num.value = parseInt(key)
const resOrderDetail = await myAxios.post('/order/list/item',{id:tableData.value[key].id}) //获取订单中详情记录
if( resOrderDetail.data.code === 1 ) {
orderDetail.value[num.value] = resOrderDetail.data.data //订单中的商品明细,多个商品
}
console.log('请求返回的resOrderDetail--->',resOrderDetail.data);
console.log('第',key,'次返回的orderDetail-->',orderDetail.value[num.value]);
console.log('总的orderDetail-->',orderDetail.value);
}
// console.log(orderDetail.value);
2024-11-04 10:30:18 +00:00
} else {
ElMessage({
message: '获取数据失败',
});
}
} catch (error) {
ElMessage({
message: '发生错误',
});
}
}
const delBatch =()=>{
//批量删除
}
2024-11-05 08:45:53 +00:00
const showDetail = (index: number, row: any , flag : number) => {
title.value = "订单详情"
2024-11-04 10:30:18 +00:00
DialogVisible.value = true;
editForm.value = row;
};
const deleteProduct = async (index: number) => {
2024-11-05 08:45:53 +00:00
// console.log(typeof index)
2024-11-04 10:30:18 +00:00
const res = await myAxios.post('/goods/delete', { id: index })
console.log(res)
if (res.data.code === 1) {
ElMessage({
type: 'success',
message: '删除成功',
})
getOrderList()
}
}
const reset = () => {
2024-11-04 11:57:46 +00:00
name.value = '';
2024-11-04 10:30:18 +00:00
};
const load =()=>{}
</script>
<style lang="scss" scoped>
2024-11-04 10:30:18 +00:00
</style>