<template>
  <div class="app-container">
    <div class="filter-container">
      <!--      <el-row :gutter="20">
        <el-form label-width="80px">
          <el-col :span="6">
            <el-form-item label="名称">
              <el-input v-model="searchForm.DICTIONARY_NAMES" placeholder="搜索名称..." class="filter-item" />
            </el-form-item>
          </el-col>
          <el-col :span="6" >
            <el-form-item label-width="10px">
              <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-left" @click="resetting">
                重置
              </el-button>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>-->
    </div>
    <el-table
      v-loading="listLoading"
      ref="multipleTable"
      :data="varList"
      :row-key="getRowKey"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
      default-expand-all>
      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="DICTIONARY_NAME" label="类目名称" />
      <el-table-column prop="DICTIONARY_LEVEL" label="类别" width="140" align="center" >
        <template slot-scope="{row}">
          {{ row.DICTIONARY_LEVEL ? (row.DICTIONARY_LEVEL === 1 ? '标准类别' : '标准项目') : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="DICTIONARY_SOURCE" label="来源" width="140" align="center" >
        <template slot-scope="{row}">
          {{ row.DICTIONARY_SOURCE ? (row.DICTIONARY_SOURCE === 1 ? '运营添加' : '企业自建') : '' }}
        </template>
      </el-table-column>
      <el-table-column prop="DICTIONARY_SORT" label="排序" width="60" align="center" />
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="{row}">
          <el-row :gutter="20">
            <el-button type="success" icon="el-icon-view" size="mini" @click="getInfo(row)">查看</el-button>
            <el-button v-show="edit" :disabled="row.COUNT_USE !== 0" type="primary" icon="el-icon-edit" size="mini" @click="handleEdit(row)">编辑</el-button>
            <el-button v-show="del" :disabled="row.COUNT_USE !== 0" type="danger" icon="el-icon-delete" size="mini" @click="handleDelete(row.DICTIONARY_ID)">删除</el-button>
          </el-row>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-btn-group">
      <div>
        <el-button type="primary" icon="el-icon-refresh" @click="getList">刷新</el-button>
        <!--        <el-button v-show="add" type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>-->
        <!--        <el-button v-show="false" type="danger" icon="el-icon-delete" plain @click="batchDel">删除</el-button>-->
      </div>
      <!--      <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />-->
    </div>
    <edit ref="edit" :title="title" href="edit" @beforeClose="getList"/>
    <info ref="info" :title="title"/>
  </div>
</template>
<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves'
import edit from './edit.vue'
import Info from './info.vue'
export default {
  components: { Info, edit, Pagination },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      add: false,
      del: false,
      edit: false,
      listQuery: {
        page: 1,
        limit: 10
      },
      total: 0,
      KEYWORDS: '',
      varList: [],
      title: '新增',
      dictId: 'f2598ba72e864eadabf0ca4b664d26b9', // 行业类型
      commonStatusList: [
        { id: 1, name: '有效' },
        { id: 2, name: '停用' }
      ],
      searchForm: {
        DICTIONARY_NAMES: ''
      }
    }
  },
  created() {
    this.getList()
    this.getDict()
  },
  methods: {
    getRowKey(row) {
      return row.DICTIONARY_ID
    },
    getQuery() {
      this.getList()
    },
    resetting() {
      this.searchForm = {
        DICTIONARY_NAMES: ''
      }
      this.getList()
    },
    getList() {
      this.listLoading = true
      requestFN(
        '/hiddenDangerCheckStandardDictionary/listTree?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          DICTIONARY_NAMES: this.searchForm.DICTIONARY_NAMES
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.hasButton()
      }).catch((e) => {
        this.listLoading = false
      })
    },
    handleAdd() {
      this.$refs.edit.init()
      this.title = '新增'
    },
    handleEdit(row) {
      this.$refs.edit.init(JSON.parse(JSON.stringify(row)))
      this.title = '编辑'
    },
    handleDelete(id) {
      this.$confirm('确定要删除吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/hiddenDangerCheckStandardDictionary/delete',
          { DICTIONARY_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(() => {
      })
    },
    batchDel() {
      const _selectData = this.$refs.multipleTable.selection
      if (_selectData == null || _selectData.length == 0) {
        this.$message({
          message: '请选中要删除的项...',
          type: 'error'
        })
        return false
      }
      const ids = _selectData.map((item, index) => {
        return item.DICTIONARY_ID
      }).join(',')

      this.$confirm('确定要删除选中的数据吗?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.listLoading = true
        requestFN(
          '/hiddenDangerCheckStandardDictionary/deleteAll',
          {
            DATA_IDS: ids
          }
        ).then(() => {
          this.$message({
            message: '删除成功',
            type: 'success'
          })
          this.listLoading = false
          this.varList = []
          this.listQuery.page = 1
          this.$refs.multipleTable.clearSelection()
          this.getList()
        }).catch((e) => {
          this.listLoading = false
        })
      }).catch(() => {
      })
    },
    hasButton: function() {
      var keys = 'hiddenDangerCheckStandardDictionary:add,hiddenDangerCheckStandardDictionary:del,hiddenDangerCheckStandardDictionary:edit,toExcel'
      requestFN(
        '/head/hasButton',
        {
          keys: keys
        }
      ).then((data) => {
        console.log(data)
        this.add = data.hiddenDangerCheckStandardDictionaryfhadminadd		// 新增权限
        this.del = data.hiddenDangerCheckStandardDictionaryfhadmindel		// 删除权限
        this.edit = data.hiddenDangerCheckStandardDictionaryfhadminedit	// 修改权限
      }).catch((e) => {
        this.listLoading = false
      })
    },
    getDict: function() {
    },
    getInfo(row) {
      this.$refs.info.init(row)
      this.title = '详情'
    },
    getResult(e) {
      this.getList()
    }
  }
}

</script>
