<template>
  <el-container>
    <el-main>
      <el-form ref="formRef" :model="form.model" :rules="form.rules">
        <el-form-item label="拒绝原因" prop="refuse_msg">
          <el-input v-model="form.model.refuse_msg" placeholder="请输入拒绝原因" />
        </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: {
      refuse_msg: '',
    },
    rules: {
      refuse_msg: [{ required: true, message: '请输入拒绝原因', trigger: 'blur' }],
    },
  });

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