田源
2024-04-18 d2d549d1c09087a886dece6ee6379b493d851dc5
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<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 v-if="permissionList.saveBtn" plain size="small" type="success" @click="savaHandler">保存</el-button>
        <el-button v-if="permissionList.syncBtn" plain size="small" type="primary" @click="syncHandler">同步</el-button>
        <span style="width: 200px;display: inline-block">
                <el-select slot="prepend" v-model="searchSelect" placeholder="请选择" size="small">
                <el-option v-for="item in searchData" :key="item.prop" :label="item.label" :value="item.prop"
                ></el-option>
              </el-select>
            </span>
        <span style="margin-left: 5px">
                 <el-input v-model="searchValue" class="attrSearch" clearable placeholder="请输入内容"
                           prefix-icon="el-icon-search"
                           size="small" type="text"></el-input>
              <el-button v-if="permissionList.searchBtn" icon="el-icon-search" plain size="small" type="primary"
                         @click="searchHandler">&nbsp;搜索</el-button>
              </span>
      </template>
    </avue-crud>
  </basic-container>
</template>
 
<script>
import {getGroupAttrPoolALlList, editGroupAttr, syncGroupAttrMapping} from '@/api/vciAttrbute'
import {getPage} from "@/api/omd/OmdAttribute";
import {mapGetters} from "vuex";
 
export default {
  name: "vciAttribute",
  data() {
    return {
      searchSelect: "groupAttrKey",
      searchValue: '',
      searchData: [
        {
          label: "集团属性编号",
          prop: "groupAttrKey",
          align: "left",
          display: false,
          width: 200,
          required: true
        }, {
          label: "集团属性名称",
          prop: "groupAttrName",
          align: "left",
          display: false
        }
      ],
      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,
            change: (val) => {
              if (!this.ChangeStatus) {
                this.ChangeName = val.value
                this.status = true;
              }
            },
            props: {
              label: 'codeMetaAttrName',
              value: 'codeMetaAttrOid',
            },
            dicData: []
          }
        ]
      },
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      selectList: [],
      ChangeName: '',
      ChangeStatus: false
    }
  },
  created() {
    this.onLoad()
    this.codeColumnOnload()
  },
  computed: {
    codeMetaColumn() {
      return this.options.column.find(column => column.prop === 'codeMetaAttrName');
    },
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        saveBtn: this.vaildData(this.permission.vciAttribute.attribute_save, false),
        syncBtn: this.vaildData(this.permission.vciAttribute.attribute_sync, false),
        searchBtn: this.vaildData(this.permission.vciAttribute.attribute_search, false),
      }
    },
  },
  methods: {
    searchHandler() {
      console.log(this.searchSelect)
      const params = {
        [`conditionMap[${this.searchSelect}_like]`]: this.searchValue,
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      getGroupAttrPoolALlList(params).then(res => {
        const data = res.data.data;
        this.data = data.records;
        this.page.total = data.total;
      })
    },
    codeMetaDis() {
      for (const item of this.data) {
        if (item.codeMetaAttrOid && item.codeMetaAttrKey && item.codeMetaAttrName) {
          if (this.codeMetaColumn.dicData.length >= 1) {
            const targetObject = this.codeMetaColumn.dicData.find(obj => obj.codeMetaAttrName === item.codeMetaAttrName);
          }
          // targetObject.disabled = true;
        }
      }
    },
    selectChange(list) {
      this.selectList = list;
    },
    async onLoad() {
      const params = {
        page: this.page.currentPage,
        limit: this.page.pageSize
      }
      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
      let updataList = []
      // console.log(this.ChangeName)
      // console.log(row.codeMetaAttrName)
      // if (this.ChangeName && this.ChangeName === row.codeMetaAttrName) {
      //   updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrOid)
      // } else {
      //   console.log('2')
      //     updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
      // }
      updataList = this.codeMetaColumn.dicData.find(item => item.codeMetaAttrOid === row.codeMetaAttrName)
 
      // 因为row里面的值是不正确的 重新赋值一遍
      if (updataList) {
        const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
        Object.assign(row, {
          codeMetaAttrOid: codeMetaAttrOid,
          codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
          codeMetaAttrName: 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.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('请开启编辑后进行保存!')
          return
        }
        const codeMetaInput = this.selectList.some(item => item.codeMetaAttrName === "");
        if (codeMetaInput) {
          this.$message.warning('请检查已勾选数据中是否存在未选择的项!');
          return
        }
        let saveList = []
        for (const item of this.selectList) {
          const updataList = this.codeMetaColumn.dicData.find(column => column.codeMetaAttrOid === item.codeMetaAttrName);
          if (updataList) {
            const {codeMetaAttrOid, codeMetaAttrKey, codeMetaAttrName} = updataList;
            Object.assign(item, {
              codeMetaAttrOid: codeMetaAttrOid,
              codeMetaAttrKey: codeMetaAttrKey.toLowerCase(),
              codeMetaAttrName: 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.success) {
          this.$message.success('保存成功!')
          await this.onLoad()
        }
 
      }
    },
    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);
 
          await this.onLoad()
        }
      }
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
 
      this.onLoad()
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
 
      this.onLoad()
    },
  }
}
</script>
 
<style scoped>
 
</style>