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/operationScheduling/components/ProductionDetailsTable.vue |  360 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 360 insertions(+), 0 deletions(-)

diff --git a/src/views/production/operationScheduling/components/ProductionDetailsTable.vue b/src/views/production/operationScheduling/components/ProductionDetailsTable.vue
new file mode 100644
index 0000000..72b4064
--- /dev/null
+++ b/src/views/production/operationScheduling/components/ProductionDetailsTable.vue
@@ -0,0 +1,360 @@
+<template>
+  <el-table :data="tableData" :border="border" style="width: 100%">
+    <el-table-column label="宸ュ簭" min-width="120">
+      <template #default="{ row, $index }">
+        <el-select
+            clearable
+            v-model="row.process"
+            placeholder="璇烽�夋嫨宸ュ簭"
+            filterable
+            :disabled="isViewMode"
+        >
+          <el-option
+              v-for="(item, index) of process_list"
+              :label="item.label"
+              :value="item.value"
+          />
+        </el-select>
+      </template>
+    </el-table-column>
+    <el-table-column label="鍗曚綅" min-width="120">
+      <template #default="{ row, $index }">
+        <el-input
+            v-model="row.unit"
+            placeholder="璇疯緭鍏ュ崟浣�"
+            :disabled="isViewMode"
+        />
+      </template>
+
+    </el-table-column>
+    <el-table-column label="鎺掍骇鏁伴噺" min-width="120">
+      <template #default="{ row, $index }">
+        <el-input
+            v-model="row.schedulingNum"
+            placeholder="璇疯緭鍏ユ帓浜ф暟閲�"
+            type="number"
+            :disabled="isViewMode"
+        />
+      </template>
+    </el-table-column>
+
+    <el-table-column label="宸ユ椂瀹氶" min-width="120">
+      <template #default="{ row, $index }">
+        <el-input
+            v-model="row.workHours"
+            placeholder="璇疯緭鍏ュ伐鏃跺畾棰�"
+            type="number"
+            @input="handleInput('workHours', $index, $event)"
+            :disabled="isViewMode"
+        >
+        </el-input>
+      </template>
+    </el-table-column>
+
+    <el-table-column label="鎺掍骇鏃ユ湡" min-width="120">
+      <template #default="{ row, $index }">
+        <el-date-picker
+            v-model="row.schedulingDate"
+            type="datetime"
+            clearable
+            placeholder="閫夋嫨鏃ユ湡"
+            format="YYYY-MM-DD"
+            value-format="YYYY-MM-DD"
+        />
+      </template>
+    </el-table-column>
+
+    <el-table-column label="鎺掍骇浜�" min-width="120">
+      <template #default="{ row, $index }">
+        <el-select
+            clearable
+            v-model="row.schedulingUserId"
+            placeholder="璇烽�夋嫨鎺掍骇浜�"
+            filterable
+            :key="`producer-select-${$index}-${userList.length}`"
+            :disabled="isViewMode"
+        >
+          <el-option
+              v-for="(item, index) of userList"
+              :key="`option-${index}-${item.key}`"
+              :label="item.value"
+              :value="item.key"
+          />
+        </el-select>
+      </template>
+    </el-table-column>
+    <el-table-column
+        label="鎿嶄綔"
+        width="120"
+        fixed="right"
+        v-if="dialogType !== 'viewRow'"
+    >
+      <template #default="{ $index }">
+        <el-button
+            type="danger"
+            size="small"
+            @click="handleDelete($index)"
+            :icon="Delete"
+        >
+          鍒犻櫎
+        </el-button>
+      </template>
+    </el-table-column>
+  </el-table>
+</template>
+
+<script setup name="ProductionDetailsTable">
+import {ref, computed, watch, onMounted, nextTick} from "vue";
+import {Delete} from "@element-plus/icons-vue";
+import {ElMessage} from "element-plus";
+import {getCoalFieldList} from "@/api/basicInformation/coalQualityMaintenance";
+import {userListAll} from "@/api/publicApi";
+const { proxy } = getCurrentInstance();
+const {process_list} = proxy.useDict("process_list");
+
+const props = defineProps({
+  modelValue: {
+    type: Array,
+    default: () => [],
+  },
+  border: {
+    type: Boolean,
+    default: false,
+  },
+  showOperations: {
+    type: Boolean,
+    default: true,
+  },
+  autoCalculate: {
+    type: Boolean,
+    default: true,
+  },
+  dialogType:{
+    type: String,
+    default:'add'
+  }
+});
+const isViewMode = computed(() => props.dialogType === "viewRow");
+const emit = defineEmits(["update:modelValue", "input-change", "delete-row"]);
+
+// 浣跨敤 v-model 杩涜鍙屽悜缁戝畾
+const tableData = computed({
+  get() {
+    return props.modelValue;
+  },
+  set(value) {
+    emit("update:modelValue", value);
+  },
+});
+
+// 澶勭悊杈撳叆鍙樺寲
+const handleInput = (field, index, value) => {
+  // 纭繚杈撳叆鍊兼槸鏁板瓧鎴栫┖瀛楃涓茶�屼笖闈炶礋鏁�
+  if (!/^\d*\.?\d*$/.test(value) && value !== "") {
+    ElMessage.error("璇疯緭鍏ユ湁鏁堢殑鏁板瓧");
+    return;
+  }
+  const newData = [...tableData.value];
+  newData[index][field] = value;
+
+  // 濡傛灉寮�鍚嚜鍔ㄨ绠楁�绘垚鏈�
+  if (
+      props.autoCalculate &&
+      [
+        "laborCost",
+        "energyCost",
+        "equipmentDepreciation",
+        "purchasePrice",
+      ].includes(field)
+  ) {
+    calculateTotalCost(newData[index]);
+  }
+
+  tableData.value = newData;
+  emit("input-change", {field, index, value, row: newData[index]});
+};
+
+// 璁$畻鎬绘垚鏈�
+const calculateTotalCost = (row) => {
+  const laborCost = parseFloat(row.laborCost) || 0;
+  const energyCost = parseFloat(row.energyConsumptionCost) || 0;
+  const equipmentDepreciation = parseFloat(row.equipmentDepreciation) || 0;
+  const purchasePrice = parseFloat(row.purchasePrice) || 0;
+
+  row.totalCost = (
+      laborCost +
+      energyCost +
+      equipmentDepreciation +
+      purchasePrice
+  ).toFixed(2);
+};
+
+// 鍒犻櫎琛�
+const handleDelete = (index) => {
+  const newData = [...tableData.value];
+  newData.splice(index, 1);
+  tableData.value = newData;
+  emit("delete-row", index);
+};
+
+// 澶勭悊鐓ょ閫夋嫨鍙樺寲
+
+// 澶勭悊鐓ょ閫夋嫨鍙樺寲锛堟柊鏂规硶锛氬悕绉伴�夋嫨杞琁D锛�
+const handleCoalSelectChange = (row, selectedName) => {
+  // 鏍规嵁閫夋嫨鐨勫悕绉版壘鍒板搴旂殑ID
+  const coalItem = weekList.value.find(item => item.value === selectedName);
+  if (coalItem) {
+    row.coalId = coalItem.key; // 璁剧疆涓篒D
+  } else {
+    row.coalId = ''; // 濡傛灉娌℃壘鍒帮紝娓呯┖
+  }
+};
+
+// 鏍规嵁ID鑾峰彇鐓ょ鍚嶇О锛堢敤浜庢樉绀猴級
+const getCoalNameById = (id) => {
+  const coalId = weekList.value.find(item => item.key == id);
+  return coalId ? coalId.value : id;
+};
+
+const weekList = ref([]);
+
+
+// 鐩戝惉琛ㄦ牸鏁版嵁鍙樺寲锛岀‘淇濇樉绀烘纭�
+watch(() => props.modelValue, (newValue) => {
+  if (newValue && weekList.value.length > 0) {
+    // 褰撴暟鎹姞杞藉畬鎴愪笖weekList宸茶幏鍙栨椂锛岀‘淇濇樉绀烘纭�
+  }
+}, {deep: true});
+
+// 鐩戝惉weekList鍙樺寲锛屽綋涓嬫媺鏁版嵁鍔犺浇瀹屾垚鍚庡鐞嗘樉绀�
+watch(weekList, (newList) => {
+  if (newList.length > 0 && tableData.value.length > 0) {
+    // 寮哄埗瑙﹀彂琛ㄦ牸閲嶆柊娓叉煋浠ョ‘淇漞l-select姝g‘鏄剧ず
+    nextTick(() => {
+      // 瑙﹀彂涓�涓井灏忕殑鏁版嵁鍙樺寲鏉ュ己鍒堕噸鏂版覆鏌�
+      const tempData = [...tableData.value];
+      tableData.value = tempData;
+    });
+  }
+}, {deep: true});
+
+onMounted(async () => {
+  let ress = await userListAll();
+  ress.data.forEach(item => {
+    let obj = {};
+    obj.value = item.nickName;
+    obj.key = item.userId;
+    userList.value.push(obj);
+  });
+})
+const dropdownList = ref([]);
+// 鑾峰彇涓嬫媺鏁版嵁
+const getDropdownData = async () => {
+  let res = await getCoalFieldList();
+  if (res.code === 200) {
+    dropdownList.value = res.data.map((item) => ({
+      value: item.coal,
+      key: item.id,
+    }));
+  } else {
+    ElMessage.error("鑾峰彇涓嬫媺鏁版嵁澶辫触");
+  }
+};
+const userList = ref([]);
+const getUserList = (async () => {
+  let res = await userListAll();
+  if (res.code === 200) {
+    userList.value = res.data.map((item) => ({
+      value: item.nickName,
+      key: item.userId,
+    }));
+  } else {
+    ElMessage.error("鑾峰彇鐢ㄦ埛鍒楄〃澶辫触");
+  }
+})
+// 鐩戝惉琛ㄦ牸鏁版嵁鍙樺寲锛岀‘淇濇樉绀烘纭�
+watch(() => props.modelValue, (newValue) => {
+  if (newValue && userList.value.length > 0) {
+    // 褰撴暟鎹姞杞藉畬鎴愪笖weekList宸茶幏鍙栨椂锛岀‘淇濇樉绀烘纭�
+  }
+}, {deep: true});
+
+// 鐩戝惉userList鍙樺寲锛屽綋涓嬫媺鏁版嵁鍔犺浇瀹屾垚鍚庡鐞嗘樉绀�
+watch(userList, (newList) => {
+  if (newList.length > 0 && tableData.value.length > 0) {
+    // 寮哄埗瑙﹀彂琛ㄦ牸閲嶆柊娓叉煋浠ョ‘淇漞l-select姝g‘鏄剧ず
+    nextTick(() => {
+      // 瑙﹀彂涓�涓井灏忕殑鏁版嵁鍙樺寲鏉ュ己鍒堕噸鏂版覆鏌�
+      const tempData = [...tableData.value];
+      tableData.value = tempData;
+    });
+  }
+}, {deep: true});
+
+const getUserNameById = (id) => {
+  const producer = userList.value.find(item => item.key == id);
+  return producer ? producer.value : id;
+};
+// 澶勭悊鐢ㄦ埛閫夋嫨鍙樺寲锛堟柊鏂规硶锛氬悕绉伴�夋嫨杞琁D锛�
+const handleUserSelectChange = (row, selectedName) => {
+  console.log("handleUserSelectChange", row, selectedName);
+  // 鏍规嵁閫夋嫨鐨勫悕绉版壘鍒板搴旂殑ID
+  const userItem = userList.value.find(item => item.value === selectedName);
+  if (userItem) {
+    row.producerId = userItem.key; // 璁剧疆涓篒D
+  } else {
+    row.producerId = ''; // 濡傛灉娌℃壘鍒帮紝娓呯┖
+  }
+};
+// 鏆撮湶鏂规硶缁欑埗缁勪欢浣跨敤
+defineExpose({
+  calculateTotalCost,
+  getDropdownData,
+  getUserList,
+  getCoalNameById, // 鏆撮湶鑾峰彇鐓ょ鍚嶇О鐨勬柟娉�
+  weekList, // 鏆撮湶weekList璁╃埗缁勪欢鍙互璁块棶
+  addRow: (rowData = {}) => {
+    const defaultRow = {
+      process: "宸ュ簭1",
+      unit: "椤�",
+      schedulingNum: "",
+      workHours: "",
+      schedulingDate: "",
+      schedulingUserId: "",
+      schedulingUserName: ""
+    };
+    tableData.value = [...tableData.value, defaultRow];
+  },
+  clearData: () => {
+    tableData.value = [];
+  },
+  // 娣诲姞涓�涓柟娉曟潵绛夊緟weekList鍔犺浇瀹屾垚
+  waitForWeekList: () => {
+    return new Promise((resolve) => {
+      if (weekList.value.length > 0) {
+        resolve();
+      } else {
+        const unwatch = watch(weekList, (newList) => {
+          if (newList.length > 0) {
+            unwatch();
+            resolve();
+          }
+        });
+      }
+    });
+  },
+  // 寮哄埗鍒锋柊琛ㄦ牸鏄剧ず
+  forceRefresh: () => {
+    nextTick(() => {
+      const tempData = [...tableData.value];
+      tableData.value = tempData;
+    });
+  }
+});
+</script>
+
+<style scoped>
+:deep(.el-table .el-table__cell) {
+  padding: 8px 0;
+}
+</style>

--
Gitblit v1.9.3