购物车:接入修改数量 API,剩余所有
parent
6bdbebe2a0
commit
e45372d4b6
|
@ -19,6 +19,13 @@ export function createFavorite(spuId) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 添加多个商品收藏
|
||||||
|
export function createFavoriteList(spuIds) {
|
||||||
|
return request.post('app-api/product/favorite/create-list', {
|
||||||
|
spuIds
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 取消商品收藏
|
// 取消商品收藏
|
||||||
export function deleteFavorite(spuId) {
|
export function deleteFavorite(spuId) {
|
||||||
return request.delete('app-api/product/favorite/delete', {
|
return request.delete('app-api/product/favorite/delete', {
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
<text v-for="property in item.sku.properties" style="padding-left: 2px">{{property.valueName}}</text>
|
<text v-for="property in item.sku.properties" style="padding-left: 2px">{{property.valueName}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class='money' v-if="item.canChecked">¥{{ fen2yuan(item.sku.price) }}</view>
|
<view class='money' v-if="item.canChecked">¥{{ fen2yuan(item.sku.price) }}</view>
|
||||||
<!-- TODO 芋艿:重选 -->
|
|
||||||
<view class="reElection acea-row row-between-wrapper" v-else>
|
<view class="reElection acea-row row-between-wrapper" v-else>
|
||||||
<view class="title">请重新选择商品规格</view>
|
<view class="title">请重新选择商品规格</view>
|
||||||
<view class="reBnt cart-color acea-row row-center-wrapper" @click.stop="reElection(item)">重选</view>
|
<view class="reBnt cart-color acea-row row-center-wrapper" @click.stop="reElection(item)">重选</view>
|
||||||
|
@ -97,16 +96,16 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- TODO -->
|
<!-- 热门推荐 -->
|
||||||
<view class='noCart' v-if="cartList.valid.length === 0 && cartList.invalid.length === 0 && canShow">
|
<view class='noCart' v-if="cartList.valid.length === 0 && cartList.invalid.length === 0 && canShow">
|
||||||
<view class='pictrue'>
|
<view class='pictrue'>
|
||||||
<image src='../../static/images/noCart.png'></image>
|
<image src='../../static/images/noCart.png' />
|
||||||
</view>
|
</view>
|
||||||
<recommend :hostProduct='hostProduct'></recommend>
|
<recommend :hostProduct='hostProduct'></recommend>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- TODO -->
|
<!-- 管理操作 -->
|
||||||
<view class='footer acea-row row-between-wrapper' v-if="cartList.valid.length > 0">
|
<view class='footer acea-row row-between-wrapper' v-if="cartList.valid.length > 0">
|
||||||
<view>
|
<view>
|
||||||
<checkbox-group @change="checkboxAllChange">
|
<checkbox-group @change="checkboxAllChange">
|
||||||
|
@ -129,10 +128,18 @@
|
||||||
</form>
|
</form>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- SKU 不可用的商品,重新选择 SKU TODO -->
|
<!-- SKU 不可用的商品,重新选择 SKU -->
|
||||||
<productWindow :attr="attr" :isShow='1' :iSplus='1' :iScart='1' @myevent="onMyEvent" @ChangeAttr="ChangeAttr"
|
<productWindow
|
||||||
@ChangeCartNum="ChangeCartNum" @attrVal="attrVal" @iptCartNum="iptCartNum" @goCat="reGoCat"
|
:attr="attr"
|
||||||
id='product-window'></productWindow>
|
:isShow='1'
|
||||||
|
:iSplus='1'
|
||||||
|
:iScart='1'
|
||||||
|
@ChangeAttr="ChangeAttr"
|
||||||
|
@ChangeCartNum="ChangeCartNum"
|
||||||
|
@iptCartNum="iptCartNum"
|
||||||
|
@close="closeAttr"
|
||||||
|
@goCat="reGoCat"
|
||||||
|
/>
|
||||||
<view class="uni-p-b-96" />
|
<view class="uni-p-b-96" />
|
||||||
<view class="uni-p-b-98" />
|
<view class="uni-p-b-98" />
|
||||||
</view>
|
</view>
|
||||||
|
@ -140,14 +147,16 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
let sysHeight = 0
|
let sysHeight = 0
|
||||||
import { cartDel, getResetCart } from '@/api/order.js';
|
|
||||||
import { getProductHot, collectAll, getProductDetail } from '@/api/store.js';
|
|
||||||
import { toLogin } from '@/libs/login.js';
|
import { toLogin } from '@/libs/login.js';
|
||||||
import { mapGetters } from "vuex";
|
import { mapGetters } from "vuex";
|
||||||
import recommend from '@/components/recommend';
|
import recommend from '@/components/recommend';
|
||||||
import productWindow from '@/components/productWindow';
|
import productWindow from '@/components/productWindow';
|
||||||
import * as TradeCartApi from '@/api/trade/cart.js';
|
import * as TradeCartApi from '@/api/trade/cart.js';
|
||||||
|
import * as ProductSpuApi from '@/api/product/spu.js'
|
||||||
|
import * as ProductFavoriteApi from '@/api/product/favorite.js';
|
||||||
import * as Util from '@/utils/util.js';
|
import * as Util from '@/utils/util.js';
|
||||||
|
import * as ProductUtil from '@/utils/product.js';
|
||||||
|
import * as PromotionActivityApi from '@/api/promotion/activity.js';
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
recommend,
|
recommend,
|
||||||
|
@ -155,13 +164,15 @@
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
goodsHidden: false,
|
sysHeight: sysHeight,
|
||||||
|
goodsHidden: false,
|
||||||
footerswitch: true,
|
footerswitch: true,
|
||||||
hostProduct: [],
|
hostProduct: [],
|
||||||
hotPage: 1,
|
hotPage: 1,
|
||||||
hotLimit: 10,
|
hotLimit: 10,
|
||||||
hotScroll: false,
|
hotScroll: false,
|
||||||
|
|
||||||
|
// 购物车列表
|
||||||
cartList: { // 购物车列表
|
cartList: { // 购物车列表
|
||||||
valid: [], // 有效
|
valid: [], // 有效
|
||||||
invalid: [] // 无效
|
invalid: [] // 无效
|
||||||
|
@ -170,22 +181,20 @@
|
||||||
selectValue: [], // 选中的数据
|
selectValue: [], // 选中的数据
|
||||||
selectCountPrice: 0.00, // 选中的金额
|
selectCountPrice: 0.00, // 选中的金额
|
||||||
cartCount: 0, // 选中的商品数量
|
cartCount: 0, // 选中的商品数量
|
||||||
|
canShow: false, // 是否可展示
|
||||||
|
|
||||||
loading: false,
|
// 重选
|
||||||
loadTitle: '加载更多', //提示语
|
cartId: 0, // 重选的 cart id
|
||||||
attr: {
|
product_id: 0, // 重选的 SPU 编号
|
||||||
cartAttr: false,
|
attr: { // productWindow 组件,使用该属性
|
||||||
productAttr: [],
|
cartAttr: false, // 是否打开属性的选择弹出
|
||||||
productSelect: {}
|
// ↓↓↓ 属性数组,结构为:id = 属性编号;name = 属性编号的名字;values[].id = 属性值的编号,values[].name = 属性值的名字;index = 选中的属性值的名字
|
||||||
|
properties: [],
|
||||||
|
productSelect: {} // 选中的 SKU
|
||||||
},
|
},
|
||||||
productValue: [], //系统属性
|
spu: {}, // 商品 SPU 详情
|
||||||
productInfo: {},
|
skuMap: [], // 商品 SKU Map
|
||||||
attrValue: '', //已选属性
|
attrValue: '', // 已选属性名的拼接,例如说 红色,大 这样的格式
|
||||||
attrTxt: '请选择', //属性页面提示
|
|
||||||
cartId: 0,
|
|
||||||
product_id: 0,
|
|
||||||
sysHeight: sysHeight,
|
|
||||||
canShow: false
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: mapGetters(['isLogin']),
|
computed: mapGetters(['isLogin']),
|
||||||
|
@ -203,6 +212,7 @@
|
||||||
this.hostProduct = [];
|
this.hostProduct = [];
|
||||||
this.hotScroll = false;
|
this.hotScroll = false;
|
||||||
this.loadend = false;
|
this.loadend = false;
|
||||||
|
this.getHostProduct()
|
||||||
|
|
||||||
// 加载购物车列表
|
// 加载购物车列表
|
||||||
this.footerswitch = true;
|
this.footerswitch = true;
|
||||||
|
@ -219,262 +229,225 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 修改购物车
|
/**
|
||||||
|
* 修改购物车
|
||||||
|
*/
|
||||||
reGoCat: function() {
|
reGoCat: function() {
|
||||||
let that = this,
|
const productSelect = this.skuMap[this.attrValue];
|
||||||
productSelect = that.productValue[this.attrValue];
|
// 如果有属性,没有选择,提示用户选择
|
||||||
//如果有属性,没有选择,提示用户选择
|
if (this.attr.properties.length &&
|
||||||
if (
|
productSelect === undefined) {
|
||||||
that.attr.productAttr.length &&
|
return this.$util.Tips({
|
||||||
productSelect === undefined
|
|
||||||
)
|
|
||||||
return that.$util.Tips({
|
|
||||||
title: "产品库存不足,请选择其它"
|
title: "产品库存不足,请选择其它"
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let q = {
|
TradeCartApi.resetCart({
|
||||||
id: that.cartId,
|
id: this.cartId,
|
||||||
productId: that.product_id,
|
skuId: this.attr.productSelect.id,
|
||||||
num: that.attr.productSelect.cart_num,
|
count: this.attr.productSelect.cart_num
|
||||||
unique: that.attr.productSelect !== undefined ?
|
}).then(res => {
|
||||||
that.attr.productSelect.unique : that.productInfo.id
|
this.attr.cartAttr = false;
|
||||||
};
|
this.$util.Tips({
|
||||||
getResetCart(q)
|
title: this.$t(`添加购物车成功`)
|
||||||
.then(function(res) {
|
});
|
||||||
that.attr.cartAttr = false;
|
this.cartList.valid = [];
|
||||||
that.$util.Tips({
|
this.getCartList();
|
||||||
title: "添加购物车成功",
|
}).catch(res => {
|
||||||
success: () => {
|
return this.$util.Tips({
|
||||||
that.loadend = false;
|
title: res
|
||||||
that.cartList.valid = [];
|
});
|
||||||
that.getCartList();
|
});
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(res => {
|
|
||||||
return that.$util.Tips({
|
|
||||||
title: res
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onMyEvent: function() {
|
|
||||||
this.$set(this.attr, 'cartAttr', false);
|
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 重选 SKU
|
||||||
|
*/
|
||||||
reElection: function(item) {
|
reElection: function(item) {
|
||||||
this.getGoodsDetails(item)
|
this.getGoodsDetails(item)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 获取产品详情
|
* 获取产品详情
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
getGoodsDetails: function(item) {
|
getGoodsDetails: function(item) {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: '加载中',
|
title: '加载中',
|
||||||
mask: true
|
mask: true
|
||||||
});
|
});
|
||||||
let that = this;
|
this.cartId = item.id;
|
||||||
that.cartId = item.id;
|
this.product_id = item.spu.id;
|
||||||
that.product_id = item.productId;
|
ProductSpuApi.getSpuDetail(item.spu.id).then(res => {
|
||||||
getProductDetail(item.productId).then(res => {
|
uni.hideLoading();
|
||||||
uni.hideLoading();
|
this.attr.cartAttr = true;
|
||||||
that.attr.cartAttr = true;
|
let spu = res.data;
|
||||||
let productInfo = res.data.productInfo;
|
let properties = ProductUtil.convertProductPropertyList(res.data.skus);
|
||||||
that.$set(that, 'productInfo', productInfo);
|
let skuMap = ProductUtil.convertProductSkuMap(res.data.skus);
|
||||||
that.$set(that.attr, 'productAttr', res.data.productAttr);
|
// 设置变量
|
||||||
that.$set(that, 'productValue', res.data.productValue);
|
this.$set(this, 'spu', spu);
|
||||||
that.DefaultSelect();
|
this.$set(this.attr, 'properties', properties);
|
||||||
}).catch(err => {
|
this.$set(this, 'skuMap', skuMap);
|
||||||
uni.hideLoading();
|
this.selectDefaultSku();
|
||||||
})
|
}).catch(err => {
|
||||||
|
uni.hideLoading();
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 关闭 productWindow 弹窗
|
||||||
|
*/
|
||||||
|
closeAttr: function () {
|
||||||
|
this.$set(this.attr, "cartAttr", false);
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* 属性变动赋值
|
* 属性变动赋值
|
||||||
*
|
*
|
||||||
|
* @param newSkuKey 新的 skuKey
|
||||||
|
* @param propertyIndex properties 的下标
|
||||||
|
* @param valueIndex values 的下标
|
||||||
*/
|
*/
|
||||||
ChangeAttr: function(res) {
|
ChangeAttr: function(newSkuKey, propertyIndex, valueIndex) {
|
||||||
let productSelect = this.productValue[res];
|
// SKU
|
||||||
if (productSelect && productSelect.stock > 0) {
|
let sku = this.skuMap[newSkuKey];
|
||||||
this.$set(this.attr.productSelect, "image", productSelect.image);
|
if (!sku) {
|
||||||
this.$set(this.attr.productSelect, "price", productSelect.price);
|
return;
|
||||||
this.$set(this.attr.productSelect, "stock", productSelect.stock);
|
}
|
||||||
this.$set(this.attr.productSelect, "unique", productSelect.id);
|
this.$set(this.attr.productSelect, "id", sku.id);
|
||||||
this.$set(this.attr.productSelect, "cart_num", 1);
|
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
|
||||||
this.$set(this, "attrValue", res);
|
this.$set(this.attr.productSelect, "price", sku.price);
|
||||||
this.$set(this, "attrTxt", "已选择");
|
this.$set(this.attr.productSelect, "stock", sku.stock);
|
||||||
} else {
|
this.$set(this.attr.productSelect, "cart_num", 1);
|
||||||
this.$set(this.attr.productSelect, "image", this.productInfo.image);
|
// SKU 关联属性
|
||||||
this.$set(this.attr.productSelect, "price", this.productInfo.price);
|
this.$set(this.attr.properties[propertyIndex], 'index',
|
||||||
this.$set(this.attr.productSelect, "stock", 0);
|
this.attr.properties[propertyIndex].values[valueIndex].name);
|
||||||
this.$set(this.attr.productSelect, "unique", this.productInfo.id);
|
this.$set(this, "attrValue", newSkuKey);
|
||||||
this.$set(this.attr.productSelect, "cart_num", 0);
|
|
||||||
this.$set(this, "attrValue", "");
|
|
||||||
this.$set(this, "attrTxt", "请选择");
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 默认选中属性
|
* 查找默认选中的 sku,设置到 attr.productSelect 中
|
||||||
*
|
*
|
||||||
*/
|
* 先找有库存的 SKU,否则找第一个 SKU
|
||||||
DefaultSelect: function() {
|
*/
|
||||||
let productAttr = this.attr.productAttr;
|
selectDefaultSku: function() {
|
||||||
let value = [];
|
const properties = this.attr.properties;
|
||||||
for (let key in this.productValue) {
|
// 获得选中的属性值的名字,例如说 "黑色,大",则 skuKey = ["黑色", "大"]
|
||||||
if (this.productValue[key].stock > 0) {
|
let skuKey = undefined;
|
||||||
value = this.attr.productAttr.length ? key.split(",") : [];
|
for (let key in this.skuMap) {
|
||||||
break;
|
if (this.skuMap[key].stock > 0) {
|
||||||
}
|
skuKey = key.split(",");
|
||||||
}
|
break;
|
||||||
for (let i = 0; i < productAttr.length; i++) {
|
}
|
||||||
this.$set(productAttr[i], "index", value[i]);
|
}
|
||||||
}
|
if (!skuKey) { // 如果找不到,则选中第一个
|
||||||
//sort();排序函数:数字-英文-汉字;
|
skuKey = Object.keys(this.skuMap)[0].split(",");
|
||||||
let productSelect = this.productValue[value.sort().join(",")];
|
}
|
||||||
if (productSelect && productAttr.length) {
|
// 使用 index 属性表示当前选中的,值为属性值的名字
|
||||||
this.$set(
|
for (let i = 0; i < properties.length; i++) {
|
||||||
this.attr.productSelect,
|
this.$set(properties[i], "index", skuKey[i]);
|
||||||
"storeName",
|
}
|
||||||
this.productInfo.storeName
|
|
||||||
);
|
let sku = this.skuMap[skuKey.join(",")];
|
||||||
this.$set(this.attr.productSelect, "image", productSelect.image);
|
if (!sku) {
|
||||||
this.$set(this.attr.productSelect, "price", productSelect.price);
|
return
|
||||||
this.$set(this.attr.productSelect, "stock", productSelect.stock);
|
}
|
||||||
this.$set(this.attr.productSelect, "unique", productSelect.id);
|
this.$set(this.attr.productSelect, "spuName", this.spu.name);
|
||||||
this.$set(this.attr.productSelect, "cart_num", 1);
|
this.$set(this.attr.productSelect, "id", sku.id);
|
||||||
this.$set(this, "attrValue", value.sort().join(","));
|
this.$set(this.attr.productSelect, "picUrl", sku.picUrl);
|
||||||
this.$set(this, "attrTxt", "已选择");
|
this.$set(this.attr.productSelect, "price", sku.price);
|
||||||
} else if (!productSelect && productAttr.length) {
|
this.$set(this.attr.productSelect, "stock", sku.stock);
|
||||||
this.$set(
|
this.$set(this.attr.productSelect, "cart_num", 1);
|
||||||
this.attr.productSelect,
|
this.$set(this, "attrValue", skuKey.join(","));
|
||||||
"storeName",
|
|
||||||
this.productInfo.storeName
|
|
||||||
);
|
|
||||||
this.$set(this.attr.productSelect, "image", this.productInfo.image);
|
|
||||||
this.$set(this.attr.productSelect, "price", this.productInfo.price);
|
|
||||||
this.$set(this.attr.productSelect, "stock", 0);
|
|
||||||
this.$set(this.attr.productSelect, "unique", this.productInfo.id);
|
|
||||||
this.$set(this.attr.productSelect, "cart_num", 0);
|
|
||||||
this.$set(this, "attrValue", "");
|
|
||||||
this.$set(this, "attrTxt", "请选择");
|
|
||||||
} else if (!productSelect && !productAttr.length) {
|
|
||||||
this.$set(
|
|
||||||
this.attr.productSelect,
|
|
||||||
"storeName",
|
|
||||||
this.productInfo.storeName
|
|
||||||
);
|
|
||||||
this.$set(this.attr.productSelect, "image", this.productInfo.image);
|
|
||||||
this.$set(this.attr.productSelect, "price", this.productInfo.price);
|
|
||||||
this.$set(this.attr.productSelect, "stock", this.productInfo.stock);
|
|
||||||
this.$set(
|
|
||||||
this.attr.productSelect,
|
|
||||||
"unique",
|
|
||||||
this.productInfo.id || ""
|
|
||||||
);
|
|
||||||
this.$set(this.attr.productSelect, "cart_num", 1);
|
|
||||||
this.$set(this, "attrValue", "");
|
|
||||||
this.$set(this, "attrTxt", "请选择");
|
|
||||||
}
|
|
||||||
},
|
|
||||||
attrVal(val) {
|
|
||||||
this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attrValues[val
|
|
||||||
.indexn]);
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 购物车数量加和数量减
|
* 购物车数量加和数量减
|
||||||
*
|
*
|
||||||
|
* @param changeValue true 增加;false 减少
|
||||||
*/
|
*/
|
||||||
ChangeCartNum: function(changeValue) {
|
ChangeCartNum: function(changeValue) {
|
||||||
//changeValue:是否 加|减
|
/// 获取当前 sku
|
||||||
//获取当前变动属性
|
let sku = this.attr.productSelect;
|
||||||
let productSelect = this.productValue[this.attrValue];
|
if (!sku) {
|
||||||
//如果没有属性,赋值给商品默认库存
|
return;
|
||||||
if (productSelect === undefined && !this.attr.productAttr.length)
|
}
|
||||||
productSelect = this.attr.productSelect;
|
|
||||||
//无属性值即库存为0;不存在加减;
|
// 设置数量
|
||||||
if (productSelect === undefined) return;
|
let stock = sku.stock || 0;
|
||||||
let stock = productSelect.stock || 0;
|
if (changeValue) {
|
||||||
let num = this.attr.productSelect;
|
sku.cart_num++;
|
||||||
if (changeValue) {
|
if (sku.cart_num > stock) {
|
||||||
num.cart_num++;
|
this.$set(this.attr.productSelect, "cart_num", stock);
|
||||||
if (num.cart_num > stock) {
|
}
|
||||||
this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
|
} else {
|
||||||
this.$set(this, "cart_num", stock ? stock : 1);
|
sku.cart_num--;
|
||||||
}
|
if (sku.cart_num < 1) {
|
||||||
} else {
|
this.$set(this.attr.productSelect, "cart_num", 1);
|
||||||
num.cart_num--;
|
}
|
||||||
if (num.cart_num < 1) {
|
}
|
||||||
this.$set(this.attr.productSelect, "cart_num", 1);
|
|
||||||
this.$set(this, "cart_num", 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 购物车手动填写
|
* 购物车手动填写
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
iptCartNum: function(e) {
|
iptCartNum: function(number) {
|
||||||
this.$set(this.attr.productSelect, 'cart_num', e);
|
this.$set(this.attr.productSelect, 'cart_num', number ? number : 1);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 删除选中的商品
|
||||||
|
*/
|
||||||
subDel: function(event) {
|
subDel: function(event) {
|
||||||
let that = this,
|
const selectValue = this.selectValue;
|
||||||
selectValue = that.selectValue;
|
if (selectValue.length === 0) {
|
||||||
if (selectValue.length > 0)
|
return this.$util.Tips({
|
||||||
cartDel(selectValue).then(res => {
|
title: '请选择产品'
|
||||||
that.loadend = false;
|
});
|
||||||
that.cartList.valid = [];
|
}
|
||||||
that.getCartList();
|
TradeCartApi.deleteCart(selectValue).then(res => {
|
||||||
});
|
this.getCartList();
|
||||||
else
|
});
|
||||||
return that.$util.Tips({
|
|
||||||
title: '请选择产品'
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
getSelectValueProductId: function() {
|
getSelectValueProductId: function() {
|
||||||
let that = this;
|
const validList = this.cartList.valid;
|
||||||
let validList = that.cartList.valid;
|
const selectValue = this.selectValue;
|
||||||
let selectValue = that.selectValue;
|
|
||||||
let productId = [];
|
let productId = [];
|
||||||
if (selectValue.length > 0) {
|
if (selectValue.length > 0) {
|
||||||
for (let index in validList) {
|
for (let index in validList) {
|
||||||
if (that.inArray(validList[index].id, selectValue)) {
|
if (this.inArray(validList[index].id, selectValue)) {
|
||||||
productId.push(validList[index].productId);
|
productId.push(validList[index].spu.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return productId;
|
return productId;
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 收藏选中的商品
|
||||||
|
*/
|
||||||
subCollect: function(event) {
|
subCollect: function(event) {
|
||||||
let that = this,
|
const spuIds = this.getSelectValueProductId();
|
||||||
selectValue = that.selectValue;
|
if (spuIds.length === 0) {
|
||||||
if (selectValue.length > 0) {
|
return this.$util.Tips({
|
||||||
let selectValueProductId = that.getSelectValueProductId();
|
title: '请选择产品'
|
||||||
collectAll(that.getSelectValueProductId()).then(res => {
|
});
|
||||||
return that.$util.Tips({
|
}
|
||||||
title: '收藏成功',
|
|
||||||
icon: 'success'
|
|
||||||
});
|
|
||||||
}).catch(err => {
|
|
||||||
return that.$util.Tips({
|
|
||||||
title: err
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return that.$util.Tips({
|
|
||||||
title: '请选择产品'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// 立即下单
|
|
||||||
subOrder: function(event) {
|
|
||||||
|
|
||||||
let that = this,
|
ProductFavoriteApi.createFavoriteList(spuIds).then(res => {
|
||||||
selectValue = that.selectValue;
|
return this.$util.Tips({
|
||||||
if (selectValue.length > 0) {
|
title: '收藏成功',
|
||||||
that.getPreOrder();
|
icon: 'success'
|
||||||
} else {
|
});
|
||||||
return that.$util.Tips({
|
}).catch(err => {
|
||||||
title: '请选择产品'
|
return that.$util.Tips({
|
||||||
});
|
title: err
|
||||||
}
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 立即下单
|
||||||
|
*/
|
||||||
|
subOrder: function(event) {
|
||||||
|
const selectValue = this.selectValue;
|
||||||
|
if (selectValue.length === 0) {
|
||||||
|
return this.$util.Tips({
|
||||||
|
title: '请选择产品'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
uni.navigateTo({
|
||||||
|
url: '/pages/users/order_confirm/index?cartIds=' + selectValue.join(',')
|
||||||
|
});
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 预下单
|
* 预下单
|
||||||
|
@ -487,6 +460,9 @@
|
||||||
})
|
})
|
||||||
this.$Order.getPreOrder("shoppingCart", shoppingCartId);
|
this.$Order.getPreOrder("shoppingCart", shoppingCartId);
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 全选 / 全不选
|
||||||
|
*/
|
||||||
checkboxAllChange: function(event) {
|
checkboxAllChange: function(event) {
|
||||||
let value = event.detail.value;
|
let value = event.detail.value;
|
||||||
if (value.length > 0) {
|
if (value.length > 0) {
|
||||||
|
@ -565,7 +541,6 @@
|
||||||
} else {
|
} else {
|
||||||
isAllSelect = false;
|
isAllSelect = false;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
} else {
|
} else {
|
||||||
if (!this.footerswitch && item.selected) {
|
if (!this.footerswitch && item.selected) {
|
||||||
selectValue.push(item.id);
|
selectValue.push(item.id);
|
||||||
|
@ -592,23 +567,6 @@
|
||||||
this.selectCountPrice = selectCountPrice;
|
this.selectCountPrice = selectCountPrice;
|
||||||
this.cartCount = cartCount;
|
this.cartCount = cartCount;
|
||||||
},
|
},
|
||||||
/**
|
|
||||||
* 购物车手动填写
|
|
||||||
*/
|
|
||||||
iptCartNum: function(index) {
|
|
||||||
let item = this.cartList.valid[index];
|
|
||||||
if (item.cartNum) {
|
|
||||||
this.setCartNum(item.id, item.cartNum);
|
|
||||||
}
|
|
||||||
this.switchSelect();
|
|
||||||
},
|
|
||||||
blurInput: function(index) {
|
|
||||||
let item = this.cartList.valid[index];
|
|
||||||
if (!item.cartNum) {
|
|
||||||
item.cartNum = 1;
|
|
||||||
this.$set(this.cartList, 'valid', this.cartList.valid)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
/**
|
/**
|
||||||
* 减少购买数量
|
* 减少购买数量
|
||||||
*/
|
*/
|
||||||
|
@ -654,7 +612,7 @@
|
||||||
* 修改购物项为指定数量
|
* 修改购物项为指定数量
|
||||||
*/
|
*/
|
||||||
setCartNum(cartId, cartNum) {
|
setCartNum(cartId, cartNum) {
|
||||||
TradeCartApi.updateCart({
|
TradeCartApi.updateCartCount({
|
||||||
id: cartId,
|
id: cartId,
|
||||||
count: cartNum
|
count: cartNum
|
||||||
}).then(res => {
|
}).then(res => {
|
||||||
|
@ -667,7 +625,6 @@
|
||||||
TradeCartApi.getCartList().then((res) => {
|
TradeCartApi.getCartList().then((res) => {
|
||||||
resolve(res.data);
|
resolve(res.data);
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
this.loading = false;
|
|
||||||
this.canShow = true;
|
this.canShow = true;
|
||||||
this.$util.Tips({
|
this.$util.Tips({
|
||||||
title: err
|
title: err
|
||||||
|
@ -709,25 +666,35 @@
|
||||||
this.$set(this.cartList, 'invalid', invalidList);
|
this.$set(this.cartList, 'invalid', invalidList);
|
||||||
|
|
||||||
// 标记加载结束
|
// 标记加载结束
|
||||||
this.loading = false;
|
|
||||||
this.canShow = true;
|
this.canShow = true;
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得“热门推荐”
|
||||||
|
*/
|
||||||
getHostProduct: function() {
|
getHostProduct: function() {
|
||||||
let that = this;
|
ProductSpuApi.getSpuPage({
|
||||||
if (that.hotScroll) return
|
recommendType: 'hot',
|
||||||
getProductHot(
|
pageNo: this.hotPage,
|
||||||
that.hotPage,
|
pageSize: this.hotLimit
|
||||||
that.hotLimit,
|
}).then(res => {
|
||||||
).then(res => {
|
const good_list = res.data.list;
|
||||||
that.hotPage++
|
this.hotPage++
|
||||||
that.hotScroll = res.data.list.length < that.hotLimit
|
this.hotScroll = good_list.length < this.hotLimit
|
||||||
that.hostProduct = that.hostProduct.concat(res.data.list)
|
|
||||||
});
|
// 设置营销活动
|
||||||
|
const spuIds = good_list.map(item => item.id);
|
||||||
|
if (spuIds.length > 0) {
|
||||||
|
PromotionActivityApi.getActivityListBySpuIds(spuIds).then(res => {
|
||||||
|
ProductUtil.setActivityList(good_list, res.data);
|
||||||
|
this.hostProduct = this.hostProduct.concat(good_list) // 放在此处,避免 Vue 监控不到数组里的元素变化
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
goodsOpen: function() {
|
goodsOpen: function() {
|
||||||
let that = this;
|
this.goodsHidden = !this.goodsHidden;
|
||||||
that.goodsHidden = !that.goodsHidden;
|
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 切换到管理
|
* 切换到管理
|
||||||
|
@ -736,21 +703,21 @@
|
||||||
this.footerswitch = !this.footerswitch;
|
this.footerswitch = !this.footerswitch;
|
||||||
this.switchSelect();
|
this.switchSelect();
|
||||||
},
|
},
|
||||||
|
/**
|
||||||
|
* 清空
|
||||||
|
*/
|
||||||
unsetCart: function() {
|
unsetCart: function() {
|
||||||
let that = this,
|
const ids = [];
|
||||||
ids = [];
|
for (let i = 0, len = this.cartList.invalid.length; i < len; i++) {
|
||||||
for (let i = 0, len = that.cartList.invalid.length; i < len; i++) {
|
ids.push(this.cartList.invalid[i].id);
|
||||||
ids.push(that.cartList.invalid[i].id);
|
}
|
||||||
}
|
TradeCartApi.deleteCart(ids).then(res => {
|
||||||
cartDel(ids).then(res => {
|
this.$util.Tips({
|
||||||
that.$util.Tips({
|
title: '清除成功'
|
||||||
title: '清除成功'
|
});
|
||||||
});
|
this.getCartList()
|
||||||
that.$set(that.cartList, 'invalid', []);
|
}).catch(res => {
|
||||||
that.getHostProduct();
|
});
|
||||||
}).catch(res => {
|
|
||||||
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
fen2yuan(price) {
|
fen2yuan(price) {
|
||||||
|
@ -766,13 +733,10 @@
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
onReachBottom() {
|
onReachBottom() {
|
||||||
// TODO 芋艿:临时禁用
|
if (this.cartList.valid.length === 0
|
||||||
if (true) {
|
&& this.cartList.invalid.length === 0
|
||||||
return;
|
&& this.hotPage != 1) {
|
||||||
}
|
this.getHostProduct();
|
||||||
let that = this;
|
|
||||||
if (that.cartList.valid.length == 0 && that.cartList.invalid.length == 0 && this.hotPage != 1) {
|
|
||||||
that.getHostProduct();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue