From 3e091224ab26252d8624b42b461ba773ee8bee0f Mon Sep 17 00:00:00 2001 From: gaoshp <291585735@qq.com> Date: 星期日, 03 十一月 2024 19:16:31 +0800 Subject: [PATCH] update --- src/views/console/base/Add.vue | 560 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 457 insertions(+), 103 deletions(-) diff --git a/src/views/console/base/Add.vue b/src/views/console/base/Add.vue index a0c6a31..8d02c26 100644 --- a/src/views/console/base/Add.vue +++ b/src/views/console/base/Add.vue @@ -1,81 +1,117 @@ <!-- * @Date: 2024-05-04 16:37:48 - * @LastEditors: Sneed - * @LastEditTime: 2024-05-05 00:16:31 - * @FilePath: /belleson-frontend/Users/mache/Documents/demo/cps-web/src/views/console/base/Add.vue + * @LastEditors: gaoshp + * @LastEditTime: 2024-10-09 23:30:14 + * @FilePath: /cps-web/src/views/console/base/Add.vue --> <template> <el-container> - <el-row> - <el-form style="width: 100%;" :model="form" :rules="rules" ref="dialogForm" label-width="120px" - label-position="center"> - <el-row> - <el-col :span="8"> - <el-form-item label="鐢熶骇鏃ュ巻缂栧彿" prop="code"> - <el-input v-model="form.code" placeholder="璇疯緭鍏ョ敓浜ф棩鍘嗙紪鍙�" clearable></el-input> - </el-form-item> - </el-col> - <el-col :span="8"> - <el-form-item label="鐢熶骇鏃ュ巻鍚嶇О" prop="name"> - <el-input v-model="form.name" placeholder="璇疯緭鍏ョ敓浜ф棩鍘嗗悕绉�" clearable></el-input> - </el-form-item> - </el-col> - <el-col :span="8"> - <el-form-item label="搴旂敤骞翠唤" prop="year"> - <el-select v-model="form.year" placeholder="" size="" @change="change"> - <el-option v-for="item in options" :key="item.value" :label="item.label" - :value="item.value" /> - </el-select> - </el-form-item> - </el-col> - <el-col :span="8"> - <el-form-item label="搴旂敤鏃ユ湡" prop="date"> - <el-date-picker v-model="form.date" type="daterange" value-format="YYYY-MM-DD" - start-placeholder="寮�濮嬫棩鏈�" end-placeholder="缁撴潫鏃ユ湡" /> - </el-form-item> - </el-col> - <el-col :span="8" :offset="1"> - <el-button-group> - <el-button :type="activeBtn == 0 ? 'primary' : ''" - @click="activeBtn = 0">鎸夎寰嬮�変腑鏃ユ湡</el-button> - <el-button :type="activeBtn == 1 ? 'primary' : ''" @click="activeBtn = 1"> - 鎸夐棿闅旈�変腑鏃ユ湡 - </el-button> - </el-button-group> - </el-col> - <el-col :offset="1"> - <el-radio-group v-model="radio"> - <el-radio :value="0">鍖呭惈鍋囨湡</el-radio> - <el-radio :value="1">涓嶅惈鍋囨湡</el-radio> - <el-radio :value="2">浠呭惈鍋囨湡</el-radio> - </el-radio-group> - </el-col> - <el-col :span="4" :offset="1"> - <el-checkbox-group v-model="checkboxGroup" size="small" style="width: 200px" @change="change"> - <el-checkbox-button v-for="item in quicks" :key="item.value" :label="item.value"> - {{ item.label }} - </el-checkbox-button> - </el-checkbox-group> + <el-main> + <el-row> + <el-form style="width: 100%;" :model="form" :rules="rules" ref="dialogForm" label-width="120px" + label-position="center"> + <el-row> + <el-col :span="8"> + <el-form-item label="鐢熶骇鏃ュ巻缂栧彿" prop="code"> + <el-input :disabled="disabled" v-model="form.code" placeholder="璇疯緭鍏ョ敓浜ф棩鍘嗙紪鍙�" + clearable></el-input> + </el-form-item> + </el-col> + <el-col :span="8"> + <el-form-item label="鐢熶骇鏃ュ巻鍚嶇О" prop="name"> + <el-input :disabled="disabled" v-model="form.name" placeholder="璇疯緭鍏ョ敓浜ф棩鍘嗗悕绉�" + clearable></el-input> + </el-form-item> + </el-col> + <el-col :span="8"> + <el-form-item label="搴旂敤骞翠唤" prop="year"> + <el-select :disabled="disabled" v-model="form.year" placeholder="" size="" + @change="changeYear"> + <el-option v-for="item in options" :key="item.value" :label="item.label" + :value="item.value" /> + </el-select> + </el-form-item> + </el-col> + <el-col :span="8"> + <el-form-item label="搴旂敤鏃ユ湡" prop="date"> + <el-date-picker v-model="form.date" type="daterange" value-format="YYYY-MM-DD" + start-placeholder="寮�濮嬫棩鏈�" end-placeholder="缁撴潫鏃ユ湡" @change="changeDate" /> + </el-form-item> + </el-col> + <el-col :span="8" :offset="1"> + <!-- <el-button-group> + <el-button :type="activeBtn == 0 ? 'primary' : ''" + @click="activeBtn = 0">鎸夎寰嬮�変腑鏃ユ湡</el-button> + <el-button :type="activeBtn == 1 ? 'primary' : ''" @click="activeBtn = 1"> + 鎸夐棿闅旈�変腑鏃ユ湡 + </el-button> + </el-button-group> --> + </el-col> + <el-col :offset="1"> + <el-radio-group v-model="holiday"> + <el-radio :label="0">鍖呭惈鍋囨湡</el-radio> + <el-radio :label="1">涓嶅惈鍋囨湡</el-radio> + <el-radio :label="2">浠呭惈鍋囨湡</el-radio> + </el-radio-group> + </el-col> + <el-col :span="4" :offset="1"> + <el-checkbox-group v-model="checkboxGroup" size="small" style="width: 200px" + @change="change"> + <el-checkbox-button v-for="item in quicks" :key="item.value" :label="item.value"> + {{ item.label }} + </el-checkbox-button> + </el-checkbox-group> - </el-col> - <el-col :span="8"> - <el-checkbox-group v-model="checkboxGroup1" size="small" style="width: 400px"> - <el-checkbox-button v-for="item in weeks" :key="item.value" :label="item.value"> - {{ item.label }} - </el-checkbox-button> - </el-checkbox-group> - </el-col> - </el-row> - <el-row v-if="months.length > 0"> - <el-col :span="6" v-for="(item, i) in months" :key="i" style="padding: 10px;"> - <!-- <Calendar :min-date="item.start" :rows="1" :attributes="item.attributes" + </el-col> + <el-col :span="8"> + <el-checkbox-group v-model="checkboxGroup1" size="small" style="width: 400px"> + <el-checkbox-button v-for="item in weeks" :key="item.value" :label="item.value"> + {{ item.label }} + </el-checkbox-button> + </el-checkbox-group> + </el-col> + </el-row> + <el-row v-if="months.length > 0"> + <el-col :span="6" v-for="(item, i) in months" :key="i" style="padding: 10px;"> + <!-- <Calendar :min-date="item.start" :rows="1" :attributes="item.attributes" @dayclick="dayclick($event, item)" /> --> - <Calendar :min-date="item.min" :rows="1" disable-page-swipe :nav-visibility="''" - :attributes='item.attributes' @dayclick="dayclick($event, item)" /> - </el-col> - </el-row> - </el-form> - </el-row> + <Calendar :initial-page="{ month: item.month + 1, year: item.year }" :rows="1" + disable-page-swipe :nav-visibility="''" :attributes='item.attributes' + @dayclick="dayclick($event, item)" /> + </el-col> + </el-row> + </el-form> + </el-row> + </el-main> + <el-footer> + <el-row style="align-items: center;"> + <el-col :span="2"> + 鐝埗鏂规 + </el-col> + <el-col :span="4"> + <el-select v-model="modelId" placeholder="" size=""> + <el-option v-for="item in shiftList" :key="item.id" :label="item.name" :value="item.id">{{ + item.name }}</el-option> + </el-select> + </el-col> + <el-col :span="2"> + 褰撳墠鎺掔彮浼樺厛 + </el-col> + <el-col :span="4"> + <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> + </el-col> + <el-col :span="2"> + <el-button type="" @click="planCancel">鍙栨秷鎺掔彮</el-button> + </el-col> + <el-col :span="2"> + <el-button type="primary" @click="save">淇濆瓨</el-button> + </el-col> + </el-row> + + </el-footer> </el-container> </template> @@ -83,19 +119,40 @@ <script> import moment from 'moment' import { Calendar, DatePicker } from 'v-calendar'; +import color from '@/utils/color' export default { components: { Calendar, DatePicker }, + props: { + shiftList: { + type: Array, + default: () => { + return [] + } + }, + drawerInfo: { + type: Object, + default: () => { + return {} + } + }, + }, data() { return { + currentDate: '', + currentDateItem: null, + disabled: false, + modelId: '', + isHighPriority: false, + dateDTOList: [], selectAttribute: [{ dot: true }], activeBtn: 0, checkboxGroup: [], checkboxGroup1: [], + holiday: 0, months: [ - ], quicks: [{ label: '宸ヤ綔鏃�', @@ -107,31 +164,31 @@ weeks: [ { label: '涓�', - value: 0 - }, - { - label: '浜�', value: 1 }, { - label: '涓�', + label: '浜�', value: 2 }, { - label: '鍥�', + label: '涓�', value: 3 }, { - label: '浜�', + label: '鍥�', value: 4 }, { - label: '鍏�', + label: '浜�', value: 5 }, { - label: '鏃�', + label: '鍏�', value: 6 + }, + { + label: '鏃�', + value: 0 }, ], options: [], @@ -152,15 +209,23 @@ } }, watch: { - checkboxGroup1() { + holiday() { + this.setDay() + }, + checkboxGroup1() { + this.setDay() }, 'form.year'(val) { this.months = [] let currentYear = moment(val, 'YYYY').format('YYYY') - 0 + this.form.date = [`${currentYear}-01-01`, `${currentYear}-12-31`] + if (currentYear == moment().format('YYYY')) { + this.form.date[0] = moment().format('YYYY-MM-DD') + } // console.log(this.months) - this.$HTTP.post('/api/blade-cps/shift-off-day/list', { + this.$HTTP.post('/api/smis/shift-off-day/list', { year: currentYear, startOffDay: `${currentYear}-01-01`, endOffDay: `${currentYear}-12-31` @@ -169,17 +234,19 @@ this.offDays = res.data } let arr = [] - res.data.forEach(v => { + this.offDays.forEach(v => { arr.push(v.startOffDay) let day = moment(v.startOffDay) while (day.add(1, 'd').unix() <= moment(v.endOffDay).unix()) { arr.push(day.format('YYYY-MM-DD')) } }) - for (let i = 0; i < 1; i++) { - console.log('>>>>', moment().year(currentYear).month(i).date(1).toDate()) + for (let i = 0; i < 12; i++) { this.months.push({ - min: new Date('2024-01-01'), + year: currentYear, + month: i, + id: `${currentYear}${i}`, + min: new Date(`${currentYear}-01-01`), attributes: [ { dot: 'yellow', @@ -196,8 +263,10 @@ }) } - console.log(this.months, '?/') }) + }, + shiftList() { + this.modelId = this.shiftList[0].id } }, created() { @@ -205,38 +274,323 @@ }, methods: { init() { - let len = 15 - let currentYear = moment().format('YYYY') - 0 - this.form.year = currentYear + if (!this.drawerInfo.id) { + let len = 15 + let currentYear = moment().format('YYYY') - 0 + this.form.year = currentYear + for (let i = 0; i < len; i++) { + this.options.push({ + label: currentYear + i, + value: currentYear + i + }) + } + this.form.date = [moment().format('YYYY-MM-DD'), moment(`${currentYear}-12-31`).format('YYYY-MM-DD')] + } else { + this.disabled = true + this.form.code = this.drawerInfo.code + this.form.name = this.drawerInfo.name + this.form.year = moment(this.drawerInfo.calendarDayVOList[0].calendarDate, 'YYYY-MM-DD').format('YYYY') - 0 + setTimeout(() => { + let currentYear = moment().format('YYYY') - 0 + this.form.date = [`${currentYear}-01-01`, `${currentYear}-12-31`] + if (currentYear == this.form.year) { + this.form.date[0] = moment().format('YYYY-MM-DD') + } + [...new Set(this.drawerInfo.calendarDayVOList.map(v => v.modelId))].forEach(item => { + let list = this.drawerInfo.calendarDayVOList.filter(v => v.modelId === item) + let ext = { + modelId: item, + // isHighPriority: list[0].isHighPriority, + } + this.setDayRange(list, ext) + }) + }, 1000) - for (let i = 0; i < len; i++) { - this.options.push({ - label: currentYear + i, - value: currentYear + i - }) } - this.form.date = [moment().format('YYYY-MM-DD'), moment(`${currentYear}-12-31`).format('YYYY-MM-DD')] - // console.log(this.form) + }, + changeDate() { + if (this.checkboxGroup1.length > 0) { + this.setDay() + } else { + + } }, change(val) { this.checkboxGroup1 = [] if (val?.some(v => v === 0)) { - this.checkboxGroup1.push(...[0, 1, 2, 3, 4]) + this.checkboxGroup1.push(...[1, 2, 3, 4, 5]) } if (val?.some(v => v === 1)) { - this.checkboxGroup1.push(...[5, 6]) + this.checkboxGroup1.push(...[0, 6]) } }, - dayclick(day, item) { + setDay() { + let currentYear = moment(this.form.year, 'YYYY').format('YYYY') - 0 + this.months.forEach((item, i) => { + let start = moment(`${currentYear}-${i + 1}-01`) + let end = i == 11 ? moment(`${currentYear + 1}-${i + 1}-01`) : moment(`${currentYear}-${i + 2}-01`) + let dates = [] + while (start.unix() < end.unix()) { + if (this.checkboxGroup1.includes(start.day()) && this.holiday === 0) { + this.pushDate(start) && dates.push(start.format('YYYY-MM-DD')) + } else if (this.checkboxGroup1.includes(start.day()) && this.holiday === 1) { + if (!this.months[i].attributes[0].dates.includes(start.format('YYYY-MM-DD'))) { + this.pushDate(start) && dates.push(start.format('YYYY-MM-DD')) + } + } else if (this.checkboxGroup1.includes(start.day()) && this.holiday === 2) { + if (this.months[i].attributes[0].dates.includes(start.format('YYYY-MM-DD'))) { + this.pushDate(start) && dates.push(start.format('YYYY-MM-DD')) + } + } + start.add(1, 'd') + } + this.months[i].attributes[1].dates = dates + }) + console.log(this.months, 'rll') + }, + setDayRange(list, ext) { + let currentYear = moment(this.form.year, 'YYYY').format('YYYY') - 0 + this.months.forEach((item, i) => { + let start = moment(`${currentYear}-${i + 1}-01`) + let end = i == 11 ? moment(`${currentYear + 1}-${i + 1}-01`) : moment(`${currentYear}-${i + 2}-01`) + let dates = [] + list.forEach(v => { + if (moment(v.calendarDate).unix() >= start.unix() && moment(v.calendarDate).unix() < end.unix()) { + dates.push(v) + } + }) + if (dates.length > 0) { + let ban = this.shiftList.find(v => v.id === ext.modelId) + this.months[i].attributes.push({ + dates: dates.map(v => v.calendarDate), + ...ext, + // highlight: color.stringToColor(ext.modelId), + highlight: { + style: { + 'background-color': ban.colour + } + }, + popover: { + label: `${ban?.code}-${ban?.name}` + }, + }) + // 浼樺厛 + console.log('------------->>>>', dates) + let hiIndex = this.months[i].attributes.findIndex(v => v.bar) + if (hiIndex > -1) { + this.months[i].attributes[hiIndex].dates.push(...dates.filter(v => v.isHighPriority === 1).map(v => v.calendarDate)) + } else { + 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, 'rllllllll') + }, + pushDate(start) { + if (start.unix() >= moment(this.form.date[0]).unix() && start.unix() <= moment(this.form.date[1]).unix()) { + return true + } + return false + }, + changeHigh(val) { + console.log('------------changeHigh') + 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) - console.log(index) if (index >= 0) { item.attributes[1].dates.splice(index, 1) } else { item.attributes[1].dates.push(day.id) } - console.log(index, item.attributes[1].dates) + 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, + calendarDate: v, + ...this.setOffDay(v) + } + }) + let ext = { + modelId: this.modelId, + // isHighPriority: this.isHighPriority ? 1 : 0, + } + + this.setDayRange(list, ext) + }, + setOffDay(time) { + let { id: offDayId } = this.offDays.find(v => moment(time).unix() >= moment(v.startOffDay).unix() && moment(time).unix() <= moment(v.endOffDay).unix()) || {} + let idOffDay = offDayId ? 1 : 0 + return { + idOffDay, + offDayId + } + }, + planCancel() { + this.months.forEach((item, i) => { + item.attributes = item.attributes.slice(0, 2) + }) + }, + save() { + 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) { + if (list.length == 0) { + return this.$message.warning('鏈帓鐝�'); + } + if (!this.drawerInfo.id) { + let data = { + codeRuleId: '', + code: this.form.code, + name: this.form.name, + year: this.form.year, + status: 1, + dateDTOList: list + } + this.$HTTP.post('/api/smis/calendar', data).then(res => { + if (res.code === 200) { + this.$emit('success') + } else { + this.$message.warning(res.msg); + } + }) + } else { + let data = { + id: this.drawerInfo.id, + dateDTOList: list + } + this.$HTTP.put('/api/smis/calendar', data).then(res => { + if (res.code === 200) { + this.$emit('success') + } else { + this.$message.warning(res.msg); + } + }) + } + + } else { + this.$message.warning('璇锋鏌ュ繀濉」'); + } + }) } } } -- Gitblit v1.9.3