<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-group ">
        <div class="filter-lable" style="width: 60px">
          搜索：
        </div>
        <div class="filter-width">
          <el-input v-model="KEYWORDS" placeholder="企业名称" class="filter-item" style="width: 150px;"/>
        </div>
      </div>
      <!--      <div class="filter-group ">-->
      <!--        <div class="filter-lable">-->
      <!--          企业类型：-->
      <!--        </div>-->
      <!--        <div class="filter-width">-->
      <!--          <SelectTree-->
      <!--            ref="corpoftype"-->
      <!--            :options="corpTypeList"-->
      <!--            :canparent="false"-->
      <!--            v-model="KEYQYLX"-->
      <!--            placeholder="请选择企业类型"-->
      <!--            style="width: 150px"-->
      <!--          />-->
      <!--        </div>-->
      <!--      </div>-->
      <div class="filter-group ">
        <div class="filter-lable" style="width: 60px">属地：</div>
        <el-select v-if="USER_LEVEL<0" v-model="PROVINCE" placeholder="省" clearable style="width: 100px" class="filter-item" >
          <el-option v-for="item in provinceList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" @click.native="getCityList(item.DICTIONARIES_ID)"/>
        </el-select>
        <el-select v-if="USER_LEVEL<1" v-model="CITY" placeholder="市" clearable style="width: 100px" class="filter-item" >
          <el-option v-for="item in cityList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" @click.native="getCountyList(item.DICTIONARIES_ID)"/>
        </el-select>
        <el-select v-if="USER_LEVEL<2" v-model="COUNTY" placeholder="区/县" clearable style="width: 100px" class="filter-item" >
          <el-option v-for="item in countyList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" @click.native="getVillageList(item.DICTIONARIES_ID)"/>
        </el-select>
        <el-select v-model="VILLAGE" placeholder="镇/街" clearable style="width: 100px" class="filter-item">
          <el-option v-for="item in villageList" :key="item.BIANMA" :label="item.NAME" :value="item.BIANMA" />
        </el-select>
      </div>
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="getQuery">
        搜索
      </el-button>
      <el-button v-waves class="filter-item" type="success" icon="el-icon-refresh" @click="goKeyReset">
        重置
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column
        :reserve-selection="true"
        type="selection"
        width="55"
        align="center"/>
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="CORP_NAME" label="企业名称" />
      <el-table-column prop="CODE" label="统一社会信用代码" />
      <el-table-column label="属地" >
        <template slot-scope="{row}">
          <span v-if="row.prvinceName">{{ row.prvinceName }}</span>
          <span v-if="row.cityName"> -- {{ row.cityName }}</span>
          <span v-if="row.countyName"> --{{ row.countyName }}</span>
          <span v-if="row.villageName"> -- {{ row.villageName }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="video_count" label="企业视频数" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button class="light-blue-btn" icon="el-icon-view" size="mini" @click="goDetail('List',row.CORPINFO_ID,row.CORP_NAME)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div/>
      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    </div>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import SelectTree from '@/components/SelectTree'
export default {
  components: { Pagination, SelectTree },
  directives: { waves },
  data() {
    return {
      USER_LEVEL: sessionStorage.getItem('user').LEVEL || -1,
      listLoading: true,
      add: true,
      del: true,
      edit: true,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      KEYWORDS: '',
      KEYQYLX: '',
      PROVINCE: '',
      CITY: '',
      COUNTY: '',
      VILLAGE: '',
      corpTypeList: [], // 请选择企业类型
      provinceList: [],
      cityList: [],
      countyList: [],
      villageList: [],
      varList: [],
      pd: []
    }
  },
  async created() {
    await this.getList()
    if (this.USER_LEVEL == -1) {
      this.getProvinceList()
    } else if (this.USER_LEVEL == 0) {
      this.getCityList(this.CITY_CODE)
    } else if (this.USER_LEVEL == 1) {
      this.getCountyList(this.CITY_CODE)
    } else if (this.USER_LEVEL == 2) {
      this.getVillageList(this.CITY_CODE)
    }
    this.getCorpType()
  },
  methods: {
    createRandom(minNum, maxNum) {
      return Math.floor(Math.random() * (maxNum - minNum + 1) + minNum)
    },
    getRowKey(row) {
      return row.CORPINFO_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    // 获取列表
    getList() {
      return new Promise((resolve) => {
        this.listLoading = true
        requestFN(
          '/corpinfo/videolistPage?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
          {
            KEYWORDS: this.KEYWORDS,
            KEYQYLX: this.KEYQYLX,
            PROVINCE: this.PROVINCE,
            CITY: this.CITY,
            COUNTY: this.COUNTY,
            VILLAGE: this.VILLAGE
          }
        ).then((data) => {
          this.listLoading = false
          this.varList = data.varList
          this.total = data.page.totalResult
          this.pd = data.pd
          this.CITY_CODE = data.CITY_CODE
          resolve()
        }).catch((e) => {
          this.listLoading = false
        })
      })
    },
    getProvinceList() {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: 'e725d2a91b8248f4b8f49889038df7de'
        }
      ).then((data) => {
        this.provinceList = data.list
      }).catch((e) => {
      })
    },
    getCityList(id) {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: id
        }
      ).then((data) => {
        this.cityList = data.list
      }).catch((e) => {
      })
    },
    getCountyList(id) {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: id
        }
      ).then((data) => {
        this.countyList = data.list
      }).catch((e) => {
      })
    },
    getVillageList(id) {
      requestFN(
        '/dictionaries/getLevels',
        {
          DICTIONARIES_ID: id
        }
      ).then((data) => {
        this.villageList = data.list
      }).catch((e) => {
      })
    },
    getCorpType() {
      requestFN(
        '/corptype/listAllCorpTypeMent',
        {
          tm: new Date().getTime(),
          DICTIONARIES_ID: '0'
        }
      ).then((data) => {
        this.corpTypeList = JSON.parse(data.zTreeNodes)
      })
        .catch((e) => {
          this.listLoading = false
        })
    },
    // 查看
    goCheck(ID) {
      this.$parent.activeName = 'IndexView'
      this.$parent.indexVal = ID
    },
    goDetail(page, ID, NAME) {
      this.$parent.activeName = page
      this.$parent.CORPINFO_ID = ID
      this.$parent.CORP_NAME = NAME
    },
    goKeyReset() {
      this.KEYWORDS = ''
      this.PROVINCE = ''
      this.CITY = ''
      this.COUNTY = ''
      this.VILLAGE = ''
      this.$refs.corpoftype.clearHandle()
      this.KEYQYLX = ''
      this.getQuery()
    }
  }
}

</script>
