<template>
  <div class="supplier">
    <div class="search-supplier">
      <div class="title_wrap">
        <div class="enterprise_title">
          供应商总台账
        </div>
      </div>
      <div class="content-supplier">
        <el-form :model="formdata" label-width="82px" label-position="right"  :inline="true" >
          <el-row>
            <el-col :span="8">
            <el-form-item label="分供方名称">
              <el-input v-model="formdata.customerName" placeholder="请输入分供方名称" clearable></el-input>
            </el-form-item>
            </el-col>
            <el-col :span="8">
            <el-form-item label="注册城市">
              <el-cascader style="width: 100%"
                v-model="formdata.areas"
                :options="addressList" :collapse-tags="true" :show-all-levels="false" clearable
                :props="provienceprops"></el-cascader>
            </el-form-item>
            </el-col>
              <el-col :span="8">
            <el-form-item label="供应商类别">
              <el-select v-model="formdata.customerClass" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in suppliertype" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
              </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
            <el-form-item label="供应商状态">
              <el-select v-model="formdata.customerState" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in customstate" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            </el-col>

            <el-col :span="8">
            <el-form-item label="评价等级">
              <el-select v-model="formdata.creditLevel" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in creditlevel" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            </el-col>
            <el-col :span="8">
            <el-form-item label="资质等级">
              <el-select v-model="formdata.credential" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in credential" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            </el-col>
          </el-row>
          <el-divider></el-divider>
          <el-row>

            <el-col :span="8">
            <el-form-item label="准入时间">
              <el-date-picker
                v-model="formdata.times"
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="至"
                start-placeholder="年/月/日"
                end-placeholder="年/月/日">
              </el-date-picker>
            </el-form-item>
            </el-col>
            <el-col :span="8">
            <el-form-item label="涉诉状态">
              <el-select multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in litigationstatus" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            </el-col>
          </el-row>
          <el-divider></el-divider>
          <el-form-item label="  ">
            <el-button type="primary" size="small" @click="getSearch">查询</el-button>
            <el-button size="small" @click="clears">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
    <div class="table-supplier">
      <div class="total-title">
        <div class="totals">共{{total}}条</div>
        <p class="total-dc" @click="customerExport">
          <img src="@/assets/images/EXCEL.png" alt="">
          <span class="excel">导出EXCEL</span>
        </p>
      </div>
      <div class="table-item-jf table-item-jf1 empty-table" v-if="total == 0 && !isSkeleton">
        <img class="item-jf-img" src="@/assets/images/kong.png" alt="">
        <div class="item-jf-titel">暂无相关数据</div>
        <div class="item-jf-text">抱歉，暂无数据，试试更换搜索条件吧</div>
      </div>
      <skeleton v-if="isSkeleton"></skeleton>

      <div class="table-item-jf table-item" v-if="!isSkeleton&&total>0">
        <el-table :data="tableData" :header-cell-style="{ background:'#f0f3fa',color: 'rgba(35,35,35,0.8)'}"
                  v-sticky-header.always="{offsetTop : '-16px',offsetBottom : '-15px'}" class="table-item1 fixed-table" border highlight-current-row
                  :header-row-class-name="setHeaderRow" :cell-class-name="setCellClass" :row-class-name="setRowClass" :header-cell-class-name="setCellClass"
                  ref="theOwnerListTable" :row-key="'customerKey'">

          <el-table-column type="index" label="序号" :fixed="tableColumnFixed" width="60" :resizable="false">
            <template slot-scope="scope">
              <span>{{(formdata.pageNum - 1) *formdata.pageSize + scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="供应商编号" prop="customerCode" :fixed="tableColumnFixed" width="120" :resizable="false">
          </el-table-column>

          <el-table-column label="供应商名称" :fixed="tableColumnFixed" width="310" :resizable="false">
            <template slot-scope="scope">
              <div style="display:flex;align-items:center">
                <el-tooltip placement="top" v-if="scope.row.customerText.length>20">
                  <div slot="content">{{scope.row.customerText}}</div>
                  <div class="renling">
                    <router-link v-if="scope.row.companyId" :to="`/enterprise/${encodeStr(scope.row.companyId)}?companyName=${scope.row.customerText}&ctmId=${scope.row.customerId}`" tag="a"
                                 class="wordprimary" v-html="scope.row.customerName"></router-link>
                    <span v-else v-html="scope.row.customerName"></span>
                  </div>
                </el-tooltip>
                <div class="renling" v-else>
                  <router-link v-if="scope.row.companyId" :to="`/enterprise/${encodeStr(scope.row.companyId)}?companyName=${scope.row.customerText}&ctmId=${scope.row.customerId}`" tag="a"
                               class="wordprimary" v-html="scope.row.customerName"></router-link>
                  <span v-else v-html="scope.row.customerName"></span>
                </div>
              </div>

            </template>

          </el-table-column>

          <el-table-column label="推荐单位" min-width="280">
            <template slot-scope="scope">
              {{scope.row.recommendOrg||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="公司注册区域" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.registerRegion||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="公司注册省" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.registerProvince||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="公司注册城市" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.registerCity||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="供应商类别" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.customerClass||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="专业类别" min-width="520" :resizable="false">
            <template slot-scope="scope">
              <el-tooltip placement="top" v-if="scope.row.groupSpecialty&&scope.row.groupSpecialty.length>35">
                <div slot="content">{{scope.row.groupSpecialty}}</div>
                <span class="ellipsis">
                  {{scope.row.groupSpecialty||"--"}}
                </span>
              </el-tooltip>
              <span class="ellipsis" v-else>
                {{scope.row.groupSpecialty||"--"}}
              </span>
            </template>
          </el-table-column>
          <el-table-column label="纳税人身份" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.paytaxType||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="纳税人税率(%)" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.taxRate||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="状态" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.customerState||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="限用/禁用状态" min-width="120" :resizable="false">
            <template slot-scope="scope">--</template>
          </el-table-column>
          <el-table-column label="劳务队长" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.leaderName||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="队长联系电话" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.laborCaptainPhone||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="队长身份证" min-width="180" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.laborCaptainIdcard||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="队伍规模" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.serviceTeamPersonnum||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="专业特长" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.serviceTeamSpeciality||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="施工承包范围" min-width="520" :resizable="false">
            <template slot-scope="scope">
              <el-tooltip placement="top-start" v-if="scope.row.constructJobScope&&scope.row.constructJobScope.length>35">
                <div slot="content">{{scope.row.constructJobScope}}</div>
                <div class="ellipsis">
                  <span>{{scope.row.constructJobScope||"--"}}</span>
                </div>
              </el-tooltip>
              <div class="ellipsis" v-else>
                  <span>{{scope.row.constructJobScope||"--"}}</span>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="资质等级" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.credential||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="注册资本(万元)" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.registerCapital||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="公司联系人" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.contactPerson||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="联系人电话" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.contactPhone||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="准入时间" min-width="180" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.approveDate2||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="公司合作数量" min-width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.enterpriseCooperationCount||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="合作项目数量" min-width="120" :resizable="false">
            <template slot-scope="scope">
              <span class="projectCooperationCount">{{scope.row.legalPerson||"--"}}</span>
            </template>
          </el-table-column>
          <el-table-column label="分包商等级" min-width="120" :resizable="false">
            <template slot-scope="scope">
              <span class="wordprimary" @click="getFBS(scope.row)" v-if="scope.row.creditlevel">{{scope.row.creditLevel}}</span>
              <span v-else>--</span>
            </template>
          </el-table-column>
          <el-table-column label="链接" min-width="160" :resizable="false">
            <template slot-scope="scope">
              <span class="wordprimary tabs" @click="goAccess(scope.row)">准入</span>
              <span class="wordprimary tabs" @click="goAssessment(scope.row)">考评</span>
              <!--<span class="wordprimary tabs" @click="goDisposal(scope.row)">处置</span>-->
            </template>
          </el-table-column>
          <el-table-column label="资源平台分类" min-width="120" :resizable="false">
            <template slot-scope="scope">--</template>
          </el-table-column>

        </el-table>
      </div>
      <div class="pagination clearfix" v-show="total>formdata.pageSize">
        <el-pagination background :page-size="formdata.pageSize" :current-page.sync="formdata.pageNum" @current-change="handleCurrentChange" layout="prev, pager, next"
                       :total="total">
        </el-pagination>
      </div>
    </div>
    <el-dialog title="等级及状态变更" :visible.sync="fbsvisib" custom-class='dialog-supplier' >
      <skeleton v-if="fbsisSkeleton"></skeleton>
      <div class="table-item-jf table-item" v-if="!fbsisSkeleton&&tableData.length>0">
        <el-table :data="tableData" :header-cell-style="{ background:'#f0f3fa',color: 'rgba(35,35,35,0.8)'}"
                  v-sticky-header.always="{offsetTop : '-16px',offsetBottom : '10px'}" class="table-item1 fixed-table" border highlight-current-row>

          <el-table-column type="index" label="序号" width="60" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="处置时间" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.row.legalPerson||'--'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="处置前状态" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.row.legalPerson||'--'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="处置后状态" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.row.legalPerson||'--'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="处置前等级" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.row.legalPerson||'--'}}</span>
            </template>
          </el-table-column>
          <el-table-column label="处置后等级" :resizable="false">
            <template slot-scope="scope">
              <span>{{scope.row.legalPerson||'--'}}</span>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { encodeStr } from "@/assets/js/common.js";
  import "@/assets/styles/public.scss";
  import "@/assets/styles/supplierlist.scss";
  import skeleton from '@/views/project/projectList/component/skeleton';
  import {customerAll,areaAll,customerExport} from '@/api/supplier/supplier';
  import { getDicts } from "@/api/system/dict/data";
  export default {
    name: 'ledger',
    components:{skeleton},
    data(){
      return{
        encodeStr,
        addressList:[],
        creditlevel:[],
        customstate:[],
        credential:[],
        litigationstatus:[],
        suppliertype:[],
        provienceprops:{
          checkStrictly:false,
          multiple:true,
          label:'value',
        },
        formdata:{
          customerName: '',
          customerClass:[],
          areas:[],
          province:[],
          city:[],
          customerState:[],
          creditLevel:[],
          credential:[],
          approveDateBegion:null,
          approveDateEnd:null,
          times:[],
          pageSize:50,
          pageNum:1,
        },
        tableData:[],
        isSkeleton:false,
        total:0,
        // table列是否悬浮
        tableColumnFixed: true,
        fbsvisib:false,
        fbsisSkeleton:false,
      }
    },
    created() {
      this.init()
      this.customerAll()
    },
    methods:{
      init(){
        //地区
        areaAll().then(res=>{
          this.addressList = res.data
        })
        //评价等级
        getDicts('credit_level').then(res=>{
          this.creditlevel = res.data
        })
        //资质等级
        getDicts('credential').then(res=>{
          this.credential = res.data
        })
        //供应商类别
        getDicts('suppliertype').then(res=>{
          this.suppliertype = res.data
        })
        //供应商状态
        getDicts('custom_state').then(res=>{
          this.customstate = res.data
        })
        //涉诉状态
        getDicts('litigation_status').then(res=>{
          this.litigationstatus = res.data
        })
      },
      customerExport(){
        let param = this.formdata
        if(param.times){
          param.approveDateBegion = param.times[0]
          param.approveDateEnd = param.times[1]
        }else{
          param.approveDateBegion = ''
          param.approveDateEnd = ''
        }
        if(param.areas){
          let province = []
          let city = []
          param.areas.forEach(item=>{
            if(item.length == 3){//到市
              if(item[1].indexOf('重庆')>-1||item[1].indexOf('北京')>-1||item[1].indexOf('天津')>-1||item[1].indexOf('上海')>-1){
                province.push(item[1])
              }else{
                city.push(item[2])
              }
            }
          })
          param.province = province
          param.city = city
        }else{
          param.province = []
          param.city = []
        }
        // this.download('/customer/export', param, `type_${new Date().getTime()}.xlsx`)
          customerExport(param).then(blob => {
            this.$download.saveAs(blob, `type_${new Date().getTime()}.xlsx`)
          })
      },
      getSearch(){
        this.formdata.pageNum = 1
        this.customerAll()
      },
      clears(){
        this.formdata={
          customerName: '',
          customerClass:[],
          areas:[],
          province:[],
          city:[],
          customerState:[],
          creditLevel:[],
          credential:[],
          approveDateBegion:null,
          approveDateEnd:null,
          times:[],
          pageSize:50,
          pageNum:1,
        }
        this.customerAll()
      },
      customerAll(){
        this.isSkeleton = true
        let param = this.formdata
        if(param.times){
          param.approveDateBegion = param.times[0]
          param.approveDateEnd = param.times[1]
        }else{
          param.approveDateBegion = ''
          param.approveDateEnd = ''
        }
        if(param.areas){
          let province = []
          let city = []
          param.areas.forEach(item=>{
            if(item.length == 3){//到市
              if(item[1].indexOf('重庆')>-1||item[1].indexOf('北京')>-1||item[1].indexOf('天津')>-1||item[1].indexOf('上海')>-1){
                province.push(item[1])
              }else{
                city.push(item[2])
              }
            }
          })
          param.province = province
          param.city = city
        }else{
          param.province = []
          param.city = []
        }
        customerAll(JSON.stringify(param)).then(res=>{
          this.tableData = res.rows
          this.total = res.total
          this.isSkeleton = false
          this.tableData.forEach(item=>{
            item.customerText = item.customerName.replace(/<\/?[^>]+(style=('|")[^'"]*)?>/gi, '')
          })
        })
      },
      handleCurrentChange(val){
        this.formdata.pageNum = val
        this.customerAll()
      },
      setHeaderRow() {
        return "owner-table-list-header";
      },
      setCellClass({ row, column, rowIndex, columnIndex }) {
        if (columnIndex == 1) {
          return "enterprise-name-column";
        }
      },
      setRowClass({ row, rowIndex }) {
        return "enterprise-name-row";
      },
      //点击分包商等级
      getFBS(row){
        this.fbsvisib = true
        this.fbsisSkeleton = true
      },
      //点击准入
      goAccess(row){
        this.$tab.openPage(row.customerName+'-准入情况', '/supplier/supplierlist/access',{customerKey:row.customerKey})
      },
      //点击考评
      goAssessment(row){
        this.$tab.openPage(row.customerName+'-供应商考评', '/supplier/supplierlist/assessment')
      },
      //点击处置
      goDisposal(row){
        this.$tab.openPage(row.customerName+'-供应商处置', '/supplier/supplierlist/disposal')
      },
    }
  }
</script>

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