<!--组织权限配置-->
<template>
  <app-container>
    <search-area
      :need-clear="false"
      :need-search-more="false"
      size="small"
      search-more-type="default"
      @search="fetchData"
    >
      <search-item>
        <dept-select v-model="listQuery.deptid" :need-top="true" placeholder="选择组织机构" />
      </search-item>
    </search-area>
    <normal-table ref="normalTable" :data="list" :query="listQuery" :columns="columns" :list-loading="listLoading" :options="options" size="small">
      <template slot="btns">
        <el-button v-if="hasPerm('/deptPermission/add')" size="small" @click="add">
          新增
        </el-button>
      </template>
      <template slot="columns">
        <el-table-column label="操作" width="120" align="center">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="detail(scope.row)">
              详情
            </el-button>
            <el-button v-if="hasPerm('/deptPermission/update')" type="text" size="small" @click="edit(scope.row)">
              修改
            </el-button>
            <el-button v-if="hasPerm('/deptPermission/delete')" type="text" size="small" @click="del(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <edit-dept-permission ref="editDeptPermission" @watchChild="fetchData" />
  </app-container>
</template>

<script>
import DeptSelect from '@/components/DeptSelect'
import EditDeptPermission from '@/views/systemConfig/deptPermission/components/editDeptPermission'
import { deptPermissionList, delDeptPermission } from '@/api/systemConfig/deptPermission'

export default {
  name: 'DeptPermission',
  components: { DeptSelect, EditDeptPermission },
  data() {
    return {
      // 查询条件
      listQuery: {
        deptid: ''
      },
      columns: [
        {
          text: '组织名称',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '支持点位类型',
          value: 'wellTypeName',
          align: 'center'
        },
        {
          text: '支持设备类型',
          value: 'deviceTypeName',
          align: 'center'
        },
        {
          text: '默认城市编码',
          value: 'area',
          align: 'center'
        },
        {
          text: '地图默认中心-经度',
          value: 'lng',
          align: 'center'
        },
        {
          text: '地图默认中心-纬度',
          value: 'lat',
          align: 'center'
        }
      ], // 显示列
      listLoading: false,
      list: [], // 表格数据列表
      // 是否需要序号列
      options: {
        needIndex: false
      }
    }
  },
  created() {
    this.fetchData()
  },
  mounted() {
    this.$refs.normalTable.initColumnsState(false)
  },
  methods: {
    // 获取数据列表
    fetchData() {
      this.listLoading = true
      deptPermissionList(this.listQuery).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    del(row) {
      this.$confirm(
        '确定要删除所选配置项吗？',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delDeptPermission(row.id).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 新增
    add() {
      this.$refs.editDeptPermission.initDialog('create')
    },
    // 修改
    edit(row) {
      this.$refs.editDeptPermission.initDialog('update', row)
    },
    // 详情
    detail(row) {
      this.$refs.editDeptPermission.initDialog('detail', row)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
