<!--
 * @Descripttion: (商品评价/tb_goods_comment 回复弹窗)
 * @version: (1.0)
 * @Author: (admin)
 * @Date: (2023-07-17)
 * @LastEditors: (admin)
 * @LastEditTime: (2023-07-17)
-->
<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="24">
          <el-form-item :label-width="labelWidth" label="回复内容" prop="goodsCommentRecoverContent">
            <el-input v-model.number="formData.goodsCommentRecoverContent" type="textarea" :rows="10" />
          </el-form-item>
        </el-col>

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

    <template #footer>
      <div key="dialog-footer">
        <el-button type="primary" @click="handleRecoverClick(formRef)" :loading="loadingStatus">确认</el-button>
      </div>
    </template>
  </el-dialog>
</template>


<script setup>
import { reactive, ref, watch } from "vue";
import modal from '@/plugins/modal.js'
import { goodsCommentRecover } from '@/api/business/GoodsManager/GoodsComments/goodsComment.js';

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

}

// -业务参数

// -业务方法


// -基础参数
const loadingStatus = ref(false)
const labelWidth = 100;
const formRef = ref();
const { proxy } = getCurrentInstance()
const emits = defineEmits(["update:modelValue"]);
const formData = ref({
  ...props.data,
});
const props = defineProps({
  modelValue: Boolean,
  data: Object,
  done: Function,
});

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

// 验证
const rules = reactive({
  goodsCommentRecoverContent: [{ required: true, message: "回复内容不能为空", trigger: "blur" }],
});

// -基础方法

// 提交
const handleRecoverClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    loadingStatus.value = true
    formData.value.goodsCommentId = props.data.goodsCommentId

    const { code, data } = await goodsCommentRecover(formData.value);
    if (code == 200) {
      modal.msgSuccess(data)
      closeDialog();
      loadingStatus.value = false
    }
  });
};
const closeDialog = () => {
  handleResetClick(formRef.value);
  props.done();
  emits("update:modelValue", false);
};
const handleResetClick = async (formEl) => {
  if (!formEl) return;
  formEl.resetFields();
};
</script>