<template>
    <div class="app-container organization-index">
        <div class="title-container">
            <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
        </div>
        <div>
            <div style="width: 100%; height: 50px;">
                <el-date-picker style="margin-right: 20px;float: left;" v-model="selectDate" type="daterange"
                    :picker-options="pickerOptions" format="yyyy 年 MM 月 dd 日" value-format="yyyy-MM-dd" range-separator="至"
                    start-placeholder="开始日期" end-placeholder="结束日期" align="right">
                </el-date-picker>
                <el-input v-model="listQuery.userName" placeholder="姓名" clearable
                    style="margin-left: 20px;width: 200px;float: left;">
                </el-input>
                <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList()"
                    round>搜索
                </el-button>
                <el-button class="filter-item" round type="success" @click="resetParams()">重置
                </el-button>
                <el-button class="filter-item" round type="info" @click="exportMajorPerformanceDeductionVO()"
                    :disabled="exportStatus">导出
                </el-button>
            </div>
            <el-table :data="performanceDeduction" fit stripe highlight-current-row
                :header-row-style="{ color: '#333333', 'font-size': '14px' }" style=" width: 100%; float: right;
                      border-left: 1px solid #ebeced;
                      border-right: 1px solid #ebeced;
                      color: #333333; font-size: 14px;">
                <el-table-column label="评估人员" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.userName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="部门内部错误个数">
                    <el-table-column label="一般错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.checkNormalMistakeScore > 0"
                                @click="setListQueryParms('初审', 'normal', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.checkNormalMistakeScore }}</el-link>
                            <span v-else>{{ row.checkNormalMistakeScore }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="较大错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.checkHardMistakeScore > 0"
                                @click="setListQueryParms('初审', 'hard', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.checkHardMistakeScore }}</el-link>
                            <span v-else>{{ row.checkHardMistakeScore }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="重大错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.checkFatalMistakeScore > 0"
                                @click="setListQueryParms('初审', 'fatal', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.checkFatalMistakeScore }}</el-link>
                            <span v-else>{{ row.checkFatalMistakeScore }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="复审错误个数">
                    <el-table-column label="一般错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.reCheckNormalMistakeScore > 0"
                                @click="setListQueryParms('复审', 'normal', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.reCheckNormalMistakeScore }}</el-link>
                            <span v-else>{{ row.reCheckNormalMistakeScore }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="较大错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.reCheckHardMistakeScore > 0"
                                @click="setListQueryParms('复审', 'hard', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.reCheckHardMistakeScore }}</el-link>
                            <span v-else>{{ row.reCheckHardMistakeScore }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="重大错误">
                        <template slot-scope="{row}">
                            <el-link type="danger" v-if="row.reCheckFatalMistakeScore > 0"
                                @click="setListQueryParms('复审', 'fatal', row.departmentId, listQuery.startTime, listQuery.endTime, row.userId)">{{
                                    row.reCheckFatalMistakeScore }}</el-link>
                            <span v-else>{{ row.reCheckFatalMistakeScore }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="抽检错误个数">
                    <el-table-column label="一般错误">
                    </el-table-column>
                    <el-table-column label="较大错误">
                    </el-table-column>
                    <el-table-column label="重大错误">
                    </el-table-column>
                </el-table-column>
                <el-table-column label="外部投诉">
                    <el-table-column label="一般错误">
                    </el-table-column>
                    <el-table-column label="较大错误">
                    </el-table-column>
                    <el-table-column label="重大错误">
                    </el-table-column>
                    <el-table-column label="服务态度恶劣">
                    </el-table-column>
                </el-table-column>
                <el-table-column label="内部投诉">
                    <el-table-column label="一般错误">
                    </el-table-column>
                    <el-table-column label="较大错误">
                    </el-table-column>
                    <el-table-column label="重大错误">
                    </el-table-column>
                    <el-table-column label="服务态度恶劣">
                    </el-table-column>
                </el-table-column>
                <el-table-column prop="allMistakeScore" label="扣分合计">
                </el-table-column>
            </el-table>
        </div>
        <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="90%"
            @open="getMajorPerformanceDeductionDetailVO()">
            <y-page-list-layout :get-page-list="getMajorPerformanceDeductionDetailVO" :page-list="pageData"
                :page-para="listQueryDetail">
                <template slot="left">
                    <el-button class="filter-item" round type="info" @click="exportPerformanceDeductionDetail()">导出
                    </el-button>
                </template>
                <parentTable ref="table" :data="pageData.records" slot="table" style="width: 100%;" :isBoard=500>
                    <el-table-column label="项目编号" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.orderId }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="是否金融" align="center">
                        <template slot-scope="{row}">
                            <span v-if="row.financial">金融</span>
                            <span v-else>非金融</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="项目名称" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.projectName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="银行/单位" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.customerName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="产品类型" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.productionType }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="产品号" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.productionNo }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="项目负责人" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.principalName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="参与人" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.members }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="评估金额(万元)" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.evaluateAmount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="评估目的" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.evaluateAim }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="扣分人" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.checkerName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="错误个数" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.mistakeCount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="加减分" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.mistakeScore }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="扣分时间" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.checkTime }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="扣分原因" align="center" show-overflow-tooltip>
                        <template slot-scope="{row}">
                            <div>{{ '一般错误：'+JSON.parse(row.reason).normalMistakes }}</div>
                            <div>{{ '较大错误：'+JSON.parse(row.reason).hardMistakes  }}</div>
                            <div>{{ '重大错误：'+JSON.parse(row.reason).fatalMistakes }}</div>
                        </template>
                    </el-table-column>
                </parentTable>
            </y-page-list-layout>
        </el-dialog>
    </div>
</template>

<script>
import Breadcrumb from '@/components/Breadcrumb'
import YPageListLayout from '@/components/YPageListLayout'

export default {
    name: 'majorPerformanceDeductionDepInternal',
    components: {
        Breadcrumb,
        YPageListLayout
    },
    data() {
        return {
            dialogVisible: false,
            dialogTitle: null,
            listLoading: false,
            // 时间
            selectDate: [],
            listQuery: {
                page: 1,
                size: 10,
                current: 1,
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null
            },
            listQueryDetail: {
                page: 1,
                size: 10,
                current: 1,
                // 审核轮次
                checkLoop: null,
                // 错误类型(normal、hard、fatal)
                mistakeType: null,
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null,
                // 部门id
                departmentId: null,
                principalId: null
            },
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            exportStatus: true,
            performanceDeduction: [],
            pageData: { records: [] },
        }
    },
    created() {
        this.selectDate.push(this.getDefaultStartDate());
        this.selectDate.push(this.getDefaultEndDate());
        this.getMajorPerformanceDeductionVOByDepId();
    },
    methods: {
        getDefaultStartDate() {
            let currentDate = new Date();
            let currentYear = currentDate.getFullYear();
            var currentMonth = String(currentDate.getMonth()).padStart(2, "0");
            if (currentMonth=='00'){
                currentYear = currentYear-1;
                currentMonth = 12
            }
            return currentYear + '-' + currentMonth + '-' + '23'
        },
        getDefaultEndDate() {
            const currentDate = new Date();
            const currentYear = currentDate.getFullYear();
            var currentMonth = String(currentDate.getMonth() + 1).padStart(2, "0");
            return currentYear + '-' + currentMonth + '-' + '22'
        },
        // 条件查询
        searchList() {
            this.getMajorPerformanceDeductionVOByDepId()
        },
        // 重置搜索条件
        resetParams() {
            this.exportStatus = true;
            this.listQuery = {
                // 重置分页
                page: 1,
                size: 10,
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null,
                // 部门id
                departmentId: null
            };
            this.selectDate = [];
            this.selectDate.push(this.getDefaultStartDate());
            this.selectDate.push(this.getDefaultEndDate());
            this.getMajorPerformanceDeductionVOByDepId();
        },
        getMajorPerformanceDeductionVOByDepId() {
            if (this.selectDate) {
                this.listQuery.startTime = this.selectDate[0] + ' 00:00:00';
                this.listQuery.endTime = this.selectDate[1] + ' 23:59:59';
            }
            this.$api.statistical.getMajorPerformanceDeductionVOByDepId(this.listQuery).then(res => {
                if (res.code === 200) {
                    this.performanceDeduction = res.data;
                    if (this.listQuery.startTime !== null && this.listQuery.endTime !== null && res.data.length > 0) {
                        this.exportStatus = false;
                    } else {
                        this.exportStatus = true;
                    }
                }
            })
        },
        exportMajorPerformanceDeductionVO() {
            this.$utils.exportUtil(
                "major/statisticalStatement/depId/getMajorPerformanceDeductionVO/export", this.listQuery,
                "导出"
            );
        },
        setListQueryParms(checkLoop, mistakeType, departmentId, startTime, endTime, userId) {
            this.dialogVisible = true;
            this.listQueryDetail.page = 1;
            this.listQueryDetail.size = 10;
            this.listQueryDetail.current = 1;
            this.listQueryDetail.checkLoop = checkLoop;
            this.listQueryDetail.mistakeType = mistakeType;
            this.listQueryDetail.departmentId = departmentId;
            this.listQueryDetail.startTime = startTime;
            this.listQueryDetail.endTime = endTime;
            if (userId) {
                this.listQueryDetail.principalId = userId;
            } else {
                this.listQueryDetail.principalId = null;
            }
            // 设置dialog标题
            if (mistakeType === 'normal') {
                this.dialogTitle = checkLoop + "：一般错误列表";
            } else if (mistakeType === 'hard') {
                this.dialogTitle = checkLoop + "：较大错误列表";
            } else if (mistakeType === 'fatal') {
                this.dialogTitle = checkLoop + "：重大错误列表";
            } else {
                this.dialogTitle = "-";
            }
        },
        // 查询错误详情列表
        getMajorPerformanceDeductionDetailVO() {
            this.$api.statistical.getMajorPerformanceDeductionDetailVO(this.listQueryDetail).then(res => {
                if (res.code === 200) {
                    this.pageData = res.data;
                }
            })
        },
        // 错误详情列表导出
        exportPerformanceDeductionDetail() {
            this.$utils.exportUtil(
                "major/statisticalStatement/getMajorPerformanceDeductionDetailVO/export", this.listQueryDetail,
                "导出"
            );
        }
    }
}
</script>