<template>
    <div class="app-container">
        <el-form class="lookForm" :model="queryParams" ref="queryForm" size="mini" :inline="true" label-width="140px">
            <el-form-item label="学生姓名" prop="stuName">
                <el-input v-model="queryParams.stuName" placeholder="请输入学生姓名" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="岗位名称" prop="postName">
                <el-input v-model="queryParams.postName" placeholder="请输入岗位名称" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="设岗部门" prop="deptName">
                <el-input v-model="queryParams.deptName" placeholder="请输入设岗部门" clearable
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="审核状态" prop="applyStatus">
                <el-select v-model="queryParams.applyStatus" placeholder="请选择审核状态" clearable>
                    <el-option v-for="dict in dict.type.qgzx_apply_status" :key="dict.value" :label="dict.label"
                        :value="dict.value" />
                </el-select>
            </el-form-item>
            <el-form-item label="结算月份" prop="applyTime">
                <el-date-picker clearable v-model="queryParams.applyTime" type="month" value-format="yyyy-MM-dd"
                    placeholder="请选择结算月份">
                </el-date-picker>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="printVClick">打印</el-button>
                <el-button type="success" plain icon="el-icon-plus" size="mini" @click="addVClick">添加学生薪资</el-button>
                <el-button type="success" plain icon="el-icon-plus" size="mini"
                    @click="addExtraVClick">添加学生薪资(未入岗学生)</el-button>
            </el-form-item>
        </el-form>

        <el-table v-loading="loading" :data="tableData">
            <el-table-column label="#" align="center" prop="id" />
            <el-table-column label="学号" align="center" prop="stuNo" />

            <el-table-column label="姓名" align="center" prop="stuName" />
            <el-table-column label="学院" align="center" prop="stuDept" />

            <el-table-column label="岗位名称" align="center" prop="postName" />
            <el-table-column label="设岗部门" align="center" prop="deptName" />
            <el-table-column label="岗位类型" align="center" prop="postType" />

            <el-table-column label="工作时长" align="center">
                <template v-slot="{ row }">
                    {{ row.postType == "固定岗位A" ? row.totalTime + "天" : row.totalTime + "小时" }}
                </template>
            </el-table-column>
            <el-table-column label="结算月份" align="center">
                <template v-slot="{ row }">
                    {{ formatDate(row.applyTime) }}
                </template>
            </el-table-column>

            <!-- <el-table-column label="薪资" align="center" prop="applyStatus">
                <template slot-scope="scope">
                    {{ scope.row.totalTime * 15 }}
                </template>
            </el-table-column> -->

            <el-table-column label="审核状态" align="center" prop="applyStatus">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.qgzx_apply_status" :value="scope.row.applyStatus" />
                </template>
            </el-table-column>
            <el-table-column label="操作" width="200" align="center">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-view" @click="lookVClick(scope.row)">查看</el-button>

                    <el-button size="mini" type="text" icon="el-icon-delete"
                        v-if="scope.row.auditRemark == '-资助办领导手动添加-'" @click="delExtra(scope.row)">删除</el-button>
                    <el-button v-else size="mini" type="text" icon="el-icon-edit"
                        @click="editVClick(scope.row)">修改工作时长</el-button>

                    <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.auditRemark != '-资助办领导手动添加-'"
                        @click="editPostTypeMoneyVClick(scope.row)">修改岗位类型|工时</el-button>

                    <el-button size="mini" type="text" icon="el-icon-edit" v-if="scope.row.auditRemark != '-资助办领导手动添加-'"
                        @click="editMonthVClick(scope.row)">修改工作月份</el-button>
                </template>
            </el-table-column>
        </el-table>



        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />


        <el-dialog title="查看" :visible.sync="lookV">
            <el-steps :active="getStep(lookForm)">
                <el-step title="指导老师填报薪资" description=""></el-step>

                <el-step title="部门领导审批" :status="isEmpty(lookForm.deptCmt) ? 'wait' : getStepStatus(lookForm.deptCmt)">
                    <template slot="description">
                        <div>
                            {{ isEmpty(lookForm.deptNoName) ? '' : lookForm.deptNoName }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.deptCmt) ? '' : lookForm.deptCmt }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.deptTime) ? '' : lookForm.deptTime }}
                        </div>
                    </template>
                </el-step>
                <el-step title="资助办领导审批" :status="isEmpty(lookForm.highCmt) ? 'wait' : getStepStatus(lookForm.highCmt)">
                    <template slot="description">
                        <div>
                            {{ isEmpty(lookForm.highName) ? '' : lookForm.highName }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.highCmt) ? '' : lookForm.highCmt }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.highTime) ? '' : lookForm.highTime }}
                        </div>
                    </template>
                </el-step>

                <el-step title="学工领导审批"
                    :status="isEmpty(lookForm.finalCmt) ? 'wait' : getStepStatus(lookForm.finalCmt)">
                    <template slot="description">
                        <div>
                            {{ isEmpty(lookForm.finalName) ? '' : lookForm.finalName }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.finalCmt) ? '' : lookForm.finalCmt }}
                        </div>
                        <div>
                            {{ isEmpty(lookForm.finalTime) ? '' : lookForm.finalTime }}
                        </div>
                    </template>
                </el-step>
            </el-steps>
            <hr />
            <el-form class="lookForm" size="mini" label-width="148px">
                <el-form-item label="学生">
                    <el-input v-model="lookForm.stuName" readonly />
                </el-form-item>
                <el-form-item label="岗位">
                    <el-input v-model="lookForm.postName" readonly />
                </el-form-item>
                <el-form-item label="总工作时长">
                    <el-input v-model="lookForm.totalTime" readonly />
                </el-form-item>
                <el-form-item label="个人签章">
                    <img v-if="lookForm.applySign" :src="baseurl + lookForm.applySign" width="200px" height="50px"
                        class="avatar">
                </el-form-item>
                <div v-if="!isEmpty(lookForm.auditRemark)">
                    <hr />
                    <el-form-item label="审核备注">
                        <el-input type="textarea" v-model="lookForm.auditRemark" readonly />
                    </el-form-item>
                </div>

                <hr />
                <el-form-item label="部门意见" v-if="!isEmpty(lookForm.deptCmt)">
                    <el-input v-model="lookForm.deptCmt" readonly />
                </el-form-item>
                <el-form-item label="部门签章" v-if="!isEmpty(lookForm.deptSign)">
                    <img v-if="lookForm.deptSign" :src="baseurl + lookForm.deptSign" width="200px" height="50px"
                        class="avatar">
                </el-form-item>
                <hr />
                <el-form-item label="资助办意见" v-if="!isEmpty(lookForm.highCmt)">
                    <el-input v-model="lookForm.highCmt" readonly />
                </el-form-item>
                <el-form-item label="资助办签章" v-if="!isEmpty(lookForm.highSign)">
                    <img v-if="lookForm.highSign" :src="baseurl + lookForm.highSign" width="200px" height="50px"
                        class="avatar">
                </el-form-item>
                <hr />
                <el-form-item label="学工处意见" v-if="!isEmpty(lookForm.finalCmt)">
                    <el-input v-model="lookForm.finalCmt" readonly />
                </el-form-item>
                <el-form-item label="学工处签章" v-if="!isEmpty(lookForm.finalSign)">
                    <img v-if="lookForm.finalSign" :src="baseurl + lookForm.finalSign" width="200px" height="50px"
                        class="avatar">
                </el-form-item>

            </el-form>
        </el-dialog>

        <el-dialog fullscreen :visible.sync="printV">
            <el-row>
                <el-col :span="4">
                    <el-input placeholder="请输入岗位名称" v-model="printQuery.postName" clearable />
                </el-col>
                <el-col :span="4">
                    <el-date-picker clearable v-model="printQuery.applyTime" type="month" value-format="yyyy-MM-dd"
                        placeholder="请选择需要打印的月份"></el-date-picker>
                </el-col>
                <el-col :span="4">
                    <treeselect style="display: inline-block;width: 300px;" v-model="printQuery.deptId"
                        :options="deptOptions1" :normalizer="normalizer" placeholder="请选择设岗部门" />
                </el-col>
            </el-row>
            <el-button @click="findPrint">查询</el-button>
            <el-button v-print="printContent">打印</el-button>
            <hr />
            <MoneyPrint id="printDiv"
                :month="isEmpty(printQuery.applyTime) ? dayjs().format('YYYY年MM月') : dayjs(printQuery.applyTime).format('YYYY年MM月')"
                :tableData="print_list" :monthDays="printMonthDays" />
        </el-dialog>

        <el-dialog :visible.sync="addV" title="添加学生薪资" :close-on-click-modal="false">
            <el-form size="small" :model="addForm" ref="addForm" label-width="100px">
                <el-form-item label="学生岗位">
                    <AllStuPostSelect v-model="addForm.stuPostId" />
                </el-form-item>
                <el-form-item label="总工作时长">
                    <el-input type="number" v-model="addForm.totalTime" />
                </el-form-item>
                <el-form-item label="月份">
                    <el-date-picker clearable v-model="addForm.applyTime" type="month" value-format="yyyy-MM-dd"
                        placeholder="请选择申请月份">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button size="mini" @click="doAdd">添加</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="editV" title="修改学生工作时长" :close-on-click-modal="false">
            <el-form size="small" :model="addForm" ref="addForm" label-width="100px">
                <el-form-item label="学生岗位">
                    <el-input readonly :value="editForm.stuName + ' - ' + editForm.postName" />
                </el-form-item>
                <el-form-item label="总工作时长">
                    <el-input type="number" v-model="editForm.totalTime" />
                </el-form-item>
                <el-form-item label="月份">
                    <el-date-picker readonly v-model="editForm.applyTime" type="month" value-format="yyyy-MM-dd">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label=" ">
                    <el-button size="mini" @click="doEdit">修改</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="extraV" title="添加学生薪资(未入岗学生)" :close-on-click-modal="false">
            <el-form class="lookForm" size="small" label-width="100px">
                <el-form-item label="学号">
                    <el-row>
                        <el-col :span="8">
                            <el-input v-model="extraForm.stuNo" />
                        </el-col>
                        <el-col :span="4">
                            <el-button type="primary" @click="findStu">查询</el-button>
                        </el-col>
                        <el-col :span="12">
                            学生姓名：{{ searchStuName }}
                        </el-col>
                    </el-row>

                </el-form-item>
                <el-form-item label="家庭经济情况">
                    <el-select v-model="extraForm.familyCondition">
                        <el-option :label="'特别困难'" :value="'特别困难'"></el-option>
                        <el-option :label="'比较困难'" :value="'比较困难'"></el-option>
                        <el-option :label="'一般困难'" :value="'一般困难'"></el-option>
                        <el-option :label="'不困难'" :value="'不困难'"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="岗位名称">
                    <el-input v-model="extraForm.postName" />
                </el-form-item>
                <el-form-item label="设岗部门">
                    <treeselect style="display: inline-block;width: 300px;" v-model="extraForm.deptId"
                        :options="deptOptions1" :normalizer="normalizer" placeholder="请选择设岗部门" />
                </el-form-item>
                <el-form-item label="指导老师">
                    <TeacherSelect :valueProps="{ value: 'employeeId', label: 'name' }" v-model="extraForm.zdlsNo" />
                </el-form-item>
                <el-form-item label="工作内容">
                    <el-input type="textarea" v-model="extraForm.workNeed" />
                </el-form-item>
                <el-form-item label="岗位类型">
                    <el-select clearable v-model="extraForm.postType" placeholder="请选择岗位类型">
                        <el-option label="固定岗位A" value="固定岗位A"></el-option>
                        <el-option label="固定岗位B" value="固定岗位B"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="工作月份">
                    <el-date-picker v-model="extraForm.applyTime" type="month" value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="工作时长">
                    <el-input type="number" v-model="extraForm.totalTime" />
                </el-form-item>
                <el-form-item label="">
                    <el-button @click="doExtraAdd">添加</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="editPostTypeMoneyV" title="修改学生工时(同时需要修改岗位类型)">
            <el-form label-width="100px" class="lookForm" size="mini">
                <el-form-item label="学号">
                    <el-input v-model="editPostTypeMoneyForm.stuNo" readonly></el-input>
                </el-form-item>
                <el-form-item label="学生姓名">
                    <el-input v-model="editPostTypeMoneyForm.stuName" readonly></el-input>
                </el-form-item>
                <el-form-item label="岗位名称">
                    <el-input v-model="editPostTypeMoneyForm.postName" readonly></el-input>
                </el-form-item>
                <el-form-item label="工作月份">
                    <el-date-picker v-model="editPostTypeMoneyForm.applyTime" readonly type="month"
                        value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="岗位类型">
                    <el-select clearable v-model="editPostTypeMoneyForm.postType" placeholder="请选择岗位类型">
                        <el-option label="固定岗位A" value="固定岗位A"></el-option>
                        <el-option label="固定岗位B" value="固定岗位B"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="工作时长">
                    <el-input type="number" v-model="editPostTypeMoneyForm.totalTime" />
                </el-form-item>
                <el-form-item label="">
                    <el-button @click="editPostTypeMoney">修改</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>

        <el-dialog :visible.sync="editMonthV" title="修改学生工作月份">
            <el-form label-width="100px" class="lookForm" size="mini">
                <el-form-item label="学号">
                    <el-input v-model="editMonthForm.stuNo" readonly></el-input>
                </el-form-item>
                <el-form-item label="学生姓名">
                    <el-input v-model="editMonthForm.stuName" readonly></el-input>
                </el-form-item>
                <el-form-item label="岗位名称">
                    <el-input v-model="editMonthForm.postName" readonly></el-input>
                </el-form-item>
                <el-form-item label="工作月份">
                    <el-date-picker v-model="editMonthForm.applyTime" type="month"
                        value-format="yyyy-MM-dd HH:mm:ss">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="岗位类型">
                    <el-input v-model="editMonthForm.postType" readonly></el-input>
                </el-form-item>
                <el-form-item label="工作时长">
                    <el-input type="number" v-model="editMonthForm.totalTime" readonly />
                </el-form-item>
                <el-form-item label="">
                    <el-button @click="editMonth">修改</el-button>
                </el-form-item>
            </el-form>
        </el-dialog>


    </div>
</template>
<script>

import { CheckImgExists, fullLoading, isEmpty, getHoliday, isSameMonth } from "@/api/helpFunc";
import MoneyPrint from "@/views/workstudy/components/MoneyPrint";
import AllStuPostSelect from "@/views/workstudy/components/AllStuPostSelect";

import { getTokenKeySessionStorage as getToken } from "@/utils/auth";


import { noAuthList as listDept } from "@/api/system/dept";
import { editMonth, doAudit, listAll as getList, zzbldAdd, zzbldEdit, addMoneyExtra, delMoneyExtra, editPostTypeMoney, getStuNameByStuNo } from "@/api/workstudy/money";
import TeacherSelect from '@/views/workstudy/components/TeacherSelect';
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import dayjs from "dayjs";


export default {
    name: "Money",
    dicts: ['qgzx_apply_status'],
    components: { AllStuPostSelect, MoneyPrint, Treeselect, TeacherSelect },
    data() {
        return {
            isEmpty,
            dayjs,
            printContent: {
                id: 'printDiv',
                extraCss: "",
                extraHead: '<meta http-equiv="Content-Language"content="zh-cn"/>',
                previewBeforeOpenCallback() {
                    console.log('正在加载预览窗口')
                },
                previewOpenCallback() {
                    console.log('已经加载完预览窗口')
                },
                beforeOpenCallback(vue) {
                    vue.printLoading = true
                    console.log('打开之前')
                },
                openCallback(vue) {
                    vue.printLoading = false
                    console.log('执行了打印')
                },
                closeCallback() {
                    console.log('关闭了打印工具')
                },
                clickMounted(vue) {
                    console.log('点击了打印按钮')
                }
            },

            editV: false,
            applyForm: {
                stuPostId: null
            },
            upload: {
                headers: { Authorization: "Bearer " + getToken() },
                // 上传的地址
                url: process.env.VUE_APP_BASE_API + "/common/upload"
            },
            baseurl: process.env.VUE_APP_BASE_API + "/",
            isEmpty,
            loading: false,

            tableData: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                postName: null
            },
            lookForm: {},

            lookV: false,

            auditForm: {
                id: null,
                deptCmt: null
            },

            printV: false,
            printQuery: {
                applyTime: null,
                deptId: null,
                postName: null,
                pageNum: 1,
                pageSize: 10000,
                applyStatus: "6"
            },
            print_list: [],
            deptOptions1: [],

            addV: false,
            addForm: {},

            editForm: {

            },
            editV: false,

            printMonthDays: 21,


            extraV: false,
            extraForm: {

            },

            editPostTypeMoneyV: false,
            editPostTypeMoneyForm: {

            },

            searchStuName: "",

            editMonthV: false,
            editMonthForm: {},
        }
    },
    created() {
        this.initDept();
        this.getList();
    },
    methods: {
        editMonthVClick(row) {
            this.editMonthForm = {};
            this.editMonthForm = { ...row };
            this.editMonthV = true;
        },
        async editMonth() {
            let sdata = { ...this.editMonthForm };
            if (isEmpty(sdata.applyTime)) {
                this.$message.info("请选择工作月份");
                return;
            }
            let loading = fullLoading(this);
            let res = await editMonth(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.editMonthV = false;
                this.getList();
            }
        },
        async findStu() {
            let loading = fullLoading(this);
            let res = await getStuNameByStuNo(this.extraForm.stuNo);
            loading.close();
            if (res.code == 200) {
                this.searchStuName = res.data.name;
            }
        },
        async editPostTypeMoney() {
            let sdata = { ...this.editPostTypeMoneyForm };

            let loading = fullLoading(this);
            let res = await editPostTypeMoney(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.editPostTypeMoneyV = false;
                this.getList();
            }
        },
        editPostTypeMoneyVClick(row) {
            this.editPostTypeMoneyForm = {};
            this.editPostTypeMoneyForm = { ...row };
            this.editPostTypeMoneyV = true;
        },
        async delExtra(row) {
            let id = row.id;
            this.$confirm('您确定删除手动添加的记录么?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(async () => {
                let loading = fullLoading(this);
                let res = await delMoneyExtra(id);
                loading.close();
                if (res.code == 200) {
                    this.$message.success(res.msg);
                    this.getList();
                }
            });
        },
        async doExtraAdd() {
            let sdata = { ...this.extraForm };
            if (isEmpty(sdata.stuNo)) {
                this.$message.info("请输入学号");
                return;
            }
            if (isEmpty(sdata.postName)) {
                this.$message.info("请输入岗位名称");
                return;
            }
            if (isEmpty(sdata.deptId)) {
                this.$message.info("请选择设岗部门");
                return;
            }
            if (isEmpty(sdata.zdlsNo)) {
                this.$message.info("请选择指导老师");
                return;
            }
            if (isEmpty(sdata.workNeed)) {
                this.$message.info("请输入工作内容");
                return;
            }
            if (isEmpty(sdata.totalTime)) {
                this.$message.info("请输入工作时长");
                return;
            }
            if (isEmpty(sdata.postType)) {
                this.$message.info("请选择岗位类型");
                return;
            }
            if (isEmpty(sdata.familyCondition)) {
                this.$message.info("请选择家庭经济情况");
                return;
            }
            if (isEmpty(sdata.applyTime)) {
                this.$message.info("请选择工作月份");
                return;
            }

            let loading = fullLoading(this);
            let res = await addMoneyExtra(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.extraV = false;
                this.getList();
            }
        },
        addExtraVClick() {
            this.searchStuName = "";
            this.extraForm = {};
            this.extraV = true;
        },
        async doEdit() {
            let sdata = { ...this.editForm };
            if (isEmpty(sdata.totalTime)) {
                this.$message.info("请输入总工作时长");
                return;
            }

            let loading = fullLoading(this);
            let res = await zzbldEdit(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.editV = false;
                this.getList();
            }
        },
        editVClick(row) {
            this.editForm = {};
            this.editForm = { ...row };
            this.editV = true;
        },

        async doAdd() {
            let sdata = { ...this.addForm };
            if (isEmpty(sdata.stuPostId)) {
                this.$message.info("请选择学生岗位");
                return;
            }
            if (isEmpty(sdata.totalTime)) {
                this.$message.info("请输入总工作时长");
                return;
            }
            if (isEmpty(sdata.applyTime)) {
                this.$message.info("请选择月份");
                return;
            }
            let loading = fullLoading(this);
            let res = await zzbldAdd(sdata);
            loading.close();
            if (res.code == 200) {
                this.$message.success(res.msg);
                this.addV = false;
                this.getList();
            }
        },
        addVClick() {
            this.addV = true;
        },
        formatDate(dateStr) {
            const date = new Date(dateStr);
            const year = date.getFullYear();
            const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份是从0开始的，所以需要+1
            return `${year}年${month}月`;
        },
        //此方法用于判断步骤条当前步骤的状态
        getStepStatus(data) {
            if (data == "同意") {
                return 'success';
            } else {
                return 'error';
            }
        },

        //此方法用于判断步骤条到哪个步骤了
        getStep(data) {
            if (!isEmpty(data.deptCmt)) { //判断部门领导有没有审批
                return 2;
            } else if (!isEmpty(data.highCmt)) { //判断资助办有没有审批
                return 3;
            } else if (!isEmpty(data.finalCmt)) { //判断学工处有没有审批
                return 4;
            } else {
                return 1;
            }
        },
        async findPrint() {
            if (isEmpty(this.printQuery.applyTime)) {
                this.$message.info("请先选择月份")
                return;
            }
            if (isEmpty(this.printQuery.deptId)) {
                this.$message.info("请先选择部门")
                return;
            }


            let workdayList = [];
            let a = new Date();
            a.setFullYear(new Date(this.printQuery.applyTime).getFullYear()); // 设置指定年份
            a.setMonth(new Date(this.printQuery.applyTime).getMonth()); // 设置指定月份
            let days = new Date(a.getFullYear(), a.getMonth() + 1, 0).getDate(); // 获取本月一共有多少天  new Date()第3个参数默认为1，就是每个月的1号，把它设置为0时， new Date()会返回上一个月的最后一天，然后通过getDate()方法得到天数
            for (let i = 1; i <= days; i++) {
                a.setDate(i) // 设置月份的日期
                let d = a.getDay(); // 获取星期几。 返回0 到 6星期日为 0、星期六为 6。
                if (d > 0 && d < 6) {
                    workdayList.push(a.toLocaleDateString());
                }
            }

            let holidayList = [];

            let year = new Date(this.printQuery.applyTime).getFullYear();

            let loading1 = fullLoading(this);
            let res1 = await getHoliday(year);
            loading1.close();
            if (res1.code == 0) {
                let data = { ...res1.holiday };
                for (let key in data) {
                    let dateStr = new Date(this.printQuery.applyTime).getFullYear() + '-' + key;
                    if (isSameMonth(new Date(dateStr), this.printQuery.applyTime)) {
                        if (data[key].holiday == true) {
                            holidayList.push(new Date(data[key].date).toLocaleDateString());
                        } else {
                            workdayList.push(new Date(data[key].date).toLocaleDateString());
                        }
                    }
                }
            }

            let tempDayList = [];
            workdayList.map(x => {

                holidayList.map(y => {
                    if (x == y) {
                        tempDayList.push(x);
                    }
                });
            });

            workdayList = workdayList.filter(x => !tempDayList.includes(x));

            let workdayCount = workdayList.length;

            this.$prompt(dayjs(this.printQuery.applyTime).format('YYYY年MM月') + "的工作日为" + workdayCount + "天,如果有误请填写并点击确定，如果正确就不填直接点击确定", '导出确认', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^(|null|-?\d+)$/,
                inputErrorMessage: ''
            }).then(async ({ value }) => {
                if (!isEmpty(value)) {
                    this.printMonthDays = value;
                } else {
                    this.printMonthDays = workdayCount;
                }

                let loading = fullLoading(this);
                let res = await getList(this.printQuery);
                loading.close();
                if (res.code == 200) {
                    this.print_list = [...res.rows];
                }

            });


        },
        normalizer(node) {
            if (node.children && !node.children.length) {
                delete node.children;
            }
            return {
                id: node.deptId,
                label: node.deptName,
                children: node.children,
            };
        },
        async initDept() {
            let res = await listDept();
            if (res.code == 200) {
                this.deptOptions1 = this.handleTree(res.data, "deptId");
            }
        },
        printVClick() {
            this.printV = true;
        },
        async handleExport() {
            if (isEmpty(this.queryParams.applyTime)) {
                this.$message.info("请选择月份");
                return;
            }

            let workdayList = [];
            let a = new Date();
            a.setFullYear(new Date(this.queryParams.applyTime).getFullYear()); // 设置指定年份
            a.setMonth(new Date(this.queryParams.applyTime).getMonth()); // 设置指定月份
            let days = new Date(a.getFullYear(), a.getMonth() + 1, 0).getDate(); // 获取本月一共有多少天  new Date()第3个参数默认为1，就是每个月的1号，把它设置为0时， new Date()会返回上一个月的最后一天，然后通过getDate()方法得到天数
            for (let i = 1; i <= days; i++) {
                a.setDate(i) // 设置月份的日期
                let d = a.getDay(); // 获取星期几。 返回0 到 6星期日为 0、星期六为 6。
                if (d > 0 && d < 6) {
                    workdayList.push(a.toLocaleDateString());
                }
            }

            let holidayList = [];

            let year = new Date(this.queryParams.applyTime).getFullYear();

            let loading = fullLoading(this);
            let res = await getHoliday(year);
            loading.close();
            if (res.code == 0) {
                let data = { ...res.holiday };
                for (let key in data) {
                    let dateStr = new Date(this.queryParams.applyTime).getFullYear() + '-' + key;

                    if (isSameMonth(new Date(dateStr), this.queryParams.applyTime)) {

                        if (data[key].holiday == true) {
                            holidayList.push(new Date(data[key].date).toLocaleDateString());
                        } else {
                            workdayList.push(new Date(data[key].date).toLocaleDateString());
                        }
                    }
                }
            }

            let tempDayList = [];
            workdayList.map(x => {

                holidayList.map(y => {
                    if (x == y) {
                        tempDayList.push(x);
                    }
                });
            });

            workdayList = workdayList.filter(x => !tempDayList.includes(x));

            console.log(2, workdayList);

            let workdayCount = workdayList.length;
            console.log(3, workdayCount);

            this.$prompt(dayjs(this.queryParams.applyTime).format('YYYY年MM月') + "的工作日为" + workdayCount + "天,如果有误请填写并点击确定，如果正确就不填直接点击确定", '导出确认', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /^(|null|-?\d+)$/,
                inputErrorMessage: ''
            }).then(({ value }) => {
                if (!isEmpty(value)) {
                    workdayCount = value;
                }

                this.queryParams.workdayCount = workdayCount;

                this.download('workstudy/money/doExport', {
                    ...this.queryParams
                }, dayjs(this.queryParams.applyTime).format('YYYY年MM月') + `勤工助学薪资_${new Date().getTime()}.xlsx`);

            });
        },
        async lookVClick(row) {
            this.lookForm = {};
            this.lookForm = { ...row };
            this.lookV = true;
        },

        async getList() {
            this.loading = true;
            let res = await getList(this.queryParams);
            this.loading = false;
            if (res.code == 200) {
                this.tableData = [...res.rows];
                this.total = res.total;
            }
        },
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },

        handleAvatarSuccess(response, file, fileList) {
            this.auditForm.highSign = response.fileName;
            this.$forceUpdate();
        },
        async doAudit() {
            let sdata = { ...this.auditForm };
            if (isEmpty(sdata.deptCmt)) {
                this.$message.info("请选择部门意见");
                return;
            }
            if (isEmpty(sdata.deptSign)) {
                this.$message.info("请上传部门签章");
                return;
            }

            if (!CheckImgExists(this.baseurl + sdata.deptSign)) {
                this.$message.info("签名失效，请重新上传");
                return;
            }

            if (sdata.deptCmt == '同意') {
                sdata.applyStatus = '2';
            } else {
                sdata.applyStatus = "10";
            }

            let loading = fullLoading(this);
            let res = await doAudit(sdata);
            loading.close();
            if (res.code == 200) {
                this.getList();
                this.$message.success(res.msg);
                this.lookV = false;
            }
        }
    }
}


</script>

<style scoped lang="scss">
.lookForm {
    .el-form-item {
        margin-bottom: 5px;
    }
}

@media print {
    html {
        background-color: #ffffff;
        height: auto;
        margin: 0px;
    }

    body {
        border: solid 1px #ffffff;
        margin: 10mm 15mm 10mm 15mm;
    }

    @page {
        size: landscape;
        /* 设置横向打印 */
        margin: 3mm;
    }
}
</style>
