<template>
<el-dialog
  :modal="true"

  :close-on-click-modal="false"
  :close-on-press-escape="false"
  destroy-on-close
  title="各单位的目录关联表新增"
  :model-value="dialogVisible"

  :before-close="handleClose"
>
  <diy-el-form :span="10" ref="formRef" v-model:model-form="forms" :forms="unitWatchDetailDialogFormConfig"></diy-el-form>
  <template #footer>
    <el-button @click="handleClose">关闭</el-button>
    <el-button type="info" @click="addSheetInfo">确定</el-button>
  </template>
</el-dialog>
</template>

<script>
import {unitWatchDetailDialogForm} from "@/data/all-forms";
import {onBeforeMount, ref} from "vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {getUnitImputationDialogAllDirSelect} from "@/service/data-gather-watch/unit-imputation-watch";
import {isValid} from "js-base64";

export default {
  name: "AddUnitWatchDialog",
  components: {DiyElForm},
  props:{
    dialogVisible:{}

  },
  setup(props,{emit}){
    const formRef = ref(null)
    const unitWatchDetailDialogFormConfig = ref({...unitWatchDetailDialogForm})
    function addSheetInfo() {
      formRef.value.refEl.validate(isValid => {
        if (isValid) {
          emit('addSheetInfo',forms.value)
        }
      })
    }
    const forms =ref({})
    onBeforeMount(() => {
      let findAllDir = unitWatchDetailDialogFormConfig.value.formItemsArr.find( i=>i.modelValue === 'CATALOG_CODE')

      getUnitImputationDialogAllDirSelect().then(res => {
        try {
          findAllDir.options = [{value:'',label:'全部'}].concat(res.msg[0].Rows.map(i => (
            {
              value:i.CODE,
              label:i.NAME,
            }
          )))
        }catch {

        }

        console.log('所有目录',res)
      })
    })
    function handleClose() {
      emit('update:dialogVisible',false)
    }
    return {
      handleClose,
      unitWatchDetailDialogFormConfig,
      forms,
      addSheetInfo,
      formRef
    }
  }
}
</script>

<style scoped lang="scss">

</style>
