<template>
  <el-container>
    <el-main>
      <el-form ref="formRef" :model="form.model" :rules="form.rules" label-width="80px">
        <el-form-item label="回复内容" prop="content">
          <el-input type="textarea" v-model="form.model.content" placeholder="请输入" />
        </el-form-item>
        <el-form-item label="选择图片">
          <sa-uploader
            v-model="form.model.images"
            :multiple="true"
            max="9"
            fileType="image"
          ></sa-uploader>
        </el-form-item>
      </el-form>
    </el-main>
    <el-footer class="sa-footer--submit">
      <el-button type="primary" @click="confirm">确定</el-button>
    </el-footer>
  </el-container>
</template>
<script setup>
  import { reactive, ref, unref } from 'vue';
  import { api } from '../order.service';

  const emit = defineEmits(['modalCallBack']);
  const props = defineProps(['modal']);

  const formRef = ref();
  const form = reactive({
    model: {
      content: '',
      images: [],
    },
    rules: {
      content: [{ required: true, message: '请输入', trigger: 'blur' }],
    },
  });

  function confirm() {
    unref(formRef).validate(async (valid) => {
      if (!valid) return;
      if (valid) {
        const { code } = await api.aftersale.addLog(props.modal.params.id, {
          content: form.model.content,
          images: form.model.images,
        });
        if (code == '200') {
          emit('modalCallBack', { event: 'confirm' });
        }
      }
    });
  }
</script>
