<template>
  <el-form label-width="120px" class="view" :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 ">{{ formData.no }}</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(formData.auditTime) }}
          </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.TRADE_AFTER_SALE_TYPE, formData.type) }}</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 ">{{
    getDictLabel(DICT_TYPE.TRADE_AFTER_SALE_WAY, formData.way) }}</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 ">{{ fenToYuan(formData.refundPrice) }}
          </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 ">{{ formData.applyReason }}</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 ">{{ formData.applyDescription }}</div>
        </el-form-item>
      </el-col>

      <el-col :span="12">
        <el-form-item label="凭证图片">
          <el-image v-for="(item, index) in formData.applyPicUrls" :key="index" :src="item"
            class="mr-10px h-60px w-60px" @click="imagePreview(formData.applyPicUrls)" />
        </el-form-item>

      </el-col>
    </el-row>

  </el-form>
</template>
<script lang="ts" setup>
import * as AfterSaleApi from '@/api/mall/trade/afterSale/index'
import { DICT_TYPE, getDictLabel, getDictObj } from '@/utils/dict'
import { formatDate } from '@/utils/formatTime'
import { useAppStore } from '@/store/modules/app'
import { createImageViewer } from '@/components/ImageViewer'
import { fenToYuan } from '@/utils'
import { isArray } from '@/utils/is'

const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)
defineOptions({ name: 'TradeAfterSaleDetail' })
const formData = ref({
  order: {},
  logs: []
})

const props = defineProps({
  obj: {
    default: {}
  }
})
/** 获得详情 */
const getDetail = async (id) => {
  if (id) {
    const res = await AfterSaleApi.getAfterSale(id)
    // 没有表单信息则关闭页面返回
    if (res == null) {
      message.notifyError('售后订单不存在')
      close()
    }
    formData.value = res
  }
}
/** 图片预览 */
const imagePreview = (args) => {
  const urlList = []
  if (isArray(args)) {
    args.forEach((item) => {
      urlList.push(item)
    })
  } else {
    urlList.push(args)
  }
  createImageViewer({
    urlList,
    zIndex: 9999
  })
}
onMounted(() => {
  getDetail(props.obj.id)
})
defineExpose({ getDetail }) // 提供 open 方法，用于打开弹窗
</script>

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