Преглед изворни кода

编辑行班次锁定,删除行清除锁定

zhonghuizhen пре 1 година
родитељ
комит
f0c3a211f5
1 измењених фајлова са 118 додато и 11 уклоњено
  1. 118 11
      src/views/business/​scheduleManage/components/adjust-edit.vue

+ 118 - 11
src/views/business/​scheduleManage/components/adjust-edit.vue

@@ -367,7 +367,7 @@ export default {
             const scheduleId = self.scheduleInfo.id
             const sql = 'select * from t_adjustment_detail where status_ in ( "待审核", "审核中", "待审批") and parent_id_ in (select id_ from t_adjustment where schedule_id_ = ' + scheduleId + ' )'
             const res = await self.$common.request('sql', sql) // 获取当前审核状态中的申请单数据
-            self.blockList = self.getBlockResult(res.variables.data || [])
+            self.blockList = self.getBlockResult(res.variables.data || [], 'default')
         },
         async handleScheduleChange (val) { // 排班改变刷新数据
             const self = this
@@ -458,10 +458,23 @@ export default {
             filterBList.forEach((el) => {
                 const index = this.getDays(startDate, el.value)
                 if (dateList[index].value === el.value) {
-                    if (dateList[index].banci.includes(el.banci)) {
-                        dateList[index].banci = dateList[index].banci.replace(el.banci, '')
-                        if (dateList[index].banci === '') {
+                    debugger
+                    const arr1 = dateList[index].banci.split(',')
+                    const arr2 = el.banci.split(',')
+                    const result = arr2.some(item => arr1.includes(item))
+                    if (result) { // 包含被锁定班次
+                        // dateList[index].banci = dateList[index].banci.replace(el.banci, '')
+                        arr2.forEach(item => { // 替换班次为空格
+                            const index = arr1.indexOf(item)
+                            if (index !== -1) {
+                                arr1[index] = ''
+                            }
+                        })
+                        // if (dateList[index].banci === '') {
+                        if (arr1.length > 0 && arr1.join('') === '') { // 全被替换为空格说明当天班次已锁定完,该日期不可用
                             dateList[index].disabled = true
+                        } else {
+                            dateList[index].banci = arr1.join(',')
                         }
                     }
                 }
@@ -469,15 +482,21 @@ export default {
             console.log('已过滤日期班次:', dateList)
             return dateList
         },
-        getBlockResult (data) {
+        getBlockResult (data, type) {
             if (data.length < 1) {
                 return {}
             }
             const blockResult = []
             const tempMap = {}
             data.forEach(item => {
-                const { create_by_, before_date_, before_adjust_ } = item
-                const key = `${create_by_}-${before_date_}`
+                let { create_by_, before_date_, before_adjust_ } = item
+                let key = `${create_by_}-${before_date_}`
+                if (type === 'adjustList') { // 如果是给编辑行分组
+                    create_by_ = item.createBy || this.$store.getters.userId
+                    before_date_ = item.beforeDate
+                    before_adjust_ = item.beforeAdjust.join(',')
+                    key = `${create_by_}-${before_date_}`
+                }
                 if (!tempMap[key]) {
                     tempMap[key] = {
                         userid: create_by_,
@@ -490,8 +509,14 @@ export default {
                 }
             })
             data.forEach(item => {
-                const { party_, after_date_, after_adjust_ } = item
-                const key2 = `${party_}-${after_date_}`
+                let { party_, after_date_, after_adjust_ } = item
+                let key2 = `${party_}-${after_date_}`
+                if (type === 'adjustList') { // 如果是给编辑行分组
+                    party_ = item.party
+                    after_date_ = item.afterDate
+                    after_adjust_ = item.afterAdjust.join(',')
+                    key2 = `${party_}-${after_date_}`
+                }
                 if (!tempMap[key2]) {
                     tempMap[key2] = {
                         userid: party_,
@@ -503,6 +528,7 @@ export default {
                     tempMap[key2].banci += `,${after_adjust_}`
                 }
             })
+
             // 按userid分组
             const blockGrouped = {}
             blockResult.forEach((item) => {
@@ -692,6 +718,10 @@ export default {
             })
         },
         handleAddParam () {
+            // 把前面填写的行加入班次日期锁定
+            if (this.formData.adjustList.length > 0) {
+                this.addFilterList(this.formData.adjustList)
+            }
             this.formData.adjustList.push({
                 recordId: '',
                 beforeDate: '',
@@ -704,10 +734,84 @@ export default {
                 party: ''
             })
         },
+        addOrDelBlockItem (blockList, blockGrouped, type) {
+            if (type === 'add') {
+                blockGrouped.forEach((itemB) => {
+                    let found = false
+                    blockList.forEach((itemA, index) => {
+                        if (itemA.value === itemB.value) {
+                            // 合并banci并去重
+                            let mergedBanci = Array.from(new Set([...itemA.banci.split(','), ...itemB.banci.split(',')]))
+                            blockList[index].banci = mergedBanci.join(',')
+                            found = true
+                        }
+                    })
+                    if (!found) {
+                        // 如果没找到相同的value,直接添加新项
+                        blockList.push(itemB)
+                    }
+                })
+            } else if (type === 'del') {
+                blockGrouped.forEach((itemB) => {
+                    let toDeleteIndex = []
+                    blockList.forEach((itemA, index) => {
+                        if (itemA.value === itemB.value) {
+                            // 获取a中子项banci删除掉含有b中子项banci的部分后的新banci
+                            let newBanci = itemA.banci.split(',').filter((banciA) => !itemB.banci.split(',').includes(banciA))
+                            if (newBanci.length === 0) {
+                                // 如果新banci为空,标记该项需要删除
+                                toDeleteIndex.push(index)
+                            } else {
+                                // 更新a中的banci
+                                blockList[index].banci = newBanci.join(',')
+                            }
+                        }
+                    })
+                    // 根据标记删除相应的项
+                    toDeleteIndex.reverse().forEach((index) => {
+                        blockList.splice(index, 1)
+                    })
+                })
+            }
+
+            return blockList
+        },
+        addFilterList (adjustList) { // 把前面填写的行加入班次日期锁定
+            const blockGrouped = this.getBlockResult(adjustList, 'adjustList') // 每次把前面的行数据分组
+            // 加入锁定数据
+            for (const key in blockGrouped) {
+                if (!this.blockList[key]) {
+                    this.blockList[key] = blockGrouped[key] // key不存在直接新增
+                } else { // key存在则合并新旧数据
+                    this.blockList[key] = this.addOrDelBlockItem(this.blockList[key], blockGrouped[key], 'add')
+                }
+            }
+            // 刷新当前用户的过滤数据
+            const filterid = this.$store.getters.userId || ''
+            if (this.beforeDateList.length > 0 && Object.keys(this.blockList).length > 0) {
+                // 过滤当前自己被占用的日期和班次
+                this.beforeDateList = this.filterBlockList(this.blockList, this.beforeDateList, filterid)
+            }
+        },
+        delFilterList (adjustList) { // 把删除的行从班次日期锁定删除
+            debugger
+            const blockGrouped = this.getBlockResult(adjustList, 'adjustList') // 数据分组
+            // 加入锁定数据
+            for (const key in blockGrouped) {
+                this.blockList[key] = this.addOrDelBlockItem(this.blockList[key], blockGrouped[key], 'del')
+            }
+            // 刷新当前用户的过滤数据
+            const filterid = this.$store.getters.userId || ''
+            if (this.beforeDateList.length > 0 && Object.keys(this.blockList).length > 0) {
+                // 过滤当前自己被占用的日期和班次
+                this.beforeDateList = this.filterBlockList(this.blockList, this.beforeDateList, filterid)
+            }
+        },
         handleSelectionChange (v) {
             this.selectionIndex = v.map(item => this.formData.adjustList.indexOf(item))
         },
         handleRemove (removeIndex, type) {
+            const self = this
             let indexList = []
             if (typeof removeIndex === 'number') {
                 indexList = [removeIndex]
@@ -720,9 +824,12 @@ export default {
                 cancelButtonText: '取消',
                 type: 'warning'
             }).then(() => {
-                indexList.forEach(i => {
-                    this.formData.adjustList.splice(i, 1)
+                const delList = []
+                indexList.forEach((i) => {
+                    delList.push(self.formData.adjustList[i])
+                    self.formData.adjustList.splice(i, 1)
                 })
+                this.delFilterList(delList) // 删除的数据解除班次锁定
             }).catch(() => {})
         },
         transformData (dataset, data, from, to) {