<template>
  <div class="data-dictionary h100">
    <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':true
   }" :form-attrs="{
     'span-attrs':{
       span:5
     }
   }" :table-header="dataDictionaryHomeTableHeader" :get-table-list="getTableTata" :filter-form="formConfig">
      <template #JUDGE_CODE="{data}">
        {{+data['JUDGE_CODE']?'已配置':'未配置'}}
      </template>
      <template #PROVIDERUNIT="{data}">
        {{store.allSelectUnit.find(i => i.value === data['PROVIDERUNIT'])?.label}}
      </template>
      <template #operation="{data}">
        <el-button  type="info" @click="$emit('changeOperation','edit',data)" v-if="!data.JUDGE_CODE || data.JUDGE_CODE === '0'">配置字典</el-button>
        <el-button  type="info" @click="$emit('changeOperation','edit',data)" v-else>修改字典</el-button>

      </template>
    </common-layout>
  </div>
</template>

<script>
import CommonLayout from "@/components/CommonLayout.vue";
import {dataDictionaryHomeFilterForm} from "@/data/all-forms";
import {dataDictionaryHomeTableHeader} from "@/data/all-table-header";
import {onBeforeMount, ref} from "vue";
import {getDataDictionaryHomeTableData} from "@/service/zsk/data-dictionary";
import {useGetUnitSelect} from "@/unit/use-method/use-unit";
import {useRootStore} from "@/stores/useStore";
import {useActiveGetTableData} from "@/unit/use-method/usePagination";

export default {
  name: "DataDictionaryHome",
  components: {CommonLayout},
  setup() {
    useActiveGetTableData(getTableTata)
    const store = useRootStore()
    const layoutRef = ref(null)
    const {formConfig} = useGetUnitSelect(dataDictionaryHomeFilterForm,'UNIT_CODE')

    function getTableTata() {
      getDataDictionaryHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        NAME:layoutRef.value.form.NAME,
        PROVIDERUNIT:layoutRef.value.form.UNIT_CODE,
        SFPZ:layoutRef.value.form.CONFIG_STATES
      }).then(res => {
        layoutRef.value.getResData(res.msg[0].Rows||[],res.msg[0].TotalRowCount)
      })

    }
    return {
      formConfig,
      dataDictionaryHomeTableHeader,
      getTableTata,
      layoutRef,
      store
    }
  }
}
</script>

<style scoped lang="scss">

</style>
