<template>
  <div  @click = 'handleALL'>
    <div class="miantitle">
      <span>客户管理</span>
      <span> / 客户列表</span>
    </div>
    <div class="app-container">
      <el-card class="box-card noborder min1370">
        <div class="tables ">
          <div class="empty" v-if="tableData.total==0 && !isSkeleton">
            <img src="@/assets/images/project/empty.png">
            <div class="p1">抱歉，没找到相关数据</div>
            <div class="p2">建议调整关键词或筛选条件，重新搜索</div>
            <div class="btn btn_primary h36 w88" @click="opennew">添加客户</div>
            <div class="btn btn_primary btn_shallow h36 w88" @click="pldrs">批量导入</div>
          </div>
          <div class="table_search">
            <div>
              <el-form ref="queryForm" :model="searchParam" :inline="true" size="small">
                <el-form-item>
                  <el-cascader
                    ref="address1"
                    :class="[`select-adaptive-${inputID1}`]"
                    :options="addressList"
                    :props="addressProps"
                    v-model="address"
                    @change="iptAdaptive(inputID1,true)"
                    placeholder="地区选择"
                    collapse-tags
                    style="width: 130px;"
                    clearable></el-cascader>
                </el-form-item>
                <el-form-item prop="companyNatures">
                  <el-select v-model="searchParam.companyNatures" :class="[`select-adaptive-${inputID2}`]" style="width: 130px;" @change="iptAdaptive(inputID2,true)" multiple collapse-tags clearable class="form-content-width" placeholder="客户性质">
                    <el-option v-for="(item, index) in companyNaturelist" :key="index" :label="item.dictLabel" :value="item.dictValue" />
                  </el-select>
                </el-form-item>
                <el-form-item prop="isOn">
                  <el-select v-model="searchParam.isOn"  :class="[`select-adaptive-${inputID3}`]" filterable clearable style="width: 130px;" @change="iptAdaptive(inputID3)" class="form-content-width" placeholder="上市公司">
                    <el-option v-for="(item, index) in isMajorlist" :key="index" :label="item.dictLabel" :value="item.dictValue" />
                  </el-select>
                </el-form-item>
                <el-form-item prop="creditLevels">
                  <el-select v-model="searchParam.creditLevels" :class="[`select-adaptive-${inputID4}`]" style="width: 130px;" @change="iptAdaptive(inputID4,true)" multiple collapse-tags clearable class="form-content-width" placeholder="资信评级">
                    <el-option v-for="(item, index) in creditLevellist" :key="index" :label="item.dictLabel" :value="item.dictValue" />
                  </el-select>
                </el-form-item>
                <el-form-item prop="companyName">
                  <!--<div class="newSearch">-->
                    <!--<el-input type="text" v-model="searchParam.companyName" clearable placeholder="输入企业名称查询"  @change="clearname" >-->
                      <!--<i slot="prefix" class="el-input__icon"><img src="@/assets/images/project/sousuo.png" width="16px" @click="handleCurrentChange(1)"></i>-->
                    <!--</el-input>-->
                  <!--</div>-->
                  <!-- 未点击前的输入框样式 -->
                  <div class="normal-search-container" @click="showSearchBox = true" v-if="!showSearchBox">
                    <img src="@/assets/images/enterprise/enterprise-search-icon.svg" alt="">
                    <span>搜索</span>
                  </div>
                  <!-- 输入框展开后样式 -->
                  <transition @enter="onEnter" appear mode="out-in">
                    <div class="cooperate-name enterprise-search-container" id="focus1" v-if="showSearchBox">
                      <el-input clearable @clear="handleSearch" @focus="clickFocus('focus1')" @blur="clickFocus('focus1')" v-model="searchParam.companyName"
                                placeholder="输入关键词查询"></el-input>
                      <span @click="handleSearch">搜索</span>
                    </div>
                  </transition>
                </el-form-item>
              </el-form>
            </div>

            <div class="dc">
              <div class="total">共{{tableData.total}}条</div>
              <div class="btn-export" @click="pldrs"><img src="@/assets/images/project/import.png">批量导入</div>
              <div class="btn btn_primary h32 p10" @click="opennew"><div class="img img1"></div>添加客户</div>
            </div>
          </div>
          <skeleton v-if="isSkeleton"></skeleton>
          <div class="table-item">
            <el-table v-show="!isSkeleton&&tableData.total > 0" class="fixed-table" v-horizontal-scroll="'hover'" ref="thistables"
                      :data="tableData.rows"
                      stripe border
                      style="width: 100%">
              <el-table-column
                prop="index"
                label="序号"
                fixed="left"
                width="60">
                <template slot-scope='scope'>
                  <span>{{ (searchParam.pageNum - 1) * searchParam.pageSize + scope.$index + 1 }}</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="date"
                label="企业名称"
                fixed="left"
                width="316">
                <template slot-scope="scope">
                  <div class="ps1">
                    <div class="wordprimary ps2" @click="toDetail(scope.row,'business')" v-html="scope.row.companyName"></div>
                    <div class="ps3">
                      <el-tooltip class="item" effect="dark" content="写跟进" placement="top" transition="" :open-delay="450">
                        <div  @click="toDetail(scope.row,'gjjl')"><img class="i" src="@/assets/images/project/edit_1.png"><img class="o" src="@/assets/images/project/edit_11.png"></div>
                      </el-tooltip>
                      <el-tooltip class="item" effect="dark" content="编辑信息" placement="top" transition="" :open-delay="450">
                        <div  @click="toDetail(scope.row,'business')"><img class="i" src="@/assets/images/project/edit_2.png"><img class="o" src="@/assets/images/project/edit_22.png"></div>
                      </el-tooltip>
                    </div>
                  </div>
                </template>

              </el-table-column>
              <el-table-column
                prop="cooperationProject"
                label="合作项目"
                width="90">
                <template slot-scope="scope">
                  {{scope.row.cooperationProject || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="followProject"
                label="跟进项目"
                width="90">
                <template slot-scope="scope">
                  {{scope.row.followProject || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="reserveProject"
                label="储备项目"
                width="90">
                <template slot-scope="scope">
                  {{scope.row.reserveProject || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="legalPerson"
                label="法定代表人"
                width="110">
                <template slot-scope="scope">
                  {{scope.row.legalPerson || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="registerAddress"
                label="注册地区"
                width="160">
                <template slot-scope="scope">
                  {{scope.row.registerAddress || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="registerCapitalStr"
                label="注册资本金（万元）"
                width="160">
                <template slot-scope="scope">
                  <span v-if="scope.row.registerCapital && scope.row.registerCapital>0">{{scope.row.registerCapital}}</span><span v-else>--</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="creditLevel"
                label="企业主体评级" width="120">
                <template slot-scope="scope">
                  {{scope.row.creditLevel || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="isOn"
                label="上市公司" width="90">
                <template slot-scope="scope">
                  {{scope.row.isOn == 1?"是":"否"}}
                </template>
              </el-table-column>
              <el-table-column
                prop="isMajor"
                label="局级大客户" width="90">
                <template slot-scope="scope">
                <span v-if="scope.row.isMajor != null">
                {{scope.row.isMajor == 1?"是":"否"}}
                </span>
                  <span v-else>--</span>
                </template>
              </el-table-column>
              <el-table-column
                prop="customerLevel"
                label="客户等级" width="90">
                <template slot-scope="scope">
                  {{scope.row.customerLevel || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="companyNature"
                label="客户性质" width="90">
                <template slot-scope="scope">
                  {{scope.row.companyNature || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="companyLevel"
                label="客户级别" width="90">
                <template slot-scope="scope">
                  {{scope.row.companyLevel || '--'}}
                </template>
              </el-table-column>
              <el-table-column
                prop="address"
                label="企业母公司" width="200">
                <template slot-scope="scope">
                  <div class="">{{scope.row.superCompany || '--'}}</div>
                </template>
              </el-table-column>
              <el-table-column :key="keys"
                               prop="mainBusiness"
                               label="主营业务" width="300">
                <template slot-scope="scope">
                  <div v-if="scope.row.mainBusiness == null || scope.row.mainBusiness == ''">--</div>
                  <div v-if="scope.row.mainBusiness1">
                    <div class="box"  v-if="scope.row.sq1==true">{{scope.row.mainBusiness1}}...<span @click="sq1(scope.row,false)">更多</span></div>
                    <div class="box"  v-else>{{scope.row.mainBusiness}}<span @click="sq1(scope.row,true)">收起</span></div>
                  </div>
                  <div v-else>{{scope.row.mainBusiness}}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="companyAttribute" :key="keys+2"
                label="发包属性" width="300">
                <template slot-scope="scope">
                  <div v-if="scope.row.companyAttribute == null || scope.row.companyAttribute == ''">--</div>
                  <div v-if="scope.row.companyAttribute1">
                    <div class="box"  v-if="scope.row.sq2==true">{{scope.row.companyAttribute1}}...<span @click="sq2(scope.row,false)">更多</span></div>
                    <div class="box"  v-else>{{scope.row.companyAttribute}}<span @click="sq2(scope.row,true)">收起</span></div>
                  </div>
                  <div v-else>{{scope.row.companyAttribute}}</div>
                </template>
              </el-table-column>
              <el-table-column
                prop="followUser"
                label="跟进人" width="110">
                <template slot-scope="scope">
                  {{scope.row.followUser || '--'}}
                </template>
              </el-table-column>
            </el-table>
          </div>
          <div class="bottems" v-if="tableData.total>searchParam.pageSize">
            <el-pagination
              background
              :page-size="searchParam.pageSize"
              :current-page="searchParam.pageNum"
              @current-change="handleCurrentChange"
              layout="prev, pager, next"
              :total="tableData.total">
            </el-pagination>
          </div>
        </div>
        <el-dialog
          class="popups"
          :visible.sync="dialogVisible"
          width="534px"
          :close-on-click-modal="false"
          @close="resetForm('ruleForm')"
        >
          <div class="poptitle">
            <img src="@/assets/images/economies/icon.png">
            <span>添加客户</span>
          </div>
          <el-form class="popform j" :model="queryParam" :rules="rules" ref="ruleForm" label-width="130px">
            <el-form-item label="企业名称：" class="row"  prop="companyName">
              <el-input type="text" placeholder="请输入" v-model="queryParam.companyName" @input="getCompany(1)"></el-input>
              <div class="resultlist infinite-list" v-if="showlist" id="box" v-infinite-scroll="load" style="overflow:auto">
                <div class="infinite-list-item" v-for="(item,index) in companData" @click="selCompany(item)"><span  v-html="item.name" :key="companypage"></span></div>
              </div>
            </el-form-item>
            <el-form-item label="客户等级：" class="row">
              <el-select  placeholder="请选择" v-model="queryParam.customerLevel">
                <el-option v-for="(item,index) in customerLevel" :key="index" :label="item.dictLabel" :value="item.dictValue"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="法定代表人：" class="row">
              <el-input type="text" placeholder="请输入" v-model="queryParam.legalPerson"></el-input>
            </el-form-item>
            <el-form-item label="注册资本（万）：" class="row">
              <el-input type="text" placeholder="请输入" v-model="queryParam.registerCapital" @input='number'></el-input>
            </el-form-item>
            <el-form-item label="企业注册地：" class="row">
              <el-cascader :props="props" @change="getAddr($event)" ref="address" v-model="queryParam.address" :options="addressList" clearable></el-cascader>
            </el-form-item>
            <el-form-item label="统一社会信用代码：" class="row">
              <el-input type="text" placeholder="请输入" v-model="queryParam.creditCode"></el-input>
            </el-form-item>
            <div class="popbot">
              <div class="wordprimary" @click="toct">前往城投平台寻找客户线索></div>
              <div class="btn btn_cancel h32" @click="resetForm('ruleForm')">返回</div>
              <div class="btn btn_primary h32" @click="submitForm('ruleForm')">添加</div>
            </div>
          </el-form>
        </el-dialog>
      </el-card>
    </div>
    <batchimport v-if="pldr" :importtype="types" @cancels="cancelimport" @getdatas="handleCurrentChange(1)"></batchimport>
  </div>
</template>

<script>
  import { getToken } from '@/utils/auth'
  import '@/assets/styles/project.scss'
  import { addCustomer, getCustomerList, importData } from '@/api/custom/custom'
  import { getDictType, getEnterprise } from '@/api/main'
  import prvinceTree from '@/assets/json/provinceTree'
  import batchimport from '../../project/projectList/component/batchImport'
  import skeleton from '../../project/projectList/component/skeleton'
  import { encodeStr } from '@/assets/js/common'
  import { v4 } from "uuid";
  import gsap from "gsap";
  export default {
  name: 'CustomList',
  components:{batchimport,skeleton},
  data() {
    return{
      encodeStr,
      pldr: false,
      types:'custom',
      searchParam:{
        companyName:'',
        pageNum:1,
        pageSize:20
      },
      address:'',
      props:{ checkStrictly: true, expandTrigger: 'hover' },
      dialogVisible:false,
      textarea:"",
      nowedit:-1,//当前正在编辑的文本
      tipslit:[],//项目标签
      tipsvalue:"",//标签填写内容
      tableData: [],//列表
      companData:[],//联想企业列表
      addressProps: {
        multiple: true,
        expandTrigger: 'hover'
      },
      //上市公司
      isMajorlist:[
        {
          dictValue: 0,
          dictLabel:'否',
        },
        {
          dictValue: 1,
          dictLabel:'是',
        }
      ],
      companyNaturelist:[],  //客户性质
      creditLevellist:[],  //资信评级
      customerLevel:[],//客户等级
      addressList:[],//地区
      //添加客户
      queryParam:{
        companyId:'',//jsk企业id
        companyName:'',//客户名称（企业名称
        customerLevel:'',//客户等级
        legalPerson:'',//法定代表人
        registerCapital:'',//注册资本
        registerAddress:'',//企业注册地址
        creditCode:'',//社会统一信用代码
        address:'',//选择的地址
        provinceId:'',
        cityId:'',
        districtId:'',
      },
      rules:{
        companyName:[{ required: true, message: '请输入非空格字符！', trigger: 'blur' },]
      },
      //批量导入
      action: process.env.VUE_APP_BASE_API + "/customer/importData",
      fileList: [],
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      // isNew:true,
      showlist:false,
      keys:1,
      isSkeleton:true,
      companypage:1,
      isscroll:false,
      inputID1:this.getUid(),
      inputID2:this.getUid(),
      inputID3:this.getUid(),
      inputID4:this.getUid(),
      showSearchBox: false
    }
  },
  created() {
    if(this.$route.query.key){
      this.searchParam.companyName=this.$route.query.key;
    }
    if(this.$route.query.type === '1'){
      this.searchParam.companyNatures=['国有企业']
    }
    if(this.$route.query.type === '2'){
      this.searchParam.companyNatures=['央企']
    }
    if(this.$route.query.type ==='3'){
      this.searchParam.companyNatures=['事业单位','机关单位']
    }
    this.$watch(() => this.$route.params,() => {
        this.getCustomerList()
        this.getDictType()
        this.prvinceTree()
        this.handleQuery()
        this.searchParam.companyName=''
      },
      // 组件创建完后获取数据，
      // 此时 data 已经被 observed 了
      { immediate: true }
    )
  },
  methods:{
    onEnter(el, done) {
      gsap.from(el, {
        opacity: 0,
        width: 0,
      });
      gsap.to(el, {
        opacity: 1,
        width: 242,
        onComplete() {
          //  完成动画聚焦输入框
          el.querySelector("input").focus();
          done();
        }
      });
    },
    async handleQuery() {
      let [type1,type2] = await Promise.all([
        getDictType('company_nature_type'),
        getDictType('credit_level_type'),
      ])
      if(type1.code==200){
        type1.data.forEach(item => {
          this.companyNaturelist.push({dictLabel:item.dictLabel,dictValue:item.dictLabel})
        })
      }
      if(type2.code==200){
        type2.data.forEach(item => {
          this.creditLevellist.push({dictLabel:item.dictLabel,dictValue:item.dictLabel})
        })
      }
    },
    sq1(item,sq){
      this.$nextTick(()=>{
        item.sq1 = sq
        this.keys++ ;
      })
    },
    sq2(item,sq){
      this.$nextTick(()=>{
        item.sq2 = sq
        this.keys++ ;
      })
    },
    handleALL(event){
      var one = document.getElementById("box");
      if(one){
        if(!one.contains(event.target)){
          this.showlist = false
        }
      }
    },
    toct(){
      this.dialogVisible = false
      this.$router.push({path:'/macro/urban'})
    },
    getDictType(){
      //获取客户等级
      getDictType('customer_level_type').then(result=>{
        this.customerLevel = result.code == 200 ? result.data:[]
      })
    },
    pldrs(){
      this.pldr = true
    },
    cancelimport(){
      this.pldr = false
    },
    //获取客户列表
    getCustomerList(){
      let params=this.searchParam
      if(this.address.length > 0){
        let arr = this.$refs.address1.getCheckedNodes();
        let provinceCode = [],cityCode = [],countyCode = [];
        for (var i in arr) {
          if (arr[i].parent) {
            if (!arr[i].parent.checked) {
              arr[i].hasChildren && cityCode.push(arr[i].value);
              !arr[i].hasChildren && countyCode.push(arr[i].value);
            }
          } else {
            provinceCode.push(arr[i].value)
          }
        }
        if(provinceCode.length > 0){
          params.provinceIds=provinceCode
        }
        if(cityCode.length > 0){
          params.cityIds=cityCode
        }
        if(countyCode.length > 0){
          params.districtIds=countyCode
        }
      }else {
        if(params.provinceIds){
          delete params.provinceIds
        }
        if(params.cityIds){
          delete params.cityIds
        }
        if(params.districtIds){
          delete params.districtIds
        }

      }
      getCustomerList(params).then(result=>{
        this.isSkeleton = false
        this.tableData = result
        this.tableData.rows.forEach(item=>{
          item.registerCapital = item.registerCapital == null?null: item.registerCapital.replace(/^\D*(\d*(?:\.\d{0,6})?).*$/g, '$1')
          if(item.mainBusiness != "" && item.mainBusiness != null && item.mainBusiness.length>84){
            item.mainBusiness1 = item.mainBusiness.substring(0,81)
            item.sq1 = true
          }else{
            item.sq1 = false
          }
          if(item.companyAttribute != "" && item.companyAttribute != null && item.companyAttribute.length>84){
            item.companyAttribute1 = item.companyAttribute.substring(0,81)
            item.sq2 = true
          }else{
            item.sq2 = false
          }
          // console.log(item)
      })
      })
    },
    //跳转到客户详情
    toDetail(row,type){
      let customerId = row.customerId
      let companyId = row.companyId
      let path = type
      // if(type == "" && companyId == null){
      //   path = 'business'
      // }
      this.$router.push({path:'/enterprise/'+encodeStr(companyId),query:{customerId:customerId,path:path}})
    },
    handleSearch(){
      this.$nextTick(() => {
        this.searchParam.pageNum = 1
        this.getCustomerList()
      })
    },
    clearname(value){
      if(value == ""){
        this.handleCurrentChange(1)
      }
    },
    //翻页
    handleCurrentChange(val) {
      this.isSkeleton = true
      this.pldr=false
      // this.isNew = false
      this.searchParam.pageNum=val
      this.getCustomerList()
    },
    //打开新建窗口
    opennew(){
      this.dialogVisible = true
    },
    getAddr(obj){
      if(obj.length == 0){
        this.queryParam.provinceId = ''
        this.queryParam.cityId = ''
        this.queryParam.districtId = ''
        return false
      }
      let labelString = this.$refs.address.getCheckedNodes()[0].pathLabels.join("-");
      this.queryParam.registerAddress = labelString
      this.queryParam.provinceId = obj[0]
      this.queryParam.cityId = obj.length>=1 ? obj[1]:''
      this.queryParam.districtId = obj.length>=2 ? obj[2]:''
    },
    //获取建设库客户
    getCompany(value){
      this.queryParam.companyId = null
      if(value == 1){
        this.companData = []
        this.companypage = 1
      }
      if (this.queryParam.companyName.length>=2){
        let param = {
          keyword:this.queryParam.companyName,
          page:{
            limit:20,
            page:this.companypage
          }
        }
        getEnterprise(JSON.stringify(param)).then(result=>{
          if(result.code != 200){
            return false
          }
          if(result.data.list != null && result.data.list.length>0){
            this.isscroll = true
            if (this.companData.length===0) {
              this.companData = result.data.list
            } else {
              let arr2 = result.data.list
              arr2.unshift(2, 0);
              Array.prototype.splice.apply(this.companData, arr2);
            }
            if(this.companData.length===0) {
              this.showlist = false
            }else{
              this.showlist = true
            }
            this.companypage += 1
          }else{
            this.isscroll = false
          }
        })
      }
    },
    load(){
      if(this.isscroll){
        this.getCompany(2)
      }
    },
    selCompany(item){
      this.queryParam.companyId = item.jskEid
      this.queryParam.companyName = item.name.replace(/<[^>]+>/g, '')
      this.queryParam.legalPerson = item.legalPerson
      let registeredCapitalStr = ""
      if(item.registeredCapitalStr == "0" || item.registeredCapitalStr == 0){
        registeredCapitalStr = ''
      }else{
        registeredCapitalStr = item.registeredCapitalStr
      }
      this.queryParam.registerCapital = registeredCapitalStr
      this.queryParam.creditCode = item.creditCode
      this.queryParam.provinceId = item.provinceId
      this.queryParam.cityId = item.cityId
      this.queryParam.districtId = item.cityId

      let list = []
      if(item.provinceId != null && item.provinceId != "")
        list.push(item.provinceId)
      if(item.cityId != null && item.cityId != "")
        list.push(item.cityId)
      if(item.districtId != null && item.districtId != "")
        list.push(item.districtId)
      this.$nextTick(()=>{
        this.queryParam.address = list
        let _this = this
        setTimeout(function() {
          if(_this.$refs.address){
            _this.queryParam.registerAddress = _this.$refs.address.getCheckedNodes()[0].pathLabels.join("-")
          }
        },1000)
      })
      this.showlist = false
    },
    //添加客户
    submitForm(formName) {
      // if(this.queryParam.companyId=="" || this.queryParam.companyId == null){
      //   this.$message.error({message:'请选择企业！',showClose:true})
      //
      //   return;
      // }
      this.$refs[formName].validate((valid) => {
        if (valid) {
          addCustomer(this.queryParam).then(result=>{
            if(result.code == 200){
              this.$message.success('添加成功！')
              this.dialogVisible = false
              this.handleCurrentChange(1)
              this.resetForm('ruleForm')
            }else{
              this.$message.error(result.msg)
            }
          })
        } else {
        }
      });
    },
    resetForm(formName) {
     this.queryParam = {
        companyId:'',//jsk企业id
        companyName:'',//客户名称（企业名称
        customerLevel:'',//客户等级
        legalPerson:'',//法定代表人
        registerCapital:'',//注册资本
        registerAddress:'',//企业注册地址
        creditCode:'',//社会统一信用代码
        address:'',//选择的地址
        provinceId:'',
        cityId:'',
        districtId:'',
      },
      this.dialogVisible = false
      this.showlist = false
    },

    //地区
    async prvinceTree() {
      // await axios.post("https://files.jiansheku.com/file/json/common/provinceTree.json", {}, {
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if (res.data.code == 200) {
      //     console.log(res.data.data)
      //   }
      // })
      // console.log(prvinceTree)
      this.addressList = prvinceTree;
      this.getadd(this.addressList)
    },
    //处理注册地数据
    getadd(row) {
      this.addrcallback(row,this.getadd)
    },
    addrcallback(row,callback){
      if(row){
        row.forEach(item => {
          item.value = item.id
            callback &&  callback(item.children)
        })
      }
    },
    //输入数字
    number(value){
      if(value == '')
        this.queryParam.registerCapital = value
      else
         this.queryParam.registerCapital = value.replace(/^\D*(\d*(?:\.\d{0,6})?).*$/g, '$1')//输入6位小数
    },
    iptAdaptive(uid, multiple = false) {
      multiple ? this.multipleAdaptiveHandle(uid) : this.iptAdaptiveHandle(uid);
    },
    getUid() {
      return v4();
    },
    // 多选处理
    async multipleAdaptiveHandle(uid) {
      try {
        await this.$nextTick();
        const dom = document.querySelector(`.select-adaptive-${uid}`);
        const iptChild = dom.querySelector(".el-input__inner");
        if (dom) {
          const textContainer = document.createElement("span");
          const textName = `text-${uid}`;
          textContainer.classList.add(textName);
          const selectChildren = dom.querySelectorAll(".el-tag");
          if (selectChildren.length) {
            let width = 0;
            selectChildren.forEach(item => {
              const text = item.textContent;
              const itemInfo = window.getComputedStyle(item);
              textContainer.style.setProperty("visibility", "hidden");
              textContainer.style.setProperty("display", "inline-block");
              textContainer.style.setProperty("font-size", "14px");
              textContainer.style.setProperty("padding", itemInfo.padding);
              textContainer.style.setProperty("box-sizing", "border-box");
              textContainer.textContent = text;
              document.body.append(textContainer);
              width += textContainer.offsetWidth + parseInt(itemInfo.marginLeft) + parseInt(itemInfo.marginRight);
              textContainer.remove();
            });
            dom.style.setProperty("width", `${width + 50}px`);
            this.handleSearch();
            return;
          }
          textContainer.style.setProperty("visibility", "hidden");
          textContainer.style.setProperty("display", "inline-block");
          textContainer.style.setProperty("font-size", "14px");
          textContainer.style.setProperty("padding", "0px 8px");
          textContainer.style.setProperty("box-sizing", "border-box");
          textContainer.textContent = iptChild.getAttribute("placeholder");
          document.body.append(textContainer);
          // let containerWidth = textContainer.offsetWidth + 12 + 8;
          let containerWidth = 130;
          textContainer.remove();
          dom.style.setProperty("width", `${containerWidth}px`);
          this.handleSearch();
        }

      } catch (error) {
        console.log(error);
      }
    },
    // 单选处理
    async iptAdaptiveHandle(uid) {
      try {
        await this.$nextTick();
        const dom = document.querySelector(`.select-adaptive-${uid}`);
        const realStyles = window.getComputedStyle(dom);
        if (dom) {
          const iptChild = dom.querySelector(".el-input__inner");
          const textContainer = document.createElement("span");
          const textName = `text-${uid}`;
          textContainer.classList.add(textName);
          textContainer.style.setProperty("visibility", "hidden");
          textContainer.style.setProperty("display", "inline-block");
          textContainer.style.setProperty("font-size", "14px");
          const hasPadding = (parseInt(realStyles.paddingLeft) || parseInt(realStyles.paddingRight)) ? true : false;
          hasPadding ? textContainer.style.setProperty("padding", "0px 8px") : null;
          textContainer.style.setProperty("box-sizing", "border-box");
          textContainer.textContent = iptChild.value ? iptChild.value : iptChild.getAttribute("placeholder");
          document.body.append(textContainer);
          // let containerWidth = textContainer.offsetWidth + 12 + 8;
          let containerWidth=0
          if(iptChild.value){
            containerWidth = 70;
          }else {
            containerWidth = 130;
          }

          textContainer.remove();
          dom.style.setProperty("width", `${containerWidth}px`);
        }
        this.handleSearch();
      } catch (error) {

      }
    },
    clickFocus(e) {
      document.getElementById(e).classList.toggle('span-ba');
    }
  }
}
</script>

<style lang="scss" scoped>
  .app-container{
    height: calc(100vh - 134px)
  }
.box-card{
  @import "@/assets/styles/search-common.scss";
  padding-top: 16px;
  width: 100%;
  height: 100%;
  ::v-deep .el-form{
    .el-input{
      line-height: 32px;
      .el-input__inner{
        height: 32px;
        line-height: 32px;
        border-radius: 4px;
        border: 0;
      }
    }
    .is-focus{
      .el-input__inner{
        background: #F4F6F9;
      }
    }

  }

}
.box{
  position: relative;
  >span{
    position: absolute;
    right: 10px;
    bottom: 0;
    color: #0081FF;
    cursor: pointer;
    &:hover{
      color: #006AD1;
    }
  }
}
  .dc{
    font-size: 12px;
    color: #3D3D3D;
    font-weight: 400;
    position: relative;
    &::after{
      content: ' ';
      width: 2px;
      height: 2px;
      background: rgba(35,35,35,0.4);
      border-radius: 50%;
      position: absolute;
      top: 16px;
      left: 14px;
    }
    >div{
      display: inline-block;
      margin-left: 20px;
    }
  }
  .img.img1{
    margin-right: 2px;
    background: url('../../../../src/assets/images/project/add_2.png')no-repeat center center;
    background-size: 100%;
  }
  .w88{
    width: 88px;
  }
  .tables{
    position: relative;
    min-height: calc(100vh - 134px);
    /*overflow: auto;*/
    .empty{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      .btn{
        margin-right: 8px;
        margin-top: 16px;
      }
    }
    .table_search{
      ::v-deep .el-cascader{
        height: 32px;
        line-height: 32px;
        .el-input{
          input{
            height: 32px !important;
          }
        }
        .el-cascader__tags{
          flex-wrap: inherit;
          margin-top: 1px;
          .el-tag{
            /*max-width: 120px;*/
          }
        }
        .el-input__suffix{
          top: 1px;
        }
      }
      .normal-search-container {
        margin-left: 12px;
        display: flex;
        align-items: center;
        cursor: pointer;
        height: 34px;
        &:hover {
          & > span {
            color: #0081ff;
          }
        }

        & > img {
          width: 16px;
          height: 16px;
          margin-left: 12px;
        }

        & > span {
          color: #232323;
          color: rgba(35, 35, 35, 0.4);
          font-weight: 400;
          margin-left: 8px;
          line-height: 22px;
          font-size: 14px;
        }
      }
      .cooperate-name {
        margin-left: 12px;
        display: flex;
        border-radius: 2px;
        border: 1px solid #d9d9d9;
        line-height: 34px;
        height: 34px;
        float: left;
        span {
          width: 60px;
          height: 32px;
          line-height: 32px;
          font-size: 14px;
          background: #f5f5f5;
          text-align: center;
          color: #0081ff;
          border: 1px solid #efefef;
          border-left: 0;
          cursor: pointer;
        }
        &.span-ba {
          border: 1px solid #0081ff;
          span {
            color: #ffffff;
            background: #0081ff;
            border: 1px solid #0081ff;
          }
        }
        ::v-deep .el-input {
          flex: 1;
        }
        ::v-deep .el-input__inner {
          border: 0;
          line-height: 32px;
          height: 32px;
          position: absolute;
          top: 0;
          padding-right: 28px;
          font-size: 12px;
          padding-left: 8px;
        }
      }
    }
  }
  .ps1{
    display: flex;
    justify-content: space-between;
    .ps2{
      width: 350px;
    }
    .ps3{
      width: 60px;
      display: flex;
      justify-content: right;
      >div{
        margin-left: 12px;
        >img{
          float: right;
          margin: 3px 0 0 4px;
          width: 14px;
        }
        .i{
          display: inline-block;
        }
        .o{
          display: none;
        }
        &:hover{
          cursor: pointer;
          .i{
            display: none;
          }
          .o{
            display: inline-block;
          }
        }
      }
    }
  }
  .popbot{
    .wordprimary{
      display: inline;
      padding-right: 26px;
    }
  }
  .app-container{
    height: auto;
  }
  .searchInput{
    width: 240px;
  }
</style>
