From 7c86b549b27bd54f6bd5de81c13f8242f91c87ff Mon Sep 17 00:00:00 2001
From: 张诺 <zhang_12370@163.com>
Date: 星期一, 16 六月 2025 18:03:27 +0800
Subject: [PATCH] 优化文件上传组件及表格显示

---
 src/views/production/index.vue |  417 +++++++++++++++++++++++++++--------------------------------
 1 files changed, 193 insertions(+), 224 deletions(-)

diff --git a/src/views/production/index.vue b/src/views/production/index.vue
index dbad178..531640a 100644
--- a/src/views/production/index.vue
+++ b/src/views/production/index.vue
@@ -1,278 +1,247 @@
 <template>
   <div class="production-container">
-    <div class="search-bar">
-      <el-input v-model="searchForm.keyword" placeholder="璇疯緭鍏ュ叧閿瘝" clearable />
-      <el-input v-model="searchForm.addUser" placeholder="璇疯緭鍏ヤ汉" clearable />
-      <el-button type="primary" @click="handleSearch">鏌ヨ</el-button>
-      <el-button @click="handleReset">閲嶇疆</el-button>
-    </div>
+    <!-- 鎼滅储琛ㄥ崟 -->
+    <el-form :inline="true" :model="queryParams" class="search-form">
+      <el-form-item label="鎼滅储">
+        <el-input
+          v-model="queryParams.searchAll"
+          placeholder="璇疯緭鍏ュ叧閿瘝"
+          clearable
+        />
+      </el-form-item>
+      <el-form-item>
+        <el-button type="primary" @click="handleSearch">鏌ヨ</el-button>
+        <el-button @click="handleReset">閲嶇疆</el-button>
+      </el-form-item>
+    </el-form>
 
-    <div class="operation-bar">
-      <el-button type="primary" @click="handleAdd">鏂板閰嶉」</el-button>
-      <el-button type="success" @click="handleAddBatch">鏂板鍔犲伐</el-button>
-      <el-button type="warning">淇敼</el-button>
-      <el-button type="danger">鍒犻櫎</el-button>
-      <el-button type="info">瀵煎嚭</el-button>
-    </div>
+    <!-- 涓昏鍐呭鍖哄煙 -->
+    <el-card>
+      <!-- 鎿嶄綔鎸夐挳 -->
+      <div class="toolbar">
+        <el-button type="success" :icon="Plus" @click="openDialog('add')">
+          鏂板鍔犲伐
+        </el-button>
+        <el-button type="danger" :icon="Delete" :disabled="!selectedRows.length">
+          鍒犻櫎
+        </el-button>
+      </div>
 
-    <el-table :data="tableData" border style="width: 100%" @selection-change="handleSelectionChange">
-      <el-table-column type="selection" width="55" />
-      <el-table-column prop="sequence" label="搴忓彿" width="80" />
-      <el-table-column prop="category" label="鐓ょ" width="120" />
-      <el-table-column prop="unit" label="鍗曚綅" width="100" />
-      <el-table-column prop="productionVolume" label="鐢熶骇鏁伴噺" width="120" />
-      <el-table-column prop="laborCost" label="浜哄伐鎴愭湰" width="120" />
-      <el-table-column prop="materialCost" label="鍘熸枡鎴愭湰" width="120" />
-      <el-table-column prop="equipmentCost" label="璁惧璐圭敤" width="120" />
-      <el-table-column prop="totalCost" label="鎬绘垚鏈�" width="120" />
-      <el-table-column prop="totalPrice" label="鎬绘垚鏈�" width="120" />
-      <el-table-column prop="profit" label="鍒╂鼎" width="100" />
-      <el-table-column prop="reviewer" label="澶嶈浜�" width="120" />
-      <el-table-column prop="date" label="鏃ユ湡" width="120" />
-      <el-table-column label="鎿嶄綔" fixed="right" width="220">
-        <template #default="scope">
-          <el-button type="primary" link @click="handleEdit(scope.row)">鐧昏</el-button>
-          <el-button type="success" link @click="handleEdit(scope.row)">缂栬緫</el-button>
-          <el-button type="danger" link @click="handleDelete(scope.row)">鍒犻櫎</el-button>
-          <el-button type="warning" link @click="handleExport(scope.row)">瀵煎嚭</el-button>
+      <!-- 鏁版嵁琛ㄦ牸 -->
+      <ETable
+        :loading="loading"
+        :table-data="tableData"
+        :columns="columns"
+        @selection-change="handleSelectionChange"
+        @edit="row => openDialog('edit', row)"
+        :show-selection="true"
+        :border="true"
+        :maxHeight="480"
+      >
+        <template #coal="{ row }">
+          <div class="coal-tags">
+            <el-tag v-for="coal in parseCoalArray(row.coal)" :key="coal" size="small">
+              {{ coal }}
+            </el-tag>
+            <span v-if="!row.coal">--</span>
+          </div>
         </template>
-      </el-table-column>
-    </el-table>
+      </ETable>
 
-    <div class="pagination">
-      <el-pagination
-        v-model:current-page="pagination.currentPage"
-        v-model:page-size="pagination.pageSize"
-        :page-sizes="[10, 20, 30, 50]"
-        :total="pagination.total"
-        layout="total, sizes, prev, pager, next, jumper"
-        @size-change="handleSizeChange"
-        @current-change="handleCurrentChange"
+      <!-- 鍒嗛〉缁勪欢 -->
+      <Pagination
+        :total="total"
+        :page="queryParams.current"
+        :limit="queryParams.size"
+        @pagination="handlePageChange"
       />
-    </div>
+    </el-card>
 
-    <!-- 寮圭獥缁勪欢 -->
-    <ProductionDialog-dialog
+    <!-- 鐢熶骇瀵硅瘽妗� -->
+    <ProductionDialog
       v-model:visible="dialogVisible"
+      ref="dialogRef"
       :type="dialogType"
-      :row-data="currentRow"
       @success="handleDialogSuccess"
     />
   </div>
 </template>
 
 <script setup>
-import { ref, reactive, onMounted } from 'vue'
-import { ElMessage, ElMessageBox } from 'element-plus'
-import { getProductionList, addProduction, updateProduction, deleteProduction, exportProduction } from '@/api/production'
-import ProductionDialog from './components/ProductionDialog.vue'
+import { ref, reactive, onMounted } from "vue";
+import { ElMessage, ElMessageBox } from "element-plus";
+import { Plus, Delete } from "@element-plus/icons-vue";
+import ProductionDialog from "./components/ProductionDialog.vue";
+import ETable from "@/components/Table/ETable.vue";
+import Pagination from "@/components/Pagination/index.vue";
+import { getProductionMasterList } from "@/api/production";
 
-// 鎼滅储琛ㄥ崟鏁版嵁
-const searchForm = reactive({
-  keyword: '',
-  addUser: ''
-})
+// 琛ㄦ牸鍒楅厤缃�
+const columns = [
+  { prop: "coal", label: "鐓ょ", minWidth: 150, slot: 'coal' },
+  { prop: "productionQuantity", label: "鐢熶骇鏁伴噺", minWidth: 120 },
+  { prop: "laborCost", label: "浜哄伐鎴愭湰", minWidth: 150 },
+  { prop: "energyConsumptionCost", label: "鑳借�楁垚鏈�", minWidth: 120 },
+  { prop: "equipmentDepreciation", label: "璁惧鎶樻棫", minWidth: 143 },
+  { prop: "totalCost", label: "鎬绘垚鏈�", minWidth: 150 },
+  { prop: "producer", label: "鐢熶骇浜�", minWidth: 150 },
+];
 
-// 琛ㄦ牸鏁版嵁
-const tableData = ref([])
-const loading = ref(false)
+// 鍝嶅簲寮忔暟鎹�
+const tableData = ref([]);
+const loading = ref(false);
+const total = ref(0);
+const selectedRows = ref([]);
+const dialogVisible = ref(false);
+const dialogType = ref("add");
+const dialogRef = ref(null);
 
-// 鍒嗛〉鏁版嵁
-const pagination = reactive({
-  currentPage: 1,
-  pageSize: 10,
-  total: 0
-})
-
-// 閫変腑鐨勮鏁版嵁
-const selectedRows = ref([])
-
-// 寮圭獥鐩稿叧
-const dialogVisible = ref(false)
-const dialogType = ref('add')
-const currentRow = ref(null)
+// 鏌ヨ鍙傛暟
+const queryParams = reactive({
+  searchAll: "",
+  current: 1,
+  size: 10,
+});
 
 // 鑾峰彇琛ㄦ牸鏁版嵁
+// 鑾峰彇琛ㄦ牸鏁版嵁
 const getList = async () => {
-  loading.value = true
+  loading.value = true;
   try {
+    // 鏋勫缓姝g‘鐨勫垎椤靛弬鏁�
     const params = {
-      ...searchForm,
-      pageNum: pagination.currentPage,
-      pageSize: pagination.pageSize
-    }
-    // const res = await getProductionList(params)
-    // 鍋囨暟鎹�
-    const res = {
-      data: {
-        list: [{
-          sequence: 1,
-          category: '鐓ょ',
-          unit: '鍗曚綅',
-          productionVolume: '鐢熶骇鏁伴噺',
-          laborCost: '浜哄伐鎴愭湰',
-          materialCost: '鍘熸枡鎴愭湰',
-          equipmentCost: '璁惧璐圭敤',
-          totalCost: '鎬绘垚鏈�',
-          totalPrice: '鎬绘垚鏈�',
-          profit: '鍒╂鼎',
-          reviewer: '澶嶈浜�',
-          date: '鏃ユ湡'
-        }],
-        total: 0
-      }
-    }
+      searchAll: queryParams.searchAll,
+      // 灏濊瘯澶氱甯歌鐨勫垎椤靛弬鏁版牸寮�
+      current: queryParams.current,
+      size: queryParams.size,
+      page: queryParams.current,
+      pageSize: queryParams.size,
+      pageNum: queryParams.current,
+      limit: queryParams.size,
+      offset: (queryParams.current - 1) * queryParams.size
+    };
     
-
-    tableData.value = res.data.list
-    pagination.total = res.data.total
+    console.log('鍙戦�佸垎椤靛弬鏁�:', params);
+    console.log(`绗�${queryParams.current}椤靛簲璇ユ樉绀虹${(queryParams.current - 1) * queryParams.size + 1}-${queryParams.current * queryParams.size}鏉℃暟鎹甡);
+    
+    const res = await getProductionMasterList(params);
+    tableData.value = res.data.records || [];
+    total.value = res.data.total || 0;
+    
+    console.log('鎺ユ敹鍒扮殑鏁版嵁:', {
+      褰撳墠椤�: queryParams.current,
+      杩斿洖鏉℃暟: tableData.value.length,
+      鎬绘潯鏁�: total.value
+    });
   } catch (error) {
-    console.error('鑾峰彇鏁版嵁澶辫触:', error)
-    ElMessage.error('鑾峰彇鏁版嵁澶辫触')
+    ElMessage.error("鑾峰彇鏁版嵁澶辫触");
+    console.error('API閿欒:', error);
   } finally {
-    loading.value = false
+    loading.value = false;
   }
-}
+};
 
-// 澶勭悊琛ㄦ牸閫夋嫨鍙樺寲
-const handleSelectionChange = (selection) => {
-  selectedRows.value = selection
-}
-
-// 鎼滅储鏂规硶
+// 鎼滅储鍜岄噸缃�
 const handleSearch = () => {
-  pagination.currentPage = 1
-  getList()
-}
+  queryParams.current = 1;
+  getList();
+};
 
-// 閲嶇疆鎼滅储
 const handleReset = () => {
-  searchForm.keyword = ''
-  searchForm.addUser = ''
-  handleSearch()
-}
+  queryParams.searchAll = "";
+  handleSearch();
+};
 
-// 鏂板閰嶉」
-const handleAdd = () => {
-  dialogType.value = 'add'
-  dialogVisible.value = true
-}
+// 鍒嗛〉澶勭悊
+const handlePageChange = ({ page }) => {
+  queryParams.current = page;
+  getList();
+};
 
-// 鏂板鍔犲伐
-const handleAddBatch = () => {
-  dialogType.value = 'add'
-  dialogVisible.value = true
-}
+// 琛ㄦ牸閫夋嫨澶勭悊
+const handleSelectionChange = (selection) => {
+  selectedRows.value = selection;
+};
 
-// 缂栬緫
-const handleEdit = (row) => {
-  currentRow.value = row
-  dialogType.value = 'edit'
-  dialogVisible.value = true
-}
-
-// 澶勭悊寮圭獥鎻愪氦
-const handleDialogSuccess = async (formData) => {
-  try {
-    if (dialogType.value === 'add') {
-      await addProduction(formData)
-      ElMessage.success('鏂板鎴愬姛')
-    } else {
-      await updateProduction({
-        ...formData,
-        id: currentRow.value.id
-      })
-      ElMessage.success('鏇存柊鎴愬姛')
-    }
-    getList()
-  } catch (error) {
-    console.error(dialogType.value === 'add' ? '鏂板澶辫触:' : '鏇存柊澶辫触:', error)
-    ElMessage.error(dialogType.value === 'add' ? '鏂板澶辫触' : '鏇存柊澶辫触')
+// 鎵撳紑瀵硅瘽妗� - 缁熶竴澶勭悊鏂板鍜岀紪杈�
+const openDialog = (type, row = null) => {
+  dialogType.value = type;
+  dialogVisible.value = true;
+  
+  if (type === 'add') {
+    dialogRef.value?.Initialization();
+  } else if (type === 'edit' && row) {
+    dialogRef.value?.editInitialization({ ...row });
   }
-}
+};
 
-// 鍒犻櫎
-const handleDelete = (row) => {
-  ElMessageBox.confirm('纭鍒犻櫎璇ヨ褰曞悧锛�', '鎻愮ず', {
-    confirmButtonText: '纭畾',
-    cancelButtonText: '鍙栨秷',
-    type: 'warning'
-  }).then(async () => {
-    try {
-      await deleteProduction(row.id)
-      ElMessage.success('鍒犻櫎鎴愬姛')
-      getList()
-    } catch (error) {
-      console.error('鍒犻櫎澶辫触:', error)
-      ElMessage.error('鍒犻櫎澶辫触')
-    }
-  }).catch(() => {
-    ElMessage.info('宸插彇娑堝垹闄�')
-  })
-}
+// 瀵硅瘽妗嗘垚鍔熷洖璋�
+const handleDialogSuccess = () => {
+  getList();
+  ElMessage.success("鎿嶄綔鎴愬姛");
+};
 
-// 瀵煎嚭
-const handleExport = async (row) => {
-  try {
-    const res = await exportProduction({ id: row.id })
-    const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
-    const fileName = `鐢熶骇鍔犲伐璁板綍_${new Date().getTime()}.xlsx`
-    if ('download' in document.createElement('a')) {
-      const elink = document.createElement('a')
-      elink.download = fileName
-      elink.style.display = 'none'
-      elink.href = URL.createObjectURL(blob)
-      document.body.appendChild(elink)
-      elink.click()
-      URL.revokeObjectURL(elink.href)
-      document.body.removeChild(elink)
-    } else {
-      navigator.msSaveBlob(blob, fileName)
-    }
-  } catch (error) {
-    console.error('瀵煎嚭澶辫触:', error)
-    ElMessage.error('瀵煎嚭澶辫触')
-  }
-}
-
-// 澶勭悊姣忛〉鏄剧ず鏁伴噺鍙樺寲
-const handleSizeChange = (val) => {
-  pagination.pageSize = val
-  getList()
-}
-
-// 澶勭悊椤电爜鍙樺寲
-const handleCurrentChange = (val) => {
-  pagination.currentPage = val
-  getList()
-}
+// 瑙f瀽鐓ょ鏁扮粍 - 绠�鍖栭�昏緫
+const parseCoalArray = (coalString) => {
+  if (!coalString) return [];
+  
+  if (Array.isArray(coalString)) return coalString;
+  
+  return String(coalString)
+    .replace(/^\[|\]$/g, '')
+    .split(',')
+    .map(item => item.trim())
+    .filter(Boolean);
+};
 
 // 缁勪欢鎸傝浇鏃跺姞杞芥暟鎹�
-onMounted(() => {
-  getList()
-})
+onMounted(getList);
 </script>
 
-<style scoped>
+<style scoped lang="scss">
 .production-container {
   padding: 20px;
+
+  .el-card:nth-child(1) {
+    margin-bottom: 20px;
+  }
 }
 
 .search-bar {
   margin-bottom: 20px;
   display: flex;
   gap: 10px;
-}
 
-.operation-bar {
+  .el-input {
+    width: 20%;
+  }
+}
+.search-form {
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
   margin-bottom: 20px;
-  display: flex;
-  gap: 10px;
-}
 
-.pagination {
-  margin-top: 20px;
-  display: flex;
-  justify-content: flex-end;
+  .el-form-item {
+    margin-right: 10px;
+  }
+
+  .el-button {
+    margin-left: 10px;
+  }
 }
-</style> 
\ No newline at end of file
+.coal-tags {
+  display: flex;
+  flex-wrap: wrap;
+  gap: 4px;
+  
+  .el-tag {
+    margin-right: 4px;
+    margin-bottom: 4px;
+    
+    &:last-child {
+      margin-right: 0;
+    }
+  }
+}
+</style>

--
Gitblit v1.9.3