quwangxin 2 anni fa
parent
commit
22cb63e45e

+ 37 - 28
src/views/material/manage/components/index-data.vue

@@ -15,22 +15,22 @@
     >
       <!-- 表头工具栏 -->
       <template v-slot:toolbar>
-          <el-button
-            size="small"
-            type="primary"
-            icon="el-icon-plus"
-            class="ele-btn-icon"
-            @click="openEdit({},2)"
-          >
-            新建物料
-          </el-button>
+        <el-button
+          size="small"
+          type="primary"
+          icon="el-icon-plus"
+          class="ele-btn-icon"
+          @click="openEdit({}, 2)"
+        >
+          新建物料
+        </el-button>
       </template>
       <template v-slot:action="{ row }">
         <el-link
           type="primary"
           :underline="false"
           icon="el-icon-copy-document"
-          @click="openEdit(row,1)"
+          @click="openEdit(row, 1)"
         >
           复制
         </el-link>
@@ -38,7 +38,7 @@
           type="primary"
           :underline="false"
           icon="el-icon-edit"
-          @click="openEdit(row,0)"
+          @click="openEdit(row, 0)"
         >
           修改
         </el-link>
@@ -56,30 +56,30 @@
       </template>
     </ele-pro-table>
     <!-- 编辑弹窗 -->
-<!--    <dict-edit :visible.sync="showEdit" :id="id" @done="reload" /> -->
+    <!--    <dict-edit :visible.sync="showEdit" :id="id" @done="reload" /> -->
   </div>
 </template>
 
 <script>
-  import { getMaterialList , removeMaterial } from '@/api/material/manage.js';
+  import { getMaterialList, removeMaterial } from '@/api/material/manage.js';
   export default {
-    components: { },
+    components: {},
     props: {
       // 物料组id
       currentId: [Number, String],
-      data:Object
+      data: Object
     },
-    data() {
+    data () {
       return {
         // 表格列配置
         columns: [
           {
             columnKey: 'index',
             type: 'index',
-            width: 45,
+            width: 55,
             align: 'center',
             showOverflowTooltip: true,
-            label:'序号'
+            label: '序号'
           },
           {
             prop: 'code',
@@ -143,7 +143,7 @@
             resizable: false,
             slot: 'action',
             showOverflowTooltip: true,
-            fixed:'right'
+            fixed: 'right'
           }
         ],
         types: {
@@ -160,26 +160,35 @@
 
     methods: {
       /* 表格数据源 */
-      datasource({ page, limit, where, order }) {
-        return getMaterialList({ pageNum: page, size: limit, ...where , categoryLevelGroupId:this.currentId });
+      datasource ({ page, limit, where, order }) {
+        return getMaterialList({
+          pageNum: page,
+          size: limit,
+          ...where,
+          categoryLevelGroupId: this.currentId
+        });
       },
       /* 刷新表格 */
-      reload(where) {
-        this.$refs.table.reload({ page: 1, where: where ,  categoryLevelGroupId:this.currentId  });
+      reload (where) {
+        this.$refs.table.reload({
+          page: 1,
+          where: where,
+          categoryLevelGroupId: this.currentId
+        });
       },
       /* 显示编辑 */
-      openEdit(row,status) {
+      openEdit (row, status) {
         this.$router.push({
           path: '/material/manage/manageMaterial',
           query: {
             chooseTab: JSON.stringify(this.data),
-            id: row.id?row.id:null,
-            status:status
+            id: row.id ? row.id : null,
+            status: status
           }
         });
       },
       /* 删除 */
-      remove(row) {
+      remove (row) {
         const loading = this.$loading({ lock: true });
         removeMaterial(row.id)
           .then((msg) => {
@@ -195,7 +204,7 @@
     },
     watch: {
       // 监听物料组id变化
-      currentId() {
+      currentId () {
         this.reload();
       }
     }

+ 24 - 16
src/views/material/manage/index.vue

@@ -2,7 +2,7 @@
   <div class="ele-body">
     <el-card shadow="never">
       <IndexSearch @search="reload" />
-<!--      <div style="margin: 5px 0; padding-left: 262px">
+      <!--      <div style="margin: 5px 0; padding-left: 262px">
         <el-button
           size="small"
           type="primary"
@@ -29,18 +29,24 @@
           :current.sync="current"
           highlight-current-row
           class="dict-table"
+          row-key="id"
           tool-class="ele-toolbar-actions"
           @done="done"
         >
           <!-- 表头工具栏 -->
-<!--          <template v-slot:toolbar>
+          <!--          <template v-slot:toolbar>
 
           </template> -->
         </ele-pro-table>
 
         <template v-slot:content>
           <!-- 物料列表 -->
-          <IndexData ref="listData" v-if="current" :current-id="current.id" :data="current"/>
+          <IndexData
+            ref="listData"
+            v-if="current"
+            :current-id="current.id"
+            :data="current"
+          />
         </template>
       </ele-split-layout>
     </el-card>
@@ -54,8 +60,8 @@
   import { getGroupPage } from '@/api/material/list';
   export default {
     name: 'SystemDictionary',
-    components: { IndexData , IndexSearch },
-    data() {
+    components: { IndexData, IndexSearch },
+    data () {
       return {
         // 表格列配置
         columns: [
@@ -77,31 +83,33 @@
         // 是否显示编辑弹窗
         showEdit: false,
         // 编辑回显数据
-        editData: null,
+        editData: null
       };
     },
 
-    created() {
-    },
+    created () {},
 
     methods: {
       /* 表格数据源 */
-      datasource() {
-        return getGroupPage({pageNum:1,size:-1});
+      datasource () {
+        return getGroupPage({ pageNum: 1, size: -1 });
       },
       /* 表格渲染完成回调 */
-      done(res) {
+      done (res) {
+        console.log(this.current, 'this.current', res);
         if (res.data?.length) {
-          this.$refs.table.setCurrentRow(res.data[0]);
+          let currentRow = null;
+          if (this.current) {
+            currentRow = res.data.find((item) => item.id == this.current.id);
+          }
+          this.$refs.table.setCurrentRow(currentRow || res.data[0]);
         }
       },
       /* 刷新表格 */
-      reload(where) {
+      reload (where) {
         this.$refs.table.reload();
         this.$refs.listData.reload(where);
-      },
-
-
+      }
     }
   };
 </script>