<template>
  <el-container>
    <el-main>
      <el-alert class="sa-alert sa-m-b-20">
        <template #title>
          <div> 注意：改价订单不会影响原分佣金额 </div>
        </template>
      </el-alert>
      <el-form ref="formRef" :model="form.model" :rules="form.rules">
        <el-form-item label="当前订单总金额" prop="refund_type">
          ¥{{ modal.params.pay_fee }}
        </el-form-item>
        <el-form-item label="修改价格" prop="pay_fee">
          <el-input v-model="form.model.pay_fee" placeholder="数值必须大于0" type="number">
            <template #append>元</template>
          </el-input>
        </el-form-item>
        <el-form-item label="改价原因" prop="change_msg">
          <el-input
            v-model="form.model.change_msg"
            autosize
            type="textarea"
            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: {
      pay_fee: '',
      change_msg: '',
    },
    rules: {
      pay_fee: [{ required: true, message: '请输入退款金额', trigger: 'blur' }],
      change_msg: [{ required: true, message: '请输入退款金额', trigger: 'blur' }],
    },
  });

  function confirm() {
    unref(formRef).validate(async (valid) => {
      if (!valid) return;
      if (valid) {
        const { code } = await api.order.changeFee(props.modal.params.id, form.model);
        if (code == '200') {
          emit('modalCallBack', { event: 'confirm' });
        }
      }
    });
  }
</script>
<style lang="scss">
  .sa-dialog {
    &.fee-dialog {
      --el-dialog-width: 500px;
    }
  }
</style>
