ludc
2024-04-16 2353af8edf94434cd571100bb16ed9fe9f12819d
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
<template>
  <basic-container>
    <avue-crud ref="crud" :data="data" :option="options" :page.sync="page" @current-change="currentChange"
               @size-change="sizeChange" @row-dblclick="handleRowClick" @row-update="handleUpdate"
               @selection-change="selectChange">
      <template slot="menuLeft">
        <el-button plain size="small" type="success" @click="savaHandler">保存</el-button>
        <el-button plain size="small" type="primary" @click="syncHandler">同步</el-button>
      </template>
    </avue-crud>
  </basic-container>
</template>
 
<script>
import {getGroupAttrPoolALlList, editGroupAttr,syncGroupAttrMapping} from '@/api/vciAttrbute'
import {getPage} from "@/api/omd/OmdAttribute";
 
export default {
  name: "vciAttribute",
  data() {
    return {
      data: [],
      options: {
        height: 'auto',
        calcHeight: 20,
        headerAlign: "center",
        border: true,
        selection: true,
        tip: false,
        index: true,
        refreshBtn: false,
        searchShowBtn: false,
        addBtn: false,
        delBtn: false,
        $cellEdit: true,
        rowKey: 'oid',
        cellBtn: true,
        highlightCurrentRow: true,
        column: [
          {
            label: '集团属性编号',
            prop: 'groupAttrKey'
          },
          {
            label: '集团属性名称',
            prop: 'groupAttrName'
          },
          {
            label: '属性编号',
            prop: 'codeMetaAttrKey'
          },
          {
            label: '属性名称',
            prop: 'codeMetaAttrName',
            type: 'select',
            cell: true,
            filterable: true,
            props: {
              label: 'codeMetaAttrName',
              value: 'codeMetaAttrOid',
            },
            dicData: []
          }
        ]
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectList: []
    }
  },
  created() {
    const params = {
      'conditionMap[groupAttrKey_like]': 'RY_',
      page: this.page.currentPage,
      limit: this.page.pageSize
    }
    this.onLoad(params)
    this.codeColumnOnload()
  },
  computed: {
    codeMetaColumn() {
      return this.options.column.find(column => column.prop === 'codeMetaAttrName');
    }
  },
  methods: {
    codeMetaDis() {
      for (const item of this.data) {
        if (item.codeMetaAttrOid && item.codeMetaAttrKey && item.codeMetaAttrName) {
          console.log(this.codeMetaColumn)
          console.log(this.codeMetaColumn.dicData)
          if (this.codeMetaColumn.dicData.length >= 1) {
            const targetObject = this.codeMetaColumn.dicData.find(obj => obj.codeMetaAttrName === item.codeMetaAttrName);
            console.log(targetObject)
          }
          // targetObject.disabled = true;
        }
      }
    },
    selectChange(list) {
      this.selectList = list;
    },
    async onLoad(params) {
      getGroupAttrPoolALlList(params).then(res => {
        const data = res.data.data;
        this.data = data.records;
        this.page.total = data.total;
      })
    },
    codeColumnOnload() {
      getPage(1, -1).then(res => {
        const data = res.data.data;
        this.codeMetaColumn.dicData = data.records.filter(item => item.name && item.name.trim() !== "") // 过滤掉name为空的属性
          .map(item => {
            return {
              codeMetaAttrOid: item.oid,
              codeMetaAttrKey: item.id,
              codeMetaAttrName: item.name,
              disabled: false
            }
          })
      })
    },
    handleRowClick(row, column) {
      if (column.label === '属性名称') this.$refs.crud.rowCell(row, row.$index)
    },
    async handleUpdate(row, index, done) {
      if (!row.codeMetaAttrName) {
        this.$message.warning('请选择要保存的属性名称!');
        done();
        return;
      }
      // row.codeMetaAttrName因为下拉框value值原因绑定为codeMetaAttrOid
      const updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
 
      // 因为row里面的值是不正确的 重新赋值一遍
      const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
      Object.assign(row, {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName});
 
      const objet = {
        oid: row.oid,
        groupAttrKey: row.groupAttrKey,
        groupAttrName: row.groupAttrName,
        codeMetaAttrOid: row.codeMetaAttrOid,
        codeMetaAttrKey: row.codeMetaAttrKey,
        codeMetaAttrName: row.codeMetaAttrName
      }
      const response = await editGroupAttr([objet])
      if (response.data.data.success) {
        this.$message.success('保存成功!')
      }
      done()
    },
    async savaHandler() {
      if (this.selectList.length <= 0) {
        this.$message.warning('请选择一条数据后进行保存!')
      } else {
        const hasTrueValue = this.selectList.some(item => !item.$cellEdit);
        if (hasTrueValue) {
          this.$message.warning('请开启编辑后保存!')
        } else {
          let saveList = []
          for (const item of this.selectList) {
            const updataList = this.codeMetaColumn.dicData.find(p => p.codeMetaAttrOid === item.codeMetaAttrName);
            const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
            Object.assign(item, {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName});
 
            item.$cellEdit = false;
            saveList.push({
              oid: item.oid,
              groupAttrKey: item.groupAttrKey,
              groupAttrName: item.groupAttrName,
              codeMetaAttrOid: item.codeMetaAttrOid,
              codeMetaAttrKey: item.codeMetaAttrKey,
              codeMetaAttrName: item.codeMetaAttrName
            })
          }
          const response = await editGroupAttr(saveList)
          if (response.data.data.success) {
            this.$message.success('保存成功!')
          }
        }
      }
    },
    async syncHandler(){
      if(this.selectList.length <= 0){
        this.$message.warning('请至少选择一条数据进行同步!')
      }else {
        const syncList = [];
        for (const item of this.selectList) {
          syncList.push({
            groupAttrKey: item.groupAttrKey,
            groupAttrName: item.groupAttrName,
          })
        }
        const response = await syncGroupAttrMapping(syncList)
        if(response.data.success){
          this.$message.success(response.data.msg)
        }
      }
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      const params = {
        'conditionMap[groupAttrKey_like]': 'RY_',
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      this.onLoad(params)
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      const params = {
        'conditionMap[groupAttrKey_like]': 'RY_',
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      this.onLoad(params)
    },
  }
}
</script>
 
<style scoped>
 
</style>