<!--
 * @Author: 曹捷
 * @Date: 2019-08-20 20:25:19
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-06-09 15:39:42
 * @Description:系统管理  字典管理
 -->
<template>

  <obitUniversalTable name="字典类型列表" :pagination="pagination">
    <template #search>
      <obit-search-form :params="params" :paramList="paramList" @search="pageQuery(true)">
      </obit-search-form>
    </template>
    <template #btn>
      <a-button type="primary" @click="addDialog">
        <i class="iconfont icon-add-bold p-r-5"></i> 新 增
      </a-button>
    </template>
    <a-table :customRow="customRow" :loading="pageLoading" rowKey="codeField" :columns="tableColumns"
      :dataSource="pageDataList" :pagination="false" class="com-table" highlight-current-row style="width: 100%">
      <template #operation="{ record  }" :key="record.codeField">
        <a-button type="link" @click="addChild(record)">新增字典</a-button>
        <a-divider type="vertical" style="height: 16px;" />
        <a-button type="link" @click="editDialog(record)">编辑</a-button>
        <a-divider type="vertical" style="height: 16px;" />
        <a-button type="link" @click="remove(record)"> 删除</a-button>
      </template>
      <template #ifAll="{record}" :key="record.codeField">
        {{record.appCode ==='ALL'?'平台通用':record.appCode}}
      </template>
      <template #expandedRowRender="{record}" :key="record.codeField">
        <dicValueIndexVue :codeField="record.codeField" :ref="'dictValue'+record.codeField"></dicValueIndexVue>
      </template>
    </a-table>
  </obitUniversalTable>
  <dictAdd :addType="pageType" v-model:open="pageVisable" :detailsInfo="detailsInfo" @reload="pageQuery(true)">
  </dictAdd>
  <dictValueAdd addType="add" :selectCode="selectCode" v-model:open="dictValueVisable" @reload="reloadDictValue(true)">
  </dictValueAdd>
</template>

<script>
import { getCurrentInstance, onMounted, reactive, toRefs } from 'vue'
import dictAdd from './dictAdd.vue'
import page from './../../../hook/page.js'
import dictValueAdd from './dictValueAdd.vue'
import dicValueIndexVue from './dicValueIndex.vue'
export default {
  components: { dictAdd, dicValueIndexVue, dictValueAdd },
  setup (props, contenxt) {
    let { proxy } = getCurrentInstance()
    let _data = reactive({
      selectCode: '',
      dictValueVisable: false,
      paramList: [
        { name: '字典类型', key: 'codeField' },
        { name: '字典描述', key: 'codeDesc' },
      ],
      tableColumns: [
        { dataIndex: 'codeField', title: '字典类型' },
        { dataIndex: 'codeDesc', title: '字典描述' },
        { slots: { customRender: 'ifAll' }, title: '平台' },
        { title: '操作', slots: { customRender: 'operation' } },
      ],
      codeField: ''
    })
    let pageIns = page({
      tableRequest: 'getSystemSysCodeList',
      removeKey: 'removeSystemSysCode',
      checkRadio (item) {
        _data.codeField = item[0]
      }
    })
    let _methods = {
      addChild (info) {
        _data.selectCode = info.codeField
        _data.dictValueVisable = true
      },
      reloadDictValue () {
        console.log(proxy)
        let refs = proxy.$refs['dictValue' + _data.selectCode]
        if (refs) {
          refs.pageQuery(true)
        }
      }
    }
    onMounted(() => {
      pageIns._method.pageQuery()
    })
    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
      ..._methods,
    }
  },
}
</script>

<style>
</style>