<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="getPage">
      <template slot="left">
        <MoreSearchBar business="MAJOR_BUSINESS" @fliterSearch="fliterSearch" @resetParams="resetParams" :listQuery="listQuery" :nodes="majorNodes">
          <template v-slot:otherButton>
            <el-button class="filter-item" round @click="showAllLabel()">显示全部列</el-button>
          </template>
        </MoreSearchBar>
      </template>
      <parentTable ref="table" v-loading="listLoading" :data="pageData.records" slot="table" style="width: 100%;" @sortTable="sortTable" @headerClick="switchHeader">
        <el-table-column label="项目名称" align="center" width="250" v-if="!hiddenLabels.includes('productionName')" prop="productionName" show-overflow-tooltip>
          <template slot-scope="{row}">
            <span class = "enableClick" @click="orderDetail(row)">{{ row.productionName==null?row.name: row.productionName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="订单号" align="center" width="150" v-if="!hiddenLabels.includes('orderId')" prop="orderId">
          <template slot-scope="{row}">
            <span class = "enableClick" @click="orderDetail(row)" @contextmenu.prevent="$doCopy(row.orderId)">{{ row.orderId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="价值意见书号" align="center" width="200" v-if="!hiddenLabels.includes('statementNo')" prop="statementNo" sortable >
          <template slot-scope="{row}">
            <span @contextmenu.prevent="$doCopy(row.statementNo)">{{ row.statementNo==null?'-': row.statementNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="报告号/复评函号" align="center" width="200" v-if="!hiddenLabels.includes('reportNo')" prop="reportNo" sortable>
          <template slot-scope="{row}">
            <span @contextmenu.prevent="$doCopy(row.reportNo)">{{ row.reportNo==null?'-': row.reportNo }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="130" v-if="!hiddenLabels.includes('nodeName')" prop="nodeName" sortable>
          <template slot-scope="{row}">
            <span>{{ row.nodeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="待办人" align="center" width="130" v-if="!hiddenLabels.includes('handler')" prop="handler">
          <template slot-scope="{row}">
            <span>{{ row.handler }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人" align="center" width="130" v-if="!hiddenLabels.includes('clientName')" prop="clientName">
          <template slot-scope="{row}">
            <span>{{ row.clientName==null?'-': row.clientName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人电话" align="center" width="130" v-if="!hiddenLabels.includes('clientTel')" prop="clientTel">
          <template slot-scope="{row}">
            <span>{{ row.clientTel==null?'-': row.clientTel }}</span>
          </template>
        </el-table-column>
        <el-table-column label="产权人" align="center" width="130" v-if="!hiddenLabels.includes('owner')" prop="owner">
          <template slot-scope="{row}">
            <span>{{ row.owner==null?'-': row.owner }}</span>
          </template>
        </el-table-column>
        <el-table-column label="评估总价" align="center" width="130" v-if="!hiddenLabels.includes('evaluateAmount')" prop="evaluateAmount">
          <template slot-scope="{row}">
            <span>{{ row.evaluateAmount==null?'-': row.evaluateAmount/10000 +'万'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="金融类型" align="center" width="130" v-if="!hiddenLabels.includes('financial')" prop="financial">
          <template slot-scope="{row}">
            <span>{{ row.financial?'金融':'非金融' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="分单类型" align="center" v-if="!hiddenLabels.includes('allotType')" prop="allotType">
          <template slot-scope="{row}">
            <span>{{ row.allotType }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户经理" align="center" v-if="!hiddenLabels.includes('clientManager')" prop="clientManager">
          <template slot-scope="{row}">
            <span>{{ row.clientManager }}</span>
          </template>
        </el-table-column>
        <el-table-column label="负责人" align="center" v-if="!hiddenLabels.includes('principal')" prop="principal">
          <template slot-scope="{row}">
            <span>{{ row.principal==null?'-': row.principal }}</span>
          </template>
        </el-table-column>
        <el-table-column label="接单部门" align="center" width="130" v-if="!hiddenLabels.includes('department')" prop="department">
          <template slot-scope="{row}">
            <span>{{ row.department }}</span>
          </template>
        </el-table-column>
        <el-table-column label="评估对象类型" align="center" width="130" v-if="!hiddenLabels.includes('businessObjectType')" prop="businessObjectType">
          <template slot-scope="{row}">
            <span>{{ row.businessObjectType }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户名称" align="center" width="130" v-if="!hiddenLabels.includes('cclienteleName')" prop="cclienteleName">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130" v-if="!hiddenLabels.includes('cclienteleSubName')" prop="cclienteleSubName">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleSubName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户联系人" align="center" width="130" v-if="!hiddenLabels.includes('cclienteleContactName')" prop="cclienteleContactName">
          <template slot-scope="{row}">
            <span>{{ row.cclienteleContactName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="客户联系人电话" align="center" width="130" v-if="!hiddenLabels.includes('cmobile')" prop="cmobile">
          <template slot-scope="{row}">
            {{ row.cmobile }}
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" width="110" v-if="!hiddenLabels.includes('created')" prop="created" sortable>
          <template slot-scope="{row}">
            {{ row.created }}
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="70" fixed="right">
          <template slot-scope="{row}">
            <el-button type="text" @click="orderDetail(row)">详情</el-button>
          </template>
        </el-table-column>
      </parentTable>
    </y-page-list-layout>
  </div>
</template>
<script>
import YPageListLayout from '@/components/YPageListLayout'
import Breadcrumb from '@/components/Breadcrumb'
import PermissionButton from '@/components/PermissionButton/PermissionButton'
import MoreSearchBar from '@/components/MoreSearchBar'
import { getCookie,setCookie,removeCookie } from '@/utils/auth'

export default {
  name: 'MajorList',
  components: {
    Breadcrumb,
    YPageListLayout,
    PermissionButton,
    MoreSearchBar
  },

  data() {
    return {
      pageData: { records: [] },
      listLoading: false,
      listQuery: {
        page: 1,
        size: 10,
        current: 1,
        descs: null,
        ascs:null,
        keyword:null,
        startDate:null,
        endDate:null
      },
      majorNodes:[],
      hiddenLabels:[],
      loading:false,
      pgLeader:false
    }
  },
  created() {
    // this.listQuery.id = this.$route.query.id;
    if (getCookie("MajorPendingList-hiddenLabels")!=undefined){
      this.hiddenLabels = JSON.parse(getCookie("MajorPendingList-hiddenLabels"))
    }
    this.listQuery.keyword = this.$route.query.keyword;
    this.getPage();
    this.getNodeEnum();
  },
  methods: {
    
    getPage() {
      this.$api.major.page(this.listQuery).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
          }
      })
    },

    getNodeEnum() {
      this.$api.workNode.nodesByBusiness("MAJOR_BUSINESS").then(res => {
                if (res.code === 200) {
                    this.majorNodes = res.data;
                }
            })
        },

    fliterSearch(params){
      this.$api.major.page(params).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },

    resetParams(){
      this.$router.push({ query: {} });
      this.listQuery = {
          current: 1,
          size: 10,
          descs: 'created',
      }
      this.getPage();
    },

    orderDetail(row){
      if (row.reportNo && row.statementNo){
        this.$router.push(`/major/detail?id=${row.majorId}&orderId=${row.orderId}&currentNodeName=${row.nodeName}&couldEdit=${false}&reportNo=${row.reportNo}&statementNo=${row.statementNo}&currentNodeId=${row.currentNodeId}&back=${'/major/list'}`)
      }else if (!row.reportNo && row.statementNo){
        this.$router.push(`/major/detail?id=${row.majorId}&orderId=${row.orderId}&currentNodeName=${row.nodeName}&couldEdit=${false}&statementNo=${row.statementNo}&currentNodeId=${row.currentNodeId}&back=${'/major/list'}`)
      }else if (row.reportNo && !row.statementNo){
        this.$router.push(`/major/detail?id=${row.majorId}&orderId=${row.orderId}&currentNodeName=${row.nodeName}&couldEdit=${false}&reportNo=${row.reportNo}&currentNodeId=${row.currentNodeId}&back=${'/major/list'}`)
      }else {
        this.$router.push(`/major/detail?id=${row.majorId}&orderId=${row.orderId}&currentNodeName=${row.nodeName}&couldEdit=${false}&currentNodeId=${row.currentNodeId}&back=${'/major/list'}`)
      }
    },
    sortTable(sortParams){
       this.listQuery.ascs = sortParams.ascs;
       this.listQuery.descs = sortParams.descs;
       this.$api.major.page(this.listQuery).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },

    switchHeader(data){
      this.hiddenLabels.push(data);
      setCookie("MajorPendingList-hiddenLabels",this.hiddenLabels);
    },
    showAllLabel(){
      removeCookie("MajorPendingList-hiddenLabels");
      location.reload();
    }
  },
  
}
</script>
<style lang="scss" scoped>
  .enableClick:hover{
    color:#1890ff;
    cursor: pointer;
 }
</style>
