cashier-ipad/pagesCreateOrder/util.js

78 lines
2.4 KiB
JavaScript

import {
returnBoolean
} from '@/commons/utils/format.js';
// 返回购物车未下单的数据
export function getNowCart(carItem,goodsList,user) {
// console.log("carItem===",carItem)
// console.log("goodsList===",goodsList)
// const nowCart = records.find(v => v.placeNum == 0)
const arr = []
if( carItem.is_temporary != 1 ){
carItem.isGrounding = false;
goodsList.map(goodsItem => {
if(carItem.product_id == goodsItem.id){
goodsItem.skuList.map(item=>{
if(carItem.product_id == item.productId){
carItem.lowPrice = item.salePrice
carItem.lowMemberPrice = item.memberPrice
carItem.specInfo = item.specInfo
if( uni.getStorageSync('shopInfo').isMemberPrice && user && user.id && user.isVip ){
carItem.salePrice = item.memberPrice
} else {
carItem.salePrice = item.salePrice
}
}
})
carItem.name = goodsItem.name
carItem.coverImg = goodsItem.coverImg
carItem.packFee = goodsItem.packFee
carItem.type = goodsItem.type
carItem.isGrounding = true;
}
carItem.number = parseFloat(carItem.number)
})
} else {
// 临时菜
console.log(carItem,'salePrice1111111111')
carItem.number = parseFloat(carItem.number)
carItem.name = carItem.product_name
carItem.lowPrice = carItem.discount_sale_amount
carItem.discount_sale_amount = 0
}
return carItem
}
// export function getNowCart(records) {
// const nowCart = records.find(v => v.placeNum == 0)
// const Cart = nowCart ? nowCart.info : []
// const goodsMap = {}
// const arr = []
// for (let i in Cart) {
// const item=Cart[i]
// const key = item.productId + '_' + item.skuId
// if (goodsMap.hasOwnProperty(key)) {
// const index = goodsMap[key]
// arr[index].number = arr[index].number * 1 + item.number
// arr[index].totalNumber = arr[index].totalNumber * 1 + item.totalNumber
// arr[index].totalAmount = arr[index].totalAmount * 1 + item.totalAmount
// arr[index].packFee = arr[index].packFee * 1 + item.packFee
// } else {
// arr.push({
// ...item,
// isPack: returnBoolean(item.isPack),
// isGift: returnBoolean(item.isGift)
// })
// goodsMap[key] = arr.length - 1;
// }
// }
// // const result = Cart.map(item => {
// // return {
// // ...item,
// // isPack: returnBoolean(item.isPack),
// // isGift: returnBoolean(item.isGift)
// // }
// // })
// return arr
// }