feat: add order

This commit is contained in:
2025-10-08 04:39:40 +08:00
parent 86a309cda0
commit a290db8b35
6 changed files with 742 additions and 1 deletions

View File

@@ -120,7 +120,7 @@ export default {
});
},
rowDel(row) {
this.$confirm('Confirmation for Delete?', {
this.$confirm('Confirmation for delete?', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'

360
src/views/kiosk/order.vue Normal file
View File

@@ -0,0 +1,360 @@
<template>
<basic-container>
<avue-crud :option="option"
v-model:search="search"
v-model:page="page"
v-model="form"
:table-loading="loading"
:data="data"
:permission="permissionList"
:before-open="beforeOpen"
ref="crud"
@row-update="rowUpdate"
@row-save="rowSave"
@row-del="rowDel"
@search-change="searchChange"
@search-reset="searchReset"
@selection-change="selectionChange"
@current-change="currentChange"
@size-change="sizeChange"
@refresh-change="refreshChange"
@on-load="onLoad">
<template #menu-left>
<el-button type="danger"
icon="el-icon-delete"
plain
v-if="permission.order_delete"
@click="handleDelete">Delete
</el-button>
</template>
<template #menu="{ row }">
<el-button type="text"
icon="el-icon-setting"
@click.stop="handleDataSub(row)">Detail
</el-button>
</template>
</avue-crud>
<el-drawer :title="`[${orderName}${orderId}] Detail`" v-model="subVisible" :direction="direction" append-to-body
:before-close="handleSubClose" size="80%">
<basic-container>
<avue-crud :option="optionSub"
:data="dataSub"
v-model:page="pageSub"
v-model="formSub"
:table-loading="loadingSub"
ref="crudSub"
@row-del="rowDelSub"
@row-update="rowUpdateSub"
@row-save="rowSaveSub"
:before-open="beforeOpenSub"
@search-change="searchChangeSub"
@search-reset="searchResetSub"
@selection-change="selectionChangeSub"
@current-change="currentChangeSub"
@size-change="sizeChangeSub"
@on-load="onLoadSub">
</avue-crud>
</basic-container>
</el-drawer>
</basic-container>
</template>
<script>
import { getList, getDetail, add, update, remove } from '@/api/kiosk/order';
import {
getList as getListSub,
getDetail as getDetailSub,
add as addSub,
update as updateSub,
remove as removeSub
} from '@/api/kiosk/orderDetail';
import option from '@/option/kiosk/order';
import optionSub from '@/option/kiosk/orderDetail';
import { mapGetters } from 'vuex';
import 'nprogress/nprogress.css';
export default {
data() {
return {
form: {},
query: {},
search: {},
loading: true,
data: [],
selectionList: [],
page: {
pageSize: 10,
currentPage: 1,
total: 0
},
option: option,
subVisible: false,
direction: 'ttb',
orderId: 0,
serialNumber: '',
orderName: 'KioskOrder:',
formSub: {},
querySub: {},
loadingSub: true,
dataSub: [],
selectionListSub: [],
pageSub: {
pageSize: 10,
currentPage: 1,
total: 0
},
optionSub: optionSub
};
},
computed: {
...mapGetters(['permission']),
permissionList() {
return {
addBtn: this.validData(this.permission.order_add, false),
viewBtn: this.validData(this.permission.order_view, false),
delBtn: this.validData(this.permission.order_delete, false),
editBtn: this.validData(this.permission.order_edit, false)
};
},
ids() {
let ids = [];
this.selectionList.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
},
subIds() {
let ids = [];
this.selectionListSub.forEach(ele => {
ids.push(ele.id);
});
return ids.join(',');
}
},
methods: {
// 主表模块
rowSave(row, done, loading) {
add(row).then(() => {
this.onLoad(this.page);
this.$message({
type: 'success',
message: 'Success!'
});
done();
}, error => {
window.console.log(error);
loading();
});
},
rowUpdate(row, index, done, loading) {
update(row).then(() => {
this.onLoad(this.page);
this.$message({
type: 'success',
message: 'Success!'
});
done();
}, error => {
window.console.log(error);
loading();
});
},
rowDel(row) {
this.$confirm('Confirmation for delete?', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'
})
.then(() => {
return remove(row.id);
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: 'success',
message: 'Success!'
});
});
},
handleDelete() {
if (this.selectionList.length === 0) {
this.$message.warning('Please select one or more');
return;
}
this.$confirm('Confirmation for delete?', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'
})
.then(() => {
return remove(this.ids);
})
.then(() => {
this.onLoad(this.page);
this.$message({
type: 'success',
message: 'Success!'
});
this.$refs.crud.toggleSelection();
});
},
beforeOpen(done, type) {
if (['edit', 'view'].includes(type)) {
getDetail(this.form.id).then(res => {
this.form = res.data.data;
});
}
done();
},
searchReset() {
this.query = {};
this.onLoad(this.page);
},
searchChange(params, done) {
this.query = params;
this.page.currentPage = 1;
this.onLoad(this.page, params);
done();
},
selectionChange(list) {
this.selectionList = list;
},
selectionClear() {
this.selectionList = [];
this.$refs.crud.toggleSelection();
},
currentChange(currentPage) {
this.page.currentPage = currentPage;
},
sizeChange(pageSize) {
this.page.pageSize = pageSize;
},
onLoad(page, params = {}) {
this.loading = true;
const {} = this.query;
let values = {};
getList(page.currentPage, page.pageSize, values).then(res => {
const data = res.data.data;
this.page.total = data.total;
this.data = data.records;
this.loading = false;
this.selectionClear();
});
},
// 子表模块
handleDataSub(row) {
this.subVisible = true;
this.orderId = row.id;
this.serialNumber = row.serialNumber;
this.onLoadSub(this.pageSub);
},
handleSubClose(hide) {
hide();
},
rowSaveSub(row, loading, done) {
row = {
...row,
orderId: this.orderId
};
addSub(row).then(() => {
loading();
this.onLoadSub(this.pageSub);
this.$message({
type: 'success',
message: 'Success!'
});
}, error => {
done();
window.console.log(error);
});
},
rowUpdateSub(row, index, loading, done) {
row = {
...row,
orderId: this.orderId
};
updateSub(row).then(() => {
loading();
this.onLoadSub(this.pageSub);
this.$message({
type: 'success',
message: 'Success!'
});
}, error => {
done();
window.console.log(error);
});
},
rowDelSub(row) {
this.$confirm('Confirmation for delete?', {
confirmButtonText: 'Confirm',
cancelButtonText: 'Cancel',
type: 'warning'
})
.then(() => {
return removeSub(row.id);
})
.then(() => {
this.onLoadSub(this.pageSub);
this.$message({
type: 'success',
message: 'Success!'
});
});
},
beforeOpenSub(done, type) {
if (['edit', 'view'].includes(type)) {
getDetailSub(this.formSub.id).then(res => {
this.formSub = res.data.data;
});
}
done();
},
searchResetSub() {
this.querySub = {};
this.onLoadSub(this.pageSub);
},
searchChangeSub(params) {
this.querySub = params;
this.onLoadSub(this.pageSub, params);
},
selectionChangeSub(list) {
this.selectionListSub = list;
},
currentChangeSub(currentPage) {
this.pageSub.currentPage = currentPage;
},
sizeChangeSub(pageSize) {
this.pageSub.pageSize = pageSize;
},
refreshChange() {
this.onLoad(this.page, this.query);
},
onLoadSub(page, params = {}) {
this.loadingSub = true;
let values = {
orderId: this.orderId
};
const {} = this.querySub;
values = {
...values
};
getListSub(page.currentPage, page.pageSize, values).then(res => {
const data = res.data.data;
this.pageSub.total = data.total;
this.dataSub = data.records;
this.selectionListSub = [];
this.loadingSub = false;
});
}
}
};
</script>
<style>
</style>