From c1b5f6edeacfa0326931d06de6773b936dbabe27 Mon Sep 17 00:00:00 2001 From: maven <2163098428@qq.com> Date: 星期二, 26 八月 2025 15:18:44 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev_JLMY' into dev_JLMY --- src/views/production/productionReporting/components/ProductionDialog.vue | 348 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 348 insertions(+), 0 deletions(-) diff --git a/src/views/production/productionReporting/components/ProductionDialog.vue b/src/views/production/productionReporting/components/ProductionDialog.vue new file mode 100644 index 0000000..4d6bf8c --- /dev/null +++ b/src/views/production/productionReporting/components/ProductionDialog.vue @@ -0,0 +1,348 @@ +<template> + <el-dialog + v-model="dialogVisible" + title="鐢熶骇鎶ュ伐" + width="70%" + @close="handleClose" + > + <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef"> + <el-row :gutter="30"> + <el-col :span="12"> + <el-form-item label="鎺掍骇鏁伴噺锛�"> + <el-input v-model="productionQuantity" placeholder="璇疯緭鍏�" clearable disabled/> + </el-form-item> + </el-col> + <el-col :span="12"> + <el-form-item label="鏈鐢熶骇鏁伴噺锛�" prop="finishedNum"> + <el-input-number + v-model="form.finishedNum" + placeholder="璇疯緭鍏�" + :min="0" + :step="0.1" + :precision="2" + clearable + style="width: 100%" + @change="changeNum" + /> + </el-form-item> + </el-col> + </el-row> + <el-row :gutter="30"> + <el-col :span="12"> + <el-form-item label="寰呯敓浜ф暟閲忥細"> + <el-input v-model="pendingNum" placeholder="璇疯緭鍏�" clearable disabled/> + </el-form-item> + </el-col> + <el-col :span="12"> + <el-form-item label="鐢熶骇浜猴細" prop="schedulingUserId"> + <el-select + v-model="form.schedulingUserId" + placeholder="閫夋嫨浜哄憳" + style="width: 100%;" + > + <el-option + v-for="user in userList" + :key="user.userId" + :label="user.nickName" + :value="user.userId" + /> + </el-select> + </el-form-item> + </el-col> + </el-row> + </el-form> + <template #footer> + <div class="dialog-footer"> + <el-button type="primary" @click="handleSubmit">纭</el-button> + <el-button @click="handleClose">鍙栨秷</el-button> + </div> + </template> + </el-dialog> +</template> + +<script setup> +import {ref, reactive, watch, onMounted, nextTick, computed} from "vue"; +import ETable from "@/components/Table/ETable.vue"; +import ETableModify from "@/components/Table/EtableModify.vue"; +import {ElMessage, ElMessageBox, ElAlert, ElText} from "element-plus"; +import {Delete, Warning, Plus} from "@element-plus/icons-vue"; +import {validateFormData, validateNumber, deepClone, createDefaultProductionRow} from "@/utils/production"; +import {useCoalData} from "./useCoalData"; +import useUserStore from "@/store/modules/user"; +import {work} from '@/api/productionScheduling/index' +import {userListAll} from "@/api/publicApi"; +const userList = ref([]) + +const data = reactive({ + form: { + successNum: 0, + schedulingNum: 0, + finishedNum: 0, + schedulingUserId: "" + }, + rules: { + schedulingNum: [{ required: true, message: "璇疯緭鍏�", trigger: "blur" },], + }, +}); +const { form, rules } = toRefs(data); +const changeNum = (value) => { + if (value > pendingNum.value) { + form.value.finishedNum = pendingNum.value + ElMessage.warning("鏈鐢熶骇鏁伴噺涓嶅彲澶т簬鎺掍骇鏁伴噺"); + } + pendingNum.value = pendingNum.value - form.value.finishedNum; +} +// Props 鍜� Emits +const props = defineProps({ + visible: {type: Boolean, default: false}, + type: {type: String, default: "add"}, + rowData: {type: Object, default: () => ({})}, +}); + +const dialogVisible = defineModel("visible", {type: Boolean, default: false}); +const emit = defineEmits(["update:visible", "success", "update:productionAndProcessing"]); + +// 鐢ㄦ埛淇℃伅鍜岀叅绉嶆暟鎹� +const userStore = useUserStore(); +const {getCoalNameById} = useCoalData(); +let userInfo; + +// 瀵硅瘽妗嗙姸鎬� +const innerVisible = ref(false); +const dialogType = ref("add"); +const loading = ref(false); +const etableRef = ref(null); + +// 鏁版嵁鐘舵�� +const tableData = ref([]); +const detailsTableData = ref([]); +const formalDatabaseData = ref([]); +const formalDatabaseSelectedData = ref([]); +const selectedIds = ref([]); +const currentRow = ref(null); +const copyForm = ref(null); +const productionQuantity = ref(0); +const pendingNum = ref(0); + + +const handleRowClick = (row) => { + currentRow.value = row; +}; + +// 鎵嬪姩璁剧疆琛ㄦ牸閫変腑鐘舵�� +const setTableSelection = (ids) => { + if (!etableRef.value || !Array.isArray(ids) || ids.length === 0) { + return; + } + + nextTick(() => { + setTimeout(() => { + try { + etableRef.value.clearSelection(); + const rowsToSelect = formalDatabaseData.value.filter((row) => + ids.includes(row.id) + ); + if (rowsToSelect.length > 0) { + etableRef.value.setRowsSelection(rowsToSelect, true); + } + } catch (error) { + } + }, 150); + }); +}; + +// 鍒濆鍖栧拰缂栬緫鍒濆鍖� +const Initialization = async () => { + tableData.value = []; + form.value = { + successNum: 0, + schedulingNum: 0, + finishedNum: 0, + schedulingUserId: "" + }; + detailsTableData.value = []; + copyForm.value = null; + dialogType.value = "add"; +}; + +const editInitialization = async (type, data) => { + //娓呯┖form + Initialization(); + productionQuantity.value = data.schedulingNum; + pendingNum.value = data.schedulingNum - data.successNum; + copyForm.value = deepClone(data); + tableData.value = data.productionInventoryList || []; + detailsTableData.value = data.productionList || []; + dialogType.value = type; + const existingOfficialIds = tableData.value + .map((item) => item.officialId) + .filter((id) => id); + selectedIds.value = existingOfficialIds; + +}; +// 鐩戝惉瀵硅瘽妗嗙姸鎬侊紝鍦ㄦ墦寮�鏃惰缃�変腑鐘舵�� +watch(innerVisible, (newVal) => { + if (newVal && selectedIds.value.length > 0) { + setTimeout(() => setTableSelection(selectedIds.value), 200); + } + // 瀵硅瘽妗嗗叧闂椂娓呯┖閫夋嫨鐘舵�� + if (!newVal) { + formalDatabaseSelectedData.value = []; + } +}); + +defineExpose({ + Initialization, + editInitialization, +}); +const handleSelectData = (row) => { + tableData.value = []; + if (!innerVisible.value) return; + const selectedData = formalDatabaseSelectedData.value; + if (selectedData.length === 0) { + ElMessage.warning("璇疯嚦灏戦�夋嫨涓�鏉℃暟鎹�"); + return; + } + let addedCount = 0; + let duplicateCount = 0; + selectedData.forEach((item) => { + const newItem = { + ...item, // 澶嶅埗鎵�鏈夊師濮嬫暟鎹� + officialId: item.id, // 淇濆瓨鍘熷鐨刬d浣滀负officialId + usedQuantity: 0, // 鍒濆浣跨敤鏁伴噺涓�0 + // 鍙互鏍规嵁闇�瑕佹坊鍔犲叾浠栧瓧娈� + }; + tableData.value.push(newItem); + addedCount++; + }); + + // 鏇存柊selectedIds锛岀‘淇濆寘鍚墍鏈夊綋鍓峵ableData涓殑officialId + const allOfficialIds = tableData.value + .map((item) => item.officialId) + .filter((id) => id); + selectedIds.value = allOfficialIds; + + // 鍏抽棴閫夋嫨瀵硅瘽妗� + innerVisible.value = false; + + // 鏄剧ず缁撴灉娑堟伅 + let message = ""; + if (addedCount > 0) { + message += `鎴愬姛娣诲姞 ${addedCount} 鏉℃暟鎹甡; + } + if (duplicateCount > 0) { + message += (message ? "锛�" : "") + `璺宠繃 ${duplicateCount} 鏉¢噸澶嶆暟鎹甡; + } + if (message) { + ElMessage.success(message); + } else { + ElMessage.info("娌℃湁鏂版暟鎹娣诲姞"); + } +}; +const handleSelectionChange = (selection) => { + formalDatabaseSelectedData.value = selection; +}; +// 鎻愪氦琛ㄥ崟 - 浣跨敤宸ュ叿鍑芥暟楠岃瘉 +const handleSubmit = async () => { + console.log(copyForm.value) + try{ + const res = await work({id: copyForm.value.id,successNum: form.value.finishedNum,schedulingUserId: form.value.schedulingUserId}) + if (res.code === 200) { + dialogVisible.value = false; + emit("success"); + } else { + ElMessage.error("鎻愪氦澶辫触"); + } + }catch (error){ + ElMessage.error("鎻愪氦澶辫触锛岃閲嶈瘯"); + } +}; +// 鍏抽棴寮圭獥 +const handleClose = () => { + dialogVisible.value = false; +}; + +// 浣跨敤鏁伴噺楠岃瘉 - 浣跨敤宸ュ叿鍑芥暟 +const handleCellEdit = (row, prop, value) => { + if (prop === "usedQuantity") { + const validation = validateNumber(value, 0, Number(row.inventoryQuantity)); + + if (!validation.isValid) { + ElMessage.warning(validation.message); + row.usedQuantity = validation.value; + return; + } + + row.usedQuantity = validation.value; + } +}; + +// 澶勭悊鐢熶骇鏄庣粏琛ㄦ牸鐨勬搷浣� - 浣跨敤宸ュ叿鍑芥暟 +const addNewRow = () => { + const newRow = createDefaultProductionRow(userInfo); + detailsTableData.value.push(newRow); +}; + + +// 鑾峰彇鐢ㄦ埛淇℃伅骞跺姞杞藉熀纭�鏁版嵁 +onMounted(async () => { + try { + let ress = await userListAll(); + userList.value = ress.data; + userInfo = await userStore.getInfo(); + } catch (error) { + ElMessage.error("鍒濆鍖栧け璐ワ紝璇烽噸璇�"); + } +}); + +// 绠�鍖栫殑浜嬩欢澶勭悊鍑芥暟 +const handleDetailsChange = (data) => { +}; + +const handleDeleteRow = (index) => { + ElMessage.success(`宸插垹闄ょ ${index + 1} 琛屾暟鎹甡); +}; + +// 鍒犻櫎鍗曚釜宸查�夋暟鎹」 +const handleRemoveItem = (row) => { + const index = tableData.value.findIndex( + (item) => item.officialId === row.officialId + ); + if (index > -1) { + tableData.value.splice(index, 1); + + // 鏇存柊selectedIds + const updatedOfficialIds = tableData.value + .map((item) => item.officialId) + .filter((id) => id); + selectedIds.value = updatedOfficialIds; + ElMessage.success("宸插垹闄ら�変腑椤�"); + } +}; + + +// 璁$畻鎬讳娇鐢ㄩ噺 +const totalUsedQuantity = computed(() => { + return tableData.value.reduce((total, item) => { + const usedQty = Number(item.usedQuantity) || 0; + return total + usedQty; + }, 0); +}); +</script> + +<style scoped lang="scss"> +.el-form { + .el-row { + padding-top: 20px; + background: rgba($color: #f8fafb, $alpha: 0.5); + } +} + +.el-row > .el-col > h1 { + font-weight: bolder; +} + +.empty-table > .el-row { + margin-bottom: 12px; +} +</style> -- Gitblit v1.9.3