<!--
 * @Descripttion: (表情包/tb_emoticon_data 编辑弹窗)
 * @version: (1.0)
 * @Author: (lwh)
 * @Date: (2023-10-28)
 * @LastEditors: (lwh)
 * @LastEditTime: (2023-10-28)
-->
<template>
  <el-dialog v-model="props.modelValue" title="修改表情包信息" width="900px" @closed="closeDialog" @open="openDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row :gutter="20">
	  

    
    
    
          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="分类guid" prop="emoticonCategoryGuid">
              <el-input v-model="formData.emoticonCategoryGuid" placeholder="请输入分类guid" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="名称" prop="emoticonDataName">
              <el-input v-model="formData.emoticonDataName" placeholder="请输入名称" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="图片" prop="emoticonDataImg">
              <UploadImage ref="uploadRef" v-model="formData.emoticonDataImg" :data=imgData :limit="1" :fileSize="5"
              :drag="true" />
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="排序" prop="emoticonDataSort">
              <el-input-number v-model.number="formData.emoticonDataSort" controls-position="right" :min="0" />
            </el-form-item>
          </el-col>






      </el-row>
    </el-form>

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

<script setup>
import { ElMessage } from 'element-plus'
import modal from '@/plugins/modal.js'
import { reactive, ref, watch } from "vue";
import {  addOrUpdateEmoticonData } from "@/api/business/EmotionManage/EmoticonDatas/emoticonData.js";


// 打开弹窗时回调
const openDialog = async () => {

}

const formData = ref({
  ...props.data,
});
watch(props, async (v) => {
  formData.value = v.data;

});

// 业务参数

// -业务方法



// -基础参数
const props = defineProps({
  modelValue: Boolean,
  data: Object,
  done: Function,
});

const loadingStatus = ref(false)
const labelWidth = 100;
const formRef = ref();
const { proxy } = getCurrentInstance()
const emits = defineEmits(["update:modelValue"]);
const imgData = ref({
  fileDir: "EmoticonData"
})

// 验证
const rules = reactive({
    emoticonDataGuid: [{ required: true, message: "不能为空", trigger: "blur", type: "number" }],
    emoticonCategoryGuid: [{ required: true, message: "分类guid不能为空", trigger: "blur", type: "number" }],
    emoticonDataImg: [{ required: true, message: "图片不能为空", trigger: "blur" }],
    emoticonDataSort: [{ required: true, message: "排序不能为空", trigger: "blur", type: "number" }],
});

// -基础方法
// 提交
const handleEditClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    loadingStatus.value = true


    const { code } = await addOrUpdateEmoticonData(formData.value);
    if (code == 200) {
      modal.msgSuccess('修改成功')
      closeDialog();
      loadingStatus.value = false
    }
  });
}

const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
}
const closeDialog = () => {
  props.done();
  emits("update:modelValue", false);
};

</script>
