zenglf
2023-08-17 7442a435d058bd17d6fc679e1b7956bf3a5d32ae
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
<template>
  <a-card
    :loading="cardLoading"
    :bordered="false"
    title="工艺参数分类"
    style="height: 100%;"
  >
    <a-spin :spinning="loading">
      <a-alert
        type="info"
        :showIcon="true"
        style="margin-right: 54px;"
      >
        <div slot="message">
          当前:<span v-if="this.currSelected.title">{{ getCurrSelectedTitle() }}</span>
          <a
            v-if="this.currSelected.title"
            style="margin-left: 10px"
            @click="onClearSelected"
          >取消</a>
        </div>
      </a-alert>
      <div class="drawer-bootom-button">
        <a-dropdown
          :trigger="['click']"
          placement="bottomCenter"
        >
          <a-menu slot="overlay">
            <a-menu-item
              key="1"
              @click="expandAll"
            >展开所有</a-menu-item>
            <a-menu-item
              key="2"
              @click="closeAll"
            >合并所有</a-menu-item>
            <a-menu-item
              key="3"
              @click="refreshTree"
            >刷新</a-menu-item>
          </a-menu>
          <a-button>
            <a-icon type="bars" />
          </a-button>
        </a-dropdown>
      </div>
      <a-input-search
        @search="handleSearch"
        style="width:100%;margin-top: 10px"
        placeholder="检索 工艺参数分类编号/名称"
        allowClear
        v-model="searchInput"
        @change="handleChange"
      />
      <!-- showLine -->
      <a-tree
        showLine
        ref="tree"
        :checkStrictly="checkStrictly"
        :expandedKeys.sync="expandedKeys"
        :selectedKeys="selectedKeys"
        :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
        :treeData="treeDataSource"
        :autoExpandParent="autoExpandParent"
        @select="onSelect"
        @expand="onExpand"
        slots="{}"
      >
        <template
          slot="title"
          slot-scope="{ title, parentId, entity, key}"
        >
          <span v-if="title.indexOf(searchValue) > -1">
            {{ title.substr(0, title.indexOf(searchValue)) }}
            <span class="replaceSearch">{{ searchValue }}</span>
            {{ title.substr(title.indexOf(searchValue) + searchValue.length) }}
          </span>
          <span v-else>{{ title }}</span>
          <a-dropdown
            v-if="entity"
            :trigger="['click']"
            placement="bottomCenter"
          >
            <a-menu slot="overlay">
              <a-menu-item v-if="key!=-1">
                <a
                  href="javascript:;"
                  @click="handleEdit(entity)"
                >编辑</a>
              </a-menu-item>
              <a-menu-item>
                <a
                  href="javascript:;"
                  @click="handleAdd(entity)"
                >
                  添加
                  <span v-if="key!=-1">
                    子
                  </span>
                  类别
                </a>
              </a-menu-item>
              <a-menu-item v-if="key!=-1">
                <a-popconfirm
                  title="确定删除吗?"
                  @confirm="() => handleDelete(entity.id)"
                >
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
              <!-- <a-menu-item v-if="entity.status==1 && key!=-1">
                <a-popconfirm
                  title="确定禁用吗?"
                  @confirm="() => handleActive(entity.id)"
                >
                  <a>禁用</a>
                </a-popconfirm>
              </a-menu-item>
 
              <a-menu-item v-if="entity.status==0">
                <a-popconfirm
                  title="确定启用吗?"
                  @confirm="() => handleActive(entity.id)"
                >
                  <a>启用</a>
                </a-popconfirm>
              </a-menu-item> -->
            </a-menu>
            <span :style="{position: 'absolute',right: 0}">
              <a-icon type="down" />
            </span>
          </a-dropdown>
        </template>
      </a-tree>
    </a-spin>
    <process-parameters-category-model
      ref="modalForm"
      @ok="modalFormOk"
      :nodeSelected="currSelected"
    ></process-parameters-category-model>
  </a-card>
</template>
 
<script>
import { getAction, postAction, deleteAction, requestPut } from '@/api/manage'
import ProcessParametersCategoryModel from './ProcessParametersCategoryModel'
import Tooltip from 'ant-design-vue/es/tooltip'
 
export default {
  name: 'ProcessParametersCategoryLeft',
  props: ['value'],
  components: {
    ProcessParametersCategoryModel,
    Tooltip,
  },
  data() {
    return {
      searchInput: '',
      cardLoading: false,
      loading: false,
      treeDataSource: [],
      selectedKeys: [],
      expandedKeys: [],
      url: {
        loadProcessParametersCategoryTree: '/eam/processParametersCategory/loadTree',
        delete: '/eam/processParametersCategory/delete',
        list: '/eam/processParametersCategory/list'
      },
      searchValue: '',
      dataList: [],
      autoExpandParent: true,
      checkStrictly: true,
      allTreeKeys: [],
      currSelected: {},
      hiding: false,
    }
  },
  created() {
    this.queryTreeData();
    this.closeAll();
  },
  methods: {
 
    getCurrSelectedTitle() {
      return !this.currSelected.title ? '' : this.currSelected.title;
    },
 
    onClearSelected() {
      this.hiding = true;
      this.currSelected = {};
      this.selectedKeys = [];
    },
 
    onSelect(selectedKeys, e) {
      this.hiding = false;
      let record = e.node.dataRef;
      this.currSelected = Object.assign({}, record);
      this.selectedKeys = [record.key];
      this.$emit('clickTreeNode', this.currSelected);
    },
 
    onExpand(expandedKeys) {
      this.expandedKeys = expandedKeys;
      this.autoExpandParent = false;
    },
 
    queryTreeData() {
      this.loading = true;
      this.cardLoading = true;
      getAction(this.url.loadProcessParametersCategoryTree).then((res) => {
        if (res.success) {
          this.dataList = [];
          this.allTreeKeys = [];
          this.currSelected = {};
          this.treeDataSource = res.result;
          this.generateList(res.result);
        } else {
          this.$message.warn(res.message);
        }
      }).finally(() => {
        this.loading = false;
        this.cardLoading = false;
      })
    },
 
    handleChange() {
      let search = this.searchInput;
      let expandedKeys = this.dataList
        .map(item => {
          if (item.title.indexOf(search) > -1) {
            return this.getParentKey(item.key, this.treeDataSource);
          }
          return null;
        })
        .filter((item, i, self) => item && self.indexOf(item) === i);
      Object.assign(this, {
        expandedKeys,
        searchValue: search,
        autoExpandParent: true,
      });
    },
 
    handleSearch(value) {
      let search = value;
      let expandedKeys = this.dataList
        .map(item => {
          if (item.title.indexOf(search) > -1) {
            return this.getParentKey(item.key, this.treeDataSource);
          }
          return null;
        })
        .filter((item, i, self) => item && self.indexOf(item) === i);
      Object.assign(this, {
        expandedKeys,
        searchValue: search,
        autoExpandParent: true,
      });
    },
 
    getParentKey(key, tree) {
      let parentKey;
      for (let i = 0; i < tree.length; i++) {
        const node = tree[i];
        if (node.children) {
          if (node.children.some(item => item.key === key)) {
            parentKey = node.key;
          } else if (
            this.getParentKey(key, node.children)) {
            parentKey = this.getParentKey(key, node.children);
          }
        }
      }
      return parentKey;
    },
 
    generateList(data) {
      for (let i = 0; i < data.length; i++) {
        const node = data[i];
        const key = node.key;
        const title = node.title;
        this.dataList.push({ key, title: title });
        this.allTreeKeys.push(key);
        if (node.children) {
          this.generateList(node.children);
        }
      }
    },
 
    expandAll() {
      this.expandedKeys = this.allTreeKeys;
    },
 
    closeAll() {
      this.expandedKeys = ['-1'];
    },
 
    refreshTree() {
      this.queryTreeData();
    },
 
    handleAdd(entity) {
      if (entity.id) {
        this.$refs.modalForm.add(entity.id);
      } else {
        this.$refs.modalForm.add('-1');
      }
      this.$refs.modalForm.title = "新增工艺参数分类";
      this.$refs.modalForm.disableSubmit = false;
    },
 
    handleEdit(entity) {
      this.$refs.modalForm.edit(entity);
      this.$refs.modalForm.title = "编辑工艺参数分类";
      this.$refs.modalForm.disableSubmit = false;
    },
    handleDelete(id) {
      let that = this;
      getAction(that.url.list, { parentId: id }).then((res) => {
        if (res.success) {
 
          if (res.result.records.length == 0) {
            deleteAction(that.url.delete, { id: id }).then((res) => {
              if (res.success) {
                that.$message.success(res.message);
                that.currSelected.title = '';
                that.queryTreeData();
              } else {
                that.$message.warning("当前工艺参数分类被" + res.message + "条工艺参数引用,无法执行删除操作!");
              }
            });
          } else {
            that.$message.warning("当前工艺参数分类有" + res.result.records.length + "条子类别信息,无法执行删除操作!");
          }
        } else {
          that.$message.warning("系统错误!");
        }
      })
    },
 
    handleActive(id) {
      if (!this.url.active) {
        this.$message.error('请设置url.active属性!')
        return;
      }
      let that = this;
      requestPut(that.url.active, {}, { id: id }).then((res) => {
        if (res.success) {
          that.$message.success(res.message);
          that.queryTreeData();
        } else {
          that.$message.warning(res.message);
        }
      })
    },
 
    modalFormOk(val) {
      // 新增/修改 成功时,重载列表
      this.queryTreeData();
    },
 
  },
  //监听
  watch: {
    // currSelected(val) {//监听currSelected 变化,将变化后的数值传递给 getCurrSelected 事件
    //   this.$bus.$emit('getCurrSelected', val)
    // },
  },
  mounted() {
  }
}
</script>
 
<style>
.replaceSearch {
  color: #00090f;
  font-weight: bold;
  background-color: rgb(204, 204, 204);
}
/* .ant-select-disabled {
  color: rgba(241, 16, 16, 0.25);
}
.ant-select-disabled .ant-select-selection {
  background: #a76b6b;
} */
/*隐藏树的默认icon*/
.ant-tree-switcher-noop {
  display: none !important;
}
/*隐藏树的默认竖线*/
.ant-tree.ant-tree-show-line li:not(:last-child):before {
  border-left: 0px;
}
 
.ant-card-body .table-operator {
  margin: 15px;
}
 
.anty-form-btn {
  width: 100%;
  text-align: center;
}
 
.anty-form-btn button {
  margin: 0 5px;
}
 
.anty-node-layout .ant-layout-header {
  padding-right: 0;
}
 
.header {
  padding: 0 8px;
}
 
.header button {
  margin: 0 3px;
}
 
.ant-modal-cust-warp {
  height: 100%;
}
 
.ant-modal-cust-warp .ant-modal-body {
  height: calc(100% - 110px) !important;
  overflow-y: auto;
}
 
.ant-modal-cust-warp .ant-modal-content {
  height: 90% !important;
  overflow-y: hidden;
}
 
#app .desktop {
  height: auto !important;
}
 
/** Button按钮间距 */
.ant-btn {
  margin-left: 3px;
}
.ant-alert {
  padding: 5px 15px 5px 37px;
}
.drawer-bootom-button {
  position: absolute;
  top: 1px;
  /* padding: 10px 16px; */
  text-align: left;
  right: 0;
  background: #fff;
  border-radius: 0 0 2px 2px;
}
</style>