<template>
  <el-dialog
    :modal="true"
    width="36%"
    :close-on-click-modal="false"
    :close-on-press-escape="false"
    destroy-on-close

    :title="currentReflectObj.dialogTitle"
    :model-value="dialogVisible"

    :before-close="handleClose"

  >
    <diy-el-form ref="formRef" v-model:model-form="forms" :forms="formConfig"/>
    <template #footer>
      <el-button :icon="SuccessFilled" @click="editOrAddSfeType">确定</el-button>
      <el-button  :icon="Close" @click="handleClose">取消</el-button>
    </template>
  </el-dialog>
</template>

<script>
import {Close, SuccessFilled} from "@element-plus/icons-vue";
import {computed, onBeforeMount, ref} from "vue";
import DiyElForm from "@/components/common/DiyElForm.vue";
import {baseRuleSateRankDialogForm, baseRuleSateTypeDialogForm} from "@/data/all-forms";
import {baseUseSafeTohJType} from "@/data/all-reflect";
import {getEncodeTypeSelect} from "@/service/zsk/safe-rule";
import {deleteSafeRuleTypeD, getSafeLevelSelect} from "@/service/zsk/base-rule/safe-type";
import {isValid} from "js-base64";

export default {
  name: "SafeTypeEditDialog",
  components: {DiyElForm},
  computed: {
    Close() {
      return Close
    },
    SuccessFilled() {
      return SuccessFilled
    }
  },
  props:{
    dialogVisible:{

    },
    type:{

    },
    currentDialogOpObj:{

    },
    dialogOperationType:{}
  },
  setup(props,{emit}){
    function delData() {

      // deleteSafeRuleTypeD
    }
    function editOrAddSfeType() {
      formRef.value.refEl.validate(isValid => {
        if (isValid) {
          emit('editOrAddSfeType',forms.value)
        }
      })
    }
     const formRef = ref(null)
    const currentReflectObj = computed(() => {
      return baseUseSafeTohJType.find(i => i.id === props.type)
    })
    onBeforeMount(() => {
      if (props.dialogOperationType!=='add'){
        forms.value = {
          ...props.currentDialogOpObj
        }
      }
      // 获取安全级别的下拉框
      getSafeLevelSelect({
        "pageIndex": "1",
        "pageSize": "10000",
        "SAFE_LEVEL": ""
      }).then(res => {
        console.log('sadsa','拿到')
        let findSafeLevel = formConfig.value.formItemsArr.find(i => i.modelValue === 'SAFE_LEVEL')
        if (findSafeLevel){
          findSafeLevel.options = [
            {value:'',label:'请选择'}
          ].concat(res.msg[0].Rows.map(it => ({
            value:it.SAFE_LEVEL_ID,
            label:it.SAFE_LEVEL,
          })))
        }
      })

    })
    const formConfig = ref({...(currentReflectObj.value?.dialogForm || {})})
    const forms = ref({})
    function handleClose() {
      emit('update:dialogVisible',false)
    }
    return {
      handleClose,
      forms,
      formConfig,
      currentReflectObj,
      editOrAddSfeType,
      formRef,
      delData
    }
  }
}
</script>

<style scoped lang="scss">

</style>
