liulingling.177216
2024-08-26 349f1cfc5fa77fbc636d542df0d8050fddec48c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
  <div class="app-container">
    <el-table border v-loading="loading" :data="productList" @select="handleSelectionChange"
              :header-cell-class-name="hideCheckAll"
              ref="productSettingTable">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="产品编号" align="center" prop="productsno"/>
      <el-table-column label="产品名称" align="center" prop="productname"/>
      <el-table-column label="计量单位" align="center" prop="muid" :formatter="muidFormat"/>
    </el-table>
  </div>
</template>
 
<script>
  import {listProduct} from "@/api/enerInfoManage/product";
 
  export default {
    name: "ProductSetting",
    data() {
      return {
        productList: [],
        selectedProduct: [],
        loading: false,
        muidOptions: []
      }
    },
    methods: {
      init(currentSelected) {
        this.selectedProduct = currentSelected;
        this.getList();
        this.getDicts("sys_unit").then(response => {
          this.muidOptions = response.data;
        });
      },
      getList() {
        this.loading = true;
 
        listProduct({}).then(response => {
          this.productList = response.rows;
          this.loading = false;
          this.$nextTick(function () {
            this.$refs.productSettingTable.data.forEach(rowData => {
              let exist = this.selectedProduct.filter(f => f.productid === rowData.productid).length;
              if (exist > 0) {
                this.$refs.productSettingTable.toggleRowSelection(rowData, true);
              }
            });
          });
        });
      },
      // 多选框选中数据
      handleSelectionChange(selection, row) {
        let rowStatus = selection.filter(f => f.productid === row.productid).length;
        if (rowStatus > 0) {
          this.selectedProduct.push({
            "productid": row.productid,
            "productsno": row.productsno,
            "productname": row.productname
          });
        } else {
          this.selectedProduct = this.selectedProduct.filter(f => f.productid !== row.productid);
        }
 
        this.$emit('productConfirmSelect', this.selectedProduct);
      },
      // 计量单位字典翻译
      muidFormat(row, column) {
        return this.selectDictLabel(this.muidOptions, row.muid);
      },
    }
  }
</script>
 
<style scoped>
 
</style>