123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- const NET = require('../../../utils/request')
- const API = require('../../../config/api')
- import { showLoading, hideLoading } from '@/utils/plugIn/globalLoading.js'
- export async function getPriceBySelect(dataList) {
- showLoading()
- const addCart = []
-
- for (let i = 0; i < dataList.length; i++) {
- const shopObj = {}
- const theCurrentShop = dataList[i]
- shopObj.shopId = theCurrentShop.shopId
- shopObj.skus = []
- for (let j = 0; j < theCurrentShop.skus.length; j++) {
- const theCurrentSku = dataList[i].skus[j]
-
- if (theCurrentSku.selected) {
- const skusObj = {}
- skusObj.ifLogistics = theCurrentSku.ifLogistics
- skusObj.number = theCurrentSku.number
- skusObj.selected = theCurrentSku.selected
- skusObj.skuId = theCurrentSku.skuId
- shopObj.skus.push(skusObj)
- }
- }
-
- if (shopObj.skus.length > 0) {
- addCart.push(shopObj)
- }
- }
- try {
- const postData = {
- type: 2,
- shops: addCart,
- voucherTotalAll: 0,
- isVoucher: false,
- voucherId: 0
- }
- const res = await NET.request(API.Settlement, postData, 'POST')
- const money = res.data.shops.reduce((previousValue, currentValue) => previousValue + currentValue.total, 0)
- return {
- money: money.toFixed(2),
- shopList: addCart
- }
- } finally {
- hideLoading()
- }
- }
- export async function getCartNumberBySelect(dataList) {
- let allNumber = 0; let checkNumber = 0; let
- isAllCheck = true
-
- for (let i = 0; i < dataList.length; i++) {
-
- const shopObj = dataList[i]
-
- for (let j = 0; j < shopObj.skus.length; j++) {
- const good = dataList[i].skus[j]
- allNumber += good.number
- if (good.selected === 1) {
- checkNumber += +good.number
- } else {
-
- if (isAllCheck) {
- isAllCheck = false
- }
- }
- }
- }
-
- uni.setStorageSync('allCartNum', allNumber)
-
- if (allNumber > 0) {
- uni.setTabBarBadge({
- index: 3,
- text: allNumber.toString()
- })
- } else {
- uni.removeTabBarBadge({
- index: 3
- })
- }
- return {
- allNumber, checkNumber, isAllCheck
- }
- }
- export const defaultCartList = [
- {
- shopId: 1,
- shopName: '12312312321312312',
- selected: 0,
- skus: [
- {
- productId: 1,
- productName: '',
- image: '',
- price: 0,
- number: 0,
- selected: 0
- },
- {
- productId: 2,
- productName: '',
- image: '',
- price: 0,
- number: 0,
- selected: 0
- },
- {
- productId: 3,
- productName: '',
- image: '',
- price: 0,
- number: 0,
- selected: 0
- }
- ]
- }
- ]
|