2 Commitit fad26fab76 ... 00ae75bf47

Tekijä SHA1 Viesti Päivämäärä
  yby 00ae75bf47 yby 2 kuukautta sitten
  yby 3a8806b7d8 yby 2 kuukautta sitten
1 muutettua tiedostoa jossa 106 lisäystä ja 24 poistoa
  1. 106 24
      src/views/enterprise/createProject.vue

+ 106 - 24
src/views/enterprise/createProject.vue

@@ -7,6 +7,7 @@
       </div>
       <div class="createproject" style="display: flex; flex-direction: row;">
         <div style="width: 30px;">
+          <el-button>对照表</el-button>
           <div id="buttonContainer">
             <el-button v-for="buttonId in buttons" :key="buttonId" @click="showInterface(buttonId)" style="width: 30px">
               对<br>象<br>表<br> {{ buttonId }}
@@ -19,8 +20,8 @@
       </div>
     </div>
     <!-- 对象表详情部分 -->
-    <div style="margin-left: 20px;width: 30%">
-      <div v-if="activeButtonId!== null" class="interface" style="border-radius: 10px; overflow-y: auto; max-height: 300px;">
+    <div style="margin-left: 20px;width: 30%;">
+      <div v-if="activeButtonId!== null" class="interface" style="border-radius: 10px; overflow-y: auto; max-height: 700px;height: 700px">
         <table style="width: 100%; border-collapse: collapse; table-layout: fixed;">
           <thead>
           <tr>
@@ -28,6 +29,9 @@
             <th style="border: 1px solid #ddd; padding: 8px;">产品名称</th>
             <th style="border: 1px solid #ddd; padding: 8px;">产品代码</th>
             <th style="border: 1px solid #ddd; padding: 8px;">引出频次</th>
+            <th v-if="showAddButton">
+              <el-button icon="el-icon-plus" @click="addRowToRightTable(null, -1)"></el-button>
+            </th>
           </tr>
           </thead>
           <tbody>
@@ -39,9 +43,10 @@
               <input
                 type="text"
                 v-model="row.name"
-                :disabled="!isEditing || row.outnum > 0 || isReferenceTable(activeButtonId)"
+                :disabled="!isEditing || row.outnum > 0 || isReferenceTable(activeButtonId) || row.nameDisabled"
                 @blur="addNewRowIfNeeded"
                 :class="isReferenceTable(activeButtonId)? 'readonly-input' : ''"
+                :style="row.inputStyle"
                 style="border: none; width: 100%;"
               />
             </td>
@@ -49,9 +54,10 @@
               <input
                 type="text"
                 v-model="row.pronum"
-                :disabled="!isEditing || row.outnum > 0 || isReferenceTable(activeButtonId)"
+                :disabled="!isEditing || row.outnum > 0 || isReferenceTable(activeButtonId) || row.pronumDisabled"
                 @blur="addNewRowIfNeeded"
                 :class="isReferenceTable(activeButtonId)? 'readonly-input' : ''"
+                :style="row.inputStyle"
                 style="border: none; width: 100%;"
               />
             </td>
@@ -80,7 +86,7 @@
       <div style="border: 1px solid #ccc; padding: 25px;border-radius: 10px;">
         <el-button style="display: block; margin-bottom: 10px;" @click="toggleAddButton">添加>></el-button>
         <el-button style="display: block; margin-bottom: 100px;"><<收回</el-button>
-        <el-button style="width: 86.36px"> 保存 </el-button>
+        <el-button style="width: 86.36px" @click="saveAndHideAddButton"> 保存 </el-button>
       </div>
     </div>
     <!-- 待转内容表 -->
@@ -97,7 +103,9 @@
                 <span style="margin-left: 5%;">项目结束日期:</span>
                 <span style="margin-left: 5%;">项目组重复
                   <select style="height: 18px; width: 50px; margin-left: 5px;">
-                    <option></option>
+                    <option value="1">1</option>
+                    <option value="2">2</option>
+                    <option value="3">3</option>
                   </select>
                 </span>
                 <span style="margin-left: 5%; border: 1px #ccc solid; padding: 5px;">实验要求</span>
@@ -107,23 +115,36 @@
                 <table>
                   <tr>
                     <td>序号</td>
-                    <td v-for="item in rightTable.data" :key="'num-' + item.uniqueId || Math.random().toString(36).substring(2)">{{ item.num }}</td>
+                    <td v-for="(item, index) in rightTable.data" :key="'num-' + item.uniqueId || Math.random().toString(36).substring(2)">
+                      {{ item.num }}
+                    </td>
                   </tr>
                   <tr>
                     <td>产品名称</td>
-                    <td v-for="item in rightTable.data" :key="'name-' + item.uniqueId || Math.random().toString(36).substring(2)">{{ item.name }}</td>
+                    <td v-for="(item, index) in rightTable.data" :key="'name-' + item.uniqueId || Math.random().toString(36).substring(2)">
+                      {{ item.name }}
+                    </td>
                   </tr>
                   <tr>
                     <td>产品代码</td>
-                    <td v-for="item in rightTable.data" :key="'pronum-' + item.uniqueId || Math.random().toString(36).substring(2)">{{ item.pronum }}</td>
+                    <td v-for="(item, index) in rightTable.data" :key="'pronum-' + item.uniqueId || Math.random().toString(36).substring(2)">
+                      {{ item.pronum }}
+                    </td>
                   </tr>
                   <tr>
                     <td>种植密度</td>
-                    <td v-for="item in rightTable.data" :key="'density-' + item.uniqueId || Math.random().toString(36).substring(2)">{{ item.density }}</td>
+                    <td v-for="(item, index) in rightTable.data" :key="'density-' + item.uniqueId || Math.random().toString(36).substring(2)">
+                      {{ item.density }}
+                    </td>
+                  </tr>
+                  <tr>
+                    <td><el-button icon="el-icon-minus" @click="clearTableData(rightTableIndex)"></el-button></td>
+                    <td v-for="(item, index) in rightTable.data" :key="'action-' + index">
+                      <el-button icon="el-icon-minus" @click="handleMinusClick(index)"></el-button>
+                    </td>
                   </tr>
                 </table>
               </div>
-              <el-button icon="el-icon-remove-outline"></el-button>
             </div>
           </div>
         </div>
@@ -153,16 +174,32 @@ export default {
       selectedRightTable: [],
       isEditing: false,
       showAddButton: false,
+      rightTableRowDeleteVisibility: [],
     };
   },
   computed: {
     filteredTableData() {
       const tableData = this.getTableData(this.activeButtonId);
-      // 过滤掉全为空值的最后一行
       while (tableData.length && Object.values(tableData[tableData.length - 1]).every(value => value === '')) {
         tableData.pop();
       }
-      return tableData;
+      return tableData.map(row => {
+        if (row.outnum > 0) {
+          return {
+            ...row,
+            nameDisabled: true,
+            pronumDisabled: true,
+            inputStyle: { backgroundColor: '#f5f5f5', cursor: 'not-allowed' }
+          };
+        } else {
+          return {
+            ...row,
+            nameDisabled: false,
+            pronumDisabled: false,
+            inputStyle: {}
+          };
+        }
+      });
     }
   },
   methods: {
@@ -199,9 +236,7 @@ export default {
     generateNewIndex(buttonId) {
       const tableData = this.getTableData(buttonId);
       const lastRow = tableData.length? tableData[tableData.length - 1] : null;
-      const lastIndex = lastRow
-        ? parseInt(lastRow.num.split('-')[1]) || 0
-        : 0;
+      const lastIndex = lastRow? parseInt(lastRow.num.split('-')[1]) || 0 : 0;
       return `obj-${String(lastIndex + 1).padStart(2, '0')}`;
     },
     createRightTable() {
@@ -209,8 +244,8 @@ export default {
         id: this.tableCounter + 1,
         title: `表 ${this.tableCounter + 1}`,
         data: [],
-        isChecked: false, // 添加 isChecked 属性,初始化为 false
-        groupCode: `2024-${String(this.tableCounter + 1).padStart(2, '0')}` // 设置组编码
+        isChecked: false,
+        groupCode: `2024-${String(this.tableCounter + 1).padStart(2, '0')}`
       };
       this.rightTables.push(newTable);
       this.tableCounter++;
@@ -225,18 +260,51 @@ export default {
       if (!activeButtonId || selectedRightTableIndex === null) {
         return;
       }
-      // 只对选中的表进行操作
       if (this.rightTables[selectedRightTableIndex].isChecked) {
+        if (rowIndex === -1) {
+          const tableData = this.getTableData(activeButtonId);
+          tableData.forEach((item, index) => {
+            if (!item.name ||!item.pronum) {
+              Message.warning('产品名称和产品代码不能为空!');
+              return;
+            }
+            const newItem = {
+              num: this.rightTables[selectedRightTableIndex].data.length + 1,
+              name: item.name,
+              pronum: item.pronum,
+              density: 10000,
+              uniqueId: Math.random().toString(36).substring(2),
+              showDeleteButton: false,
+            };
+            this.rightTables[selectedRightTableIndex].data.push(newItem);
+          });
+          this.$set(this.rightTables, selectedRightTableIndex, this.rightTables[selectedRightTableIndex]);
+          return;
+        }
+        if (!row.name ||!row.pronum) {
+          Message.warning('产品名称和产品代码不能为空!');
+          return;
+        }
         const newItem = {
           num: this.rightTables[selectedRightTableIndex].data.length + 1,
           name: row.name,
           pronum: row.pronum,
           density: 10000,
-          uniqueId: Math.random().toString(36).substring(2) // 生成临时唯一 ID
+          uniqueId: Math.random().toString(36).substring(2),
+          showDeleteButton: false,
         };
         this.rightTables[selectedRightTableIndex].data.push(newItem);
-        // 更新选中表的数据显示
         this.$set(this.rightTables, selectedRightTableIndex, this.rightTables[selectedRightTableIndex]);
+        this.increaseOutnum(rowIndex);
+      }
+    },
+    increaseOutnum(rowIndex) {
+      const activeButtonId = this.activeButtonId;
+      if (!activeButtonId) return;
+      const tableData = this.getTableData(activeButtonId);
+      if (tableData[rowIndex]) {
+        tableData[rowIndex].outnum++;
+        this.$set(this.tableDataMap, activeButtonId, tableData);
       }
     },
     isReferenceTable(buttonId) {
@@ -260,14 +328,28 @@ export default {
       this.isEditing = true;
     },
     saveChanges() {
-      // 保存逻辑可以根据实际需求进行实现
       this.isEditing = false;
-      // 更新数据映射,去除空行
       const tableData = this.filteredTableData;
       this.$set(this.tableDataMap, this.activeButtonId, tableData);
     },
     toggleAddButton() {
-      this.showAddButton =!this.showAddButton;
+      this.showAddButton = true;
+    },
+    saveAndHideAddButton() {
+      this.showAddButton = false;
+    },
+    handleMinusClick(index) {
+      const selectedRightTableIndex = this.activeRightTableIndex;
+      if (selectedRightTableIndex === null) return;
+      this.rightTables[selectedRightTableIndex].data.splice(index, 1);
+      this.rightTables[selectedRightTableIndex].data.forEach((item, newIndex) => {
+        item.num = newIndex + 1;
+      });
+    },
+    clearTableData(index) {
+      if (index!== null) {
+        this.rightTables[index].data = [];
+      }
     },
   },
 };