<template>
    <div class="app-container">
        <div class="title-container">
            <breadcrumb id="breadcrumb-container" class="breadcrumb-container" />
        </div>
        <y-page-list-layout :page-list="pageData" :page-para="listQuery" :get-page-list="selectRepertoryPage">
            <template slot="left">
                <el-input style="margin-left: 20px;width: 300px;float: left;" class="filter-item"
                    v-model="listQuery.keyWord" placeholder="项目编号/报告号/项目名称" clearable>
                </el-input>
                <el-date-picker style="margin-left: 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-select v-model="listQuery.departmentId" filterable placeholder="接单部门"
                    style=" width: 200px;margin-left: 10px;float: left;">
                    <el-option v-for="(d, id) in allotDepartment" :label="d.name" :value="d.id"></el-option>
                </el-select>
                <el-button class="filter-item" style="margin-left: 10px;float: left;" type="primary" @click="searchList"
                    round>搜索
                </el-button>
                <el-button class="filter-item" style="float: left;" round type="success" @click="resetParams()">重置
                </el-button>
            </template>
            <template slot="right">
                <el-button class="filter-item" style="float: right;" round type="primary" :disabled="exportStatus"
                    @click="repertoryExport()">导出
                </el-button>
            </template>

            <parentTable ref="table" v-loading="listLoading" :data="pageData.records" slot="table" style="width: 100%;">
                <el-table-column label="项目编号" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.orderId }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="项目名称" align="center" width="300">
                    <template slot-scope="{row}">
                        <span>{{ row.reportName || row.statementName || row.orderName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="报告号" align="center" width="250">
                    <template slot-scope="{row}">
                        <span>{{ row.reportNo == null ? '-' : row.reportNo }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估目的" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.purposeName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估方法" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.methodName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估作业开始日" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.startTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="估价作业结束日" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.endTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="估价时点" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.valuationBasisDate }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估总值(万元)" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.evaluateAmount }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估单价(元)" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.evaluatePrice }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="委托人" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.bailor }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="委托人电话" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.bailorContactTel }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="第一报告人" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.firstReporter }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="第一报告人注册号" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.firstReporterRegistrationNo }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="参与报告人" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>待开发</span>
                    </template>
                </el-table-column>
                <el-table-column label="参与报告人注册号" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>待开发</span>
                    </template>
                </el-table-column>
                <el-table-column label="客户名称" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.customerName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="业务来源" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.customerSubName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="项目经理" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.managerName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="项目负责人" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.principalName }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="入库时间" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.repertoryInTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="出库时间" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.repertoryOutTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="归档时间" align="center" width="200">
                    <template slot-scope="{row}">
                        <span>{{ row.archivedTime }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="市场部门" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.marketDepartment }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="评估部门" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.evaluateDepartment }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="产品实收金额" align="center" width="150">
                    <template slot-scope="{row}">
                        <span>{{ row.productionRealAmount }}</span>
                    </template>
                </el-table-column>
            </parentTable>
        </y-page-list-layout>
    </div>
</template>

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

export default {
    name: 'AssetsRepertoryList',
    components: {
        Breadcrumb,
        YPageListLayout,
    },
    data() {
        return {
            pageData: { records: [] },
            listLoading: false,
            // 时间
            selectDate: '',
            listQuery: {
                page: 1,
                size: 10,
                current: 1,
                // 关键字
                keyWord: null,
                // 开始时间
                startTime: null,
                // 结束时间
                endTime: null,
                departmentId: null
            },
            // 接单部门
            allotDepartment: [],
            // 用户下拉列表
            allUsers: [],
            // 业务类型下拉列表
            assetsBusinessGeners: [
                {
                    value: '单项资产',
                    label: '单项资产'
                }, {
                    value: '整体资产',
                    label: '整体资产'
                }, {
                    value: '无形资产',
                    label: '无形资产'
                }, {
                    value: '债权',
                    label: '债权'
                }, {
                    value: '其他',
                    label: '其他'
                }
            ],
            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
        }
    },
    created() {
        // 获取分单部门
        this.getAllotDepartment();
        // 获取资产业务订单
        this.selectRepertoryPage();
    },
    methods: {
        // 无条件分页查询
        selectRepertoryPage() {
            if (this.selectDate) {
                this.listQuery.startTime = this.selectDate[0] + ' 00:00:00';
                this.listQuery.endTime = this.selectDate[1] + ' 23:59:59';
            }
            this.$api.assets.selectRepertoryPage(this.listQuery).then(res => {
                if (res.code === 200) {
                    this.pageData = res.data;
                    if (this.listQuery.startTime !== null && this.listQuery.endTime !== null && res.data.records.length > 0) {
                        this.exportStatus = false;
                    }else {
                        this.exportStatus = true;
                    }
                }
            })
        },
        // 条件查询
        searchList() {
            // 重置分页
            this.listQuery.page = 1
            this.listQuery.size = 10
            this.selectRepertoryPage()
        },
        // 重置搜索条件
        resetParams() {
            this.exportStatus = true;
            this.selectDate = '';
            this.$router.push({ query: {} });
            this.listQuery = {
                current: 1,
                size: 10,
            }
            this.selectRepertoryPage();
        },
        // 资产入库数据导出
        repertoryExport() {
            this.$utils.exportUtil(
                "/assets/repertoryExport", this.listQuery,
                "导出"
            );
        },
        // 获取部门下拉列表
        getAllotDepartment() {
            this.$api.department.allot('ASSETS_BUSINESS').then(res => {
                if (res.code === 200) {
                    this.allotDepartment = res.data;
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped></style>