| | |
| | | <!-- |
| | | * @Date: 2024-05-04 16:37:48 |
| | | * @LastEditors: Sneed |
| | | * @LastEditTime: 2024-05-05 21:02:54 |
| | | * @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-col :span="8"> |
| | | <el-form-item label="生产日历编号" prop="code"> |
| | | <el-input v-model="form.code" placeholder="请输入生产日历编号" clearable></el-input> |
| | | <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 v-model="form.name" placeholder="请输入生产日历名称" clearable></el-input> |
| | | <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 v-model="form.year" placeholder="" size="" @change="change"> |
| | | <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-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="结束日期" /> |
| | | start-placeholder="开始日期" end-placeholder="结束日期" @change="changeDate" /> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="8" :offset="1"> |
| | | <el-button-group> |
| | | <!-- <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-button-group> --> |
| | | </el-col> |
| | | <el-col :offset="1"> |
| | | <el-radio-group v-model="holiday"> |
| | |
| | | 当前排班优先 |
| | | </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> |
| | |
| | | <script> |
| | | import moment from 'moment' |
| | | import { Calendar, DatePicker } from 'v-calendar'; |
| | | import color from '@/utils/color' |
| | | export default { |
| | | components: { |
| | | Calendar, |
| | |
| | | default: () => { |
| | | return [] |
| | | } |
| | | } |
| | | }, |
| | | drawerInfo: { |
| | | type: Object, |
| | | default: () => { |
| | | return {} |
| | | } |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | | currentDate: '', |
| | | currentDateItem: null, |
| | | disabled: false, |
| | | modelId: '', |
| | | isHighPriority: false, |
| | | dateDTOList: [], |
| | |
| | | } |
| | | }, |
| | | watch: { |
| | | |
| | | holiday() { |
| | | this.setDay() |
| | | }, |
| | |
| | | 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` |
| | |
| | | year: currentYear, |
| | | month: i, |
| | | id: `${currentYear}${i}`, |
| | | min: new Date('2024-01-01'), |
| | | min: new Date(`${currentYear}-01-01`), |
| | | attributes: [ |
| | | { |
| | | dot: 'yellow', |
| | |
| | | }) |
| | | |
| | | } |
| | | console.log(this.months, '?/') |
| | | }) |
| | | }, |
| | | shiftList() { |
| | |
| | | } |
| | | }, |
| | | created() { |
| | | |
| | | this.init() |
| | | }, |
| | | 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 = [] |
| | |
| | | let currentYear = moment(this.form.year, 'YYYY').format('YYYY') - 0 |
| | | this.months.forEach((item, i) => { |
| | | let start = moment(`${currentYear}-${i + 1}-01`) |
| | | let end = moment(`${currentYear}-${i + 2}-01`) |
| | | let end = i == 11 ? moment(`${currentYear + 1}-${i + 1}-01`) : moment(`${currentYear}-${i + 2}-01`) |
| | | let dates = [] |
| | | console.log(start.format('YYYY-MM-DD'), start.unix() >= moment(this.form.date[0]).unix() && start.unix() <= moment(this.form.date[1]).unix()) |
| | | while (start.unix() < end.unix()) { |
| | | if (this.checkboxGroup1.includes(start.day()) && this.holiday === 0) { |
| | | this.pushDate(start) && dates.push(start.format('YYYY-MM-DD')) |
| | |
| | | } |
| | | 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 false |
| | | }, |
| | | dayclick(day, item) { |
| | | 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, |
| | | // isHighPriority: this.isHighPriority ? 1 : 0, |
| | | calendarDate: v, |
| | | ...this.setOffDay(v) |
| | | } |
| | | }) |
| | | console.log(list) |
| | | this.dateDTOList = list |
| | | 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()) || {} |
| | |
| | | } |
| | | }, |
| | | 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 (this.dateDTOList.length == 0) { |
| | | if (list.length == 0) { |
| | | return this.$message.warning('未排班'); |
| | | } |
| | | let data = { |
| | | codeRuleId: '', |
| | | code: this.form.code, |
| | | name: this.form.name, |
| | | year: this.form.year, |
| | | status: 1, |
| | | dateDTOList: this.dateDTOList |
| | | } |
| | | this.$HTTP.post('/api/blade-cps/calendar', data).then(res => { |
| | | if (res.code === 200) { |
| | | this.$emit('success') |
| | | } else { |
| | | this.$message.warning(res.msg); |
| | | if (!this.drawerInfo.id) { |
| | | let data = { |
| | | codeRuleId: '', |
| | | code: this.form.code, |
| | | name: this.form.name, |
| | | year: this.form.year, |
| | | status: 1, |
| | | dateDTOList: list |
| | | } |
| | | }) |
| | | console.log(this.form, this.dateDTOList) |
| | | 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('请检查必填项'); |
| | | } |
| | | }) |
| | | } |