gaoshp
2024-11-04 eef1ef0be935d4a3d8fc691b2666f41796b2d4a5
src/views/console/base/CalenderTab.vue
@@ -1,7 +1,7 @@
<!--
 * @Date: 2024-04-04 22:45:43
 * @LastEditors: gaoshp
 * @LastEditTime: 2024-10-01 20:16:51
 * @LastEditTime: 2024-10-09 22:59:25
 * @FilePath: /cps-web/src/views/console/base/CalenderTab.vue
-->
<template>
@@ -21,7 +21,7 @@
            <el-header>
                <span>日历【{{ selectInfo.code }}】{{ selectInfo.name }}</span>
                <el-button type="primary" style="margin-left: auto;" size="small" @click="relationWork">关联工位</el-button>
                <!-- <el-button type="primary" size="small">编辑日历</el-button> -->
                <el-button type="primary" size="small" @click="edit">编辑日历</el-button>
                <el-popconfirm title="确定删除吗?" @confirm="table_del">
                    <template #reference>
                        <el-button type="primary" size="small">删除</el-button>
@@ -29,13 +29,24 @@
                </el-popconfirm>
            </el-header>
            <el-main>
                <el-row :gutter="12" v-show="shiftListName">
                    {{ shiftListName }}
                <el-row :gutter="12" v-show="shiftListName.length > 0">
                    <el-button v-for="item in shiftListName"
                        :style="{ backgroundColor: item.colour || '#2563eb', color: '#fff' }">{{
                            item.code +
                            '-' +
                            item.name
                        }}</el-button>
                </el-row>
                <el-row>
                    <el-col :span="6" style="padding:  10px;" v-for="item in months" :key="item.month">
                        <Calendar :initial-page="{ month: item.month + 1, year: item.year }" :rows="1"
                            disable-page-swipe :nav-visibility="''" :attributes='item.attributes' />
                            disable-page-swipe :nav-visibility="''" :attributes='item.attributes'>
                            <!-- <template #day-popover="row">
                                <div class="text-xs text-gray-700 dark:text-gray-300">
                                    123123{{ row }}
                                </div>
                            </template> -->
                        </Calendar>
                    </el-col>
                </el-row>
                <!-- :initial-page="{ month: item.month + 1, year: item.year }" -->
@@ -44,7 +55,7 @@
        </el-container>
        <el-drawer v-if="drawer" v-model="drawer" size="80%" title="生产日历" :direction="direction"
            :before-close="handleClose">
            <Add v-if="drawer" :shiftList="shiftList" @success="success"></Add>
            <Add v-if="drawer" :shiftList="shiftList" :drawerInfo="drawerInfo" @success="success"></Add>
        </el-drawer>
        <el-drawer v-model="raworkVisible" size="80%" title="生产日历" :direction="direction" :before-close="handleClose">
            <el-container v-if="raworkVisible">
@@ -66,6 +77,7 @@
import 'v-calendar/style.css';
import Add from './Add.vue'
import moment from 'moment';
import color from '@/utils/color'
export default {
    components: {
        Calendar,
@@ -75,7 +87,7 @@
    data() {
        return {
            shiftList: [],
            shiftListName: '',
            shiftListName: [],
            selectInfo: {},
            drawer: false,
            months: [],
@@ -92,6 +104,9 @@
                label: 'title',
                children: 'children',
            },
            drawerInfo: {},
            color
        }
    },
    created() {
@@ -99,12 +114,15 @@
        this.init()
    },
    methods: {
        edit() {
            this.drawer = true
            this.drawerInfo = this.selectInfo
        },
        relationWork() {
            this.$HTTP.post('/api/blade-cps/group/groupWorkstation', { groupCategory: 1, groupType: 'group_workstation' }).then(res => {
            this.$HTTP.post('/api/smis/group/groupWorkstation', { groupCategory: 1, groupType: 'group_workstation' }).then(res => {
                if (res.code === 200) {
                    this.raworkVisible = true
                    this.workStations = this.formatData(res.data)
                    console.log(this.workStations)
                }
            })
@@ -161,11 +179,11 @@
            } else {
                this.save(workstation.map(v => v.id))
            }
            console.log(this.$refs.workstations.getCheckedNodes().filter(v => v.isWorkstation))
            // console.log(this.$refs.workstations.getCheckedNodes().filter(v => v.isWorkstation))
        },
        save(workstationIdList) {
            console.log(workstationIdList, this.selectInfo)
            this.$HTTP.post('/api/blade-cps/calendar/associate-workstation', {
            this.$HTTP.post('/api/smis/calendar/associate-workstation', {
                calendarCode: this.selectInfo.code,
                workstationIdList
            }).then(res => {
@@ -178,37 +196,39 @@
            })
        },
        dayclick(day) {
            console.log(day)
            // console.log(day)
        },
        init() {
            this.$HTTP.post('/api/blade-cps/shift/list', { statusList: [1] }).then(res => {
            this.$HTTP.post('/api/smis/shift/list', { statusList: [1] }).then(res => {
                if (res.code === 200) {
                    this.shiftList = res.data
                }
            })
        },
        select(row) {
            this.selectInfo = {
                ...row
            }
            this.months = []
            this.$HTTP.get(`/api/blade-cps/calendar/${row.id}`).then(res => {
            this.$HTTP.get(`/api/smis/calendar/${row.id}`).then(res => {
                if (res.code === 200) {
                    console.log(res.data)
                    // console.log(res.data)
                    this.setDay(res.data)
                    let current = this.shiftList.find(v => v.id == res.data.calendarDayVOList[0].modelId)
                    console.log('////', this.shiftList, res.data.calendarDayVOList[0].id)
                    if (current) {
                        this.shiftListName = `${current.code}-${current.name}`
                    // console.log('////', this.shiftList, res.data.calendarDayVOList[0].id)
                    let modelIds = [...new Set(res.data.calendarDayVOList.map(v => v.modelId))]
                    if (modelIds.length > 0) {
                        this.shiftListName = this.shiftList.filter(v => modelIds.includes(v.id))
                    } else {
                        this.shiftListName = ''
                        this.shiftListName = []
                    }
                }
                this.selectInfo = {
                    ...row,
                    calendarDayVOList: res.data.calendarDayVOList
                }
            })
        },
        table_del() {
            this.$HTTP.delete(`/api/blade-cps/calendar/${this.selectInfo.id}`).then(res => {
            this.$HTTP.delete(`/api/smis/calendar/${this.selectInfo.id}`).then(res => {
                if (res.code == 200) {
                    this.$message.success("操作成功");
                    this.load(true)
@@ -217,6 +237,7 @@
        },
        add() {
            this.drawer = true
            this.drawerInfo = {}
        },
        load(flag) {
            if (flag) this.current = 0;
@@ -245,7 +266,7 @@
        },
        setDay(data) {
            let year = data.year
            this.$HTTP.post('/api/blade-cps/shift-off-day/list', {
            this.$HTTP.post('/api/smis/shift-off-day/list', {
                year: year,
                startOffDay: `${year}-01-01`,
                endOffDay: `${year}-12-31`
@@ -261,6 +282,29 @@
                    })
                    for (let i = 0; i < 12; i++) {
                        let modelIds = [...new Set(data.calendarDayVOList.map(v => v.modelId))]
                        let ext = modelIds.map(v => {
                            let ban = this.shiftListName.find(item => item.id === v)
                            console.log(ban.colour)
                            return {
                                highlight: {
                                    // color: ban.colour || color.stringToColor(v),
                                    // fillMode: 'light',
                                    style: {
                                        'background-color': ban.colour
                                    }
                                },
                                dates: data.calendarDayVOList.filter(item => {
                                    return moment(item.calendarDate).month() === i && item.modelId === v
                                }).map(v => v.calendarDate),
                                popover: {
                                    label: `${ban?.code}-${ban?.name}`
                                },
                            }
                        })
                        console.log('---------youxian')
                        this.months.push({
                            year: year,
                            month: i,
@@ -272,16 +316,22 @@
                                        return moment(item).month() === i
                                    })
                                },
                                ...ext,
                                // 优先
                                {
                                    highlight: true,
                                    dates: data.calendarDayVOList.filter(item => {
                                        console.log(moment(item).month(), '>>>123')
                                        return moment(item.calendarDate).month() === i
                                    }).map(v => v.calendarDate),
                                    }).filter(item => item.isHighPriority).map(item => item.calendarDate),
                                    bar: {
                                        style: {
                                            backgroundColor: 'red',
                                        }
                                    },
                                }
                            ]
                        })
                    }
                }
            })