|
|
<template> <div class="customer-css"> <el-dialog title="批量维护工作日历" v-drag v-bind="$attrs" v-on="$listeners" width="800px" class="customer-dialog" > <el-form :inline="true" label-position="top" label-width="100px" style="margin-top: -5px;"> <el-form-item :label="'日历编码:'"> <el-input v-model="calendarSearchData.calendarId" style="width: 130px"></el-input> </el-form-item> <el-form-item :label="'日历描述:'"> <el-input v-model="calendarSearchData.calendarDesc" style="width: 130px"></el-input> </el-form-item> <el-form-item :label="'起始时间:'"> <el-date-picker style="width: 130px" v-model="calendarSearchData.startDate" value-format="yyyy-MM-dd" placeholder="选择日期"> </el-date-picker> </el-form-item> <el-form-item :label="'工作日类型:'"> <el-select v-model="calendarSearchData.datetype" style="width: 130px" placeholder="请选择"> <el-option v-for="(item, index) in selectList" :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> <el-button @click="refreshModel()" type="primary" style="margin-top: 0px">{{'查询'}}</el-button> <el-button @click="saveList()" type="primary" style="margin-top: 0px">{{'保存日历'}}</el-button> </el-form-item> </el-form> <div class="calendar"> <el-table height="400" :data="dataList3" border :vertical-align="'middle'" @selection-change="selectionChangeHandle" style="width: 100%;" :row-style="{height:'20px'}"> <el-table-column v-for="(item,index) in columnList3" :key="index" :sortable="item.columnSortable" :prop="item.columnProp" :header-align="item.headerAlign" :show-overflow-tooltip="item.showOverflowTooltip" :align="item.align" :fixed="item.fixed" :width="item.columnWidth" :label="item.columnLabel"> <template slot-scope="scope"> <span v-if="!item.columnHidden"> {{scope.row[item.columnProp]}}</span> <span v-if="item.columnImage"><img :src="scope.row[item.columnProp]" style="width: 100px; height: 80px"/></span> </template> </el-table-column> <el-table-column type="selection" align="center" width="30px"> </el-table-column>
<el-table-column prop="val0" header-align="center" align="left" :label="this.timeArray[0]"> <template slot-scope="scope"> <el-select v-model="scope.row.val0" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value">
</el-option> </el-select> </template> </el-table-column> <el-table-column prop="val1" header-align="center" align="left" :label="this.timeArray[1]"> <template slot-scope="scope"> <el-select v-model="scope.row.val1" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val2" header-align="center" align="left" :label="this.timeArray[2]"> <template slot-scope="scope"> <el-select v-model="scope.row.val2" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val3" header-align="center" align="left" :label="this.timeArray[3]"> <template slot-scope="scope"> <el-select v-model="scope.row.val3" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val4" header-align="center" align="left" :label="this.timeArray[4]"> <template slot-scope="scope"> <el-select v-model="scope.row.val4" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val5" header-align="center" align="left" :label="this.timeArray[5]"> <template slot-scope="scope"> <el-select v-model="scope.row.val5" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val6" header-align="center" align="left" :label="this.timeArray[6]"> <template slot-scope="scope"> <el-select v-model="scope.row.val6" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val7" header-align="center" align="left" :label="this.timeArray[7]"> <template slot-scope="scope"> <el-select v-model="scope.row.val7" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> <el-table-column prop="val8" header-align="center" align="left" :label="this.timeArray[8]"> <template slot-scope="scope"> <el-select v-model="scope.row.val8" placeholder="请选择" style="height: 12px;padding: 0px " filterable allow-create> <el-option v-for="item in selectList " :key="index" :label="item.label" :value="item.value"> </el-option> </el-select> </template> </el-table-column> </el-table> </div> <el-footer style="height:40px;margin-top: 20px;text-align:center" > <el-button type="primary" @click="closeDialog">关闭</el-button> </el-footer> </el-dialog> </div></template>
<script>import { getCalendarData, saveCalendar, delCalendar, calendarDatetypeInfo, batchSaveCDData,}from "@/api/base.js"export default { name: "calendar", data () { return { selectList:[], calendarModelFlag:false, calendarModelDisableFlag:false, newCalendarData:{ site:'', calendarId:'', calendarDesc:'', status:'使用中', id:0, }, columnList:[ { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038TableSite', tableId: "6038Table", tableName: "工作日类型表", columnProp: "site", headerAlign: "center", align: "left", columnLabel: "工厂编号", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038TableCalendarId', tableId: "6038Table", tableName: "工作日类型表", columnProp: "calendarId", headerAlign: "center", align: "left", columnLabel: "日历编码", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038TableCalendarDesc', tableId: "6038Table", tableName: "工作日类型表", columnProp: "calendarDesc", headerAlign: "center", align: "left", columnLabel: "日历描述", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 160 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038TableStatus', tableId: "6038Table", tableName: "工作日类型表", columnProp: "status", headerAlign: "center", align: "left", columnLabel: "使用状态", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 },
], columnList2: [ { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Scheduledate', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "scheduledate", headerAlign: "center", align: "left", columnLabel: "日期", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Datetype', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "datetype", headerAlign: "center", align: "left", columnLabel: "工作日类型", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Worktime', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "worktime", headerAlign: "center", align: "right", columnLabel: "累计工作时间", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime1', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime1", headerAlign: "center", align: "left", columnLabel: "休息时间点1", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration1', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration1", headerAlign: "center", align: "right", columnLabel: "休息时长1", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime2', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime2", headerAlign: "center", align: "left", columnLabel: "休息时间点2", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration2', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration2", headerAlign: "center", align: "right", columnLabel: "休息时长2", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime3', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime3", headerAlign: "center", align: "left", columnLabel: "休息时间点3", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration3', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration3", headerAlign: "center", align: "right", columnLabel: "休息时长3", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime4', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime4", headerAlign: "center", align: "left", columnLabel: "休息时间点4", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration4', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration4", headerAlign: "center", align: "right", columnLabel: "休息时长4", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime5', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime5", headerAlign: "center", align: "left", columnLabel: "休息时间点5", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration5', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration5", headerAlign: "center", align: "right", columnLabel: "休息时长5", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptexacttime6', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptexacttime6", headerAlign: "center", align: "left", columnLabel: "休息时间点6", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table2Exceptduration6', tableId: "6038Table2", tableName: "工作日历表2", columnProp: "exceptduration6", headerAlign: "center", align: "right", columnLabel: "休息时长6", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 } ], columnList3:[ { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table3Site', tableId: "6038Table3", tableName: "工作日历表3", columnProp: "site", headerAlign: "center", align: "left", columnLabel: "工厂编码", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 80 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table3CalendarId', tableId: "6038Table3", tableName: "工作日历表3", columnProp: "calendarId", headerAlign: "center", align: "left", columnLabel: "日历编码", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 80 }, { userId: this.$store.state.user.name, functionId: 6038, serialNumber: '6038Table3CalendarDesc', tableId: "6038Table3", tableName: "工作日历表3", columnProp: "calendarDesc", headerAlign: "center", align: "left", columnLabel: "日历描述", columnHidden: false, columnImage: false, columnSortable: false, sortLv: 0, status: true, fixed: false, columnWidth: 100 }, ], maintainColumnList2:[], height:'200', searchData:{ site:'', calendarId:'', status:'使用中', }, calendarSearchData:{ site:this.$store.state.user.site.toString(), calendarId:'', calendarDesc:'', startDate:'', endDate:'', datetype:'', }, dataList:[], dataList2:[], dataList3:[], timeArray:[], valueList:[], valList:[], dataListSelections:[], } }, mounted() { this.$nextTick(()=>{ this.height = window.innerHeight - 150; }) }, watch: { '$route' (to, from) { if(localStorage.getItem('calendar')!=undefined){ this.jump(); } } }, methods: {
//初始化页面的方法
init(searchData){ //设置参数
this.calendarSearchData.startDate = searchData.scheduledDate;
//调用方法
this.maintainCalendar();
},
/*刷新页面的数据*/ maintainCalendar(){ this.getSelectData(); this.calendarSearchData.calendarId = ''; this.calendarSearchData.calendarDesc =''; //this.calendarSearchData.startDate = this.GetDateStr(0);
this.calendarSearchData.endDate = this.GetDateStr(9); this.refreshModel(); },
jump(){ let data=JSON.parse(localStorage.getItem('calendar')); localStorage.removeItem('calendar'); getCalendarData(data).then(({data}) => { this.dataList = data.rows }) }, // 多选数据
selectionChangeHandle (val) { this.dataListSelections = val }, getData(){ if(localStorage.getItem('calendar')!=undefined){ this.jump(); }else { getCalendarData(this.searchData).then(({data}) => { this.dataList = data.rows }) } }, newCalendarModel(){ this.newCalendarData.id=0, this.newCalendarData.site=this.$store.state.user.site, this.newCalendarData.calendarId='', this.newCalendarData.calendarDesc='', this.newCalendarData.status='使用中', this.calendarModelDisableFlag=false; this.calendarModelFlag=true; }, editData(row){ this.newCalendarData.id=1, this.newCalendarData.site=row.site, this.newCalendarData.calendarId=row.calendarId, this.newCalendarData.calendarDesc=row.calendarDesc, this.newCalendarData.status=row.status, this.calendarModelDisableFlag=true; this.calendarModelFlag=true; }, calendarSave(){ saveCalendar(this.newCalendarData).then(({data}) => { if (data.code == 200) { this.getData() this.calendarModelFlag=false; this.$message({ message: '操作成功', type: 'success', duration: 1500, onClose: () => { } }) } else { this.$alert(data.msg, '错误', { confirmButtonText: '确定' }) } }) }, delData(row){ this.$confirm(`是否删除此条工作日历?`, '提示', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
}).then(() => { let inData={ site:row.site.toString(), calendarId:row.calendarId, } delCalendar(inData).then(({data}) => { if (data.code == 200) { this.getData() this.$message({ message: '操作成功', type: 'success', duration: 1500, onClose: () => { } }) } else { this.$alert(data.msg, '错误', { confirmButtonText: '确定' }) } }) }) }, refreshModel(){ this.getAll(); let mainData={ site:this.$store.state.user.site.toString(), calendarId:this.calendarSearchData.calendarId, calendarDesc:this.calendarSearchData.calendarDesc, } getCalendarData(mainData).then(({data}) => { let list=data.rows; if(list.length>0){ for (let i = 0; i <list.length ; i++) { list[i].val0=this.calendarSearchData.datetype; list[i].val1=this.calendarSearchData.datetype; list[i].val2=this.calendarSearchData.datetype; list[i].val3=this.calendarSearchData.datetype; list[i].val4=this.calendarSearchData.datetype; list[i].val5=this.calendarSearchData.datetype; list[i].val6=this.calendarSearchData.datetype; list[i].val7=this.calendarSearchData.datetype; list[i].val8=this.calendarSearchData.datetype; } } this.dataList3 = list; }) }, getSelections(){
}, getSelectData () { this.selectList = []; let newData={ value:'', label:'请选择', } this.selectList.push(newData) let inputData={ site:this.$store.state.user.site.toString() }; calendarDatetypeInfo(inputData).then(({data}) => { let list = data.rows this.calendarSearchData.datetype= list[0].datetype; for (let i = 0; i < list.length; i++) { let resultData = { value: list[i].datetype, label: list[i].datetype } this.selectList.push(resultData) } }) }, //获取日期
GetDateStr(AddDayCount) { var dd = new Date(); dd.setDate(dd.getDate()+AddDayCount);//获取AddDayCount天后的日期
var y = dd.getFullYear(); var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期,不足10补0 var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号,不足10补0 return y+"-"+m+"-"+d; }, //获取区间所有时间并生成动态列
getAll(){ let begin=this.calendarSearchData.startDate; var dd = new Date(begin); dd.setDate(dd.getDate() + 8);//获取AddDayCount天后的日期
var y = dd.getFullYear(); var m = (dd.getMonth()+1)<10?"0"+(dd.getMonth()+1):(dd.getMonth()+1);//获取当前月份的日期,不足10补0 var d = dd.getDate()<10?"0"+dd.getDate():dd.getDate();//获取当前几号,不足10补0 let end=y+"-"+m+"-"+d; var startNum = parseInt(begin.replace(/-/g, ''), 10); var endNum = parseInt(end.replace(/-/g, ''), 10); if (startNum > endNum) { this.$alert('结束时间不能在开始时间之前!', '错误', { confirmButtonText: '确定' }) return false; } if(this.DateDiff(begin, end)>9){ this.$alert('时间不得相差10天!', '错误', { confirmButtonText: '确定' }) return false; } this.timeArray = []; this.maintainColumnList2=[]; let ab = begin.split("-"); let ae = end.split("-"); let db = new Date(); db.setUTCFullYear(ab[0], ab[1]-1, ab[2]); let de = new Date(); de.setUTCFullYear(ae[0], ae[1]-1, ae[2]); let unixDb=db.getTime(); let unixDe=de.getTime(); for(let k=unixDb;k<=unixDe;){ this.timeArray.push(this.dateFormat(new Date(parseInt(k)))); k=k+24*60*60*1000; }
for (let i = 0; i <this.timeArray.length ; i++) { let property = this.timeArray[i]; let val = "val"+i; this.maintainColumnList2.push( { columnProp:val, headerAlign:'center', align:'left', width:'100px', columnLabel:property, value:'', } ); } }, dateFormat(date){ let s=''; s+=date.getFullYear()+'-'; // 获取年份。
s+=(date.getMonth()+1)+"-"; // 获取月份。
s+= date.getDate(); // 获取日。
return(s); // 返回日期。
}, //计算两个日期相差多少天
DateDiff(sDate1, sDate2) { let aDate = sDate1.split("-"); let oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); //转换为yyyy-MM-dd格式
aDate = sDate2.split("-"); let oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]); let iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 / 24); return iDays; }, saveList() { let inData = { timeList: this.timeArray, batchCDVoList: this.dataListSelections } batchSaveCDData(inData).then(({data}) => { if (data && data.code == 200) { this.$message({ message: '操作成功', type: 'success', duration: 1500, onClose: () => { } }) } else { this.$alert(data.msg, '错误', { confirmButtonText: '确定' }) } }) },
/*关闭modal*/ closeDialog(){ this.$emit('update:visible', false); },
}, created() { this.getData() }}</script>
<style >.calendar .el-table .cell { height: 27px;}</style>
|