1
lzhe
2024-06-21 9c094a1fe3e1ae3dadef6433f8401818fe2b8304
src/views/mdc/configComp/Board.vue
@@ -1,7 +1,7 @@
<!--
 * @Date: 2024-04-15 23:58:36
 * @LastEditors: Sneed
 * @LastEditTime: 2024-04-16 00:26:46
 * @LastEditTime: 2024-04-17 00:45:20
 * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/mdc/configComp/Board.vue
-->
<template>
@@ -11,37 +11,40 @@
                页面排列方式
            </el-col>
            <el-col :span="4">
                <el-radio-group v-model="radio">
                    <el-radio :label="1">充满屏幕</el-radio>
                    <el-radio :label="2">设置行列</el-radio>
                <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 v-model="radio" :min="1" :max="4" @change="handleChange" />
                <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 v-model="radio" :min="1" :max="4" @change="handleChange" />
                <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-col :span="2" class="label-title">
                柔性产线
        </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>
            <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 v-model="radio" /><span>千文科技</span>
                                <el-button style="margin-left: auto">设为默认</el-button>
                                <el-button style="margin-left: auto">默认</el-button>
                            <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>
@@ -49,7 +52,7 @@
                </el-card>
            </el-col>
            <el-col class="label-title">
            <!-- <el-col class="label-title">
                车间
            </el-col>
            <el-col :span="6">
@@ -78,18 +81,136 @@
                    </template>
                    <p>所有的 > 千文科技</p>
                </el-card>
            </el-col>
            </el-col> -->
        </el-row>
    </el-main>
</template>
<script>
export default {
    data() {
        return {
            radio: ''
    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>