<template>
  <div class="data-dictionary h100">
    <common-layout  ref="layoutRef" :table-attrs="{
     'has-operation':true
   }" :form-attrs="{
     'span-attrs':{
       span:5
     }
   }" :table-header="syncRuleHomeTableHeader" :get-table-list="getTableTata" :filter-form="formConfig">
      <template #operation="{data}">
        <el-button  type="info" v-if="data.RULES_SUM > 0" @click="$emit('changeOperation','edit',data)">修改规则</el-button>
        <el-button  type="info" v-else @click="$emit('changeOperation','edit',data)">配置规则</el-button>

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

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

export default {
  name: "SyncRuleHome",
  components: {CommonLayout},
  setup() {
    const layoutRef = ref(null)
    const store =useRootStore()
    useActiveGetTableData(getTableTata)
    const {formConfig} = useGetUnitSelect(dataDictionaryHomeFilterForm,'UNIT_CODE')
    // onMounted(() => {
    //   nextTick(() => {
    //     const findItem = formConfig.value.formItemsArr.find(i => i.modelValue === 'UNIT_CODE')
    //     console.log('store.allSelectUnit',store.allSelectUnit,findItem)
    //
    //     findItem.options = [...store.allSelectUnit]
    //   })
    // })
    function getTableTata() {
      getSyncHomeTableData({
        pageIndex:layoutRef.value.pageIndex,
        pageSize:layoutRef.value.pageSize,
        CONFIG_STATES:layoutRef.value.form.CONFIG_STATES,
        CATALOG_NAME:layoutRef.value.form.NAME,
        UNIT_CODE:layoutRef.value.form.UNIT_CODE,

      }).then(res =>{
        layoutRef.value.getResData(res.msg[0].Rows,res.msg[0].TotalRowCount)
      })

    }
    return {
      formConfig,
      syncRuleHomeTableHeader,
      getTableTata,
      layoutRef
    }
  }
}
</script>

<style scoped lang="scss">

</style>
