<template>
  <div class="corePersonnel">
    <head-form
      title="同地区城投"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    >
      <template slot="slot">
        <div class="search-box">
          <span style="cursor: pointer;" @click="handleSearch">筛选<i class="el-icon-caret-bottom" style="color:rgba(35,35,35,0.4);margin-left: 5px"></i></span>
          <div v-show="searchState" ref="showContent" class="search-main">
            <div class="item">
              <span class="wrap_label">行政等级</span>
              <div class="item_ckquery">
                <span :class="{color_text:xzdjCalss == ''}" @click="changeXZDJ('')">全部</span>
                <template v-for="(item,index) in xzdj">
                  <span :class="{color_text:index+1 === xzdjCalss}" @click="changeXZDJ(index+1)">{{item.name}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">城投业务类型</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in typeList">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">主体评级</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in ztpj">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">股东背景</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in gdbj">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">股权关系</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in gqgx">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">平台重要性</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in pt">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label" style="width: 78px;">开发区类别</span>
              <div class="item_ckquery">
                <span>全部</span>
                <template v-for="(item,index) in lfqType">
                  <span>{{item}}</span>
                </template>
              </div>
            </div>
            <div class="item">
              <span class="wrap_label">更多筛选</span>
              <div class="item_ckquery">
                <span :class="addresslength>0?'select-active':''">注册地区{{addresslength>0?(addresslength+'项'):''}}</span>
                <el-cascader ref="address" class="cascader-region" popper-class='cascader-region-addd'
                             @input="addressListbtn"  v-model="addressType" :options="addressList" :props="props" collapse-tags></el-cascader>
              </div>
            </div>
          </div>
        </div>
      </template>
    </head-form>

    <tables
      :tableLoading="tableLoading"
      :tableData="tableData"
      :forData="forData"
      :tableDataTotal="tableDataTotal"
      :queryParams="queryParams"
      @handle-current-change="handleCurrentChange"
      @sort-change="sortChange"
    >
      <template slot="companyName" slot-scope="data">
        <router-link :to="''+ data.row.companyId" style="color: #0081FF">{{ data.row.companyName }}</router-link>
      </template>
    </tables>

  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import dataRegion from '@/assets/json/dataRegion'
import {
  urbanInvestmentPage
} from '@/api/detail/party-a/urbanLnvestment'
export default {
  name: 'SameRegion',
  mixins: [mixin],
  components: {

  },
  data() {
    return {
      queryParams: {
        provinceId: 500000,
        cityId: 500100,
        pageNum: 1,
        pageSize: 15
      },
      forData: [
        {label: '企业名称', prop: 'companyName', width: '369', slot: true},
        {label: '区域', prop: 'area', width: '100'},
        {label: '主体评级', prop: 'bratingSubjectLevel', width: '110'},
        {label: '债劵余额（亿元）', prop: 'bondBalance', width: '130'},
        {label: '行政级别', prop: 'uipExecutiveLevel', width: '120'},
        {label: '股东背景', prop: 'shareholderBg', width: '120'},
        {label: '股权关系', prop: 'equityRelationship', width: '120'},
        {label: '平台重要性', prop: 'platformImportance', width: '120'},
        {label: '城投业务类型', prop: 'uipBusinessType', width: '120'},
        {label: '实控人', prop: 'actualController', width: '280'},
        {label: '最新报告期', prop: 'latestReportPeriod', width: '120'},
        {label: '总资产（亿元）', prop: 'totalAssets', width: '120'},
        {label: '归母净资产（亿元）', prop: 'belongNetAssets', width: '140'},
        {label: '货币资金（亿元）', prop: 'monetaryFunds', width: '130'},
        {label: '土地资产（亿元）', prop: 'landAssets', width: '130'},
        {label: '受限资产（亿元）', prop: 'restrictedAssets', width: '130'},
        {label: '应收账款（亿元）', prop: 'accountsReceivable', width: '130'},
        {label: '其他应收款（亿元）', prop: 'otherReceivable', width: '140'},
        {label: '公益性&准公益性主营占比（%）', prop: 'econData001', width: '200'},
        {label: '应收类款项来自政府占比（%）', prop: 'receivableFromGovRatio', width: '200'},
        {label: '政府补助（亿元）', prop: 'govSubsidy', width: '130'},
        {label: '专项应付款（亿元）', prop: 'specialPayable', width: '140'},
        {label: '营业收入（亿元）', prop: 'operatingIncome', width: '130'},
        {label: '所属开发区', prop: 'developmentZone', width: '120'}
      ],
      formData: [
        { type: 0, fieldName: 'penalizeReasonType', value: '', placeholder: '筛选', options: []},
        { type: 3, fieldName: 'keys', value: '', placeholder: '请输入关键词', options: []},
      ],
      xzdj:[
        {
          name:'省级',
          key:1,
        },
        {
          name:'地级市',
          key:2,
        },
        {
          name:'区县级',
          key:3,
        }
      ],
      selected:[],
      xzdjCalss:'',
      typeList:['土地开发整理','基础设施建设','棚改保障房建设','公用事业','文化旅游','交通建设运营','产投平台'],
      ztpj:['AAA','AA+','AA','A+','A','A-','BBB+','其他'],
      gdbj:['政府','财政','国资委','其他'],
      gqgx:['直接控股','间接控股'],
      pt:['重要平台','主要平台','一般平台'],
      lfqType:['国家级经开','国家级高新区','国家海关监管区域','国家级新区','国家边和区','其他国家级','省级新区','省级开发区'],
      props: {
        value: 'id',
        multiple: true,
      },
      addressList: [],
      addressType: [],
      addresslength: 0,
      searchState:false,
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0,
    }
  },
  created() {
    this.handleQuery()
  },
  computed: {

  },
  methods: {
    dataRegion() {
      // await axios.post("https://files.jiansheku.com/file/json/common/dataRegion.json", {}, {
      //   headers: {
      //     'Content-Type': 'application/json'
      //   }
      // }).then(res => {
      //   if (res.data.code == 200) {
      //     console.log(res.data.data)
      //   }
      // })
      var str = [];
      for (let x = 0; x < 3; x++) {
        for (let i = 0; i < dataRegion.length; i++) {
          if (dataRegion[i].regionLevel == x + 1 && x + 1 == 1) {
            str.push({
              'id': dataRegion[i].id,
              "label": dataRegion[i].regionName,
              "short": dataRegion[i].short,
              "value": dataRegion[i].parentId,
              "children": []
            });
          } else if (dataRegion[i].regionLevel == x + 1 && x + 1 == 2) {
            for (let j = 0; j < str.length; j++) {
              if (str[j].id == dataRegion[i].parentId) {
                str[j].children.push({
                  'id': dataRegion[i].id,
                  "label": dataRegion[i].regionName,
                  "short": dataRegion[i].short,
                  "value": dataRegion[i].parentId,
                  "children": []
                });
              }
            }
          } else if (dataRegion[i].regionLevel == x + 1 && x + 1 == 3) {
            for (let j = 0; j < str.length; j++) {
              for (let k = 0; k < str[j].children.length; k++) {
                if (str[j].children[k].id == dataRegion[i].parentId) {
                  str[j].children[k].children.push({
                    'id': dataRegion[i].id,
                    "label": dataRegion[i].regionName,
                    "short": dataRegion[i].short,
                    "value": dataRegion[i].parentId
                    // "children":[]
                  });
                }
              }
            }
          }
        }
      }
      this.addressList = str;
    },

    handleSearch(event){
      // this.searchState=!this.searchState;
      let dom = this.$refs.showContent;
      if (!dom.contains(event.target)) {
        this.searchState = !this.searchState;
        document.removeEventListener('click', this.handleSearch);
      }
    },
    changeXZDJ(index) {
      this.xzdjCalss = index;
    },
    addressListbtn() {
      let arr = this.$refs.address.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 || cityCode.length > 0 || countyCode.length > 0) {
        this.addresslength = provinceCode.length + cityCode.length + countyCode.length;
      } else {
        this.addresslength = 0;
      }
    },

    handleQuery(params){
      this.tableLoading = true
      let data = params ? params : this.queryParams
      urbanInvestmentPage(data).then(res => {
          this.tableData = res.data.list
          this.tableDataTotal = res.data.totalCount
        this.tableLoading = false
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.corePersonnel{
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
  .query-box{
    margin: 10px 0 20px;
  }
  .search-box{
    display: inline-block;
    margin-right: 32px;
    /*cursor: pointer;*/
    color:#232323;
    position: relative;
    .search-main{
      background: #ffffff;
      box-shadow: 0px 4px 10px 0px rgba(0,0,0,0.1);
      border-radius: 4px;
      width: 880px;
      height: 337px;
      padding: 16px;
      position: absolute;
      top: 25px;
      left: 0;
      z-index: 2001;
      .item{
        margin-bottom: 5px;
        display: flex;
        /*align-items: center;*/
        font-size: 14px;
        .wrap_label{
          color: rgba(35,35,35,0.8);
          margin-right: 12px;
          line-height: 30px;
        }
        .item_ckquery{
          position: relative;
          span{
            color: #232323;
            padding: 5px 12px;
            display: inline-block;
            cursor: pointer;
          }
          .color_text{
            background: #F3F4F5;
            border-radius: 4px;
            color: #0081FF;
          }
          .select-active{
            color: #0081FF;
          }
        }

        .cascader-region {
          position: absolute;
          left: 0;
          top: -6px;
          opacity: 0;
          line-height: 22px;
        }
      }
    }
  }
}
</style>
