<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-form-item label="供应商名称">
              <el-input v-model="formdata.customerName" placeholder="请输入供应商名称"></el-input>
            </el-form-item>
            <el-form-item label="劳务队长">
              <el-input v-model="formdata.leaderName" placeholder="请输入劳务队长"></el-input>
            </el-form-item>
            <el-form-item label="注册城市">
              <el-cascader
                v-model="formdata.areas"
                :options="addressList" :collapse-tags="true" :show-all-levels="false" clearable
                :props="provienceprops"></el-cascader>
            </el-form-item>
          </el-row>
          <el-row>
            <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-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-form-item label="专业类别">
              <el-cascader clearable
                           v-model="formdata.groupSpecialtys"
                           :options="groupSpecialty" :collapse-tags="true"
                           :props="groupprops"></el-cascader>
            </el-form-item>
          </el-row>
          <el-row>
            <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-form-item label="纳税人身份">
              <el-select v-model="formdata.paytaxType" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in paytaxtype" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="纳税人税率">
              <el-select v-model="formdata.taxRate" multiple placeholder="请选择" :collapse-tags="true" clearable>
                <el-option v-for="(item,index) in taxrate" :label="item.dictLabel" :value="item.dictValue" :key="index"></el-option>
              </el-select>
            </el-form-item>
          </el-row>
          <el-row>
            <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-row>
          <el-divider></el-divider>
          <el-form-item label="  ">
            <el-button type="primary" size="small" @click="handleCurrentChange(1)">查询</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>
      </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&&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
                  :header-row-class-name="setHeaderRow" :cell-class-name="setCellClass" :row-class-name="setRowClass" :header-cell-class-name="setCellClass"
                  ref="theOwnerListTable">

          <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="380" :resizable="false">
            <template slot-scope="scope">
              <div class="renling">
                <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)}?path=cooperationRecord&companyName=${scope.row.customerName}`" 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)}?path=cooperationRecord&companyName=${scope.row.customerName}`" tag="a"
                                 class="wordprimary" v-html="scope.row.customerName"></router-link>
                    <span v-else v-html="scope.row.customerName"></span>
                  </div>
                </div>
              </div>

            </template>

          </el-table-column>
          <el-table-column label="二级市场编码" width="120" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.secondaryCode||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="营业执照号码" min-width="180">
            <template slot-scope="scope">
              {{scope.row.unifySocialCode||"--"}}
            </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="85" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.representative||"--"}}
            </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="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.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="85" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.credential||"--"}}
            </template>
          </el-table-column>
          <el-table-column label="主项资质" min-width="85" :resizable="false">
            <template slot-scope="scope">
              --
            </template>
          </el-table-column>
          <el-table-column label="劳务资质" min-width="85" :resizable="false">
            <template slot-scope="scope">
              --
            </template>
          </el-table-column>
          <el-table-column label="施工队长" min-width="85" :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="85" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.serviceTeamPersonnum||'--'}}
            </template>
          </el-table-column>
          <el-table-column label="专业特长" min-width="85" :resizable="false">
            <template slot-scope="scope">
              {{scope.row.serviceTeamSpeciality||"--"}}
            </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>{{scope.row.projectCooperationCount||"--"}}</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)">{{scope.row.creditLevel||"--"}}</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>
            </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 { areaAll, bizDictData, custmerInfolist } from '@/api/supplier/supplier'
  import { getDicts } from '@/api/system/dict/data'
  import {queryConditionFiltering} from '@/utils/index'
  export default {
    name: 'laborSubcontractingTeam',
    components:{skeleton},
    data(){
      return{
        encodeStr,
        addressList:[],
        arealist:[],
        creditlevel:[],
        customstate:[],
        credential:[],
        paytaxtype:[],
        taxrate:[],
        groupSpecialty:[],
        provienceprops:{
          checkStrictly:false,
          multiple:true,
          label:'value',
        },
        groupprops:{
          checkStrictly:false,
          multiple:true,
          value:'id',
        },
        formdata:{
          customerClass:'劳务分包队伍',
          pageNum:1,
          pageSize:50,
          times:[],
          customerName:"",
          leaderName:"",
          areas:[],
          customerState:[],
          credential:[],
          groupSpecialtys:[],
          groupSpecialtyId:[],
          creditLevel:[],
          paytaxType:[],
          taxRate:[],
          registerProvince:[],
          registerCity:[],
          approveDate2Start:null,
          approveDate2End:null,
        },
        tableData:[],
        isSkeleton:false,
        total:0,
        // table列是否悬浮
        tableColumnFixed: true,
        fbsvisib:false,
        fbsisSkeleton:false,
      }
    },
    created() {
      this.init()
      this.cusoomerInfolist()
    },
    methods:{
      init(){
        //评价等级
        getDicts('credit_level').then(res=>{
          this.creditlevel = res.data
        })
        //供应商状态
        getDicts('custom_state').then(res=>{
          this.customstate = res.data
        })
        //纳税人身份
        getDicts('paytaxtype').then(res=>{
          this.paytaxtype = res.data
        })
        //纳税人税率
        getDicts('taxrate').then(res=>{
          this.taxrate = res.data
        })
        //资质等级
        getDicts('credential').then(res=>{
          this.credential = res.data
        })
        // this.dataRegion()
        //专业类别
        bizDictData().then(res=>{
          this.groupSpecialty = res.data
        })
        // 地区树
        areaAll().then(res=>{
          this.addressList = res.data
        })
      },
      clears(){
        this.formdata = {
          customerClass: '劳务分包队伍',
          pageNum: 1,
          pageSize: 50,
          times: [],
          customerName: '',
          leaderName: '',
          areas: [],
          customerState: [],
          credential: [],
          groupSpecialtys: [],
          groupSpecialtyId: [],
          creditLevel: [],
          paytaxType: [],
          taxRate: [],
          registerProvince: [],
          registerCity: [],
          approveDate2Start: null,
          approveDate2End: null
        }
        this.cusoomerInfolist()
      },
      cusoomerInfolist(){
        this.isSkeleton = true
        let param = this.formdata
        if(param.times){
          param.approveDate2Start = param.times[0]
          param.approveDate2End = param.times[1]
        }else{
          param.approveDate2Start = ''
          param.approveDate2End = ''
        }
        param.groupSpecialtyId = []
        if(param.groupSpecialtys){
          param.groupSpecialtys.forEach(item=>{
            param.groupSpecialtyId.push(item[item.length-1])
          })
        }
        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.registerProvince = province
          param.registerCity = city
        }else{
          param.registerProvince = []
          param.registerCity = []
        }
        custmerInfolist(queryConditionFiltering(this.formdata)).then(res=>{
          this.isSkeleton = false
          this.tableData = res.rows
          this.total = res.total
          this.tableData.forEach(item=>{
            item.customerText = item.customerName.replace(/<\/?[^>]+(style=('|")[^'"]*)?>/gi, '')
          })
        })
      },
      handleCurrentChange(val){
        this.formdata.pageNum = val
        this.cusoomerInfolist()
      },
      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('测试一下-供应商考评', '/supplier/supplierlist/assessment')
      },
    }
  }
</script>

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

