<template>
  <ContentWrap :class="{ 'mobile-card': mobile }" style="border:none;padding: 1rem 0 0 1rem;">
    <el-descriptions>
        <el-descriptions-item labelClassName="no-colon">
          <el-timeline>
            <el-timeline-item
              v-for="saleLog in formData.logs"
              :key="saleLog.id"
              :timestamp="formatDate(saleLog.createTime)"
              placement="top"
            >
              <div class="el-timeline-right-content">
                <span>{{ saleLog.content }}</span>
              </div>
              <template #dot>
                <span
                  :style="{ backgroundColor: getUserTypeColor(saleLog.userType) }"
                  class="dot-node-style"
                >
                  {{ getDictLabel(DICT_TYPE.USER_TYPE, saleLog.userType)[0] || '系' }}
                </span>
              </template>
            </el-timeline-item>
          </el-timeline>
        </el-descriptions-item>
      </el-descriptions>
  </ContentWrap>
</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'
const appStore = useAppStore()
const mobile = computed(() => appStore.getMobile)
defineOptions({ name: 'TradeAfterSaleDetail' })
const formData = ref({
  order: {},
  logs: []
})

const props = defineProps({
  obj: {
    default: {}
  }
})
/** 获得 userType 颜色 */
const getUserTypeColor = (type: number) => {
  const dict = getDictObj(DICT_TYPE.USER_TYPE, type)
  switch (dict?.colorType) {
    case 'success':
      return '#67C23A'
    case 'info':
      return '#909399'
    case 'warning':
      return '#E6A23C'
    case 'danger':
      return '#F56C6C'
  }
  return '#409EFF'
}
/** 获得详情 */
const getDetail = async (id) => {
  if (id) {
    const res = await AfterSaleApi.getAfterSale(id)
    // 没有表单信息则关闭页面返回
    if (res == null) {
      message.notifyError('售后订单不存在')
      close()
    }
    formData.value = res
  }
}
onMounted(() => {
  getDetail(props.obj.id)
})
defineExpose({ getDetail }) // 提供 open 方法，用于打开弹窗
</script>

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