From 9ccaa7a607481405ee22519aa49c786a46b95e22 Mon Sep 17 00:00:00 2001
From: gaoshp <291585735@qq.com>
Date: 星期三, 09 十月 2024 23:01:52 +0800
Subject: [PATCH] 优先

---
 src/views/console/base/Add.vue         |  147 ++++++++++++++++++++++++++++++++++++++++--------
 src/views/console/base/CalenderTab.vue |   19 +++++-
 2 files changed, 137 insertions(+), 29 deletions(-)

diff --git a/src/views/console/base/Add.vue b/src/views/console/base/Add.vue
index eb1458e..5a4e836 100644
--- a/src/views/console/base/Add.vue
+++ b/src/views/console/base/Add.vue
@@ -1,7 +1,7 @@
 <!--
  * @Date: 2024-05-04 16:37:48
  * @LastEditors: gaoshp
- * @LastEditTime: 2024-10-08 22:02:06
+ * @LastEditTime: 2024-10-09 22:50:13
  * @FilePath: /cps-web/src/views/console/base/Add.vue
 -->
 <template>
@@ -98,7 +98,7 @@
                     褰撳墠鎺掔彮浼樺厛
                 </el-col>
                 <el-col :span="4">
-                    <el-switch v-model="isHighPriority" active-text="浼樺厛" inactive-text="涓嶄紭鍏�" />
+                    <el-switch v-model="isHighPriority" @change="changeHigh" active-text="浼樺厛" inactive-text="涓嶄紭鍏�" />
                 </el-col>
                 <el-col :span="2">
                     <el-button type="primary" @click="plan">鎺掔彮</el-button>
@@ -141,6 +141,8 @@
     },
     data() {
         return {
+            currentDate: '',
+            currentDateItem: null,
             disabled: false,
             modelId: '',
             isHighPriority: false,
@@ -284,7 +286,6 @@
                 }
                 this.form.date = [moment().format('YYYY-MM-DD'), moment(`${currentYear}-12-31`).format('YYYY-MM-DD')]
             } else {
-                console.log('>>>>>>>>>>', this.drawerInfo)
                 this.disabled = true
                 this.form.code = this.drawerInfo.code
                 this.form.name = this.drawerInfo.name
@@ -299,9 +300,8 @@
                         let list = this.drawerInfo.calendarDayVOList.filter(v => v.modelId === item)
                         let ext = {
                             modelId: item,
-                            isHighPriority: list[0].isHighPriority,
+                            // isHighPriority: list[0].isHighPriority,
                         }
-                        console.log(list)
                         this.setDayRange(list, ext)
                     })
                 }, 1000)
@@ -325,7 +325,6 @@
             }
         },
         setDay() {
-            console.log('setDay1')
             let currentYear = moment(this.form.year, 'YYYY').format('YYYY') - 0
             this.months.forEach((item, i) => {
                 let start = moment(`${currentYear}-${i + 1}-01`)
@@ -375,15 +374,22 @@
                             label: `${ban?.code}-${ban?.name}`
                         },
                     })
+                    // 浼樺厛
+                    this.months[i].attributes.push({
+                        dates: dates.filter(v => v.isHighPriority === 1).map(v => v.calendarDate),
+                        bar: {
+                            style: {
+                                backgroundColor: 'red',
+                            }
+                        },
+                    })
                     this.months[i].attributes[1] = {
                         highlight: true,
                         dates: []
                     }
                 }
-
-
             })
-            console.log(this.months, 'rll')
+            console.log(this.months, 'rllllllll')
         },
         pushDate(start) {
             if (start.unix() >= moment(this.form.date[0]).unix() && start.unix() <= moment(this.form.date[1]).unix()) {
@@ -391,32 +397,123 @@
             }
             return false
         },
-        dayclick(day, item) {
+        changeHigh(val) {
+            if (this.currentDateItem) {
+                // 璁剧疆浼樺厛
+                let index = this.currentDateItem.attributes.findIndex(item => !!item.bar)
+                if (val) {
+                    if (index === -1) {
+                        this.currentDateItem.attributes.push({
+                            bar: {
+                                style: {
+                                    backgroundColor: 'red',
+                                }
+                            },
+                            dates: [this.currentDate]
+                        })
+                    } else {
+                        this.currentDateItem.attributes[index].dates.push(this.currentDate)
+                    }
+                } else {
+                    let i = this.currentDateItem.attributes[index].dates.findIndex(v => v === this.currentDate)
+                    this.currentDateItem.attributes[index].dates.splice(i, 1)
+                }
 
+            } else {
+                this.isHighPriority = false
+            }
+            console.log(this.months)
+        },
+        dayclick(day, item) {
             let index = item.attributes[1].dates.findIndex(v => v === day.id)
             if (index >= 0) {
                 item.attributes[1].dates.splice(index, 1)
             } else {
                 item.attributes[1].dates.push(day.id)
             }
+            let list = this.getPlanDate()
+            let highDates = this.getHighDate()
+            this.currentDate = day.id
+            if (list.find(v => v.calendarDate === day.id)) {
+                this.currentDateItem = item
+                if (highDates.indexOf(this.currentDate) > -1) {
+                    this.isHighPriority = true
+                } else {
+                    this.isHighPriority = false
+                }
+            } else {
+                this.currentDateItem = null
+                this.isHighPriority = false
+            }
+
+            console.log('------currentDate', this.currentDate, item, highDates)
+        },
+        getHighDate() {
+            let list = []
+            this.months.forEach(item => {
+                item.attributes.forEach((v, i) => {
+                    if (i > 1 && v.bar) {
+                        v.dates.forEach(child => {
+                            list.push(child)
+                        })
+
+                    }
+                })
+            })
+            return list
+        },
+        getPlanDate() {
+            // 浼樺厛绾�
+            let list = []
+            this.months.forEach(item => {
+                item.attributes.forEach((v, i) => {
+                    if (i > 1 && v.modelId) {
+
+                        v.dates.forEach(child => {
+                            // 閲嶅鎺掔彮鍘婚噸
+                            let repeatIndex = list.findIndex(v => v.calendarDate === child)
+                            if (repeatIndex > -1) {
+                                list.splice(repeatIndex, 1, {
+                                    modelId: v.modelId,
+                                    // isHighPriority: v.isHighPriority,
+                                    calendarDate: child,
+                                    ...this.setOffDay(child)
+                                })
+                            } else {
+                                list.push({
+                                    modelId: v.modelId,
+                                    // isHighPriority: v.isHighPriority,
+                                    calendarDate: child,
+                                    ...this.setOffDay(child)
+                                })
+                            }
+
+                        })
+
+                    }
+                })
+            })
+            return list
         },
         plan() {
             if (!this.modelId) {
                 return this.$message.warning('璇烽�夋嫨鐝鏂规');
             }
             let dateDTOList = this.months.map(item => item.attributes[1].dates)
+            console.log('------plan', dateDTOList)
             let list = dateDTOList.flat(2).map(v => {
                 return {
                     modelId: this.modelId,
-                    isHighPriority: this.isHighPriority ? 1 : 0,
+                    // isHighPriority: this.isHighPriority ? 1 : 0,
                     calendarDate: v,
                     ...this.setOffDay(v)
                 }
             })
             let ext = {
                 modelId: this.modelId,
-                isHighPriority: this.isHighPriority ? 1 : 0,
+                // isHighPriority: this.isHighPriority ? 1 : 0,
             }
+
             this.setDayRange(list, ext)
         },
         setOffDay(time) {
@@ -433,21 +530,19 @@
             })
         },
         save() {
-            let list = []
-            this.months.forEach(item => {
-                item.attributes.forEach((v, i) => {
-                    if (i > 1) {
-                        v.dates.forEach(child => {
-                            list.push({
-                                modelId: v.modelId,
-                                isHighPriority: v.isHighPriority,
-                                calendarDate: child,
-                                ...this.setOffDay(child)
-                            })
-                        })
-
+            let highDates = this.getHighDate()
+            let list = this.getPlanDate().map(v => {
+                if (highDates.indexOf(v.calendarDate) > -1) {
+                    return {
+                        ...v,
+                        isHighPriority: 1
                     }
-                })
+                } else {
+                    return {
+                        ...v,
+                        isHighPriority: 0
+                    }
+                }
             })
             this.$refs.dialogForm.validate(async (valid) => {
                 if (valid) {
diff --git a/src/views/console/base/CalenderTab.vue b/src/views/console/base/CalenderTab.vue
index 422f0ca..95fc076 100644
--- a/src/views/console/base/CalenderTab.vue
+++ b/src/views/console/base/CalenderTab.vue
@@ -1,7 +1,7 @@
 <!--
  * @Date: 2024-04-04 22:45:43
  * @LastEditors: gaoshp
- * @LastEditTime: 2024-10-08 22:01:18
+ * @LastEditTime: 2024-10-09 22:59:25
  * @FilePath: /cps-web/src/views/console/base/CalenderTab.vue
 -->
 <template>
@@ -282,7 +282,7 @@
                     })
 
                     for (let i = 0; i < 12; i++) {
-                        data.calendarDayVOList.map(v => v.modelId)
+
                         let modelIds = [...new Set(data.calendarDayVOList.map(v => v.modelId))]
                         let ext = modelIds.map(v => {
                             let ban = this.shiftListName.find(item => item.id === v)
@@ -303,6 +303,8 @@
                                 },
                             }
                         })
+                        console.log('---------youxian')
+
                         this.months.push({
                             year: year,
                             month: i,
@@ -314,7 +316,18 @@
                                         return moment(item).month() === i
                                     })
                                 },
-                                ...ext
+                                ...ext,
+                                // 浼樺厛
+                                {
+                                    dates: data.calendarDayVOList.filter(item => {
+                                        return moment(item.calendarDate).month() === i
+                                    }).filter(item => item.isHighPriority).map(item => item.calendarDate),
+                                    bar: {
+                                        style: {
+                                            backgroundColor: 'red',
+                                        }
+                                    },
+                                }
                             ]
                         })
                     }

--
Gitblit v1.9.3