<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="PERSONAL_BUSINESS" :nodes="personalNodes"  @fliterSearch="fliterSearch" @resetParams="resetParams" :listQuery="listQuery">
          <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%;" @headerClick="switchHeader">
        <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)">{{ row.orderId }}</span>
          </template>
        </el-table-column>
        <el-table-column label="坐落" align="center" width="300" v-if="!hiddenLabels.includes('location')" prop="location">
          <template slot-scope="{row}">
            <span class="enableClick" @click="orderDetail(row)">{{ row.location }}</span>
          </template>
        </el-table-column>
        <el-table-column label="当前节点" align="center" width="130"  v-if="!hiddenLabels.includes('currentNodeName')" prop="currentNodeName">
          <template slot-scope="{row}">
            <span>{{ row.currentNodeName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="处理人" align="center" width="130" v-if="!hiddenLabels.includes('handlerName')" prop="handlerName">
          <template slot-scope="{row}">
            <span>{{ row.handlerName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="面积" align="center" width="130" v-if="!hiddenLabels.includes('acreage')" prop="acreage">
          <template slot-scope="{row}">
            <span>{{ row.acreage? row.acreage: '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="单价" align="center" width="130" v-if="!hiddenLabels.includes('price')" prop="price">
          <template slot-scope="{row}">
            <span>{{ row.price? row.price: '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="总价" align="center" width="130" v-if="!hiddenLabels.includes('amount')" prop="amount">
          <template slot-scope="{row}">
            <span>{{ row.amount? row.amount: '-' }}</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?row.clientName:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="业务来源" align="center" width="130" v-if="!hiddenLabels.includes('clientSubName')" prop="clientSubName">
          <template slot-scope="{row}">
            <span>{{ row.clientSubName?row.clientSubName:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="中介" align="center" width="130" v-if="!hiddenLabels.includes('agent')" prop="agent">
          <template slot-scope="{row}">
            <span>{{ row.agent?row.agent:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人" align="center" width="130" v-if="!hiddenLabels.includes('contactName')" prop="contactName">
          <template slot-scope="{row}">
            <span>{{ row.contactName?row.contactName:'-'}}</span>
          </template>
        </el-table-column>
        <el-table-column label="联系人电话" align="center" width="130" v-if="!hiddenLabels.includes('contactTel')" prop="contactTel">
          <template slot-scope="{row}">
            <span>{{ row.contactTel?row.contactTel:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人" align="center" v-if="!hiddenLabels.includes('bailorA')" prop="bailorA">
          <template slot-scope="{row}">
            <span>{{ row.bailorA?row.bailorA:(row.bailorB?row.bailorB:'-')}}</span>
          </template>
        </el-table-column>
        <el-table-column label="委托人电话" align="center" width="130" v-if="!hiddenLabels.includes('bailoraTel')" prop="bailoraTel">
          <template slot-scope="{row}">
            <span>{{ row.bailorATel?row.bailorATel:(row.bailorBTel?row.bailorBTel:'-')}}</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" width="130" v-if="!hiddenLabels.includes('outwardStaffName')" prop="outwardStaffName">
          <template slot-scope="{row}">
            <span>{{ row.outwardStaffName? row.outwardStaffName: '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="内业人员" align="center" width="130" v-if="!hiddenLabels.includes('inwardStaffName')" prop="inwardStaffName">
          <template slot-scope="{row}">
            <span>{{ row.inwardStaffName?row.inwardStaffName:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="定价人员" align="center" width="130" v-if="!hiddenLabels.includes('pricingStaffName')" prop="pricingStaffName">
          <template slot-scope="{row}">
            <span>{{ row.pricingStaffName?row.pricingStaffName:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="下单时间" align="center" width="110" v-if="!hiddenLabels.includes('created')" prop="created">
          <template slot-scope="{row}">
            {{ row.created }}
          </template>
        </el-table-column>
        <el-table-column label="节点生成时间" align="center" width="110" v-if="!hiddenLabels.includes('nodeTime')" prop="nodeTime" >
          <template slot-scope="{row}">
            {{ row.nodeTime }}
          </template>
        </el-table-column>
        <el-table-column label="最新备注" align="center" width="150" v-if="!hiddenLabels.includes('comments')" prop="comments">
          <template slot-scope="{row}">
            <span>{{ row.comments?row.comments:'-' }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="80" 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: 'PersonalPendingList',
  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
      },
      personalNodes:[],
      hiddenLabels:[]
    }
  },

  
  created() {
    if (getCookie("PersonalPendingList-hiddenLabels")!=undefined){
      this.hiddenLabels = JSON.parse(getCookie("PersonalPendingList-hiddenLabels"))
    }
    this.listQuery.keyword = this.$route.query.keyword;
    this.getPage();
    this.getNodeEnum();
  },
  methods: {
    getPage() {
      if (getCookie('PersonalPendingList') != undefined){
        this.listQuery.size = parseInt(getCookie('PersonalPendingList'));
      }
      this.$api.personal.list(this.listQuery).then(res=>{
        if (res.code ===200){
            this.pageData = res.data;
        }
      })
    },

    getNodeEnum() {
            this.$api.workNode.nodesByBusiness("PERSONAL_BUSINESS").then(res => {
                if (res.code === 200) {
                    this.personalNodes = res.data;
                }
            })
        },
    fliterSearch(params){
      this.$api.personal.list(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();
    },
    searchList() {
      // 重置分页
      this.listQuery.page = 1
      this.listQuery.size = 10
      this.getPage()
    },

    orderDetail(row){
      this.$router.push(`/personal/readonly/detail?id=${row.id}&currentNodeName=${row.currentNodeName}&orderId=${row.orderId}&back=${'/personal/pending/list'}`)
    },

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