gaoshp
2024-06-02 b46e6d2306515f94bf77c06e8d80ac76267e3ddb
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
<!--
 * @Date: 2024-04-15 23:58:36
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-17 00:45:20
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/configComp/Board.vue
-->
<template>
    <el-main>
        <el-row>
            <el-col :span="2" class="label">
                页面排列方式
            </el-col>
            <el-col :span="4">
                <el-radio-group v-model="form.way" @change="submit('mdc.realtime.setting')">
                    <el-radio label="1">充满屏幕</el-radio>
                    <el-radio label="2">设置行列</el-radio>
                </el-radio-group>
            </el-col>
            <el-col :span="2" class="label" :offset="2">
                设置行数
            </el-col>
            <el-col :span="4">
                <el-input-number @change="submit('mdc.realtime.setting')" v-model="form.line" :min="1" :max="4" />
            </el-col>
            <el-col :span="2" class="label" :offset="2">
                设置列数
            </el-col>
            <el-col :span="4">
                <el-input-number @change="submit('mdc.realtime.setting')" v-model="form.column" :min="1" :max="5" />
            </el-col>
            <el-col class="title">
                下面陈列拥有标签的所有工位组,请选择需要在实时看板页面查询的组,并设定一个默认组
                如果未配置查询组,实时工况页面默认查询所有工位
            </el-col>
        </el-row>
        <el-row v-for="item in dictsNew" :key="item.dictKey">
            <el-col :span="24" class="label-title">
                {{ item.dictValue }}
            </el-col>
            <el-col :span="6" v-for="(v, i) in item.children" :key="v.id" :offset="i > 0 ? 2 : 0">
                <el-card class="my-card" @click="radio = true">
                    <template #header>
                        <div class="card-header">
                            <div class="card-line"><el-checkbox :disabled="v.isDefault" @change="submit1"
                                    v-model="v.isSelect" /><span>千文科技</span>
                                <el-button v-if="v.isDefault" style="margin-left: auto">默认</el-button>
                                <el-button @click="setDefault(v)" v-else style="margin-left: auto">设为默认</el-button>
                            </div>
                        </div>
                    </template>
                    <p>所有的 > 千文科技</p>
                </el-card>
            </el-col>
 
            <!-- <el-col class="label-title">
                车间
            </el-col>
            <el-col :span="6">
                <el-card class="my-card" @click="radio = true">
                    <template #header>
                        <div class="card-header">
                            <div class="card-line"><el-checkbox v-model="radio" /><span>千文科技</span><el-button
                                    style="margin-left: auto">设为默认</el-button>
                                <el-button style="margin-left: auto">默认</el-button>
                            </div>
                        </div>
                    </template>
                    <p>所有的 > 千文科技</p>
                </el-card>
 
            </el-col>
            <el-col :span="6" :offset="2">
                <el-card class="my-card" @click="radio = true">
                    <template #header>
                        <div class="card-header">
                            <div class="card-line"><el-checkbox v-model="radio" /><span>千文科技</span><el-button
                                    style="margin-left: auto">设为默认</el-button>
                                <el-button style="margin-left: auto">默认</el-button>
                            </div>
                        </div>
                    </template>
                    <p>所有的 > 千文科技</p>
                </el-card>
            </el-col> -->
        </el-row>
    </el-main>
</template>
 
<script>
export default {
    computed: {
        dictsNew() {
            return this.dicts.filter(v => v?.children?.length > 0)
        }
    },
    data() {
        return {
            form: {
                id: '',
                way: '1',
                line: 1,
                column: 1,
            },
            id: '',
            dicts: []
        }
    },
    created() {
        this.init()
        this.getDetail('mdc.realtime.setting', this.form)
    },
    methods: {
        init() {
            this.$HTTP.get('/api/blade-system/param-biz/detail?paramKey=mdc_chosen_groups').then(re => {
                this.id = re.data.id
                let chosen = []
                let normalId = ''
                try {
                    chosen = JSON.parse(re.data.paramValue).map(v => v.groupId)
                    normalId = JSON.parse(re.data.paramValue).find(v => v.isDefault).groupId
                } catch (error) {
 
                }
                Promise.all([
                    this.$HTTP.get('/api/blade-system/dict/dictionary?code=group_tag').then(res => {
                        this.dicts = []
                        this.dicts.push(...res.data.map(({ dictKey, dictValue }) => ({
                            dictKey, dictValue
                        })))
                    }),
                    this.$HTTP.get('/api/blade-system/dict/dictionary?code=beltline_type').then(res => {
                        this.dicts.push(...res.data.map(({ dictKey, dictValue }) => ({
                            dictKey, dictValue
                        })))
                    })
                ]).then(res => {
                    this.$HTTP.get('/api/blade-cps/apply-settings/list-workstation-group?groupCategory=&groupTag=&groupType=group_workstation').then(res => {
                        this.dicts.forEach(v => {
                            v.children = res.data.filter(item => item.groupTag == v.dictKey).map(item => {
                                return {
                                    groupId: item.id,
                                    groupName: item.name,
                                    groupCode: item.code,
                                    isDefault: item.id === normalId,
                                    isSelect: chosen.indexOf(item.id) > -1
                                }
                            })
                        })
                    })
 
                })
            })
 
        },
        getDetail(paramKey, obj) {
            this.$HTTP.get('/api/blade-system/param/detail', { paramKey }).then(res => {
                Object.keys(obj).forEach(key => {
                    try {
                        obj[key] = JSON.parse(res.data.paramValue)[key]
                    } catch (error) {
                        console.error(error)
                    }
                })
                obj.id = res.data.id
            })
        },
        submit(paramKey) {
            let paramValue = {
                ...this.form
            }
            delete paramValue.id
            paramValue = JSON.stringify(paramValue)
            this.$HTTP.post('/api/blade-system/param/submit', { id: this.form.id, paramKey, paramValue }).then(res => {
                if (res.code === 200) {
                    this.$message.success(`操作成功`)
                    this.getDetail('mdc.realtime.setting', this.form)
                }
            })
        },
        submit1() {
            let paramValue = []
            this.dictsNew.forEach(v => {
                let children = v?.children?.filter(item => item.isSelect) || []
                children = children.map(item => {
                    let current = { ...item }
                    delete current.isSelect
                    return current
                })
                paramValue.push(...children)
            })
            paramValue = JSON.stringify(paramValue)
            this.$HTTP.post('/api/blade-system/param-biz/submit', { id: this.id, paramKey: 'mdc_chosen_groups', paramValue }).then(res => {
                if (res.code === 200) {
                    this.$message.success(`操作成功`)
                    this.init()
                }
 
            })
        },
        setDefault({ groupId }) {
            this.dicts.forEach(item => {
                item?.children.forEach(v => {
                    if (groupId == v.groupId) {
                        v.isDefault = true
                        v.isSelect = true
                    } else {
                        v.isDefault = 0
                    }
                })
            })
            this.submit1()
        }
    }
}
</script>
 
<style lang="scss" scoped>
.label {
    display: flex;
    align-items: center;
 
}
 
.label-title {
    margin-bottom: 14px;
}
 
.my-card {
    max-width: 480px;
    cursor: pointer;
}
 
.title {
    padding: 10px 0;
    font-size: 14px;
}
 
.card-line {
    display: flex;
    align-items: center;
 
    span {
        margin: 0 10px;
    }
}
</style>