| ¶Ô±ÈÐÂÎļþ |
| | |
| | | <template> |
| | | <div class="app-container"> |
| | | <PageHeader content="å·¥èºè·¯çº¿é¡¹ç®"> |
| | | <template #right-button> |
| | | <el-button type="primary" @click="handleAdd">æ°å¢</el-button> |
| | | </template> |
| | | </PageHeader> |
| | | |
| | | <el-table |
| | | v-loading="tableLoading" |
| | | border |
| | | :data="tableData" |
| | | :header-cell-style="{ background: '#F0F1F5', color: '#333333' }" |
| | | row-key="id" |
| | | tooltip-effect="dark" |
| | | class="lims-table" |
| | | > |
| | | <el-table-column align="center" label="åºå·" width="60" type="index" /> |
| | | <el-table-column label="å·¥åºåç§°" prop="processId" width="200"> |
| | | <template #default="scope"> |
| | | {{ getProcessName(scope.row.processId) || '-' }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="产ååç§°" prop="productName" min-width="160" /> |
| | | <el-table-column label="è§æ ¼åç§°" prop="model" min-width="140" /> |
| | | <el-table-column label="åä½" prop="unit" width="100" /> |
| | | <el-table-column label="æä½" align="center" fixed="right" width="150"> |
| | | <template #default="scope"> |
| | | <el-button type="primary" link size="small" @click="handleEdit(scope.row)">ç¼è¾</el-button> |
| | | <el-button type="danger" link size="small" @click="handleDelete(scope.row)">å é¤</el-button> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | |
| | | <!-- æ°å¢/ç¼è¾å¼¹çª --> |
| | | <el-dialog |
| | | v-model="dialogVisible" |
| | | :title="operationType === 'add' ? 'æ°å¢å·¥èºè·¯çº¿é¡¹ç®' : 'ç¼è¾å·¥èºè·¯çº¿é¡¹ç®'" |
| | | width="500px" |
| | | @close="closeDialog" |
| | | > |
| | | <el-form |
| | | ref="formRef" |
| | | :model="form" |
| | | :rules="rules" |
| | | label-width="120px" |
| | | > |
| | | <el-form-item label="å·¥åº" prop="processId"> |
| | | <el-select |
| | | v-model="form.processId" |
| | | placeholder="è¯·éæ©å·¥åº" |
| | | clearable |
| | | style="width: 100%" |
| | | > |
| | | <el-option |
| | | v-for="process in processOptions" |
| | | :key="process.id" |
| | | :label="process.name" |
| | | :value="process.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="产ååç§°" prop="productModelId"> |
| | | <el-button type="primary" @click="showProductSelectDialog = true"> |
| | | {{ form.productName && form.model |
| | | ? `${form.productName} - ${form.model}` |
| | | : 'éæ©äº§å' }} |
| | | </el-button> |
| | | </el-form-item> |
| | | |
| | | <el-form-item label="åä½" prop="unit"> |
| | | <el-input |
| | | v-model="form.unit" |
| | | :placeholder="form.productModelId ? 'æ ¹æ®éæ©ç产åèªå¨å¸¦åº' : '请å
éæ©äº§å'" |
| | | clearable |
| | | :disabled="true" |
| | | /> |
| | | </el-form-item> |
| | | </el-form> |
| | | |
| | | <template #footer> |
| | | <el-button @click="closeDialog">åæ¶</el-button> |
| | | <el-button type="primary" @click="handleSubmit" :loading="submitLoading">ç¡®å®</el-button> |
| | | </template> |
| | | </el-dialog> |
| | | |
| | | <!-- 产åéæ©å¯¹è¯æ¡ --> |
| | | <ProductSelectDialog |
| | | v-model="showProductSelectDialog" |
| | | @confirm="handleProductSelect" |
| | | single |
| | | /> |
| | | </div> |
| | | </template> |
| | | |
| | | <script setup> |
| | | import { ref, computed, getCurrentInstance, onMounted } from "vue"; |
| | | import ProductSelectDialog from "@/views/basicData/product/ProductSelectDialog.vue"; |
| | | import { findProcessRouteItemList, addOrUpdateProcessRouteItem } from "@/api/productionManagement/processRouteItem.js"; |
| | | import { processList } from "@/api/productionManagement/productionProcess.js"; |
| | | import { useRoute } from 'vue-router' |
| | | import { ElMessageBox } from 'element-plus' |
| | | |
| | | const route = useRoute() |
| | | const { proxy } = getCurrentInstance() || {}; |
| | | |
| | | const routeId = computed(() => route.query.id); |
| | | |
| | | const tableLoading = ref(false); |
| | | const tableData = ref([]); |
| | | const dialogVisible = ref(false); |
| | | const operationType = ref('add'); // add | edit |
| | | const formRef = ref(null); |
| | | const submitLoading = ref(false); |
| | | |
| | | const processOptions = ref([]); |
| | | const showProductSelectDialog = ref(false); |
| | | |
| | | const form = ref({ |
| | | id: undefined, |
| | | routeId: routeId.value, |
| | | processId: undefined, |
| | | productModelId: undefined, |
| | | productName: "", |
| | | model: "", |
| | | unit: "", |
| | | }); |
| | | |
| | | const rules = { |
| | | processId: [{ required: true, message: 'è¯·éæ©å·¥åº', trigger: 'change' }], |
| | | productModelId: [{ required: true, message: 'è¯·éæ©äº§å', trigger: 'change' }], |
| | | }; |
| | | |
| | | // æ ¹æ®å·¥åºIDè·åå·¥åºåç§° |
| | | const getProcessName = (processId) => { |
| | | if (!processId) return ''; |
| | | const process = processOptions.value.find(p => p.id === processId); |
| | | return process ? process.name : ''; |
| | | }; |
| | | |
| | | // è·åå表 |
| | | const getList = () => { |
| | | tableLoading.value = true; |
| | | findProcessRouteItemList({ routeId: routeId.value }) |
| | | .then(res => { |
| | | tableData.value = res.data || []; |
| | | tableLoading.value = false; |
| | | }) |
| | | .catch(err => { |
| | | tableLoading.value = false; |
| | | console.error("è·åå表失败ï¼", err); |
| | | proxy?.$modal?.msgError("è·åå表失败"); |
| | | }); |
| | | }; |
| | | |
| | | // è·åå·¥åºå表 |
| | | const getProcessList = () => { |
| | | processList({}) |
| | | .then(res => { |
| | | processOptions.value = res.data || []; |
| | | }) |
| | | .catch(err => { |
| | | console.error("è·åå·¥åºå¤±è´¥ï¼", err); |
| | | }); |
| | | }; |
| | | |
| | | // æ°å¢ |
| | | const handleAdd = () => { |
| | | operationType.value = 'add'; |
| | | resetForm(); |
| | | dialogVisible.value = true; |
| | | }; |
| | | |
| | | // ç¼è¾ |
| | | const handleEdit = (row) => { |
| | | operationType.value = 'edit'; |
| | | form.value = { |
| | | id: row.id, |
| | | routeId: routeId.value, |
| | | processId: row.processId, |
| | | productModelId: row.productModelId, |
| | | productName: row.productName || "", |
| | | model: row.model || "", |
| | | unit: row.unit || "", |
| | | }; |
| | | dialogVisible.value = true; |
| | | }; |
| | | |
| | | // å é¤ |
| | | const handleDelete = (row) => { |
| | | ElMessageBox.confirm('确认å é¤è¯¥å·¥èºè·¯çº¿é¡¹ç®ï¼', 'æç¤º', { |
| | | confirmButtonText: '确认', |
| | | cancelButtonText: 'åæ¶', |
| | | type: 'warning' |
| | | }) |
| | | .then(() => { |
| | | // è°ç¨å 餿¥å£ï¼ä¼ å个对象ï¼å
å«idï¼ |
| | | addOrUpdateProcessRouteItem({ |
| | | id: row.id, |
| | | routeId: routeId.value, |
| | | }) |
| | | .then(() => { |
| | | proxy?.$modal?.msgSuccess('å 餿å'); |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy?.$modal?.msgError('å é¤å¤±è´¥'); |
| | | }); |
| | | }) |
| | | .catch(() => {}); |
| | | }; |
| | | |
| | | // 产åéæ© |
| | | const handleProductSelect = (products) => { |
| | | if (products && products.length > 0) { |
| | | const product = products[0]; |
| | | form.value.productModelId = product.id; |
| | | form.value.productName = product.productName; |
| | | form.value.model = product.model; |
| | | form.value.unit = product.unit || ""; |
| | | showProductSelectDialog.value = false; |
| | | // 触å表åéªè¯ |
| | | formRef.value?.validateField('productModelId'); |
| | | } |
| | | }; |
| | | |
| | | // æäº¤ |
| | | const handleSubmit = () => { |
| | | formRef.value.validate((valid) => { |
| | | if (valid) { |
| | | submitLoading.value = true; |
| | | |
| | | // æå»ºæäº¤æ°æ®å¯¹è±¡ï¼å个对象形å¼ï¼ |
| | | const submitData = { |
| | | routeId: routeId.value, |
| | | processId: form.value.processId, |
| | | productModelId: form.value.productModelId, |
| | | }; |
| | | |
| | | if (operationType.value === 'add') { |
| | | // æ°å¢ï¼ä¼ å个对象 |
| | | addOrUpdateProcessRouteItem(submitData) |
| | | .then(() => { |
| | | proxy?.$modal?.msgSuccess('æ°å¢æå'); |
| | | closeDialog(); |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy?.$modal?.msgError('æ°å¢å¤±è´¥'); |
| | | }) |
| | | .finally(() => { |
| | | submitLoading.value = false; |
| | | }); |
| | | } else { |
| | | // ç¼è¾ï¼ä¼ å个对象ï¼å
å«id |
| | | addOrUpdateProcessRouteItem({ |
| | | ...submitData, |
| | | id: form.value.id, |
| | | }) |
| | | .then(() => { |
| | | proxy?.$modal?.msgSuccess('ä¿®æ¹æå'); |
| | | closeDialog(); |
| | | getList(); |
| | | }) |
| | | .catch(() => { |
| | | proxy?.$modal?.msgError('ä¿®æ¹å¤±è´¥'); |
| | | }) |
| | | .finally(() => { |
| | | submitLoading.value = false; |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | }; |
| | | |
| | | // é置表å |
| | | const resetForm = () => { |
| | | form.value = { |
| | | id: undefined, |
| | | routeId: routeId.value, |
| | | processId: undefined, |
| | | productModelId: undefined, |
| | | productName: "", |
| | | model: "", |
| | | unit: "", |
| | | }; |
| | | formRef.value?.resetFields(); |
| | | }; |
| | | |
| | | // å
³éå¼¹çª |
| | | const closeDialog = () => { |
| | | dialogVisible.value = false; |
| | | resetForm(); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | | getList(); |
| | | getProcessList(); |
| | | }); |
| | | </script> |
| | | |
| | | <style scoped> |
| | | :deep(.el-table__row) { |
| | | transition: background-color 0.2s; |
| | | } |
| | | |
| | | :deep(.el-table__row:hover) { |
| | | background-color: #f9fafc !important; |
| | | } |
| | | </style> |