<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    width="75%"
    :visible="visible"
    :confirm-loading="loading"
    :title="'订单详情'"
    :body-style="{ paddingBottom: '8px' }"
    @update:visible="updateVisible"
    :footer="null"
  >
    <a-form
      :label-col="{ md: { span: 4 }, sm: { span: 24 } }"
      :wrapper-col="{ md: { span: 19 }, sm: { span: 24 } }"
    >
      <div class="base-form" style="margin-bottom: 20px">
        <a-descriptions title="订单详情" bordered>
          <a-descriptions-item label="订单号">
            {{ cashier.outTradeNo }}
          </a-descriptions-item>
          <a-descriptions-item label="客户ID">
            {{ cashier.buyerId }}
          </a-descriptions-item>
          <a-descriptions-item label="支付标识">
            {{ cashier.code }}
          </a-descriptions-item>
          <a-descriptions-item label="数量">
            {{ cashier.amount }}
          </a-descriptions-item>
          <a-descriptions-item label="支付时间">
            {{ cashier.payTime }}
          </a-descriptions-item>
          <a-descriptions-item label="订单状态">
            {{ cashier.orderStatus }}
          </a-descriptions-item>
          <a-descriptions-item label="商户名称">
            {{ cashier.merchantName }}
          </a-descriptions-item>
          <a-descriptions-item label="手机号码">
            {{ cashier.mobile }}
          </a-descriptions-item>
          <a-descriptions-item label="消息">
            {{ cashier.msg }}
          </a-descriptions-item>
          <a-descriptions-item label="支付方式">
            {{ cashier.payType }}
          </a-descriptions-item>
          <a-descriptions-item label="交易金额">
            <a-statistic type="circle" :value="cashier.totalAmount" />
          </a-descriptions-item>
          <a-descriptions-item label="实收金额">
            <a-statistic type="circle" :value="cashier.receiptAmount" />
          </a-descriptions-item>
          <a-descriptions-item label="手续费">
            <a-statistic :value="cashier.feeAmount" />
          </a-descriptions-item>
          <a-descriptions-item label="第三方交易手续费">
            <a-statistic :value="cashier.feeAmount" />
          </a-descriptions-item>
          <a-descriptions-item label="结算金额">
            <a-statistic :value="cashier.settleAmount" />
          </a-descriptions-item>
          <a-descriptions-item label="备注">
            {{ cashier.orderRemark }}
          </a-descriptions-item>
        </a-descriptions>
      </div>
    </a-form>
  </ele-modal>
</template>

<script lang="ts" setup>
  import { ref, reactive, watch } from 'vue';
  import { Form } from 'ant-design-vue';
  import { assignObject } from 'ele-admin-pro';
  import type { Cashier } from '@/api/apps/cashier/model';
  import { AntDesignOutlined } from '@ant-design/icons-vue';

  const useForm = Form.useForm;

  const props = defineProps<{
    // 弹窗是否打开
    visible: boolean;
    // 修改回显的数据
    data?: Cashier | null;
  }>();

  const emit = defineEmits<{
    (e: 'done'): void;
    (e: 'update:visible', visible: boolean): void;
  }>();

  // 用户信息
  const cashier = reactive<Cashier>({
    cashierId: 0,
    outTradeNo: '',
    buyerId: '',
    payType: '',
    code: '',
    amount: undefined,
    totalAmount: undefined,
    feeAmount: undefined,
    receiptAmount: undefined,
    settleAmount: undefined,
    orderRemark: '',
    orderStatus: '',
    payTime: '',
    merchantName: '',
    mobile: '',
    msg: '',
    tenantId: 2
  });

  // 请求状态
  const loading = ref(true);

  const { resetFields } = useForm(cashier);

  /* 更新visible */
  const updateVisible = (value: boolean) => {
    emit('update:visible', value);
  };

  /* 打开外部链接 */
  // const openUrl = (record) => {
  //   window.open(record.panel);
  // };

  watch(
    () => props.visible,
    (visible) => {
      if (visible) {
        if (props.data) {
          loading.value = false;
          assignObject(cashier, props.data);
        }
      } else {
        resetFields();
      }
    }
  );
</script>
<style lang="less">
  .tab-pane {
    min-height: 100px;
  }
</style>
