yangys
2025-08-16 f1b4ff31d9cb91fcda228a9781ddb8b3c792f8ba
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
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<template>
  <el-row>
    <el-col :span="5">
      <div class="box">
        <el-scrollbar>
          <basic-container>
            <avue-tree :option="treeOption" :data="treeData" @node-click="nodeClick" />
          </basic-container>
        </el-scrollbar>
      </div>
    </el-col>
    <el-col :span="19">
      <basic-container>
        <avue-crud
          :addBtn="false"
          :option="option"
          :table-loading="loading"
          :data="data"
          ref="crud"
          v-model:search="search"
          v-model:page="mypage"
          @search-change="searchChange"
          @search-reset="searchReset"
          @current-change="currentChange"
          @size-change="sizeChange"
          @refresh-change="refreshChange"
          @on-load="onLoad"
        >
          <template #menu-left>
            <el-button type="primary" size="default" icon="el-icon-circle-plus" plain @click="handleExport">导出</el-button>
 
 
            <el-upload :show-file-list="false" class="upload-demo"
                action="/api/blade-mdm/machine/import"
                       :on-change="handleChange">
              <el-button type="primary" plain size="default">导入</el-button>
            </el-upload>
 
 
 
            <el-button type="primary" size="default" icon="el-icon-circle-plus" plain @click="handleAdd">新增</el-button>
          </template>
          <template #menu="scope">
            <el-button type="primary" text size="default" icon="el-icon-upload" @click.stop="handleEdit(scope.row, scope.index)">编辑</el-button>
            <el-button type="primary" text size="default" icon="el-icon-upload" @click.stop="handleDel(scope.row, scope.index)">删除</el-button>
            <el-button type="primary" text size="default" icon="el-icon-upload" @click.stop="handleUp(scope.row, scope.index)">产生机床回传机构树</el-button>
          </template>
 
          <template #status="{ row }">
            <span>{{ row.status=="1"?"启用":"禁用" }}</span>
          </template>
        </avue-crud>
 
        <el-dialog :title="machineTitle" append-to-body v-model="editBox" width="60%">
          <avue-form ref="editFormModal1" :option="editFormModal" v-model="editForm" @submit="formSubmit" @resetForm="resetForm">
            <template #ownerDept="{}">
              <el-tree-select v-model="editForm.ownerDept" :data="organizationTreeList" :props="treePropsConfig"/>
            </template>
          </avue-form>
        </el-dialog>
      </basic-container>
    </el-col>
  </el-row>
</template>
 
<script>
import { exportBlob } from '@/api/common';
import { getToken } from '@/utils/auth';
import NProgress from 'nprogress';
import { downloadXls } from '@/utils/util';
import 'nprogress/nprogress.css';
import { getDeptLazyTree } from '@/api/system/dept';
export default {
  data() {
    var that = this;
    return {
      treeOption: {
        nodeKey: 'id',
        lazy: true,
        treeLoad: function (node, resolve) {
          const parentId = node.level === 0 ? 0 : node.data.id;
          getDeptLazyTree(parentId).then(res => {
            resolve(
              res.data.data.map(item => {
                return {
                  ...item,
                  leaf: !item.hasChildren,
                };
              })
            );
          });
        },
        addBtn: false,
        menu: false,
        size: 'small',
        props: {
          labelText: '标题',
          label: 'title',
          value: 'value',
          children: 'children',
        },
      },
      treeData: [],
      treePropsConfig: {
        value:  'id',
        label: 'title',
        children: 'children'
      },
      organizationTreeList: [],
      machineTitle: "新增",
      isAdd: true,
      editBox: false,
      search: {
        keyword: "",
        machineGroupCode: ""
      },
      loading: true,
      mypage: {
        size: 10,
        current: 1,
        total: 0,
      },
      editForm: {},
      option: {
        index: true,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        labelWidth: 120,
        emptyBtn: false,
        searchSpan: 8,
        column: [
          {
            label: '编号/名称',
            type: 'input',
            prop: 'keyword',
            search: true,
            hide: true,
            showColumn: false
          },
          {
            label: '机床编号',
            prop: 'code'
          },
          {
            label: '机床型号',
            prop: 'name',
          },
          {
            label: '机床组',
            prop: 'machineGroupName',
            search: true,
            type: 'select',
            dicUrl: '/blade-system/dict-biz/dictionary?code=machine_group',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            span: "8"
          },
          {
            label: '机床类型',
            prop: 'machineSpecName',
          },
          {
            label: '生产厂商',
            prop: 'manufacturer',
          },
          {
            label: '操作员',
            prop: 'operator',
          },
          {
            label: '状态',
            prop: 'status',
            slot: true,
          },
        ],
      },
      editFormModal: {
        labelWidth: 160,
        submitBtn: true,
        submitText: "保存",
        emptyBtn: false,
        column: [
          {
            label: '机床编号',
            prop: 'code',
            type: 'input',
            span: 12,
            dataType: 'string',
            rules: [
              {
                required: true,
                message: '请输入机床编号',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '机床型号',
            prop: 'name',
            type: 'input',
            span: 12,
            dataType: 'string',
            rules: [
              {
                required: true,
                message: '请输入机床型号',
                trigger: 'blur'
              }
            ]
          },
          {
            label: '机床类型',
            prop: 'machineSpec',
            type: 'select',
            span: 12,
            dicUrl: '/blade-system/dict-biz/dictionary?code=machine_spec',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择机床类型',
                trigger: 'change'
              }
            ]
          },
          {
            label: '所属机床组',
            prop: 'machineGroupCode',
            type: 'select',
            span: 12,
            dicUrl: '/blade-system/dict-biz/dictionary?code=machine_group',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            },
            rules: [
              {
                required: true,
                message: '请选择所属机床组',
                trigger: 'change'
              }
            ]
          },
          {
            label: '操作员',
            prop: 'operator',
            type: 'input',
            span: 12,
            dataType: 'string',
          },
          {
            label: '所属组织',
            prop: 'ownerDept',
            type: 'tree',
            span: 12,
            rules: [
              {
                required: true,
                message: '请选择所属组织',
                trigger: 'click'
              }
            ]
          },
          {
            label: '生产商',
            prop: 'manufacturer',
            type: 'input',
            span: 12,
            dataType: 'string',
          },
          {
            label: '系统控制',
            prop: 'controlSystem',
            type: 'select',
            span: 12,
            dicUrl: '/blade-system/dict-biz/dictionary?code=machine_control_system',
            props: {
              label: 'dictValue',
              value: 'dictKey',
            }
          },
          {
            label: '状态',
            prop: 'status',
            type: 'checkbox',
            span: 12,
            dicData: [{
              label: '启用',
              value: 1
            }]
          },
          {
            label: '程序下发目录',
            prop: 'progSendDir',
            type: 'input',
            span: 12,
            dataType: 'string',
          },
          {
            label: '程序回传目录',
            prop: 'progReceiveDir',
            type: 'input',
            span: 12,
            dataType: 'string',
          },
          {
            label: '程序临时目录',
            prop: 'progTempDir',
            type: 'input',
            span: 12,
            dataType: 'string',
          },
          {
            label: '备注',
            prop: 'remark',
            type: 'textarea',
            span: 24,
            dataType: 'string',
          },
        ]
      },
      data: [],
    };
  },
  methods: {
    handleChange(a,b,c) {
      console.log(a,b,c);
    },
    nodeClick(data) {
      this.treeDeptId = data.id;
      this.mypage.current = 1;
      this.onLoad(this.page);
    },
    handleAdd() {
      this.machineTitle = "新增";
      this.isAdd = true;
      this.editBox = true;
      this.$refs.editFormModal1.resetForm();
    },
    handleEdit(row,index) {
      this.machineTitle = "编辑";
      this.isAdd = false;
      axios({
        url: '/blade-mdm/machine/detail',
        method: 'get',
        params: {id: row.id},
      }).then(
        res => {
          res.data.data.status = [res.data.data.status];
          this.editForm = res.data.data;
          this.editBox = true;
        },
        error => {
          this.loading = false;
        }
      );
    },
    handleDel(row,index) {
      this.loading = true;
      axios({
        url: '/blade-mdm/machine/remove',
        method: 'post',
        params: {ids: row.id},
      }).then(
        res => {
          this.loading = false;
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.onLoad();
          done();
        },
        error => {
          this.loading = false;
        }
      );
    },
    handleUp(row,index) {
      this.loading = true;
      axios({
        url: '/blade-mdm/machine/gen-fileback-dirs',
        method: 'post',
        params: {id: row.id},
      }).then(
        res => {
          this.loading = false;
          this.$message({
            type: 'success',
            message: '操作成功!',
          });
          this.onLoad();
          done();
        },
        error => {
          this.loading = false;
        }
      );
    },
    handleExport() {
      this.$confirm('是否导出?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        NProgress.start();
        exportBlob(
          `/blade-mdm/machine/export?${this.website.tokenHeader}=${getToken()}`
        ).then(res => {
          downloadXls(res.data, `导出机床${this.$dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`);
          NProgress.done();
        });
      });
    },
    formSubmit(params, done) {
      var obj = {...params};
      if(params.status.length == 0) {
        obj.status = "0";
      }else {
        obj.status = "1";
      }
      if(this.isAdd) {  //新增
        var url = '/blade-mdm/machine/save';
      }else {
        var url = '/blade-mdm/machine/update';
      }
      this.loading = true;
      axios({url: url,method: 'post',data: obj}).then(res => {
        this.loading = false;
        if(res,res.data.success) {
          this.editBox = false;
          this.$message({type: 'success',message: '操作成功!'});
          this.onLoad();
        }else {
          this.$message({type: 'error',message: res.data.msg});
        }
        done();
      });
    },
    handleView() {
 
    },
    searchReset() {
      //this.onLoad(this.mypage);
    },
    searchChange(params, done) {
      this.mypage.current = 1;
      this.onLoad();
      done();
    },
    currentChange(current) {
      this.mypage.current = current;
    },
    sizeChange(size) {
      this.mypage.size = size;
    },
    refreshChange() {
      
    },
    onLoad() {
      this.$nextTick(()=> {
        this.loading = true;
        var obj = {
          keyword: this.search.keyword,
          machineGroupCode: this.search.machineGroupName,
          current: this.mypage.current,
          size: this.mypage.size,
          deptId: this.treeDeptId
        }
        axios({
          url: '/blade-mdm/machine/page',
          method: 'get',
          params: obj,
        }).then(
          res => {
            const data = res.data.data;
            this.mypage.total = data.total;
            this.data = data.records;
            this.loading = false;
          },
          error => {
              
          }
        );
      })
    },
    traversalLabelValueToTree(tree) {  //遍历数组
      return tree.map(node => {
        // 1. 添加 label 和 value 字段
        const newNode = {
          ...node,
          label: node.fullName,
          value: node.id,
        };
        // 2. 如果有 children,递归处理
        if (node.children && node.children.length > 0) {
          newNode.children = this.traversalLabelValueToTree(node.children);
        }
        return newNode;
      });
    }
  },
  mounted() { 
    //所属组织 /api/blade-system/dept/tree
    axios({url: '/blade-system/dept/tree',method: 'get'}).then(resp => {
      this.organizationTreeList = this.traversalLabelValueToTree(resp.data.data);
    })
  }
};
</script>
 
<style lang="scss">
.upload-demo {
  display: inline-block;
  margin-left: 6px;
  margin-right: 6px;
}
</style>