<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-group ">
        <div class="filter-lable">
          企业名称：
        </div>
        <div class="filter-width">
          <el-input v-model="KEYWORDS" placeholder="搜索" class="filter-item"/>
        </div>
      </div>
      <div :style="{'margin-top': searchFromCollapse ? '0px' : '10px'}" class="filter-group">
        <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>
    </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="IS_MAJOR_HAZARD" label="是否重大危险源企业" >
        <template slot-scope="{row}">
          <span v-if="row.IS_MAJOR_HAZARD == '0'">否</span>
          <span v-if="row.IS_MAJOR_HAZARD == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="IS_MAJOR_HAZARD_PUSH" label="是否开启重大危险源企业数据推送" >
        <template slot-scope="{row}">
          <span v-if="row.IS_MAJOR_HAZARD_PUSH == '0'">否</span>
          <span v-if="row.IS_MAJOR_HAZARD_PUSH == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="IS_MAIN_TECHNOLO" label="是否重点工艺企业" >
        <template slot-scope="{row}">
          <span v-if="row.IS_MAIN_TECHNOLO == '0'">否</span>
          <span v-if="row.IS_MAIN_TECHNOLO == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="IS_MAIN_TECHNOLO_PUSH" label="是否开启重点工艺企业数据推送" >
        <template slot-scope="{row}">
          <span v-if="row.IS_MAIN_TECHNOLO_PUSH == '0'">否</span>
          <span v-if="row.IS_MAIN_TECHNOLO_PUSH == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="IS_MAIN_TECHNOLO" label="是否专项检查企业" >
        <template slot-scope="{row}">
          <span v-if="row.IS_SPE_CORP == '0'">否</span>
          <span v-if="row.IS_SPE_CORP == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column prop="IS_MAIN_TECHNOLO_PUSH" label="是否开启专项检查数据推送" >
        <template slot-scope="{row}">
          <span v-if="row.IS_SPE_CORP_PUSH == '0'">否</span>
          <span v-if="row.IS_SPE_CORP_PUSH == '1'">是</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" >
        <template slot-scope="{row}">
          <el-button type="warning" icon="el-icon-edit" size="mini" @click="handleEdit(row)">配置企业类型</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>
    <el-dialog :visible.sync="dialogFormEdit" title="配置企业类型" width="600px">
      <el-form ref="form" :model="form" label-width="250px" style="width: 500px;">
        <el-form-item label="是否重大危险源企业" prop="IS_MAIN_TECHNOLO">
          <el-radio v-model="form.IS_MAJOR_HAZARD" label="1">是</el-radio>
          <el-radio v-model="form.IS_MAJOR_HAZARD" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="是否开启重大危险源企业数据推送" prop="IS_MAIN_TECHNOLO">
          <el-radio v-model="form.IS_MAJOR_HAZARD_PUSH" label="1">是</el-radio>
          <el-radio v-model="form.IS_MAJOR_HAZARD_PUSH" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="是否重点工艺企业" prop="IS_MAIN_TECHNOLO">
          <el-radio v-model="form.IS_MAIN_TECHNOLO" label="1">是</el-radio>
          <el-radio v-model="form.IS_MAIN_TECHNOLO" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="是否开启重点工艺企业数据推送" prop="IS_MAIN_TECHNOLO_PUSH">
          <el-radio v-model="form.IS_MAIN_TECHNOLO_PUSH" label="1">是</el-radio>
          <el-radio v-model="form.IS_MAIN_TECHNOLO_PUSH" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="是否专项检查企业" prop="IS_SPE_CORP">
          <el-radio v-model="form.IS_SPE_CORP" label="1">是</el-radio>
          <el-radio v-model="form.IS_SPE_CORP" label="0">否</el-radio>
        </el-form-item>
        <el-form-item label="是否开启专项检查数据推送" prop="IS_SPE_CORP_PUSH">
          <el-radio v-model="form.IS_SPE_CORP_PUSH" label="1">是</el-radio>
          <el-radio v-model="form.IS_SPE_CORP_PUSH" label="0">否</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormEdit = false">取 消</el-button>
        <el-button type="primary" @click="fnUpdCorpType">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves'
// waves directive
export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      varList: [],
      total: 0,
      form: {
        IS_MAJOR_HAZARD: '0',
        IS_MAJOR_HAZARD_PUSH: '0',
        IS_MAIN_TECHNOLO_PUSH: '0',
        IS_MAIN_TECHNOLO: '0',
        IS_SPE_CORP: '0',
        IS_SPE_CORP_PUSH: '0'
      },
      dialogFormEdit: false,
      KEYWORDS: '',
      CORPINFO_ID: '',
      searchFromCollapse: true,
      listQuery: {
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    var user = sessionStorage.getItem('user')
    var obj = JSON.parse(user)
    if (obj && (obj.AGENCY_MANAGEMENT_ID === '' || obj.AGENCY_MANAGEMENT_ID == null)) {
      this.isAdmin = true
    }
    this.getList(this.ROLE_ID)
    this.getDict()
    this.getDictByDicId('e725d2a91b8248f4b8f49889038df7de').then(data => {
      this.areaList = data
    })
  },
  methods: {

    getRowKey(row) {
      return row.CORPINFO_ID
    },
    // 搜索
    getQuery() {
      this.$refs.multipleTable.clearSelection()
      this.getList()
    },
    // 获取列表
    getList() {
      this.listLoading = true
      this.POSSESSION
      var possession = ''
      var possessionLevel = ''
      if (this.POSSESSION && this.POSSESSION.length > 0) {
        possession = this.POSSESSION[this.POSSESSION.length - 1]
        possessionLevel = this.POSSESSION.length
      }
      requestFN(
        '/corpinfo/list?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          KEYWORDS: this.KEYWORDS,
          ISSMALL: '2',
          PAGETYPE: '1',
          POSSESSION: possession,
          POSSESSIONLEVEL: possessionLevel
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
        this.hasButton()
        this.pd = data.pd
      }).catch((e) => {
        this.listLoading = false
      })
    },
    // 重置
    goKeyReset() {
      this.KEYWORDS = ''
      this.getQuery()
    },
    // 修改
    handleEdit(row) {
      this.CORPINFO_ID = row.CORPINFO_ID
      this.form.IS_MAIN_TECHNOLO = row.IS_MAIN_TECHNOLO
      this.form.IS_MAJOR_HAZARD_PUSH = row.IS_MAJOR_HAZARD_PUSH
      this.form.IS_MAIN_TECHNOLO_PUSH = row.IS_MAIN_TECHNOLO_PUSH
      this.form.IS_MAJOR_HAZARD = row.IS_MAJOR_HAZARD
      this.form.IS_SPE_CORP = row.IS_SPE_CORP
      this.form.IS_SPE_CORP_PUSH = row.IS_SPE_CORP_PUSH
      this.dialogFormEdit = true
    },
    fnUpdCorpType() {
      this.$confirm('确定要修改企业类型吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/corpinfo/updCorpType',
          {
            CORPINFO_ID: this.CORPINFO_ID,
            IS_MAIN_TECHNOLO: this.form.IS_MAIN_TECHNOLO,
            IS_MAJOR_HAZARD_PUSH: this.form.IS_MAJOR_HAZARD_PUSH,
            IS_MAIN_TECHNOLO_PUSH: this.form.IS_MAIN_TECHNOLO_PUSH,
            IS_MAJOR_HAZARD: this.form.IS_MAJOR_HAZARD,
            IS_SPE_CORP: this.form.IS_SPE_CORP,
            IS_SPE_CORP_PUSH: this.form.IS_SPE_CORP_PUSH
          }
        ).then(() => {
          this.$message({
            message: '修改成功',
            type: 'success'
          })
          this.listLoading = false
          this.dialogFormEdit = false
          this.varList = []
          this.listQuery.page = 1
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
        this.listLoading = false
      }).catch(() => {
        this.listLoading = false
      })
    },
    handleDelete(id) {
      this.$confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/corpinfo/delete',
          {
            CORPINFO_ID: id
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.varList = []
          this.listQuery.page = 1
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },

    // 判断按钮权限，用于是否显示按钮
    hasButton: function() {
      var keys = 'corpinfo:add,corpinfo:del,corpinfo:edit,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        this.add = data.corpinfofhadminadd		// 新增权限
        this.del = data.corpinfofhadmindel		// 删除权限
        this.edit = data.corpinfofhadminedit	// 修改权限
      }).catch((e) => {
        this.listLoading = false
      })
    },

    // 获取数据字典数据
    getDictByDicId(dicId) {
      var dicListVal = []
      return new Promise((resolve) => {
        let id = ''
        if (!dicId) {
          id = '0'
        } else {
          id = dicId
        }
        requestFN(
          '/dictionaries/getLevelsAndSCount',
          {
            DICTIONARIES_ID: id
          }
        ).then((data) => {
          if (data.list.length > 0) {
            dicListVal = data.list.map((e) => {
              if (e.zcount == '0') {
                return { value: e.DICTIONARIES_ID.toString(), numValue: e.BIANMA.toString(), label: e.NAME, id: e.DICTIONARIES_ID, leaf: true }
              } else {
                return { value: e.DICTIONARIES_ID.toString(), numValue: e.BIANMA.toString(), label: e.NAME, id: e.DICTIONARIES_ID, children: [], leaf: false }
              }
            })
          } else {
            dicListVal = undefined
          }
          return resolve(dicListVal)
        }).catch((e) => {
        })
      })
    }
  }
}

</script>
<style>
  .el-table .yellow-row {
    background: rgba(248, 231, 28, 0.2);

  }

  .el-table .red-row {
    background: rgba(252, 2, 33, 0.2);
  }
  .el-table .green-row {
    background: rgba(26, 208, 22, 0.2);
  }

</style>
<style lang="sass" scoped>
  .uo-flex
    display: flex
  .filter-container
    position: relative
    .filter-flot
      position: absolute
      right: 0
      top: 0

</style>

