<template>
  <el-dialog
    :modal="true"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    title="选择模板"
    :append-to-body="true"
    :model-value="dialogVisible"
    width="40%"
    :before-close="handleClose"
  >
   <diy-el-form ref="formRef" v-model:model-form="forms" :forms="formConfig">
     <template #formItemAfter>
       <el-col span="7">
         <el-form-item prop="" label="">
           <el-button @click="importE" type="info">导入</el-button>
         </el-form-item>
       </el-col>

     </template>
   </diy-el-form>
  </el-dialog>
</template>

<script>
import DiyElForm from "@/components/common/DiyElForm.vue";
import {onBeforeMount, ref} from "vue";
import {chooceTemplate} from "@/data/all-forms";
import {getGoolFlowTemplate, getGoolFlowTemplate2} from "@/service/task-manage/task-set";

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

    }
  },
  setup(props,{emit}) {
    onBeforeMount(() => {
      let findItem = formConfig.value.formItemsArr.find(i => i.modelValue === 'lc')
      // findItem.selectEvent = (val) => {
      //
      // }
      getGoolFlowTemplate().then(res => {
        let data = res.msg[0].Rows
        let findItem = formConfig.value.formItemsArr.find(i => i.modelValue === 'lc')
        findItem.options = [{
          label:'全部模板',
          value:''
        }].concat(data.map(i => ({
          ...i,
          value:i.ID,
          label:i.TITLE
        })))
      })
    })
    const formConfig=  ref({...chooceTemplate})
    const formRef = ref(null)
    const forms = ref({

    })
    function importE() {
      formRef.value.refEl.validate((isValid) => {
        if (isValid){
          getGoolFlowTemplate2(forms.value['lc']).then(res => {
            emit('importE',res.msg[0].Rows[0],true)

          })

        }
      })
    }
    function handleClose() {
      emit("update:dialogVisible", false)
    }
    return {
      handleClose,
      forms,
      formConfig,
      formRef,importE


    }
  }
}
</script>

<style scoped lang="scss">

</style>
