<template>
  <app-container>
    <search-area
      :need-clear="false"
      :need-search-more="false"
      type="seperate"
      size="small"
      search-more-type="default"
      @search="fetchData"
    >
      <!--一般查询条件-->
      <search-item>
        <el-select
          v-model="listQuery.deptid"
          placeholder="组织id"
          clearable
        >
          <el-option
            v-for="item in deptidList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </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 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="edit(scope.row)">
              修改
            </el-button>
            <el-button type="text" size="small" @click="del(scope.row)">
              删除
            </el-button>
            <el-button type="text" size="small" @click="detail(scope.row)">
              详情
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <edit-list-dept ref="editAlarmContent" @watchChild="fetchData" />
  </app-container>
</template>

<script>
import editListDept from '@/views/systemConfig/deptPermission/components/editDeptPermission'
import { deptList, delDept } from '@/api/systemConfig/deptPermission'

export default {
  name: 'DeptPermission',
  components: { editListDept },
  data() {
    return {
      // 查询条件
      listQuery: {
        deptid: '',
        offset: 1,
        sort: 'id',
        order: 'asc'
      },
      deptidList: [
        {
          label: '3213213',
          value: '0'
        },
        {
          label: '9873213',
          value: '1'
        }
      ],
      columns: [
        {
          text: '组织名称',
          value: 'deptName',
          align: 'center'
        },
        {
          text: '支持井类型',
          value: 'wellType',
          align: 'center'
        },
        {
          text: '支持设备类型',
          value: 'deviceType',
          align: 'center'
        },
        {
          text: '地图默认中心经度',
          value: 'lng',
          align: 'center'
        },
        {
          text: '地图默认中心纬度',
          value: 'lat',
          align: 'center'
        }
      ], // 显示列
      listLoading: false,
      deviceModelList: [], // 设备类型列表
      list: [], // 表格数据列表
      // 是否需要序号列
      options: {
        needIndex: false
      }
    }
  },
  created() {
    this.fetchData()
  },
  mounted() {
    this.$refs.normalTable.initColumnsState(false)
  },
  methods: {
    // 获取数据列表
    fetchData() {
      this.listLoading = true
      deptList(this.listQuery).then(response => {
        this.list = response.data
        this.listLoading = false
      })
    },
    del(row) {
      this.$confirm(
        '确定要删除所选设备吗？',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delDept(row.id).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 新增
    add() {
      this.$refs.editAlarmContent.initDialog('create')
    },
    // 修改
    edit(row) {
      this.$refs.editAlarmContent.initDialog('update', row)
    },
    // 详情
    detail(row) {
      this.$refs.editAlarmContent.initDialog('detail', row)
    }
  }
}
</script>

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