<!--
  @description: 字典配置列表弹框
  @Modifier: haofengxian
  @routerPath:
  @date: 2020-7-31-11:31
-->
<template>
  <div>
    <el-dialog
      :visible.sync="seeTypeDialogVisible"
      title="字典列表"
      width="720px"
      custom-class="el-dialog__body-p8 el-dialog_table"
    >
      <div class="mb10">
        <el-button type="primary" plain @click="typeEntryAdd()">
          类型录入
        </el-button>
      </div>
      <section>
        <el-table
          ref="multipleTable"
          :data="seeDialogTableData"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            prop="typename"
            label="类型名称"
          />
          <el-table-column
            prop="typecode"
            align="center"
            label="类型编码"
          />
          <el-table-column label="操作" align="center" width="100">
            <template slot-scope="scope">
              <el-link type="primary" @click="typeEntryUpdate(scope.row)">
                [编辑]
              </el-link>
              <el-link type="primary" @click="typeEntryDelete(scope.row.id,scope.$index)">
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
        <!--分页组件-->
        <pagination :pagination-data="paginationData" @change="loadData" />
      </section>
    </el-dialog>
    <dictionaryTypeEditDialog ref="dictionaryTypeEdit" @loadData="loadData" />
  </div>
</template>

<script>
// 接口
import { delType, getTypeList } from '@api/common/tools'
// 混入公共方法
import { ListMixin } from '@/mixins/ListMixin'
// 组件
import pagination from '@comp/common/pagination/pagination'// 分页
import dictionaryTypeEditDialog from './dictionaryTypeEdit-dialog' // 数据类型录入

export default {
  name: 'DictionaryConfigurationDialog',
  components: {
    pagination, // 分页
    dictionaryTypeEditDialog
  },
  mixins: [ListMixin],
  data() {
    return {
      seeDialogTableData: [], // 字典类型列表
      // 分类信息
      typegroup: {
        typegroupid: '', // 分类id,字典分类表主键id
        typegroupname: '' // 分类名称
      },
      seeTypeDialogVisible: false // 查看类型
    }
  },
  methods: {
    // 初始化字典类型列表
    loadData() {
      const params = {
        pageNo: this.paginationData.pageNo,
        pageSize: this.paginationData.pageSize,
        typegroupid: this.typegroup.typegroupid // 分类id,字典分类表主键id
      }
      getTypeList(params).then(res => {
        const { data } = res
        this.seeDialogTableData = data.records
        this.paginationData.total = data.total
      }).catch(() => {
      })
    },
    // 父组件触发打开弹框查看类型
    openDialogSeeType(typeGroupRow) {
      this.typegroup.typegroupid = typeGroupRow.id // 分类id
      this.typegroup.typegroupname = typeGroupRow.typegroupname // 分类名称
      this.loadData() // 加载列表数据
      this.seeTypeDialogVisible = true // 打开弹框
    },
    // 点击类型类型录入新增
    typeEntryAdd() {
      this.$refs.dictionaryTypeEdit.openDictionaryTypeEdit('create', this.typegroup)
    },
    // 点击类型录入编辑
    typeEntryUpdate(typeRow) {
      this.$refs.dictionaryTypeEdit.openDictionaryTypeEdit('update', this.typegroup, typeRow)
    },
    // 删除
    typeEntryDelete(id, index) {
      this.$confirm('确认要删除字典吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        delType(id).then(() => {
          this.$message.success('删除成功')
          this.seeDialogTableData.splice(index, 1)
          this.loadData()
        })
      })
    }
  }
}
</script>

<style scoped>

</style>
