<template>
  <el-form label-width="120px" class="view" v-loading="formLoading" :class="{ 'mobile-card': mobile }">
    <el-row>
      <el-col :span="12">
        <el-form-item label="商户单号">
         <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.merchantOrderId }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12" v-if="detailData.no">
        <el-form-item label="支付单号">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.no }}</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="应用编号">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.appId }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="应用名称">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.appName }}</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="支付状态">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ getDictLabel(DICT_TYPE.PAY_ORDER_STATUS, detailData.status) }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="支付金额">
          <div class="el-input el-input--default is-disabled el-input--suffix ">￥{{ (detailData.price / 100.0).toFixed(2) }}</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="手续费">
          <div class="el-input el-input--default is-disabled el-input--suffix ">￥{{ (detailData.channelFeePrice / 100.0).toFixed(2) }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="手续费比例">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ (detailData.channelFeeRate / 100.0).toFixed(2) }}%</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="支付时间">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ formatDate(detailData.successTime) }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="失效时间">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ formatDate(detailData.expireTime) }}</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="创建时间">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ formatDate(detailData.createTime) }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="更新时间">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ formatDate(detailData.updateTime) }}</div>
        </el-form-item>
      </el-col>
    </el-row>
    <el-row>
      <el-col :span="12">
        <el-form-item label="商品标题">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.subject }}</div>
        </el-form-item>
      </el-col>
      <el-col :span="12">
        <el-form-item label="商品描述">
          <div class="el-input el-input--default is-disabled el-input--suffix ">{{ detailData.body }}</div>
        </el-form-item>
      </el-col>
    </el-row>
  </el-form>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getDictLabel } from '@/utils/dict'
import * as OrderApi from '@/api/pay/order'
import { formatDate } from '@/utils/formatTime'
import { useAppStore } from '@/store/modules/app'
const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)
defineOptions({ name: 'PayOrderDetail' })

const dialogVisible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({
  extension: {}
})
const props = defineProps({
  obj: {
    default: {}
  }
})
/** 打开弹窗 */
const open = async (id: number) => {
  dialogVisible.value = true
  // 设置数据
  detailLoading.value = true
  try {
    detailData.value = await OrderApi.getOrderDetail(id)
    if (!detailData.value.extension) {
      detailData.value.extension = {}
    }
  } finally {
    detailLoading.value = false
  }
}
onMounted(() => {
  open(props.obj.id)
})
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<style src="@/styles/PcComponents.css"  lang="scss" scoped></style>
