<template>
  <el-dialog v-model="props.modelValue" title="修改支付订单信息" width="900px" @closed="closeDialog">
    <el-form ref="formRef" :model="formData" :rules="rules">
      <el-row :gutter="20">
	  
    
    

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="超时付款订单号" prop="paymentOvertimeNumber">
              <el-input v-model="formData.paymentOvertimeNumber" placeholder="请输入超时付款订单号" />
            </el-form-item>
          </el-col>





    
          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="操作状态(1待支付 |2已支付 | 3已取消 | 4已退款)" prop="paymentStatus">
              <el-select v-model="formData.paymentStatus" placeholder="请选择操作状态(1待支付 |2已支付 | 3已取消 | 4已退款)">
                <el-option v-for="item in  paymentStatusOptions" :key="item.dictValue" :label="item.dictLabel" :value="parseInt(item.dictValue)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="核销后价格/操作金额" prop="paymentMoney">
              <el-input v-model="formData.paymentMoney" placeholder="请输入核销后价格/操作金额" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="核销前价格" prop="paymentBeforeMoney">
              <el-input v-model="formData.paymentBeforeMoney" placeholder="请输入核销前价格" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="退款订单号" prop="paymentRefundNumber">
              <el-input v-model="formData.paymentRefundNumber" placeholder="请输入退款订单号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="微信支付订单号" prop="paymentWeixinNumber">
              <el-input v-model="formData.paymentWeixinNumber" placeholder="请输入微信支付订单号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="系统订单号" prop="paymentNumber">
              <el-input v-model="formData.paymentNumber" placeholder="请输入系统订单号" />
            </el-form-item>
          </el-col>

          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="操作客户guid(外键)" prop="customerGuid">
              <el-input v-model="formData.customerGuid" placeholder="请输入操作客户guid(外键)" />
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="业务订单guid(外键)" prop="paymentBusinessGuid">
              <el-input v-model="formData.paymentBusinessGuid" placeholder="请输入业务订单guid(外键)" />
            </el-form-item>
          </el-col>
    
          <el-col :lg="12">
            <el-form-item :label-width="labelWidth" label="购买类型(1|  )" prop="paymentBuytype">
              <el-select v-model="formData.paymentBuytype" placeholder="请选择购买类型(1|  )">
                <el-option v-for="item in  paymentBuytypeOptions" :key="item.dictValue" :label="item.dictLabel" :value="parseInt(item.dictValue)"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="handleEditClick(formRef)">编辑</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 { addOrUpdatePayment } from "@/api/business/payments/payment.js";

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

const labelWidth = 100;
const formRef = ref();
const { proxy } = getCurrentInstance()
const emits = defineEmits(["update:modelValue"]);
const formData = ref({
  ...props.data,
});
const imgData = ref({
  fileDir: "Payment"
})

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

// 验证
const rules = reactive({
    paymentGuid: [{ required: true, message: "支付订单guid不能为空", trigger: "blur", type: "number" }],
    paymentStatus: [{ required: true, message: "操作状态(1待支付 |2已支付 | 3已取消 | 4已退款)不能为空", trigger: "change", type: "number" }],
    paymentNumber: [{ required: true, message: "系统订单号不能为空", trigger: "blur" }],
    customerGuid: [{ required: true, message: "操作客户guid(外键)不能为空", trigger: "blur" }],
    paymentBuytype: [{ required: true, message: "购买类型(1|  )不能为空", trigger: "change", type: "number" }],
});

// 操作状态(1待支付 |2已支付 | 3已取消 | 4已退款)选项列表
const paymentStatusOptions = ref([
	{ dictLabel: '', dictValue: '1' },
	{ dictLabel: '', dictValue: '2' },
]);
// 购买类型(1|  )选项列表
const paymentBuytypeOptions = ref([
	{ dictLabel: '', dictValue: '1' },
	{ dictLabel: '', dictValue: '2' },
]);

// 业务参数


// -业务方法


// -基础方法
// 提交
const handleEditClick = async (formEl) => {
  if (!formEl) return;
  formEl.validate(async (valid) => {
    if (!valid) {
      return;
    }
    const { code } = await addOrUpdatePayment(formData.value);
    if (code == 200) {
      modal.msgSuccess('修改成功')
      closeDialog();
    }
  });
}

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

</script>
