Blame view

src/components/machine/printerRuleDiv.vue 2.93 KB
d68983e7   wuxw   保养功能开发完成
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
  <template>
    <el-card class="box-card">
      <div class="button-group">
        <el-button type="primary" size="small" @click="openAddModal">
          <i class="el-icon-plus"></i>{{ $t('common.add') }}
        </el-button>
        <el-button type="primary" size="small" @click="openEditModal">
          <i class="el-icon-edit"></i>{{ $t('common.edit') }}
        </el-button>
        <el-button type="primary" size="small" @click="openDeleteModal">
          <i class="el-icon-delete"></i>{{ $t('common.delete') }}
        </el-button>
      </div>
  
      <div class="vc-org margin-top">
        <el-tree :data="printerRules" :props="defaultProps" @node-click="handleNodeClick" highlight-current></el-tree>
      </div>
  
      <add-printer-rule ref="addPrinterRule" @success="getPrinterRules" />
      <edit-printer-rule ref="editPrinterRule" @success="getPrinterRules" />
      <delete-printer-rule ref="deletePrinterRule" @success="getPrinterRules" />
    </el-card>
  </template>
  
  <script>
  import { listPrinterRules } from '@/api/machine/printerRuleApi'
  import { getCommunityId } from '@/api/community/communityApi'
  import AddPrinterRule from '@/components/machine/addPrinterRule'
  import EditPrinterRule from '@/components/machine/editPrinterRule'
  import DeletePrinterRule from '@/components/machine/deletePrinterRule'
  
  export default {
    name: 'PrinterRuleDiv',
    props: {
      value: {
        type: Object,
        default: () => ({})
      }
    },
    components: {
      AddPrinterRule,
      EditPrinterRule,
      DeletePrinterRule
    },
    data() {
      return {
        printerRules: [],
        defaultProps: {
          children: 'children',
          label: 'ruleName'
        },
        curRule:{},
        communityId: ''
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.getPrinterRules()
    },
    methods: {
      async getPrinterRules() {
        try {
          const params = {
            page: 1,
            row: 100,
            communityId: this.communityId
          }
          const { data } = await listPrinterRules(params)
          this.printerRules = data
          if (this.printerRules.length > 0) {
            this.handleNodeClick(this.printerRules[0])
          }
        } catch (error) {
          console.error('获取打印机规则失败:', error)
        }
      },
      handleNodeClick(data) {
        this.curRule = data
      },
      openAddModal() {
        this.$refs.addPrinterRule.open()
      },
      openEditModal() {
        if (!this.curRule.ruleId) {
          this.$message.warning(this.$t('printerRule.selectRule'))
          return
        }
        this.$refs.editPrinterRule.open(this.curRule)
  
      },
      openDeleteModal() {
        if (!this.curRule.ruleId) {
          this.$message.warning(this.$t('printerRule.selectRule'))
          return
        }
        this.$refs.deletePrinterRule.open(this.curRule)
      },
      refreshList() {
        this.getPrinterRules()
      }
    }
  }
  </script>
  
  <style scoped>
  .button-group {
    margin-bottom: 15px;
  }
  
  .vc-org {
    max-height: 500px;
    overflow-y: auto;
  }
  
  .margin-top {
    margin-top: 15px;
  }
  </style>