<template>
  <el-dialog v-model="props.modelValue" title="编辑${functionName}" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row>
        
        ${col}

      </el-row>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button type="primary" @click="handleEditClick(formRef)" :loading="isBtnLod">编辑</el-button>
        <el-button @click="handleResetClick(formRef)">重置</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
import { reactive, ref, watch } from "vue";
import { edit${className} ${dictFunName} } from "~/service/${businessName}";
import { useLoginStore } from "~/store";

// --业务参数
${mapParm}


// --业务方法
${dictFun}




// --基础参数
const store = useLoginStore();
const headers = {
  Accept: "application/json",
  ...store.headers,
};
const isBtnLod = ref(false);
const formRef = ref();
const labelWidth = 100;
const props = defineProps({
  modelValue: Boolean,
  data: Object,
  done: Function,
});
const emits = defineEmits(["update:modelValue"]);
const formData = ref({
  ...props.data,
});
const uoloadData = ref({
  dirName: "${className}"
})


// --基础方法
watch(props, (v) => {
  formData.value = v.data;
  
  ${mapOpen}
});

// 打开弹窗时执行
const openDialog = () => {
  ${dictFunName2}
};

const closeDialog = () => {
  props.done();
  emits("update:modelValue", false);
};

const rules = reactive({
  ${rules}
});

const handleEditClick = async (formEl) => {
  console.log(formData.value);
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    isBtnLod.value = true;

    ${mapFun}
    const { code } = await edit${className}(formData.value);
    if (code == 0) {
      closeDialog();
      props.done();
    }
    isBtnLod.value = false;
  });
};
const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>

<style lang="less" scoped>

</style>
