0109出勤导出

This commit is contained in:
shijing 2023-01-09 11:06:05 +08:00
parent 9c3ceb1ca9
commit fbfc4e7522
3 changed files with 141 additions and 11 deletions

View File

@ -7,9 +7,9 @@ VUE_APP_TITLE = '曲阳金隅安全智能管控平台'
# 接口地址 # 接口地址
#VUE_APP_API_BASEURL = http://1.203.161.103:2800/api #VUE_APP_API_BASEURL = http://1.203.161.103:2800/api
#VUE_APP_WS_API = 'ws://localhost:8000' #VUE_APP_WS_API = 'ws://localhost:8000'
#VUE_APP_API_BASEURL = http://222.222.144.147:6013/api VUE_APP_API_BASEURL = http://222.222.144.147:6013/api
#VUE_APP_API_BASEURL = http://10.99.5.79:20309/api #VUE_APP_API_BASEURL = http://10.99.5.79:20309/api
VUE_APP_API_BASEURL = http://127.0.0.1:8001/api #VUE_APP_API_BASEURL = http://127.0.0.1:8001/api
#VUE_APP_BASEURL = http://127.0.0.1:8000 #VUE_APP_BASEURL = http://127.0.0.1:8000

View File

@ -16,21 +16,22 @@
"cropperjs": "1.5.12", "cropperjs": "1.5.12",
"crypto-js": "4.1.1", "crypto-js": "4.1.1",
"d3": "^7.6.1", "d3": "^7.6.1",
"dagre-d3": "^0.6.4", "dagre-d3": "^0.4.18",
"echarts": "5.3.2", "echarts": "5.3.2",
"element-plus": "2.2.3", "element-plus": "2.2.3",
"json-editor-vue3": "^1.0.6", "json-editor-vue3": "^1.0.6",
"nprogress": "0.2.0", "nprogress": "0.2.0",
"qrcodejs2": "0.0.2", "qrcodejs2": "0.0.2",
"sortablejs": "1.15.0", "sortablejs": "1.15.0",
"tinymce": "6.0.3", "tinymce": "^6.3.1",
"vue": "3.2.36", "vue": "3.2.36",
"vue-i18n": "9.1.10", "vue-i18n": "9.1.10",
"vue-router": "4.0.15", "vue-router": "4.0.15",
"vuedraggable": "4.0.3", "vuedraggable": "4.0.3",
"vuex": "4.0.2", "vuex": "4.0.2",
"xgplayer": "2.31.6", "xgplayer": "2.31.6",
"xgplayer-hls": "2.5.2" "xgplayer-hls": "2.5.2",
"xlsx": "^0.18.5"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "7.18.2", "@babel/core": "7.18.2",

View File

@ -2,8 +2,16 @@
<el-container> <el-container>
<el-header> <el-header>
<div class="left-panel"> <div class="left-panel">
<el-cascader v-model="query.employee__belong_dept" :options="deptData" clearable placeholder="部门/单位" @change="handleQuery" :show-all-levels="false" :props="{emitPath:false,checkStrictly: true}"/> <el-cascader
<el-date-picker v-model="query.employee__belong_dept"
ref="belongDept"
:options="deptData" clearable
placeholder="部门/单位"
@change="handleQuery"
:show-all-levels="false"
:props="{emitPath:false,checkStrictly: true}"
/>
<el-date-picker
v-model="monthV" v-model="monthV"
type="month" type="month"
style="margin-left:4px" style="margin-left:4px"
@ -28,7 +36,7 @@
type="primary" type="primary"
:loading = 'dLoading' :loading = 'dLoading'
icon="el-icon-download" icon="el-icon-download"
@click="exportExcel" @click="exportList"
></el-button> ></el-button>
</div> </div>
</div> </div>
@ -38,9 +46,7 @@
ref="table" ref="table"
:apiObj="apiObj" :apiObj="apiObj"
row-key="id" row-key="id"
stripe stripe
> >
<el-table-column label="人员类型" prop="employee"> <el-table-column label="人员类型" prop="employee">
<template #default="scope"> <template #default="scope">
@ -82,7 +88,9 @@
</el-container> </el-container>
</template> </template>
<script> <script>
import * as XLSX2 from "xlsx";
import { genTree } from "@/utils/verificate"; import { genTree } from "@/utils/verificate";
import { fill } from "lodash";
export default { export default {
name: "clock_record", name: "clock_record",
components: {}, components: {},
@ -90,8 +98,10 @@ export default {
return { return {
apiObj: this.$API.hrm.clock_record.list, apiObj: this.$API.hrm.clock_record.list,
deptData: [], deptData: [],
tableData:[],
monthV: null, monthV: null,
query: {}, query: {},
userList:[],
selection: [], selection: [],
type_:{ type_:{
10: {"label": "上班打卡", "color": ""}, 10: {"label": "上班打卡", "color": ""},
@ -105,6 +115,9 @@ export default {
"door": "门禁", "door": "门禁",
"location": "定位" "location": "定位"
}, },
excelName:'',
weekList : ['姓名','星期'],
daysList:['姓名','日期'],
dLoading: false, dLoading: false,
}; };
}, },
@ -124,6 +137,10 @@ export default {
this.query.year = null; this.query.year = null;
this.query.month = null; this.query.month = null;
} }
if(this.query.employee__belong_dept){
let getCheckedNodes = this.$refs['belongDept'].getCheckedNodes()[0].data;
this.excelName = getCheckedNodes.name;
}
this.$refs.table.queryData(this.query) this.$refs.table.queryData(this.query)
}, },
exportExcel(){ exportExcel(){
@ -141,7 +158,119 @@ export default {
window.open(res.path, "_blank"); window.open(res.path, "_blank");
this.dLoading = false; this.dLoading = false;
}).catch(e=>{this.dLoading = false;}) }).catch(e=>{this.dLoading = false;})
} },
//
getOneData(id){
let that = this;
return new Promise((resolve,reject)=>{
that.$API.hrm.clock_record.list.req({page:1,page_size:400,year:that.query.year,month:that.query.month,employee:id})
.then(res=>{
resolve(res.results)
})
})
},
exportList(){
let that = this;
let days = new Date(this.query.year, this.query.month , 0).getDate();
let weekList = ['姓名','星期'],daysList=['姓名','日期'],titleData = [];
for(var i = 1;i<= days;i++){
let weekNum = new Date(this.query.year,this.query.month,i).getDay();
let week=that.getDayWeek(weekNum)
daysList.push(i);
weekList.push(week);
}
let chartName = this.excelName+that.query.year+'年'+that.query.month+'月考勤统计表';
titleData.push(chartName)
let tableData = [];
tableData.push(titleData)
tableData.push(weekList)
tableData.push(daysList)
that.$API.hrm.employee.list.req({page:1,page_size:999,belong_dept:that.query.employee__belong_dept})
.then(res=>{
let promiseList = [];
let rowData1 = [],rowData2=[];
that.userList=res.results;
that.userList.forEach ((item)=> {
promiseList.push(that.getOneData(item.id))
})
Promise.all(promiseList).then(res=> {
debugger;
console.log(res)
that.userList.forEach ((item,index)=> {
let recordList = res[index];
rowData1 = [
item.name,
'上班打卡',
]
rowData2 = [
item.name,
'下班打卡',
]
recordList.forEach(recordItem=>{
let dateInd = new Date(recordItem.update_time).getDate();
let dateIndex = parseInt(dateInd);
if(recordItem.type==10){
rowData1[dateIndex+1] = '√';
}else{
rowData2[dateIndex+1] = '√';
}
})
tableData.push(rowData1);
tableData.push(rowData2);
})
let ws = XLSX2.utils.aoa_to_sheet(tableData);
let wb = XLSX2.utils.book_new();
//
const font = {
name: '宋体',
sz: 12,
bold: true,
color: { rgb: '00000000' },
}
//
const alignment = {
horizontal: 'center',
vertical: 'center',
}
// ws['A0'].s = {
// font,
// alignment,
// }
// s start //r row 0 //c col 0
let cNumber = daysList.length-1;
let merge = [{ s: { r: 0, c: 0 }, e: { r: 0, c:cNumber } }];//{ s: { r: 0, c: 0 }, e: { r: 1, c: 0 } },
for(let i = 1;i<tableData.length;i++){
merge.push({ s: { r: i, c: 0 }, e: { r: i+1, c: 0 } })
i++
}
ws['!merges'] = merge;
let closList = new Array(31).fill({wch: 2 });
closList.unshift({wch:8})
closList.unshift({wch:15})
ws['!cols'] = closList;
XLSX2.utils.book_append_sheet(wb, ws, chartName); // 簿
XLSX2.writeFile(wb, chartName+'.xlsx'); //
});
})
},
getDayWeek(day){
switch(day){
case 0:
return '日';
case 1:
return '一';
case 2:
return '二';
case 3:
return '三';
case 4:
return '四';
case 5:
return '五';
case 6:
return '六';
}
},
}, },
}; };
</script> </script>