gaoshp
2024-04-23 f28363d03c3539b0219c5b58ea8b7db37d50be6f
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
<!--
 * @Date: 2024-04-01 20:28:18
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-13 22:12:39
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/basic-data/working-condition/index.vue
-->
<template>
    <el-main>
        <el-card shadow="never">
            <el-container>
                <el-header style="justify-content:flex-start">
                    <el-button @click="table_add" type="primary" icon="el-icon-plus"></el-button>
                    <el-button type="danger" plain icon="el-icon-delete" @click="batchDel"></el-button>
                </el-header>
                <el-main>
                    <el-table v-bind="$attrs" :data="tableData" :row-key="rowKey" :border="true" :stripe="true"
                        @selection-change="selectionChange">
                        <el-table-column type="selection" />
                        <el-table-column prop="dataItem" label="工位变量名称" />
                        <el-table-column prop="dataTypeDesc" label="数据标签" />
                        <el-table-column prop="usageName" label="计算方法" />
                        <el-table-column prop="collectSettingItem" label="采集变量名称" />
                        <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 title="确定删除吗?" @confirm="table_del(scope.row, scope.$index, '0')">
                                        <template #reference>
                                            <el-button text type="primary" size="small">删除</el-button>
                                        </template>
                                    </el-popconfirm>
                                </el-button-group>
                            </template>
                        </el-table-column>
                    </el-table>
                </el-main>
                <el-drawer v-model="drawer" title="新建" :before-close="handleClose">
                    <el-form :model="form" :rules="rules" :disabled="mode == 'show'" ref="dialogForm"
                        label-width="120px" label-position="center">
                        <el-row>
                            <el-col :span="24">
                                <el-form-item label="工位变量名称" prop="dataItem">
                                    <el-input style="width: 240px" v-model="form.dataItem" placeholder="工位变量名称"
                                        clearable></el-input>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="数据标签" prop="usageId">
                                    <el-select v-model="form.usageId" clearable placeholder="数据标签" style="width: 240px">
                                        <el-option v-for="item in workstation_param_type" :key="item.id"
                                            :label="item.usageName" :value="item.id" />
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="24">
                                <el-form-item label="采集变量名称" prop="collectSettingItem">
                                    <el-input style="width: 240px" v-model="form.collectSettingItem"
                                        placeholder="采集变量名称" clearable></el-input>
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <template #footer>
                        <div style="flex: auto">
                            <el-button @click="cancelClick">cancel</el-button>
                            <el-button type="primary" @click="confirmClick">confirm</el-button>
                        </div>
                    </template>
                </el-drawer>
            </el-container>
        </el-card>
    </el-main>
</template>
 
<script>
import config from "@/config/table";
export default {
    data() {
        return {
            config,
            tableData: [],
            workstation_param_type: [],
            drawer: false,
            form: {
                dataItem: '',
                usageId: '',
                collectSettingItem: ''
            },
            rules: {
                dataItem: [
                    { required: true, message: '请输入工位变量名称' }
                ],
                usageId: [
                    { required: true, message: '请选择数据标签' }
                ],
                collectSettingItem: [
                    { required: true, message: '请输入采集变量名称' }
                ],
            },
            selection: []
        }
    },
    created() {
        this.init()
    },
    methods: {
        init() {
 
            this.$API.workingCondition.getwcsUsageList.get().then(res => {
                this.workstation_param_type = res.data
            })
            this.$API.workingCondition.getList.get().then(res => {
                if (res.code == 200) {
                    this.tableData = res.data
                }
            })
        },
        batchDel() {
            console.log(this.selection)
            this.$API.workingCondition.del.post(
                {}, this.selection.map(v => v.id)
            ).then(res => {
                this.drawer = false
                this.init()
            })
        },
        selectionChange(selection) {
            this.selection = selection
        },
        table_add() {
            this.row = {}
            this.drawer = true
            this.$nextTick(() => {
                this.$refs.dialogForm.resetFields()
            })
        },
        table_edit(row) {
            this.row = row
            this.form.dataItem = row.dataItem
            this.form.usageId = row.usageId
            this.form.collectSettingItem = row.collectSettingItem
            this.drawer = true
        },
        table_del(row) {
            this.$API.workingCondition.del.post(
                {}, [row.id]
            ).then(res => {
                this.drawer = false
                this.init()
            })
        },
        cancelClick() {
            this.drawer = false
        },
        confirmClick() {
            let { collectType: dataType } = this.workstation_param_type.find(v => v.id === this.form.usageId)
            this.$refs.dialogForm.validate().then(res => {
                if (res) {
                    if (!this.row.id) {
                        this.$API.workingCondition.save.post([
                            {
                                ...this.form,
                                dataType
                            }
                        ]).then(res => {
                            this.drawer = false
                            this.init()
                        })
                    } else {
                        this.$API.workingCondition.update.post(
                            {
                                ...this.row,
                                ...this.form,
                                dataType
                            }
                        ).then(res => {
                            this.drawer = false
                            this.init()
                        })
                    }
 
                }
            })
        },
    }
}
</script>
 
<style lang="scss" scoped></style>