import { reactive, ref } from 'vue'
interface amout {
  freightAmount: number
  payAmount: number
  promotionAmount: number
  totalAmount: number
}
interface cart {
  calcAmount: amout
  cartPromotionItemList: Array<any>[]
}

export interface addressType {
  city: string
  defaultStatus?: number
  detailAddress: string
  id?: number
  memberId?: number
  name: string
  phoneNumber: string
  postCode: string
  province: string
  region: string
}
export const cartConfirm = reactive({
  calcAmount: {} as amout,
  cartPromotionItemList: [] as Array<any>[],
  memberReceiveAddressList: [] as Array<addressType>,
  orderInfo: {} as any
})
type Item = {
  key: string
  value: string
}
export const formateAttr = (productAttr: string) => {
  let arr = null as any
  try {
    arr = JSON.parse(productAttr)
  } catch (err) {}
  if (Array.isArray(arr)) {
    let str: string = ''
    let item: Item
    for (item of arr) {
      str += `${item.key}: ${item.value} `
    }
    return str
  }
  return productAttr
}
