<!--
 * @Author: 曹捷
 * @Date: 2019-08-20 20:25:19
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-09-01 17:53:16
 * @Description:系统管理  字典管理
 -->
<template>

  <obitUniversalTable type="rightTable" name="字典类型列表" :pagination="pagination" v-if="$fmt(['sys_normal_disable'])">
    <template #left>
      <appListVue v-model:value="params.appId" @change="changeApp(params.appId)"></appListVue>
    </template>
    <template #search>
      <obit-search-form :params="params" :paramList="paramList" @search="pageQuery(true)">
      </obit-search-form>
    </template>
    <template #btn>
      <a-button @click="refreshCache" class="m-r-15">
        <i class="iconfont icon-refresh  p-r-5"></i> 清除缓存
      </a-button>
      <!-- <a-button @click="removeAll" class="m-r-15">
        <i class="iconfont icon-ashbin  p-r-5"></i> 删除全部
      </a-button> -->
      <a-button type="primary" @click="addDialog">
        <i class="iconfont icon-add-bold p-r-5"></i> 新 增
      </a-button>
    </template>
    <a-table :loading="pageLoading" rowKey="dictType" :columns="tableColumns" :row-selection="rowSelection"
      :dataSource="pageDataList" :pagination="false" :expandRowByClick="true" class="obit-atable" highlight-current-row
      style="width: 100%">
      <template #appId="{record}" :key="record.appId">
        <span v-if="record.appId==0">是</span>
        <span v-else>否</span>
      </template>
      <template #operation="{ record  }" :key="record.dictType">
        <a-button class="operation-btn" type="link" @click.stop="addChild(record)">新增字典</a-button>
        <a-button class="operation-btn" type="link" @click.stop="editDialog(record)">编辑</a-button>
        <a-button class="operation-btn" type="link" @click.stop="remove(record)" v-if="record.status==='1'"> 删除
        </a-button>
      </template>
      <template #expandedRowRender="{record}" :key="record.dictType">
        <dicValueIndexVue :codeField="record.dictType" :appId="record.appId" :ref="'dictValue'+record.dictType">
        </dicValueIndexVue>
      </template>
    </a-table>
  </obitUniversalTable>
  <dictAdd :addType="pageType" v-model:open="pageVisable" :detailsInfo="detailsInfo" :appId="appId"
    @reload="pageQuery(true)">
  </dictAdd>
  <dictValueAdd addType="add" :selectCode="selectCode" :appId="appId" v-model:open="dictValueVisable"
    @reload="reloadDictValue(true)">
  </dictValueAdd>
</template>

<script>
import { getCurrentInstance, reactive, toRefs, inject } from 'vue'
import dictAdd from './dictAdd.vue'
import page from './../../../hook/page.js'
import dictValueAdd from './dictValueAdd.vue'
import dicValueIndexVue from './dicValueIndex.vue'
import appListVue from '../components/appList.vue'
export default {
  components: { dictAdd, dicValueIndexVue, dictValueAdd, appListVue },
  setup (props, contenxt) {
    let { proxy } = getCurrentInstance()
    let http = inject('http')
    let _data = reactive({
      selectCode: '',
      dictValueVisable: false,
      paramList: [
        { name: '字典名称', key: 'dictName' },
        { name: '字典类型', key: 'dictType' },
        {
          type: 'ajax',
          key: 'status',
          name: '状态',
          valuename: 'dictValue',
          labelname: 'dictLabel',
          ajaxurl: 'system/dict/data/type/sys_normal_disable',
        },
        {
          type: 'ajax',
          key: 'isAll',
          name: '平台通用',
          valuename: 'dictValue',
          labelname: 'dictLabel',
          ajaxurl: 'system/dict/data/type/sys_is_all',
        },
        { name: '操作时间', endKey: 'endTime', startKey: 'beginTime', type: 'dateBetween' },
      ],
      tableColumns: [
        { dataIndex: 'dictId', title: '字典编号', width: 100 },
        { dataIndex: 'dictName', title: '字典名称', width: 120 },
        { dataIndex: 'dictType', title: '字典类型', width: 180 },
        { dataIndex: 'status', customRender: ({ text, record, index }) => proxy.$fmt('sys_normal_disable', text), title: '状态', width: 100 },
        { dataIndex: 'remark', title: '备注', width: 150 },
        { title: '平台通用', slots: { customRender: 'appId' }, width: 100 },
        { dataIndex: 'createTime', title: '创建时间', width: 180 },
        { title: '操作', slots: { customRender: 'operation' }, width: 200 },
      ],
      codeField: '',
      appId: '',
    })
    let pageIns = page({
      url: 'system/dict/type/pageList',
      key: 'dictId',
      removeUrl: 'system/dict/type/remove',
    })
    let _methods = {
      changeApp (item) {
        _data.appId = item
        pageIns._method.pageQuery()
      },
      addChild (info) {
        _data.selectCode = info.dictType
        _data.appId = info.appId
        _data.dictValueVisable = true
      },
      reloadDictValue () {
        let refs = proxy.$refs['dictValue' + _data.selectCode]
        if (refs) {
          refs.pageQuery(true)
        }
      },
      refreshCache () {
        http.sysPost('system/dict/type/refreshCache').then(res => {
          proxy.$message.success('清除成功')
        })
      }
    }
    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
      ..._methods,
    }
  },
}
</script>

<style>
</style>