<template>
  <div class="app-container urban">
    <div class="content">
      <div class="flex-box query-box">
        <div class="flex-box query-params">
          <span class="common-title">城投平台</span>
        </div>
      </div>
      <div class="search">
        <el-radio v-model="radio" label="1">含下属辖区</el-radio>
        <el-radio v-model="radio" label="2">本级</el-radio>
        <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>
        <el-input class="search-input" placeholder="输入企业名称关键词" v-model="queryParams.key">
          <template slot="prepend"><i class="el-icon-search"></i></template>
          <el-button slot="append">搜索</el-button>
        </el-input>
      </div>
      <div class="list-box">
        <div class="item">
          <div class="left">
            <p>115<span>家</span></p>
            <span>平台家数</span>
          </div>
          <img src="@/assets/images/urban/img1.png">
        </div>
        <div class="item">
          <div class="left">
            <p>18,737.90<span>亿元</span></p>
            <span>授信余额</span>
          </div>
          <img src="@/assets/images/urban/img2.png">
        </div>
        <div class="item">
          <div class="left">
            <p>18,737.90<span>亿元</span></p>
            <span>资产总额</span>
          </div>
          <img src="@/assets/images/urban/img3.png">
        </div>
        <div class="item">
          <div class="left">
            <p>18,737.90<span>亿元</span></p>
            <span>营收账款</span>
          </div>
          <img src="@/assets/images/urban/img4.png">
        </div>
        <div class="item">
          <div class="left">
            <p>18,737.90<span>亿元</span></p>
            <span>非标余额</span>
          </div>
          <img src="@/assets/images/urban/img5.png">
        </div>
      </div>
    </div>
    <div class="content">
      <div class="flex-box query-box">
        <div class="flex-box query-params">
          <span class="common-title">主要指标</span>
        </div>
        <div class="flex-box query-ability">
          <span class="flex-box"><img src="@/assets/images/ability_excel.png">导出EXCEL</span>
        </div>
      </div>
      <div class="table-item">
        <el-table
          v-loading="tableLoading"
          :data="tableData"
          element-loading-text="Loading"
          border
          fit
          highlight-current-row
        >
          <el-table-column label="序号" width="50" align="left" fixed>
            <template slot-scope="scope">{{ pageIndex * pageSize - pageSize + scope.$index + 1 }}</template>
          </el-table-column>
          <el-table-column prop="name" label="公司名称" width="250" fixed>
            <template slot-scope="scope">{{ scope.row.name }}
              <span class="table-span" style="color: #3D3D3D;" v-if="scope.row.state === 0"><img src="@/assets/images/urban/rl_icon1.png"/>认领</span>
              <span class="table-span" style="color: rgba(35,35,35,0.4);" v-if="scope.row.state === 1"><img src="@/assets/images/urban/rl_icon2.png"/>已认领</span>
            </template>
          </el-table-column>
          <el-table-column prop="value" label="区域" width="100" />
          <el-table-column prop="pm" label="招标数量" sortable  width="120" />
          <el-table-column prop="bl" label="城投拿地" sortable width="140" />
          <el-table-column prop="bl" label="供应商" sortable width="170" />
          <el-table-column prop="bl" label="主体评级" sortable width="140" />
          <el-table-column prop="bl" label="债券余额（亿元）" sortable width="140" />
          <el-table-column prop="bl" label="行政级别" width="140" />
          <el-table-column prop="bl" label="股东背景" width="140" />
          <el-table-column prop="bl" label="股权关系" width="140" />
          <el-table-column prop="bl" label="平台重要性" width="140" />
          <el-table-column prop="bl" label="城投业务类型" width="140" >
            <template slot="header" slot-scope="scope">
              <span>城投业务类型
                <el-tooltip popper-class="tips" effect="light" content="   根据主营业务构成划分为土地开发整理、基础设施建设、交通建设运营、棚改保障房建设、公用事业等8大类型。" placement="top">
                  <i class="el-icon-warning-outline"></i>
                </el-tooltip>
              </span>
            </template>
          </el-table-column>
          <el-table-column prop="bl" label="实控人" width="200" />
          <el-table-column prop="bl" label="最新报告期" width="120" />
          <el-table-column prop="bl" label="总资产（亿元）" sortable width="120" />
          <el-table-column prop="bl" label="归母净资产（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="货币资金（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="土地资产（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="受限资产（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="应收账款（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="其他应收款（亿元）" sortable width="160" />
          <el-table-column prop="bl" label="公益性＆准公益性主营占比（%）" width="160" />
          <el-table-column prop="bl" label="应收类款项来自政府占比（%）" width="160" />
          <el-table-column prop="bl" label="政府补助（亿元）" width="120" />
          <el-table-column prop="bl" label="专项应付款（亿元）" width="140" />
          <el-table-column prop="bl" label="营业收入（亿元）" width="140" />
          <el-table-column prop="bl" label="归母净利润（亿元）" width="140" />
          <el-table-column prop="bl" label="净资产收益率（%）" width="140" />
          <el-table-column prop="bl" label="经营现金流量净额（亿元）" width="160" />
          <el-table-column prop="bl" label="筹资现金流量净额（亿元）" width="160" />
          <el-table-column prop="bl" label="投资现金流量净额（亿元）" width="160" />
          <el-table-column prop="bl" label="总负债（亿元）" width="160" />
          <el-table-column prop="bl" label="有息债务（亿元）" width="160" />
          <el-table-column prop="bl" label="有息债务/总负债（%）" width="160" />
          <el-table-column prop="bl" label="资产负债率（%）" width="160" />
          <el-table-column prop="bl" label="综合融资成本（%）" width="160" />
          <el-table-column prop="bl" label="现金比率" width="160" />
          <el-table-column prop="bl" label="现金流量比率" width="160" />
          <el-table-column prop="bl" label="现金到期债务比" width="160" />
          <el-table-column prop="bl" label="授信余额/全部债务（%）" width="160" />
          <el-table-column prop="bl" label="EBITDA保障倍数" width="160" />
          <el-table-column prop="bl" label="私募债余额占比（%）" width="160" />
          <el-table-column prop="bl" label="一年内到期债权占比（%）" width="160" />
          <el-table-column prop="bl" label="债券余额/有息债务（%）" width="160" />
          <el-table-column prop="bl" label="借款余额（亿元）" width="160" />
          <el-table-column prop="bl" label="借款/有息债务（%）" width="160" />
          <el-table-column prop="bl" label="非标余额（亿元）" width="160" />
          <el-table-column prop="bl" label="非标余额/有息债务（%）" width="160" />
          <el-table-column prop="bl" label="对外担保金额（亿元）" width="160" />
          <el-table-column prop="bl" label="对外担保比例（%）" width="160" />
          <el-table-column prop="bl" label="所属开发区" width="160" />
          <el-table-column prop="bl" label="开发区类别" width="160" />
        </el-table>
      </div>
      <div class="pagination-box">
        <el-pagination background :current-page="pageIndex" :page-size="pageSize" :total="tableDataTotal" layout="prev, pager, next, jumper" @current-change="handleCurrentChange" @size-change="handleSizeChange" />
      </div>
    </div>
  </div>
</template>

<script>
  import dataRegion from '@/assets/json/dataRegion'
export default {
  name: 'Urban',
  data() {
    return {
      queryParams:{
        key:''
      },
      tableData:[
        {
          name:'重庆市江北区国有资本投资运营管理集团有限公司',
          pm:'1/306',
          value:'江北区',
          bl:'129.386',
          state:1
        },
        {
          name:'重庆市江北区国有资本投资运营管理集团有限公司',
          pm:'1/306',
          value:'江北区',
          bl:'129.386',
          state:0
        },
      ],
      tableLoading: false,
      pageIndex: 1,
      pageSize: 10,
      tableDataTotal: 120,
      radio:'2',
      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,
    }
  },
  watch:{
    searchState:{
      handler(newVal, olVal) {
        if (newVal) {
          setTimeout(() => {
            document.addEventListener('click', this.handleSearch);
          }, 0);
        } else {
          document.removeEventListener('click', this.handleSearch);
        }
      }
    }
  },
  created() {
    this.dataRegion()
  },
  methods: {
    //地区
    async 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;
    },
    // 重置页数
    handleSizeChange(val) {
      this.pageIndex = 1
      this.pageSize = val
      // this.querySubmit()
    },
    // 跳转指定页数
    handleCurrentChange(val) {
      this.pageIndex = val
      // this.querySubmit()
    },
    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);
      }
    },
    active(index, item) {
      // this.selected.indexOf(item) 判断item下标是否为-1，
      // 是-1则数组中匹配不到该数据，添加
      // 不是-1则说明匹配到了，抹除
      if (this.selected.indexOf(item) !== -1) {
        this.selected.splice(this.selected.indexOf(item), 1); //取消
      } else {
        this.selected.push(item);//选中添加到数组里
      }
      console.log(JSON.parse(JSON.stringify(this.selected)));
    },
    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;
      }
    },
  },
}
</script>

<style lang="scss" scoped>
  .app-container{
    padding: 0;
  }
  .urban{
    .content{
      background: #ffffff;
      padding: 16px;
      margin-bottom: 16px;
      border-radius: 4px;
      .search{
        margin-top: 22px;
        .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: 99;
            .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;
              }
            }
          }
        }
        ::v-deep .search-input{
          /*::v-deep .el-input{*/
            width: 250px;
            height: 32px;
            .el-input-group__prepend:first-child{
              padding: 0;
              background-color:#ffffff;
              border-right: 0;
              padding-left: 8px;
              i{
                color:#0081FF;
              }
            }
            .el-input__inner{
              border-left: 0;
              height: 32px;
              line-height: 32px;
            }
            .el-input-group__append:last-child{
              width: 60px;
              padding: 0;
              text-align: center;
              background: #F5F5F5;
              color:#0081FF;
              border-left: 0;
            }
          /*}*/
        }

      }
      .table-item{
        margin-top: 22px;
      }
      .table-span{
        img{
          width: 16px;
          height: 16px;
          margin-bottom: -4px;
          margin-right: 5px;
          margin-left: 20px;
        }
      }
      .list-box{
        display: flex;
        justify-content: space-between;
        .item{
          margin-top: 24px;
          width: 19%;
          height: 96px;
          background: url("../../../assets/images/urban/icon_bg.png") no-repeat;
          background-size: 100%;
          .left{
            margin-left: 16px;
            float: left;
            margin-top: 24px;
            p{
              font-size: 26px;
              font-weight: 700;
              margin: 0;
              span{
                margin-left: 3px;
              }
            }
            span{
              font-size: 14px;
              color: #3D3D3D;
              font-weight: 400;
            }
          }
          img{
            float: right;
            margin-right: 16px;
            width: 41px;
            height: 42px;
            margin-top: 27px;
          }
        }
      }
    }
  }
</style>
