From 8b5bfdeb201b2653fb648f742b6d4ff5ff05ff6c Mon Sep 17 00:00:00 2001
From: lixiangyu <lixiangyu@xalxzn.com>
Date: 星期三, 27 八月 2025 17:59:29 +0800
Subject: [PATCH] refactor(刀具管理): 重构刀具管理相关组件结构

---
 src/views/cms/RatedLifeList.vue |  428 +++++++++++++++++++++++++++++++++++------------------
 1 files changed, 283 insertions(+), 145 deletions(-)

diff --git a/src/views/cms/RatedLifeList.vue b/src/views/cms/RatedLifeList.vue
index dc721ec..0a7b55f 100644
--- a/src/views/cms/RatedLifeList.vue
+++ b/src/views/cms/RatedLifeList.vue
@@ -1,61 +1,19 @@
 <template>
   <a-card :bordered="false">
-    <!-- 鏌ヨ鍖哄煙 -->
-    <div class="table-page-search-wrapper">
-      <a-form layout="inline" @keyup.enter.native="searchQuery">
-        <a-row :gutter="24">
-          <a-col :md="6" :sm="8">
-            <a-form-item label="鍒�鍏风紪鐮�">
-              <a-input placeholder="璇疯緭鍏ュ垁鍏风紪鐮�" v-model="queryParam.cuttingId" />
-            </a-form-item>
-          </a-col>
-          <a-col :md="6" :sm="8">
-              <a-form-item label="宸ヤ欢鏉愯川">
-                <a-input placeholder="璇疯緭鍏ュ伐浠舵潗璐�" v-model="queryParam.workpieceMaterial" />
-              </a-form-item>
-            </a-col>
-            <a-col
-            :md="6"
-            :sm="8"
-          >
-            <span
-              style="float: left;overflow: hidden;"
-              class="table-page-search-submitButtons"
-            >
-              <a-button
-                type="primary"
-                @click="searchQuery"
-                icon="search"
-              >鏌ヨ</a-button>
-              <a-button
-                type="primary"
-                @click="searchReset"
-                icon="reload"
-                style="margin-left: 8px"
-              >閲嶇疆</a-button>
-            </span>
-          </a-col>
-        </a-row>
-      </a-form>
-    </div>
-    <!-- 鏌ヨ鍖哄煙-END -->
-
-    <!-- 鎿嶄綔鎸夐挳鍖哄煙 -->
-    <div class="table-operator">
-      <a-button @click="handleAdd" type="primary" icon="plus">鏂板</a-button>
-      <a-button type="primary" icon="download" @click="handleExportXls('棰濆畾瀵垮懡')">瀵煎嚭</a-button>
-      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
-        <a-button type="primary" icon="import">瀵煎叆</a-button>
-      </a-upload>
+    <!-- 鏂板鎸夐挳 -->
+    <div class="table-operator" style="margin-bottom: 10px;">
+      <a-button
+        @click="handleAdd"
+        type="primary"
+        icon="plus"
+        :disabled="!selectedCuttingId || selectedCuttingId === '' || selectedCuttingId === '-1'"
+      >
+        鏂板
+      </a-button>
     </div>
 
     <!-- table鍖哄煙-begin -->
     <div>
-      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
-        <i class="anticon anticon-info-circle ant-alert-icon"></i> 宸查�夋嫨 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>椤�
-        <a style="margin-left: 24px" @click="onClearSelected">娓呯┖</a>
-      </div>
-
       <a-table
         ref="table"
         size="middle"
@@ -66,7 +24,6 @@
         :dataSource="dataSource"
         :pagination="ipagination"
         :loading="loading"
-        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
         class="j-table-force-nowrap"
         @change="handleTableChange">
 
@@ -90,23 +47,49 @@
           </a-button>
         </template>
 
-        <span slot="action" slot-scope="text, record">
-          <a @click="handleEdit(record)">缂栬緫</a>
+        <!-- 鍙紪杈戝崟鍏冩牸 -->
+        <template
+          v-for="col in ['workpieceMaterial', 'ratedLife']"
+          :slot="col"
+          slot-scope="text, record"
+        >
+          <div :key="col">
+            <a-input
+              v-if="record.editable"
+              style="margin: -5px 0"
+              :value="text"
+              @change="e => handleChange(e.target.value, record.id, col)"
+            />
+            <template v-else>
+              {{ text }}
+            </template>
+          </div>
+        </template>
 
-          <a-divider type="vertical" />
-          <a-dropdown>
-            <a class="ant-dropdown-link">鏇村 <a-icon type="down" /></a>
-            <a-menu slot="overlay">
-              <a-menu-item>
-                <a @click="handleDetail(record)">璇︽儏</a>
-              </a-menu-item>
-              <a-menu-item>
-                <a-popconfirm title="纭畾鍒犻櫎鍚�?" @confirm="() => handleDelete(record.id)">
-                  <a>鍒犻櫎</a>
-                </a-popconfirm>
-              </a-menu-item>
-            </a-menu>
-          </a-dropdown>
+        <!-- 鎿嶄綔鍒� -->
+        <span slot="action" slot-scope="text, record">
+          <div class="editable-row-operations">
+            <span v-if="record.editable">
+              <a-popconfirm title="纭畾淇濆瓨?" @confirm="() => save(record.id)">
+                <a>淇濆瓨</a>
+              </a-popconfirm>
+              <a style="margin-left: 8px" @click="() => cancel(record.id)">鍙栨秷</a>
+            </span>
+            <span v-else>
+              <a :disabled="editingKey !== ''" @click="() => edit(record.id)">缂栬緫</a>
+              <a-divider type="vertical" />
+              <a-dropdown>
+                <a class="ant-dropdown-link">鏇村 <a-icon type="down" /></a>
+                <a-menu slot="overlay">
+                  <a-menu-item>
+                    <a-popconfirm title="纭畾鍒犻櫎鍚�?" @confirm="() => handleDelete(record.id)">
+                      <a>鍒犻櫎</a>
+                    </a-popconfirm>
+                  </a-menu-item>
+                </a-menu>
+              </a-dropdown>
+            </span>
+          </div>
         </span>
 
       </a-table>
@@ -117,91 +100,246 @@
 </template>
 
 <script>
+import '@/assets/less/TableExpand.less'
+import { mixinDevice } from '@/utils/mixin'
+import { JeecgListMixin } from '@/mixins/JeecgListMixin'
+import { putAction, getAction, postAction } from '@/api/manage'
+import RatedLifeModal from './modules/RatedLifeModal'
 
-  import '@/assets/less/TableExpand.less'
-  import { mixinDevice } from '@/utils/mixin'
-  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
-  import RatedLifeModal from './modules/RatedLifeModal'
-
-  export default {
-    name: 'RatedLifeList',
-    mixins:[JeecgListMixin, mixinDevice],
-    components: {
-      RatedLifeModal
-    },
-    data () {
-      return {
-        description: '棰濆畾瀵垮懡绠$悊椤甸潰',
-        // 琛ㄥご
-        columns: [
-          {
-            title: '#',
-            dataIndex: '',
-            key:'rowIndex',
-            width:60,
-            align:"center",
-            customRender:function (t,r,index) {
-              return parseInt(index)+1;
-            }
-          },
-          {
-            title:'鍒�鍏风紪鐮�',
-            align:"center",
-            dataIndex: 'cuttingId',
-            sorter: true
-          },
-          {
-            title:'宸ヤ欢鏉愯川',
-            align:"center",
-            dataIndex: 'workpieceMaterial'
-          },
-          {
-            title:'棰濆畾瀵垮懡',
-            align:"center",
-            dataIndex: 'ratedLife'
-          },
-          {
-            title: '鎿嶄綔',
-            dataIndex: 'action',
-            align:"center",
-            fixed:"right",
-            width:147,
-            scopedSlots: { customRender: 'action' }
+export default {
+  name: 'RatedLifeList',
+  mixins:[JeecgListMixin, mixinDevice],
+  components: {
+    RatedLifeModal
+  },
+  props: {
+    selectedCuttingId: {
+      type: String,
+      default: ''
+    }
+  },
+  data () {
+    return {
+      description: '棰濆畾瀵垮懡绠$悊椤甸潰',
+      editingKey: '',
+      // 琛ㄥご
+      columns: [
+        {
+          title: '#',
+          dataIndex: '',
+          key:'rowIndex',
+          width:60,
+          align:"center",
+          customRender:function (t,r,index) {
+            return parseInt(index)+1;
           }
-        ],
-        url: {
-          list: "/cms/ratedLife/list",
-          delete: "/cms/ratedLife/delete",
-          deleteBatch: "/cms/ratedLife/deleteBatch",
-          exportXlsUrl: "/cms/ratedLife/exportXls",
-          importExcelUrl: "cms/ratedLife/importExcel",
-
         },
-        dictOptions:{},
-        superFieldList:[],
+        {
+          title:'鍒�鍏风紪鐮�',
+          align:"center",
+          dataIndex: 'cuttingId_dictText',
+          sorter: true
+        },
+        {
+          title:'宸ヤ欢鏉愯川',
+          align:"center",
+          dataIndex: 'workpieceMaterial',
+          scopedSlots: { customRender: 'workpieceMaterial' }
+        },
+        {
+          title:'棰濆畾瀵垮懡',
+          align:"center",
+          dataIndex: 'ratedLife',
+          scopedSlots: { customRender: 'ratedLife' }
+        },
+        {
+          title: '鎿嶄綔',
+          dataIndex: 'action',
+          align:"center",
+          scopedSlots: { customRender: 'action' },
+          width: 200,
+        }
+      ],
+      url: {
+        list: "/cms/ratedLife/list",
+        delete: "/cms/ratedLife/delete",
+        deleteBatch: "/cms/ratedLife/deleteBatch",
+        exportXlsUrl: "/cms/ratedLife/exportXls",
+        importExcelUrl: "cms/ratedLife/importExcel",
+        edit: "/cms/ratedLife/edit",
+        add: "/cms/ratedLife/add"
+      },
+      dictOptions:{},
+      superFieldList:[],
+    }
+  },
+  created() {
+    this.getSuperFieldList();
+  },
+  computed: {
+    importExcelUrl: function(){
+      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
+    },
+  },
+  methods: {
+    initDictConfig(){
+    },
+    getRatedLife(cuttingId) {
+      this.queryParam.cuttingId = cuttingId;
+      // this.ipagination.current = 1;
+      this.loadData(1);
+    },
+    getSuperFieldList(){
+      let fieldList=[];
+      fieldList.push({type:'string',value:'cuttingId',text:'鍒�鍏稩D'})
+      fieldList.push({type:'string',value:'workpieceMaterial',text:'宸ヤ欢鏉愯川'})
+      fieldList.push({type:'number',value:'ratedLife',text:'棰濆畾瀵垮懡'})
+      this.superFieldList = fieldList
+    },
+
+    // 鏂板琛�
+    handleAdd() {
+      // 濡傛灉宸茬粡鍦ㄧ紪杈戠姸鎬侊紝鑷姩鍙栨秷褰撳墠缂栬緫椤�
+      if (this.editingKey !== '') {
+        // 鏌ユ壘姝e湪缂栬緫鐨勮褰曞苟鍙栨秷缂栬緫
+        const editingRecord = this.dataSource.find(item => item.id === this.editingKey);
+        if (editingRecord) {
+          this.cancel(this.editingKey);
+        }
+      }
+
+      // 鍒涘缓鏂扮殑绌烘暟鎹」
+      const newRow = {
+        id: 'new_' + new Date().getTime(), // 涓存椂ID
+        cuttingId: this.queryParam.cuttingId,
+        workpieceMaterial: '',
+        ratedLife: '',
+        editable: true,
+        isNew: true // 鏍囪涓烘柊娣诲姞鐨勮
+      };
+
+      // 灏嗘柊琛屾彃鍏ュ埌鏁版嵁婧愬紑澶�
+      this.dataSource = [newRow, ...this.dataSource];
+      this.editingKey = newRow.id;
+    },
+
+    // 缂栬緫琛屾暟鎹�
+    edit(key) {
+      // 鍏堜繚瀛樺綋鍓嶆暟鎹殑鍓湰
+      const newData = [...this.dataSource];
+      const target = newData.find(item => key === item.id);
+      this.editingKey = key;
+
+      if (target) {
+        target.editable = true;
+        this.dataSource = newData;
       }
     },
-    created() {
-    this.getSuperFieldList();
+
+    // 淇濆瓨缂栬緫鐨勬暟鎹�
+    save(key) {
+      const newData = [...this.dataSource];
+      const target = newData.find(item => key === item.id);
+
+      if (target) {
+        delete target.editable;
+        this.dataSource = newData;
+
+        // 鍒ゆ柇鏄柊澧炶繕鏄紪杈�
+        if (target.isNew) {
+          // 鏂板鎿嶄綔
+          const params = { ...target };
+          delete params.id;
+          delete params.isNew;
+          // 鍒犻櫎鍒涘缓鏃堕棿瀛楁锛岃鍚庣鑷姩鐢熸垚
+          delete params.createTime;
+          delete params.updateTime;
+
+          postAction(this.url.add, params).then(res => {
+            if (res.success) {
+              this.$message.success('鏂板鎴愬姛');
+              this.editingKey = '';
+              this.loadData(); // 閲嶆柊鍔犺浇鏁版嵁
+            } else {
+              this.$message.error(res.message);
+            }
+          }).catch(err => {
+            this.$message.error('鏂板澶辫触');
+            console.log(err);
+          });
+        } else {
+          // 缂栬緫鎿嶄綔 - 鍙彂閫侀渶瑕佹洿鏂扮殑瀛楁
+          const params = {
+            id: target.id,
+            cuttingId: target.cuttingId,
+            workpieceMaterial: target.workpieceMaterial,
+            ratedLife: target.ratedLife,
+          };
+
+          putAction(this.url.edit, params).then(res => {
+            if (res.success) {
+              this.$message.success('淇濆瓨鎴愬姛');
+              this.editingKey = '';
+              this.loadData(); // 閲嶆柊鍔犺浇鏁版嵁
+            } else {
+              this.$message.error(res.message);
+            }
+          }).catch(err => {
+            this.$message.error('淇濆瓨澶辫触');
+            console.log(err);
+          });
+        }
+      }
     },
-    computed: {
-      importExcelUrl: function(){
-        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
-      },
+
+    // 鍙栨秷缂栬緫
+    cancel(key) {
+      const newData = [...this.dataSource];
+      const targetIndex = newData.findIndex(item => key === item.id);
+      this.editingKey = '';
+
+      if (targetIndex >= 0) {
+        // 濡傛灉鏄柊澧炵殑琛岋紝鐩存帴鍒犻櫎
+        if (newData[targetIndex].isNew) {
+          newData.splice(targetIndex, 1);
+          this.dataSource = newData;
+        } else {
+          // 濡傛灉鏄紪杈戠殑琛岋紝浠庡悗绔噸鏂拌幏鍙栨暟鎹互鎭㈠鍘熷鍊�
+          const target = newData[targetIndex];
+          getAction(this.url.list, { id: key }).then(res => {
+            if(res.success && res.result.records.length > 0) {
+              const originalData = res.result.records[0];
+              Object.keys(target).forEach(key => {
+                if(key !== 'editable') {
+                  target[key] = originalData[key];
+                }
+              });
+              delete target.editable;
+              this.dataSource = newData;
+            }
+          });
+        }
+      }
     },
-    methods: {
-      initDictConfig(){
-      },
-      getSuperFieldList(){
-        let fieldList=[];
-        fieldList.push({type:'string',value:'cuttingId',text:'鍒�鍏稩D'})
-        fieldList.push({type:'string',value:'workpieceMaterial',text:'宸ヤ欢鏉愯川'})
-        fieldList.push({type:'number',value:'ratedLife',text:'棰濆畾瀵垮懡'})
-        this.superFieldList = fieldList
+
+    // 澶勭悊鍗曞厓鏍煎�煎彉鍖�
+    handleChange(value, key, column) {
+      const newData = [...this.dataSource];
+      const target = newData.find(item => key === item.id);
+
+      if (target) {
+        target[column] = value;
+        this.dataSource = newData;
       }
     }
   }
+}
 </script>
+
 <style scoped>
-  @import '~@assets/less/common.less';
-</style>
\ No newline at end of file
+@import '~@assets/less/common.less';
+
+.editable-row-operations a {
+  margin-right: 8px;
+}
+</style>

--
Gitblit v1.9.3