<template>
  <div class="app-container organization-index">
    <div class="title-container">
      <breadcrumb id="breadcrumb-container" class="breadcrumb-container"/>
    </div>
      <y-page-list-layout :get-page-list="getMajorStat" :page-list="majorStat" :page-para="listQuery1" :pageSizes="[10, 20, 30, 50, 100, 200, 500, 1000]">
        <template slot="left">
          <el-input v-model="listQuery1.keyword" placeholder="项目编号、产品号、人员、金额" clearable
          style="width: 300px;float: left;">
        </el-input>
        <el-select  clearable  v-model="listQuery1.ifSaveFile" placeholder="归档状态" style="margin-left: 20px;width: 150px;float: left;">
                  <el-option :value="false" label="未归档">未归档</el-option>
                  <el-option :value="true" label="已归档">已归档</el-option>
              </el-select>
              <el-select  clearable  v-model="listQuery1.financial" placeholder="分类" style="width: 150px;float: left;margin-left:20px;">
                  <el-option :value="true" label="金融">金融</el-option>
                  <el-option :value="false" label="非金融">非金融</el-option>
              </el-select>
          <el-date-picker  clearable v-model="claimDate" type="daterange" align="center" unlink-panels
                        range-separator="至" start-placeholder="认领日期（开始）" end-placeholder="认领日期（结束）" :picker-options="pickerOptions"
                        value-format="yyyy-MM-dd" style="margin-left: 20px;float: left;">
          </el-date-picker>
          <el-date-picker  clearable v-model="paymentDate" type="daterange" align="center" unlink-panels
                        range-separator="至" start-placeholder="到账日期（开始）" end-placeholder="到账日期（结束）" :picker-options="pickerOptions"
                        value-format="yyyy-MM-dd" style="margin-left: 20px;float: left;">
          </el-date-picker>
          <el-button class="filter-item" style="margin-left:20px;float: left;" type="primary" @click="searchList1" round>搜索
          </el-button>
          <el-button class="filter-item" style="float: left;" round type="success" @click="resetSearch1()">重置
          </el-button>
          <el-button class="filter-item" style="float: left;" round type="info" @click="exportMajorStat()">导出
          </el-button>
        </template>
        <el-table
          size="medium"
          slot="table"
          row-key="id"
          :data="majorStat.records"
          fit border
          highlight-current-row
          :header-row-style="{color: '#333333'}"
          style="border-left: 1px solid #EBECED;border-right: 1px solid #EBECED;color: #333333;">
          <el-table-column label="序号" align="center" type="index">
          </el-table-column>
          <el-table-column label="分类" align="center">
            <template slot-scope="{row}">
              <span>{{ row.financial?'金融':'非金融' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="是否归档" align="center">
            <template slot-scope="{row}">
              <span>{{ row.ifSaveFile?'已归档':'未归档' }}</span>
            </template>
          </el-table-column>
          <el-table-column label="项目编号" width="150"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.orderId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品号" width="200"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.reportNo }}</span>
            </template>
          </el-table-column>
          <el-table-column label="产品类型"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.productionType==='REPORT'?'报告':(row.productionType==='STATEMENT'?'意见书':(row.productionType==='LETTER'?'复评函':'-'))}}</span>
            </template>
          </el-table-column>
          <el-table-column label="项目名称"  width="150" show-overflow-tooltip  align="center" >
            <template slot-scope="{row}">
              <span>{{ row.name }}</span>
            </template>
          </el-table-column>
          <el-table-column label="市场部"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.marketDepartment }}</span>
            </template>
          </el-table-column>
          <el-table-column label="评估部"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.evaluateDepartment }}</span>
            </template>
          </el-table-column>
          <el-table-column label="客户经理" align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientManager }}</span>
            </template>
          </el-table-column>
          <el-table-column label="负责人"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.principal }}</span>
            </template>
          </el-table-column>
          <el-table-column label="到账时间" width="110" align="center">
            <template slot-scope="{row}">
              <span>{{ row.payDateTime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="认领时间" width="110" align="center">
            <template slot-scope="{row}">
              <span>{{ row.claimDatetime }}</span>
            </template>
          </el-table-column>
          <el-table-column label="应收款(元)"   align="center">
            <template slot-scope="{row}">
              <span>{{ row.orderShouldAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="认领金额(元)"   align="center">
            <template slot-scope="{row}">
              <span  style="color:red">{{ row.claimAmount }}</span>
            </template>
          </el-table-column>
          <el-table-column label="认领人"  align="center">
            <template slot-scope="{row}">
              <span>{{ row.claimUser }}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column label="客户名称"   align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="业务来源"   align="center">
            <template slot-scope="{row}">
              <span>{{ row.clientSubName }}</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.evaluateAmount/10000 }}</span>
            </template>
          </el-table-column>
        </el-table>
      </y-page-list-layout>
  </div>
</template>
<script>
  import Breadcrumb from '@/components/Breadcrumb'
  import YPageListLayout from '@/components/YPageListLayout'

  export default {
    name: 'realFundStat',
    components: {
      Breadcrumb,
      YPageListLayout
    },
    data() {
      return {
        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]);
                    }
                }]
            },
        claimDate: [],
        paymentDate: '',
        listQuery1: {
          page: 1,
          size: 1000,
          descs: 'id',
          keyword:null,
          startDate: '',
          endDate: '',
        },
        majorStat:{
          records:[]
        }
      }
    },
    created() {
      this.claimDate.push(this.getDefaultStartDate());
      this.claimDate.push(this.getDefaultEndDate());
        this.getMajorStat();
    },
    methods: {
   
      handleClick(tab, event) {
      
      },

      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'
    },


        
    resetSearch1() {
      this.$router.push({ query: {} });
      this.claimDate = [this.getDefaultStartDate(), this.getDefaultEndDate()];
      this.paymentDate = '',
      this.listQuery1 = {
        current: 1,
        size: 1000,
        descs: 'id',
        startDate:null,
        endDate:null,
        payStartDate:null,
        payEndDate:null
      }
      this.getMajorStat()
    },
   
    searchList1() {
      // 重置分页
      this.listQuery1.page = 1
      this.listQuery1.size = 1000
      if (this.claimDate){
        this.listQuery1.startDate = this.claimDate[0]+' 00:00:00';
        this.listQuery1.endDate = this.claimDate[1]+ ' 23:59:59';
      }
      if (this.paymentDate){
        this.listQuery1.payStartDate = this.paymentDate[0]+' 00:00:00';
        this.listQuery1.payEndDate = this.paymentDate[1]+ ' 23:59:59';
      }
      this.getMajorStat()
    },

      getMajorStat(){
        let loadingInstance = this.$loading({ fullscreen: true });

        if (this.claimDate) {
          this.listQuery1.startDate = this.claimDate[0] + ' 00:00:00';
          this.listQuery1.endDate = this.claimDate[1] + ' 23:59:59';
        }
        this.$api.financeClaim.getMajorStat(this.listQuery1).then(res=>{
          if (res.code === 200){
            loadingInstance.close();
              this.majorStat = res.data;
          }
        })
      },
      exportMajorStat(){
        this.$utils.exportUtil(
        "/financeClaim/major/stat/export", this.listQuery1,
        "导出"
      );
      }
    }
  }
</script>
<style scoped lang="scss">

</style>
