import { memberType } from '@/constant'
import request from '@/helpers/request'
import { orderStatus } from '@/views/order-detail/orderStatus'
import dayjs from 'dayjs'
// LIVE: '直播课',
// PRACTICE: '陪练课',
// VIDEO: '视频课',
// VIP: '开通会员',
// MUSIC: '单曲点播'
export const formatOrderDetail = async (item: any) => {
  const type = item.goodType
  let tempList: any = {}

  switch (type) {
    case 'PINAO_ROOM':
      {
        try {
          const res = await getPinaoDetail(item.bizId)
          console.log('res', res)
          tempList = {
            orderType: item.goodType,
            goodsName: item.goodName,
            ...res
          }
        } catch (e: any) {
          throw new Error(e.message)
        }
      }
      break
  }
  tempList.orderType = type
  tempList.goodName = item.goodName
  orderStatus.orderObject.orderList.push(tempList)
}

// 获取时长详情失败
export const getPinaoDetail = async (id: any) => {
  try {
    const res = await request.get(`/api-teacher/pianoRoomSettings/detail/${id}`)
    return res.data
  } catch {
    throw new Error('获取时长详情失败')
  }
}

export const tradeOrder = (result: any, callBack?: any) => {
  const {
    orderNo,
    actualPrice,
    orderDesc,
    orderName,
    orderType,
    orderDetailList
  } = result
  orderStatus.orderObject.orderType = orderType
  orderStatus.orderObject.orderName = orderName
  orderStatus.orderObject.orderDesc = orderDesc
  orderStatus.orderObject.actualPrice = actualPrice
  orderStatus.orderObject.orderNo = orderNo
  orderStatus.orderObject.actualPrice = actualPrice
  orderStatus.orderObject.orderList = []
  try {
    orderDetailList.forEach(async (item: any) => {
      await formatOrderDetail(item)
    })
    callBack && callBack()
  } catch {
    //
  }
}
