แก้ไข้ API ออกคำสั่ง Step2

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-08-09 16:10:02 +07:00
parent 742fda67f6
commit 5dfa5bea4f
3 changed files with 86 additions and 27 deletions

View file

@ -70,6 +70,7 @@ export default {
//ข้อมูลเลือกรายชื่อออกคำสั่ง, ลบรายชื่อ //ข้อมูลเลือกรายชื่อออกคำสั่ง, ลบรายชื่อ
personsOrder: (orderId: string) => `${order}/order/persons/${orderId}`, personsOrder: (orderId: string) => `${order}/order/persons/${orderId}`,
personsselectedOrder: (orderId: string) => `${order}/order/persons-selected/${orderId}`,
//เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป //เปลี่ยน status ของคำสั่งไปขั้นตอนถัดไป
nextOrder: (orderId: string) => `${order}/order/next/${orderId}`, nextOrder: (orderId: string) => `${order}/order/next/${orderId}`,

View file

@ -109,7 +109,7 @@ div
flat flat
round round
color="red" color="red"
@click="dialogDeleteData(props.row.personId)" @click="dialogDeleteData(props.row.personalId)"
icon="mdi-delete" icon="mdi-delete"
> >
<q-tooltip>ลบขอม</q-tooltip> <q-tooltip>ลบขอม</q-tooltip>
@ -226,7 +226,7 @@ div
<q-separator /> <q-separator />
<q-card-section class="q-pa-sm bg-grey-1"> <q-card-section class="q-pa-sm bg-grey-1">
<d-table <d-table
:rows="rows" :rows="rows2"
:columns="columns" :columns="columns"
:visible-columns="visibleColumns" :visible-columns="visibleColumns"
:filter="filter" :filter="filter"
@ -370,7 +370,9 @@ const columns = ref<QTableProps["columns"]>([
}, },
]); ]);
const rows = ref<ResponseData[]>([]); const rows = ref<ResponseData[]>([]);
const rows2 = ref<ResponseData[]>([]);
const selected = ref([]); const selected = ref([]);
const orderId = ref<string>(route.params.orderid.toString());
onMounted(async () => { onMounted(async () => {
await conditionData(); await conditionData();
@ -390,17 +392,17 @@ const conditionData = async () => {
const getData = async (id: string) => { const getData = async (id: string) => {
showLoader(); showLoader();
await http await http
.get(config.API.personsOrder(id)) .get(config.API.personsselectedOrder(id))
.then((res) => { .then((res) => {
const data = res.data.result; const data = res.data.result;
// console.log(data); console.log(data);
let list: ResponseData[] = []; let list: ResponseData[] = [];
data.map((r: ResponseData) => { data.map((r: ResponseData) => {
list.push({ list.push({
education: r.education ?? "", education: r.education ?? "",
idCard: r.idCard ?? "", idCard: r.idCard ?? "",
name: r.name ?? "", name: r.name ?? "",
personId: r.personId ?? "", personalId: r.personalId ?? "",
selectStatus: r.selectStatus !== null ? r.selectStatus : false, selectStatus: r.selectStatus !== null ? r.selectStatus : false,
sequence: r.sequence !== null ? r.sequence : 0, sequence: r.sequence !== null ? r.sequence : 0,
}); });
@ -456,8 +458,9 @@ const deleteData = async (id: string) => {
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
}) })
.finally(() => { .finally(async () => {
hideLoader(); hideLoader();
await conditionData();
}); });
}; };
@ -535,19 +538,74 @@ const modalOpenClose = () => {
} }
}; };
const modalAddChange = () => { const modalAddChange = async () => {
modalAdd.value = !modalAdd.value; modalAdd.value = !modalAdd.value;
if (modalAdd.value == true) {
await fetchaddlist(orderId.value);
} else await conditionData();
};
const fetchaddlist = async (id: string) => {
showLoader();
await http
.get(config.API.personsOrder(id))
.then((res) => {
const data = res.data.result;
console.log(data);
let list = [];
list = data.map((r: ResponseData) => ({
education: r.education ?? "",
idCard: r.idCard ?? "",
name: r.name ?? "",
personalId: r.personalId ?? "",
selectStatus: r.selectStatus !== null ? r.selectStatus : false,
sequence: r.sequence !== null ? r.sequence : 0,
}));
rows2.value = list.filter((e: any) => e.selectStatus === false);
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
hideLoader();
});
}; };
const saveModalAdd = () => { const saveModalAdd = () => {
if (myFormAdd.value !== null) { if (myFormAdd.value !== null) {
myFormAdd.value.validate().then(async (result: boolean) => { myFormAdd.value.validate().then(async (result: boolean) => {
if (result) { if (result && selected.value.length !== 0) {
modalAddChange(); $q.dialog({
title: "ยืนยันการเพิ่มรายชื่อออกคำสั่ง",
message: "ต้องการยืนยันการเพิ่มรายชื่อออกคำสั่งนี้ใช่หรือไม่?",
cancel: {
flat: true,
color: "negative",
},
persistent: true,
}).onOk(async () => {
let data = [];
data.push(...selected.value.map((e: any) => e.personalId));
// console.log(data);
addlist(data);
});
} }
}); });
} }
}; };
const addlist = async (data: Object) => {
await http
.post(config.API.personsOrder(orderId.value), data)
.then(() => {
// console.log(res);
success($q, "บันทึกสำเร็จ");
})
.catch((e: any) => {
console.log(e);
messageError($q, e);
})
.finally(() => {
modalAddChange();
});
};
const click = (e: any) => { const click = (e: any) => {
console.log(e); console.log(e);
@ -555,28 +613,28 @@ const click = (e: any) => {
}; };
const save = () => { const save = () => {
// if (selected.value.length > 0) { // if (selected.value.length > 0) {
// next(); // next();
// } else { // } else {
// dialogMessage( // dialogMessage(
// $q, // $q,
// "", // "",
// "", // "",
// "warning", // "warning",
// undefined, // undefined,
// "orange", // "orange",
// undefined, // undefined,
// undefined, // undefined,
// true // true
// ); // );
// } // }
next(); next();
}; };
const selectData = (row: any) => {}; const selectData = (row: any) => {};
const refresh = async () => { const refresh = async () => {
await conditionData(); // await conditionData();
modalAddChange(); modalAddChange();
selected.value = []; selected.value = [];
}; };

View file

@ -2,7 +2,7 @@ interface ResponseData {
education: string; education: string;
idCard: string; idCard: string;
name: string; name: string;
personId: string; personalId: string;
selectStatus: boolean; selectStatus: boolean;
sequence: number; sequence: number;
} }