<!--
 * @Author: 曹捷
 * @Date: 2019-08-20 20:25:19
 * @LastEditors: 曹捷
 * @LastEditTime: 2021-06-09 15:40:01
 * @Description: file content
 -->
<template>
  <div v-if="$fmt(['sys_normal_disable'])">
    <a-table :loading="pageLoading" rowKey="dictCode" :columns="tableColumns" :dataSource="pageDataList"
      :pagination="false" class="com-table" highlight-current-row style="width: 100%">
      <template #status="{record}" :key="record.dictCode">
        <obit-switch v-model:value="record.status" unCheckedChildren="停用" checkedChildren="正常" activeValue="0"
          inactiveValue="1">
        </obit-switch>
      </template>
      <template #operation="{ record  }" :key="record.dictCode">
        <a-button class="operation-btn" type="link" @click="editDialog(record)">编辑</a-button>
        <a-button class="operation-btn" type="link" @click="remove(record)" v-if="record.status==='1'"> 删除</a-button>
      </template>
    </a-table>
  </div>
  <dictValueAdd :addType="pageType" :appId="appId" :selectCode="codeField" v-model:open="pageVisable"
    :detailsInfo="detailsInfo" @reload="pageQuery(true)">
  </dictValueAdd>
</template>

<script>
import { getCurrentInstance, reactive, toRefs, watch } from 'vue'
import dictValueAdd from './dictValueAdd.vue'
import page from './../../../hook/page.js'
export default {
  components: { dictValueAdd },
  props: {
    codeField: {
      type: String
    },
    appId: {
      type: String
    },
  },
  setup (props, contenxt) {
    let { proxy } = getCurrentInstance()
    let _data = reactive({
      tableColumns: [
        { dataIndex: 'dictCode', title: '字典编码' },
        { dataIndex: 'dictLabel', title: '字典标签' },
        { dataIndex: 'dictValue', title: '字典键值' },
        { dataIndex: 'dictSort', title: '字典排序' },
        { dataIndex: 'status', customRender: ({ text, record, index }) => proxy.$fmt('sys_normal_disable', text), title: '状态' },
        { dataIndex: 'remark', title: '备注' },
        { dataIndex: 'createTime', title: '创建时间' },
        { title: '操作', slots: { customRender: 'operation' }, width: "200px" },
      ],
      codeValue: ''
    })
    let pageIns = page({
      url: 'system/dict/data/pageList',
      key: 'dictCode',
      removeUrl: 'system/dict/data/remove',
      removeAll: 'system/dict/data/removeAll',
      data: {
        pagination: {
          pageSize: 30
        }
      },
      getQueryParam () {
        return {
          dictType: props.codeField,
          appId: props.appId
        }
      }
    })
    watch(() => props.codeField, () => {
      pageIns._method.pageQuery(true)
    })
    pageIns._method.pageQuery(true)

    return {
      ...toRefs(pageIns._data),
      ...pageIns._method,
      ...toRefs(_data),
    }
  },
}
</script>

<style>
</style>