<template>
  <div class="app-container">
    <search-form
      :listLoading="listLoading"
      @change="searchHandle"
      @add="openPopup"
    />
    <table-list
      :operationsDefaultLength="3"
      :listLoading="listLoading"
      :data="tableData"
      :columns="listConfig"
      :currentPage="currentPage"
      :pageSize="pageSize"
      :totalRecords="totalRecords"
      @currentChange="pageHandle"
      @sizeChange="sizeChange"
      :isAdd="true"
      @add="openPopup"
    />
    <dict-edit
      :isShow="isPopupShow"
      :curObj="curObj"
      @close="closePopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Dict'
import DictEdit from './components/popup/DictEdit'
import baseTable from '_m/baseTable.js'
export default {
  name: 'basePublicDictSys',
  components: {
    SearchForm,
    DictEdit
  },
  provide () {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  created () {},
  data () {
    return {
      apiStr: 'base.admdicttypelist',
      searchForm: null,
      isPopupShow: false,
      // noCreated: true,
      curObj: {}
    }
  },
  mounted () {
    this.listConfig = {
      rows: [
        { label: '类型编号', prop: 'dict_type' },
        { label: '类型名称', prop: 'dict_name' },
        { label: '类型说明', prop: 'remark', fullShow: true },
        { label: '更新人', prop: 'update_by' },
        { label: '更新时间', prop: 'update_at' },
        { label: '操作', width: 230, type: 'handle2',
          operations: [
            { label: '编辑', func: this.openPopup, btnType: 'primary' },
            { label: '管理内容详情', func: this.linkDtl, btnType: 'success' },
            { label: '删除', func: this.delHandle, btnType: 'danger', hide: 'nosys' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle (row) {
      const msgHtml = `确定要删除此字典吗？`
      this.$msg(msgHtml, 'confirm', ()=> {
        this.$api.base.dicttypedel({
          dict_id: row.id,
        }).then(data => {
          this.$msgs(`删除成功！`)
          this.fetchData()
        })
      }, null, true)
    },
    linkDtl (row) {
      this.$router.push(`/base/dictDtl?dict_type=${row.dict_type}&dict_name=${row.dict_name}&id=${row.id}`)
    },
    openPopup (row) {
      this.curObj = row
      this.isPopupShow = true
    },
    closePopup (obj) {
      this.isPopupShow = false
      if (obj) {
        this.fetchData()
      }
    }
  }
}
</script>
