<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-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList1()"
                    round>搜索
                </el-button>
                <el-button class="filter-item" round type="success" @click="resetParams1()">重置
                </el-button>
                <el-button class="filter-item" round type="info" @click="exportPersonalDepEfficiencyVO()"
                    :disabled="exportStatus">导出
                </el-button>
            </div>
            <el-table :data="depEfficiency" fit stripe highlight-current-row
                :header-row-style="{ color: '#333333', 'font-size': '14px' }" :header-cell-style="{ 'text-align': 'center' }"
                        :cell-style="{ 'text-align': 'center' }" 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.evaluateAim }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="接单数">
                    <el-table-column label="当期">
                        <template slot-scope="{row}">
                            <el-link v-if="row.currentPeriodOrderVolume > 0"
                                @click="setListQueryParms(row.evaluateAim, 'order', listQueryByDepartment.startTime, listQueryByDepartment.endTime)">
                                {{ row.currentPeriodOrderVolume }}
                            </el-link>
                            <span v-else>{{ row.currentPeriodOrderVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYOrderVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQOrderVolume }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="预评">
                    <el-table-column label="当期">
                        <template slot-scope="{row}">
                            <el-link v-if="row.currentPeriodStatementVolume > 0"
                                @click="setListQueryParms(row.evaluateAim, 'statement', listQueryByDepartment.startTime, listQueryByDepartment.endTime)">
                                {{ row.currentPeriodStatementVolume }}
                            </el-link>
                            <span v-else>{{ row.currentPeriodStatementVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYStatementVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQStatementVolume }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="报告">
                    <el-table-column label="当期">
                        <template slot-scope="{row}">
                            <!-- 报告包含了意见函复评函,所以是reportAndLetter -->
                            <el-link v-if="row.currentPeriodReportVolume > 0"
                                @click="setListQueryParms(row.evaluateAim, 'reportAndLetter', listQueryByDepartment.startTime, listQueryByDepartment.endTime)">
                                {{ row.currentPeriodReportVolume }}
                            </el-link>
                            <span v-else>{{ row.currentPeriodReportVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYReportVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQReportVolume }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="应收款">
                    <el-table-column label="当期">
                        <template slot-scope="{row}">
                            <el-link v-if="row.currentPeriodShouldAmountSum > 0"
                                @click="setListQueryParms(row.evaluateAim, 'should', listQueryByDepartment.startTime, listQueryByDepartment.endTime)">
                                {{ row.currentPeriodShouldAmountSum }}
                            </el-link>
                            <span v-else>{{ row.currentPeriodShouldAmountSum }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYShouldAmountSum }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQShouldAmountSum }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="实收款">
                    <el-table-column label="当期">
                        <template slot-scope="{row}">
                            <el-link v-if="row.currentPeriodRealAmountSum > 0"
                                @click="setListQueryParms(row.evaluateAim, 'real', listQueryByDepartment.startTime, listQueryByDepartment.endTime)">
                                {{ row.currentPeriodRealAmountSum }}
                            </el-link>
                            <span v-else>{{ row.currentPeriodRealAmountSum }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYRealAmountSum }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQRealAmountSum }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="实收款总计">
                    <template slot-scope="{row}">
                        <span>{{ row.totalRealAmountSum }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="出单率">
                    <el-table-column label="当期(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.currentPeriodOrderHasReportVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYOrderHasReportVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQOrderHasReportVolume }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
                <el-table-column label="死单率">
                    <el-table-column label="当期(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.currentPeriodDeadOrderVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="同比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.YoYDeadOrderVolume }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="环比(%)">
                        <template slot-scope="{row}">
                            <span>{{ row.QoQDeadOrderVolume }}</span>
                        </template>
                    </el-table-column>
                </el-table-column>
            </el-table>
        </div>
        <el-dialog title="个贷订单列表" :visible.sync="dialogVisible" width="70%" @open="getPersonalEfficiencyDetailVO()">
            <y-page-list-layout :get-page-list="getPersonalEfficiencyDetailVO" :page-list="pageData" :page-para="listQueryDetail">
                <template slot="left">
                    <el-button class="filter-item" round type="info" @click="exportPersonalEfficiencyDetailVO()">导出
                    </el-button>
                </template>
                <parentTable ref="table" :data="pageData.records" slot="table" style="width: 100%;" :isBoard=800
                    class="tableFull">
                    <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>{{ row.location }}</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.customerSubName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="中介" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.agent }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="委托人" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.bailor }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="面积" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.acreage }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="单价" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.price }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="总价" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.amount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="出意见书时间" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.writeStatementDate }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="出报告时间" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.writeReportDate }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="价值时点" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.valuationDate }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="用途" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.purpose }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="订单应收款(元)" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.shouldAmount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="订单实收款(元)" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.realAmount }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="客户经理" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.clientManagerName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="当前实例节点名称" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.currentNodeName }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="当前节点处理人" align="center">
                        <template slot-scope="{row}">
                            <span>{{ row.handlerName }}</span>
                        </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: 'assetsEvaluateEfficiency',
    components: {
        Breadcrumb,
        YPageListLayout
    },
    data() {
        return {
            dialogVisible: false,
            listLoading: false,
            // 时间
            selectDate: [],
            listQueryByDepartment: {
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null,
                // 部门id
                departmentId: null
            },
            listQueryDetail: {
                page: 1,
                size: 10,
                current: 1,
                // 评估目的(咨询、抵押、按揭、合计)
                evaluateAim: null,
                // 效率类型(订单:order、预评:statement、报告:report、应收款:should、实收款:real)
                efficiencyType: null,
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null
            },
            // 下单部门
            marketDepartment: [],
            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,
            depEfficiency: [],
            pageData: { records: [] },
        }
    },
    created() {
        this.selectDate.push(this.getDefaultStartDate());
        this.selectDate.push(this.getDefaultEndDate());
        this.getPersonalDepEfficiencyVO();
    },
    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'
        },
        // 条件查询
        searchList1() {
            this.getPersonalDepEfficiencyVO()
        },
        // 重置搜索条件
        resetParams1() {
            this.exportStatus = true;
            this.listQueryByDepartment = {
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null,
                // 部门id
                departmentId: null
            };
            this.selectDate = [];
            this.selectDate.push(this.getDefaultStartDate());
            this.selectDate.push(this.getDefaultEndDate());
            this.getPersonalDepEfficiencyVO();
        },
        getPersonalDepEfficiencyVO() {
            if (this.selectDate) {
                this.listQueryByDepartment.startTime = this.selectDate[0] + ' 00:00:00';
                this.listQueryByDepartment.endTime = this.selectDate[1] + ' 23:59:59';
            }
            this.$api.statistical.getPersonalDepEfficiencyVO(this.listQueryByDepartment).then(res => {
                if (res.code === 200) {
                    this.depEfficiency = res.data;
                    if (this.listQueryByDepartment.startTime !== null && this.listQueryByDepartment.endTime !== null && res.data.length > 0) {
                        this.exportStatus = false;
                    } else {
                        this.exportStatus = true;
                    }
                }
            })
        },
        exportPersonalDepEfficiencyVO() {
            this.$utils.exportUtil(
                "personal/statisticalStatement/department/getPersonalDepEfficiencyVO/export", this.listQueryByDepartment,
                "导出"
            );
        },
        setListQueryParms(evaluateAim, efficiencyType, startTime, endTime) {
            this.dialogVisible = true;
            this.listQueryDetail.page = 1;
            this.listQueryDetail.size = 10;
            this.listQueryDetail.current = 1;
            this.listQueryDetail.evaluateAim = evaluateAim;
            this.listQueryDetail.efficiencyType = efficiencyType;
            this.listQueryDetail.startTime = startTime;
            this.listQueryDetail.endTime = endTime;
        },
        // 效率详情列表查询
        getPersonalEfficiencyDetailVO() {
            this.$api.statistical.getPersonalEfficiencyDetailVO(this.listQueryDetail).then(res => {
                if (res.code === 200) {
                    this.pageData = res.data;
                }
            })
        },
        // 效率详情列表查询导出
        exportPersonalEfficiencyDetailVO() {
            this.$utils.exportUtil(
                "personal/statisticalStatement/getPersonalEfficiencyDetailVO/export", this.listQueryDetail,
                "导出"
            );
        }
    }
}
</script>

<style scoped lang="scss">
/* el-table 列数据为空自动显示 - */
.tableFull :empty::before {
    content: '-';
    color: gray;
}
</style>