Преглед изворни кода

feat: 添加设备实例关联功能

yusheng пре 1 месец
родитељ
комит
3160fa398e

+ 7 - 0
src/api/ruleManagement/plan.js

@@ -139,3 +139,10 @@ export async function batchUnbindByMeter(data) {
   }
   return Promise.reject(new Error(res.data.message));
 }
+export async function queryBindSubstanceList(params) {
+  const res = await request.get(`/main/asset/queryBindSubstanceList`, {params});
+  if (res.data.code == 0) {
+    return res.data.data;
+  }
+  return Promise.reject(new Error(res.data.message));
+}

+ 10 - 3
src/views/ledgerAssets/components/MaterialAdd.vue

@@ -15,7 +15,6 @@
         ref="table"
         :columns="columns"
         :datasource="datasource"
-        :selection.sync="selection"
         row-key="id"
         :initLoad="false"
         @cell-click="cellClick"
@@ -30,7 +29,12 @@
           <span>{{ row.position[0] && row.position[0].pathName }}</span>
         </template>
         <template v-slot:action="{ row }">
-          <el-radio class="radio" v-model="radio" :disabled="row.isBindMainDevice"  :label="row.id">
+          <el-radio
+            class="radio"
+            v-model="radio"
+            :disabled="row.isBindMainDevice"
+            :label="row.id"
+          >
             <i></i>
           </el-radio>
         </template>
@@ -151,6 +155,9 @@
 
       // 单击获取id
       cellClick(row) {
+        if (row.isBindMainDevice) {
+          return;
+        }
         this.current = row;
         this.radio = row.id;
       },
@@ -160,7 +167,7 @@
           return;
         }
 
-        this.$emit('chooseEquipment',this.current);
+        this.$emit('chooseEquipment', this.current);
         this.handleClose();
       }
     }

+ 214 - 0
src/views/ledgerAssets/components/accountingLedgerList1.vue

@@ -0,0 +1,214 @@
+<template>
+  <el-dialog
+    title="设备实例"
+    :visible.sync="visible"
+    :before-close="handleClose"
+    :close-on-click-modal="false"
+    :close-on-press-escape="false"
+    append-to-body
+    width="70%"
+    :maxable="true"
+  >
+    <el-card shadow="never">
+      <ele-pro-table
+        ref="table"
+        :columns="columns"
+        :datasource="datasource"
+        row-key="id"
+        max-height="500"
+        :initLoad="false"
+        :needPage="false"
+      >
+        <template v-slot:toolbar>
+          <el-button
+            size="small"
+            type="primary"
+            icon="el-icon-plus"
+            class="ele-btn-icon"
+            @click="handleAdd()"
+            :disabled="count>=current.dosage"
+          >
+            关联设备实例
+          </el-button>
+        </template>
+        <template v-slot:modelType="{ row }">
+          <span>{{ row.category.modelType }}</span>
+        </template>
+        <template v-slot:specification="{ row }">
+          <span>{{ row.category.specification }}</span>
+        </template>
+        <template v-slot:pathName="{ row }">
+          <span>{{ row.position[0] && row.position[0].pathName }}</span>
+        </template>
+        <template v-slot:action="{ row }">
+          <el-link type="primary" @click="batchUnbind(row)">解绑</el-link>
+        </template>
+      </ele-pro-table>
+    </el-card>
+
+    <div class="rx-sc">
+      <el-button size="small" @click="handleClose">关闭</el-button>
+    </div>
+    <MaterialAdd
+      ref="MaterialAddRef"
+      @chooseEquipment="chooseEquipment"
+    ></MaterialAdd>
+  </el-dialog>
+</template>
+
+<script>
+  import { queryBindSubstanceList } from '@/api/ruleManagement/plan';
+  import MaterialAdd from './MaterialAdd.vue';
+  import { bomSubstanceBind, batchUnbind } from '@/api/ledgerAssets';
+
+  export default {
+    components: { MaterialAdd },
+    data() {
+      return {
+        visible: false,
+        bomCategoryId: '',
+        substanceId: '',
+        current: {},
+        count: 0,
+        // 表格列配置
+        columns: [
+          {
+            label: '设备名称',
+            prop: 'name'
+          },
+          {
+            label: '编码',
+            prop: 'code'
+          },
+          {
+            label: '固资编码',
+            prop: 'fixCode'
+          },
+          {
+            label: '使用人',
+            prop: 'usePerson'
+          },
+          {
+            label: '使用岗位',
+            prop: 'postName'
+          },
+          {
+            label: '片区负责人负责人',
+            prop: 'areaPersonInChargeUserName'
+          },
+          {
+            label: '有效开始时间',
+            prop: 'startTime'
+          },
+          {
+            label: '有效结束时间',
+            prop: 'endTime'
+          },
+          {
+            prop: 'category.modelType',
+            label: '型号',
+            showOverflowTooltip: true,
+            minWidth: 110
+          },
+          {
+            prop: 'category.specification',
+            label: '规格',
+            showOverflowTooltip: true,
+            minWidth: 110
+          },
+          {
+            label: '设备位置',
+            prop: 'pathName',
+            formatter: (_row) => {
+              const positionDetail =
+                _row.position &&
+                _row.position.length != 0 &&
+                _row.position[0].detailPosition
+                  ? _row.position[0].detailPosition
+                  : '-';
+              return _row.deviceLocationName
+                ? _row.deviceLocationName + '-' + positionDetail
+                : '';
+            }
+          },
+          {
+            columnKey: 'action',
+            label: '操作',
+            width: 120,
+            align: 'center',
+            slot: 'action'
+          }
+        ]
+      };
+    },
+    methods: {
+      chooseEquipment(row) {
+        bomSubstanceBind({
+          bomCategoryId: this.bomCategoryId,
+          bomCategorySubstanceId: row.id,
+          substanceId: this.substanceId
+        }).then((res) => {
+          this.$refs.table.reload();
+          this.$message.success('操作成功!');
+        });
+      },
+      batchUnbind(row) {
+        batchUnbind({
+          bomCategorySubstanceIds: [row.id],
+          substanceId: this.substanceId
+        }).then((res) => {
+         this.$refs.table.reload();
+          this.$message.success('解绑成功!');
+        });
+      },
+
+      /* 表格数据源 */
+      async datasource({}) {
+        let data = await queryBindSubstanceList({
+          id: this.substanceId,
+          bomCategoryId: this.bomCategoryId,
+          pageNum: 1,
+          type: 0,
+          size: 1000
+        });
+        this.count = data.list.length;
+
+        return data.list;
+      },
+      handleAdd() {
+        this.$refs.MaterialAddRef.open(this.current);
+      },
+
+      open(row) {
+        this.substanceId = row.substanceId;
+        this.bomCategoryId = row.id;
+        this.current = row;
+        this.visible = true;
+        this.$nextTick(() => {
+          this.$refs.table.reload();
+        });
+      },
+
+      handleClose() {
+        this.visible = false;
+      }
+    }
+  };
+</script>
+
+<style lang="scss" scoped>
+  ::v-deep {
+    .el-checkbox__input.is-disabled .el-checkbox__inner {
+      background-color: #c1c1c1 !important;
+    }
+  }
+  .ml60 {
+    margin-left: 60px;
+  }
+  .rx-sc {
+    flex: 0 0 50px;
+    display: flex;
+    align-items: center;
+    justify-content: center;
+  }
+</style>

+ 32 - 57
src/views/ledgerAssets/equipment/components/detailedList.vue

@@ -8,8 +8,6 @@
       :datasource="datasource"
       class="dict-table"
       tool-class="ele-toolbar-actions"
-      @select="selectChange"
-      @select-all="changeSelectAll"
     >
       <template v-slot:toolbar>
         <div class="toolbar_box">
@@ -112,23 +110,16 @@
           type="primary"
           :underline="false"
           @click="open(row)"
-          v-if="!row.bomCategorySubstanceId"
           >关联设备实例</el-link
         >
-        <el-link
-          type="primary"
-          :underline="false"
-          @click="batchUnbind(row)"
-          v-else
-          >解除绑定</el-link
-        >
+
       </template>
     </ele-pro-table>
     <print ref="printRef"></print>
-    <MaterialAdd
-      ref="MaterialAdd"
-      @chooseEquipment="chooseEquipment"
-    ></MaterialAdd>
+
+    <accountingLedgerList1
+      ref="accountingLedgerList1Ref"
+    ></accountingLedgerList1>
   </div>
 </template>
 
@@ -136,23 +127,22 @@
   import BOMSearch from './BOM-search.vue';
   import { getBomPageCategoryId, contactList } from '@/api/material/BOM';
   import { getByCode } from '@/api/system/dictionary-data';
-  import { bomSubstanceBind, batchUnbind } from '@/api/ledgerAssets';
   import print from './print.vue';
-  import MaterialAdd from '@/views/ledgerAssets/components/MaterialAdd.vue';
+  import accountingLedgerList1 from '@/views/ledgerAssets/components/accountingLedgerList1.vue';
   export default {
     name: 'SystemDictionary',
-    components: { BOMSearch, print, MaterialAdd },
+    components: { BOMSearch, print, accountingLedgerList1 },
 
     data() {
       return {
         // 表格列配置
         columns: [
-          {
-            width: 45,
-            type: 'selection',
-            columnKey: 'selection',
-            align: 'center'
-          },
+          // {
+          //   width: 45,
+          //   type: 'selection',
+          //   columnKey: 'selection',
+          //   align: 'center'
+          // },
           {
             label: '序号',
             columnKey: 'index',
@@ -364,27 +354,12 @@
       },
       open(row) {
         this.bomId = row.id;
-        this.$refs.MaterialAdd.open(row);
-      },
-      chooseEquipment(row) {
-        bomSubstanceBind({
-          bomCategoryId: this.bomId,
-          bomCategorySubstanceId: row.id,
+        this.$refs.accountingLedgerList1Ref.open({
+          ...row,
           substanceId: this.substanceId
-        }).then((res) => {
-          this.reload();
-          this.$message.success('操作成功!');
-        });
-      },
-      batchUnbind(row) {
-        batchUnbind({
-          bomCategorySubstanceIds: [row.bomCategorySubstanceId],
-          substanceId: this.substanceId
-        }).then((res) => {
-          this.reload();
-          this.$message.success('解绑成功!');
         });
       },
+
       /* 刷新表格 */
       reload(where) {
         this.$refs.table.reload({ where });
@@ -419,23 +394,23 @@
         } else {
           this.$message.warning('请选择数据!');
         }
-      },
-      // 全选
-      changeSelectAll(arr) {
-        console.log(arr);
-        if (arr.length != 0) {
-          this.checkRadioData = arr;
-        } else {
-          this.checkRadioData = [];
-        }
-      },
-      selectChange(selection, row) {
-        if (selection.length != 0) {
-          this.checkRadioData = selection;
-        } else {
-          this.checkRadioData = [];
-        }
       }
+      // 全选
+      // changeSelectAll(arr) {
+      //   console.log(arr);
+      //   if (arr.length != 0) {
+      //     this.checkRadioData = arr;
+      //   } else {
+      //     this.checkRadioData = [];
+      //   }
+      // },
+      // selectChange(selection, row) {
+      //   if (selection.length != 0) {
+      //     this.checkRadioData = selection;
+      //   } else {
+      //     this.checkRadioData = [];
+      //   }
+      // }
     }
   };
 </script>