| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <div class="search_form"> |
| | | <div> |
| | | <span class="search_title">产å大类ï¼</span> |
| | | <el-tree-select |
| | | v-model="searchForm.productCategory" |
| | | :data="productOptions" |
| | | placeholder="è¯·éæ©" |
| | | clearable |
| | | check-strictly |
| | | :render-after-expand="false" |
| | | style="width: 240px" |
| | | @change="handleQuery" |
| | | /> |
| | | <span class="search_title ml10">å½å
¥æ¥æï¼</span> |
| | | <el-date-picker v-model="searchForm.registerDate" value-format="YYYY-MM-DD" format="YYYY-MM-DD" type="daterange" |
| | | placeholder="è¯·éæ©" clearable @change="changeDaterange" /> |
| | | <el-button type="primary" @click="handleQuery" style="margin-left: 10px" |
| | | >æç´¢</el-button |
| | | > |
| | | </div> |
| | | <div> |
| | | <el-button type="primary" @click="openDialog('create')">æ°å¢è®¢å</el-button> |
| | | <el-button @click="handleOut">导åº</el-button> |
| | | </div> |
| | | </div> |
| | | <div class="table_list"> |
| | | <PIMTable |
| | | rowKey="id" |
| | | :column="tableColumn" |
| | | :tableData="tableData" |
| | | :page="page" |
| | | :tableLoading="tableLoading" |
| | | @pagination="pagination" |
| | | > |
| | | <template #action="{ row }"> |
| | | <el-button type="primary" link @click="handleEdit(row)">ç¼è¾</el-button> |
| | | <el-button type="danger" link @click="handleDelete(row)">å é¤</el-button> |
| | | </template> |
| | | </PIMTable> |
| | | </div> |
| | | <el-dialog v-model="dialogVisible" :title="dialogTitle" width="40%" @close="closeDialog"> |
| | | <el-form ref="formRef" :model="form" :rules="formRules" label-width="100px"> |
| | | <el-form-item label="å½å
¥æ¥æ" prop="registerDate"> |
| | | <el-date-picker v-model="form.registerDate" type="date" value-format="YYYY-MM-DD" format="YYYY-MM-DD" placeholder="è¯·éæ©å½å
¥æ¥æ" style="width: 100%"/> |
| | | </el-form-item> |
| | | <el-form-item label="产å大类" prop="productCategory"> |
| | | <el-input |
| | | v-model="form.productCategory" |
| | | placeholder="请è¾å
¥äº§å大类" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="è§æ ¼åå·" prop="specificationModel"> |
| | | <el-input |
| | | v-model="form.specificationModel" |
| | | placeholder="请è¾å
¥è§æ ¼åå·" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="åä½" prop="unit"> |
| | | <el-input |
| | | v-model="form.unit" |
| | | placeholder="请è¾å
¥åä½" |
| | | clearable |
| | | /> |
| | | </el-form-item> |
| | | <el-form-item label="æ°é" prop="quantity"> |
| | | <el-input-number v-model="form.quantity" :min="0" :step="0.1" style="width: 100%"/> |
| | | </el-form-item> |
| | | </el-form> |
| | | <template #footer> |
| | | <div class="dialog-footer"> |
| | | <el-button type="primary" @click="submitForm">确认</el-button> |
| | | <el-button @click="closeDialog">åæ¶</el-button> |
| | | </div> |
| | | </template> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import {onMounted, ref, reactive, toRefs, getCurrentInstance} from "vue"; |
| | | import { ElMessageBox } from "element-plus"; |
| | | import dayjs from "dayjs"; |
| | | import {schedulingListPage, addProductionOrder, updateProductionOrder, deleteProductionOrder} from "@/api/productionManagement/productionOrder.js"; |
| | | import {productTreeList} from "@/api/basicData/product.js"; |
| | | const { proxy } = getCurrentInstance(); |
| | | |
| | | const tableColumn = ref([ |
| | | { |
| | | label: "å½å
¥æ¥æ", |
| | | prop: "registerDate", |
| | | width: 120, |
| | | }, |
| | | { |
| | | label: "ç产订åå·", |
| | | prop: "orderNo", |
| | | }, |
| | | { |
| | | label: "产å大类", |
| | | prop: "productCategory", |
| | | }, |
| | | { |
| | | label: "è§æ ¼åå·", |
| | | prop: "specificationModel", |
| | | }, |
| | | { |
| | | label: "åä½", |
| | | prop: "unit", |
| | | }, |
| | | { |
| | | label: "æ°é", |
| | | prop: "quantity", |
| | | }, |
| | | // { |
| | | // label: "æäº§æ°é", |
| | | // prop: "schedulingNum", |
| | | // width: 100, |
| | | // }, |
| | | // { |
| | | // label: "å®å·¥æ°é", |
| | | // prop: "successNum", |
| | | // width: 100, |
| | | // }, |
| | | { |
| | | label: "æä½", |
| | | prop: "action", |
| | | width: 120, |
| | | fixed: "right", |
| | | dataType: "slot", |
| | | align: "center", |
| | | slot: "action" |
| | | } |
| | | ]); |
| | | const tableData = ref([]); |
| | | const tableLoading = ref(false); |
| | | const page = ref({ |
| | | current: 1, |
| | | size: 100, |
| | | total: 0, |
| | | }); |
| | | const dialogVisible = ref(false); |
| | | const dialogTitle = ref(""); |
| | | const dialogMode = ref(""); // 'create' æ 'edit' |
| | | const formRef = ref(); |
| | | const productOptions = ref([]); |
| | | const form = reactive({ |
| | | id: null, |
| | | registerDate: dayjs().format("YYYY-MM-DD"), |
| | | productCategory: "", |
| | | specificationModel: "", |
| | | unit: "", |
| | | quantity: null, |
| | | }); |
| | | const formRules = { |
| | | registerDate: [{ required: true, message: "è¯·éæ©å½å
¥æ¥æ", trigger: "change" }], |
| | | productCategory: [{ required: true, message: "请è¾å
¥äº§å大类", trigger: "blur" }], |
| | | specificationModel: [{ required: true, message: "请è¾å
¥è§æ ¼åå·", trigger: "blur" }], |
| | | unit: [{ required: true, message: "请è¾å
¥åä½", trigger: "blur" }], |
| | | quantity: [{ required: true, message: "请è¾å
¥æ°é", trigger: "blur" }], |
| | | }; |
| | | |
| | | const data = reactive({ |
| | | searchForm: { |
| | | productCategory: "", |
| | | registerDate: null, // å½å
¥æ¥æ |
| | | entryDateStart: undefined, |
| | | entryDateEnd: undefined, |
| | | }, |
| | | }); |
| | | const { searchForm } = toRefs(data); |
| | | |
| | | const openDialog = (mode, row = null) => { |
| | | dialogMode.value = mode; |
| | | if (mode === 'create') { |
| | | dialogTitle.value = "æ°å¢ç产订å"; |
| | | resetForm(); |
| | | } else if (mode === 'edit') { |
| | | dialogTitle.value = "ç¼è¾ç产订å"; |
| | | resetForm(); |
| | | |
| | | console.log('ç¼è¾æ°æ®:', row); |
| | | |
| | | // å¡«å
ç¼è¾æ°æ® |
| | | form.id = row.id; |
| | | form.registerDate = row.registerDate; |
| | | form.productCategory = row.productCategory; |
| | | form.specificationModel = row.specificationModel; |
| | | form.unit = row.unit; |
| | | form.quantity = row.quantity; |
| | | } |
| | | |
| | | dialogVisible.value = true; |
| | | }; |
| | | |
| | | const closeDialog = () => { |
| | | dialogVisible.value = false; |
| | | }; |
| | | |
| | | const resetForm = () => { |
| | | form.id = null; |
| | | form.registerDate = dayjs().format("YYYY-MM-DD"); |
| | | form.productCategory = ""; |
| | | form.specificationModel = ""; |
| | | form.unit = ""; |
| | | form.quantity = null; |
| | | }; |
| | | |
| | | const submitForm = () => { |
| | | formRef.value?.validate(async (valid) => { |
| | | if (!valid) return; |
| | | try { |
| | | const payload = { |
| | | registerDate: form.registerDate, |
| | | productCategory: form.productCategory, |
| | | specificationModel: form.specificationModel, |
| | | unit: form.unit, |
| | | quantity: form.quantity, |
| | | }; |
| | | |
| | | if (dialogMode.value === 'create') { |
| | | await addProductionOrder(payload); |
| | | proxy.$modal.msgSuccess("æ°å¢æå"); |
| | | } else if (dialogMode.value === 'edit') { |
| | | payload.id = form.id; |
| | | await updateProductionOrder(payload); |
| | | proxy.$modal.msgSuccess("ç¼è¾æå"); |
| | | } |
| | | |
| | | closeDialog(); |
| | | getList(); |
| | | } catch (err) { |
| | | console.error(`${dialogMode.value === 'create' ? 'æ°å¢' : 'ç¼è¾'}失败`, err); |
| | | proxy.$modal.msgError(`${dialogMode.value === 'create' ? 'æ°å¢' : 'ç¼è¾'}失败ï¼è¯·éè¯`); |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // ç¼è¾æ¹æ³ |
| | | const handleEdit = (row) => { |
| | | openDialog('edit', row); |
| | | }; |
| | | |
| | | // å 餿¹æ³ |
| | | const handleDelete = (row) => { |
| | | proxy.$modal.confirm(`ç¡®å®è¦å é¤ç产订å"${row.orderNo}"åï¼`, "å é¤ç¡®è®¤", { |
| | | confirmButtonText: "ç¡®å®", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning", |
| | | }).then(async () => { |
| | | try { |
| | | await deleteProductionOrder([row.id]); |
| | | proxy.$modal.msgSuccess("å 餿å"); |
| | | getList(); // å·æ°å表 |
| | | } catch (err) { |
| | | console.error("å é¤å¤±è´¥", err); |
| | | proxy.$modal.msgError("å é¤å¤±è´¥ï¼è¯·éè¯"); |
| | | } |
| | | }).catch(() => { |
| | | proxy.$modal.msg("已忶å é¤"); |
| | | }); |
| | | }; |
| | | |
| | | const getProductOptions = () => { |
| | | return productTreeList().then((res) => { |
| | | productOptions.value = convertIdToValue(res || []); |
| | | }); |
| | | }; |
| | | |
| | | const convertIdToValue = (data) => { |
| | | return data.map((item) => { |
| | | const { id, children, ...rest } = item; |
| | | const newItem = { |
| | | ...rest, |
| | | value: id, |
| | | }; |
| | | if (children && children.length > 0) { |
| | | newItem.children = convertIdToValue(children); |
| | | } |
| | | return newItem; |
| | | }); |
| | | }; |
| | | |
| | | const findNodeById = (nodes, value) => { |
| | | for (let i = 0; i < nodes.length; i++) { |
| | | if (nodes[i].value === value) { |
| | | return nodes[i].label; |
| | | } |
| | | if (nodes[i].children && nodes[i].children.length > 0) { |
| | | const label = findNodeById(nodes[i].children, value); |
| | | if (label) return label; |
| | | } |
| | | } |
| | | return null; |
| | | }; |
| | | |
| | | |
| | | // æ¥è¯¢å表 |
| | | /** æç´¢æé®æä½ */ |
| | | const handleQuery = () => { |
| | | page.value.current = 1; |
| | | getList(); |
| | | }; |
| | | const pagination = (obj) => { |
| | | page.value.current = obj.page; |
| | | page.value.size = obj.limit; |
| | | getList(); |
| | | }; |
| | | const changeDaterange = (value) => { |
| | | if (value) { |
| | | searchForm.value.entryDateStart = value[0]; |
| | | searchForm.value.entryDateEnd = value[1]; |
| | | } else { |
| | | searchForm.value.entryDateStart = undefined; |
| | | searchForm.value.entryDateEnd = undefined; |
| | | } |
| | | handleQuery(); |
| | | }; |
| | | const getList = () => { |
| | | tableLoading.value = true; |
| | | // æé ä¸ä¸ªæ°ç对象ï¼ä¸å
å«entryDateåæ®µå total åæ®µ |
| | | const { total, ...pageParams } = page.value; |
| | | const params = { ...searchForm.value, ...pageParams }; |
| | | params.registerDate = undefined; |
| | | if (params.productCategory) { |
| | | // 妿æ¯å¯¹è±¡ç±»åï¼è·åå
¶labelï¼åç§°ï¼è䏿¯valueï¼IDï¼ |
| | | if (typeof params.productCategory === "object") { |
| | | params.productCategory = findNodeById(productOptions.value, params.productCategory) || params.productCategory; |
| | | } |
| | | // 妿æ¯IDï¼è½¬æ¢ä¸ºåç§° |
| | | else if (typeof params.productCategory === "string" || typeof params.productCategory === "number") { |
| | | const categoryName = findNodeById(productOptions.value, params.productCategory); |
| | | if (categoryName) { |
| | | params.productCategory = categoryName; |
| | | } |
| | | } |
| | | } |
| | | schedulingListPage(params).then((res) => { |
| | | tableLoading.value = false; |
| | | tableData.value = res.data.records; |
| | | page.value.total = res.data.total; |
| | | }).catch(() => { |
| | | tableLoading.value = false; |
| | | }) |
| | | }; |
| | | |
| | | // å¯¼åº |
| | | const handleOut = () => { |
| | | ElMessageBox.confirm("éä¸çå
容å°è¢«å¯¼åºï¼æ¯å¦ç¡®è®¤å¯¼åºï¼", "导åº", { |
| | | confirmButtonText: "确认", |
| | | cancelButtonText: "åæ¶", |
| | | type: "warning", |
| | | }) |
| | | .then(() => { |
| | | proxy.download("/salesLedger/scheduling/export", {}, "ç产订å.xlsx"); |
| | | }) |
| | | .catch(() => { |
| | | proxy.$modal.msg("已忶"); |
| | | }); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getProductOptions(); |
| | | // ä¸è®¾ç½®é»è®¤æ¥æï¼å
¨é¨æ¡ä»¶ä¸ºç©ºå è½½ |
| | | searchForm.value.registerDate = null; |
| | | searchForm.value.entryDateStart = undefined; |
| | | searchForm.value.entryDateEnd = undefined; |
| | | getList(); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped lang="scss"></style> |