gaoshp
2024-09-24 138000232b9b05097a09700fea9fbd51f084043c
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
<!--
 * @Date: 2024-04-27 20:04:34
 * @LastEditors: gaoshp
 * @LastEditTime: 2024-09-24 21:03:08
 * @FilePath: /cps-web/src/views/tpm/MachineTab.vue
-->
<template>
    <el-container>
        <el-aside width="200px" v-loading="showGrouploading">
            <el-container>
                <el-main class="nopadding">
                    <el-tree :expand-on-click-node="false" ref="group" default-expand-all node-key="id" :data="group"
                        :current-node-key="params.groupId" :highlight-current="true" @node-click="nodeClick"></el-tree>
                </el-main>
            </el-container>
        </el-aside>
        <el-container>
            <el-header>
                <div class="left-panel">
                    <el-button size="small" @click="table_add" type="primary" icon="el-icon-plus"></el-button>
                    <el-button size="small" type="danger" plain icon="el-icon-delete" @click="batchDel"
                        :disabled="selection.length == 0"></el-button>
                    <!-- <el-button type="primary" plain>导入</el-button>
                                    <el-button type="primary" plain>批量操作</el-button> -->
                </div>
                <div class="right-panel">
                    <div class="right-panel-search">
                        <span>类型</span>
                        <el-select v-model="params.machineTypeId" style="width: 240px" clearable>
                            <el-option v-for="item in types" :key="item.value" :label="item.label"
                                :value="item.value" />
                        </el-select>
                        <span>状态</span>
                        <el-select v-model="params.status" style="width: 240px">
                            <el-option v-for="item in status" :key="item.value" :label="item.label"
                                :value="item.value" />
                        </el-select>
                        <el-input v-model="params.machineName" style="width: 240px" placeholder="请输入机器名称"
                            clearable></el-input>
                        <el-button @click="search" type="primary" icon="el-icon-search"></el-button>
                    </div>
                </div>
            </el-header>
            <el-main class="nopadding">
                <scTable highlight-current-row @dataChange="dataChange" @row-click="rowClick" ref="table"
                    :params="params" :apiObj="apiObj" @selection-change="selectionChange" stripe>
                    <el-table-column type="selection" width="50"></el-table-column>
                    <el-table-column label="机器编号" prop="machineCode" width="120"></el-table-column>
                    <el-table-column label="机器名称" prop="machineName" width="120"></el-table-column>
                    <el-table-column label="所属机器组" prop="groupName" width="120"></el-table-column>
                    <el-table-column label="机器类型" prop="machineTypeName" width="120"></el-table-column>
                    <el-table-column label="机器序列号" prop="serialNo" width="120"></el-table-column>
                    <el-table-column label="短编号" prop="shortCode" width="120"></el-table-column>
                    <el-table-column label="机器规格" prop="machineModel" width="120"></el-table-column>
                    <el-table-column label="使用状态" prop="machineUseStatusName" width="120"></el-table-column>
                    <el-table-column label="操作" fixed="right" align="right" width="160">
                        <template #default="scope">
                            <el-button-group>
                                <el-button text type="primary" size="small"
                                    @click="table_edit(scope.row, scope.$index)">编辑</el-button>
                                <el-popconfirm width="220" cancel-button-text="停用" confirm-button-text="删除"
                                    title="删除数据会影响已关联的业务 ,若您想在已关联的业务中依然显示这些数据, 您可以选择 停用 操作。停用后此数据将不能再被新业务使用。"
                                    @confirm="table_del(scope.row, scope.$index, '0')"
                                    @cancel="table_del(scope.row, scope.$index, '1')">
                                    <template #reference>
                                        <el-button text type="primary" size="small">删除</el-button>
                                    </template>
                                </el-popconfirm>
                            </el-button-group>
                        </template>
                    </el-table-column>
                </scTable>
            </el-main>
        </el-container>
        <Dialog ref="dialog" @success="success"></Dialog>
    </el-container>
</template>
 
<script>
import Dialog from './machine/Dialog.vue'
export default {
    components: {
        Dialog
    },
    data() {
        return {
            apiObj: this.$API.machineManagement.getList,
            group: [],
            params: {
                groupId: '',
                machineTypeId: '',
                status: 1,
            },
            treeCheckKey: '',
            status: [
                {
                    label: '启用',
                    value: 1
                },
                {
                    label: '停用',
                    value: 0
                }
            ],
            types: [],
            selection: []
        }
    },
    created() {
        this.init()
        this.getTreeData()
    },
    methods: {
        init() {
            this.$HTTP.get('/api/blade-cps/device-types/page?keyWord=&current=1&size=-1').then(res => {
                if (res.code === 200) {
                    this.types = res.data.records.map(item => ({
                        label: item.name,
                        value: item.id
                    }))
                }
            })
        },
        getTreeData() {
            this.$HTTP.get('/api/blade-cps/group/tree?groupCategory=1&groupType=group_machine').then(res => {
                if (res.code === 200) {
                    this.group = res.data
                    // this.params.groupId = res.data[0].id
                    this.nodeClick(res.data[0])
                }
            })
        },
        nodeClick(node) {
            this.params.groupId = node.id
            this.search()
        },
        search() {
            this.$refs.table.reload(this.params)
        },
        table_add() {
            this.$refs.dialog.open('add', {
                groupId: this.params.groupId
            })
        },
        table_edit(row) {
            this.$refs.dialog.open('edit', { id: row.id })
        },
        success() {
            this.getTreeData()
        },
        table_del(row, index, type) {
            this.$HTTP.delete(`/api/blade-cps/machine?type=${type}`, {
                ids: [row.id]
            }).then(res => {
                if (res.code === 200) {
                    this.$message.success("操作成功");
                    this.getTreeData()
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
        selectionChange(selection) {
            this.selection = selection
        },
        batchDel() {
            if (this.selection.length === 0) {
                return this.$message.warning("请选择");
            }
            this.$HTTP.delete(`/api/blade-cps/machine?type=1`, {
                ids: this.selection.map(item => item.id)
            }).then(res => {
                if (res.code === 200) {
                    this.$message.success("操作成功");
                    this.getTreeData()
                } else {
                    this.$message.error(res.msg);
                }
            })
        },
    }
}
</script>
 
<style lang="scss" scoped></style>