import { orderStatus } from '@/views/order-detail/orderStatus'
import { postMessage } from '@/helpers/native-message'
import { Dialog } from 'vant'
import qs from 'query-string'

export const getRandomKey = () => {
  const key = '' + new Date().getTime() + Math.floor(Math.random() * 1000000)
  return key
}

export const musicBuy = (item: any, callBack?: any, moreQuery = {}) => {
  const behaviorId = localStorage.getItem('behaviorId') || ''
  const url = qs.stringifyUrl({
    url: location.origin + '/accompany',
    query: {
      id: item.id,
      behaviorId,
      ...moreQuery
    }
  })
  postMessage({
    api: 'openAccompanyWebView',
    content: {
      url,
      // url: 'http://192.168.3.13:3000/colexiu.html?id=' + item.id,
      orientation: 0,
      isHideTitle: true,
      statusBarTextColor: false,
      isOpenLight: true
    }
  })
  return
  // play :0 不能看,1 能看
  const path =
    !item.play && item.chargeType === 'VIP' ? '/memberCenter' : '/orderDetail'
  if (!item.play && item.chargeType === 'VIP') {
    Dialog.confirm({
      title: '提示',
      message: '您还不是会员，是否加入会员？',
      confirmButtonColor: 'var(--van-primary)'
    }).then(() => {
      callBack && callBack(path)
    })
    return
  } else if (!item.play && item.chargeType === 'CHARGE') {
    orderStatus.orderObject.orderType = 'MUSIC'
    orderStatus.orderObject.orderName = item.musicSheetName
    orderStatus.orderObject.orderDesc = item.musicSheetName
    orderStatus.orderObject.actualPrice = item.musicPrice
    orderStatus.orderObject.orderList = [
      {
        orderType: 'MUSIC',
        goodsName: item.musicSheetName,
        actualPrice: item.musicPrice,
        ...item
      }
    ]
    callBack && callBack(path)
  }
}
