feat : 使商城列表 商品详情 购物车 的商品数量保持一致

This commit is contained in:
赵毅 2025-07-19 16:28:15 +08:00
parent 7b1dc4a1fa
commit cc1d99ad1c
3 changed files with 745 additions and 620 deletions

View File

@ -1,15 +1,27 @@
<template> <template>
<view> <view>
<div class="header"> <div class="header">
<div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }"> <div
class="searchBox"
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }"
>
<div class="searchBox_left" @click="back"> <div class="searchBox_left" @click="back">
<u-icon name="arrow-left" size="20px" color="#000"></u-icon> <u-icon name="arrow-left" size="20px" color="#000"></u-icon>
</div> </div>
</div> </div>
</div> </div>
<div class="swiper"> <div class="swiper">
<swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000" @change="changeIndex"> <swiper
<swiper-item v-for="(item, index) in currentGG.goods_carousel" :key="index"> :indicator-dots="false"
:autoplay="true"
:interval="3000"
:duration="1000"
@change="changeIndex"
>
<swiper-item
v-for="(item, index) in currentGG.goods_carousel"
:key="index"
>
<image :src="picUrl + item"></image> <image :src="picUrl + item"></image>
</swiper-item> </swiper-item>
</swiper> </swiper>
@ -20,8 +32,9 @@
</div> </div>
<div class="Money"> <div class="Money">
<div class="MoneyMark"></div>{{ currentGG.sales_price }} <div class="MoneyUnit">/{{ currentGG.goods_unit }} <div class="MoneyMark"></div>
</div> {{ currentGG.sales_price }}
<div class="MoneyUnit">/{{ currentGG.goods_unit }}</div>
<div class="oldMoney">{{ currentGG.market_price }}</div> <div class="oldMoney">{{ currentGG.market_price }}</div>
</div> </div>
@ -30,25 +43,35 @@
<!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> --> <!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> -->
<div class="GGBox"> <div class="GGBox">
<div class="GG_left"> <div class="GG_left">
<div class="GG_Item" v-for="(item, index) in info.commodity_goods_info_list" :key="item.id" <div
@click="changeGG(item, index)" :class="index == currentGGIndex ? 'active' : ''"> class="GG_Item"
v-for="(item, index) in info.commodity_goods_info_list"
:key="item.id"
@click="changeGG(item, index)"
:class="index == currentGGIndex ? 'active' : ''"
>
{{ item.goods_spec }} / {{ item.goods_unit }} {{ item.goods_spec }} / {{ item.goods_unit }}
</div> </div>
</div> </div>
<div class="GG_rigth">{{ info.commodity_goods_info_list.length }}<u-icon size="26rpx" <div class="GG_rigth">
name="arrow-right"></u-icon></div> {{ info.commodity_goods_info_list.length }}<u-icon
size="26rpx"
name="arrow-right"
></u-icon>
</div>
</div> </div>
<div class="Tit">{{ currentGG.goods_name }}</div> <div class="Tit">{{ currentGG.goods_name }}</div>
<div class="Msg">{{ currentGG.commodity_brief }}</div> <div class="Msg">{{ currentGG.commodity_brief }}</div>
<div class="GoodsMsg"> <div class="GoodsMsg">商品详情</div>
商品详情
</div>
<div class="Msg_Item"> <div class="Msg_Item">
<div class="Msg_ItemTit">商品编号</div> <div class="Msg_ItemTit">商品编号</div>
<div class="Msg_ItemCon" @click="copys(currentGG.goods_no)">{{ currentGG.goods_no }} <image <div class="Msg_ItemCon" @click="copys(currentGG.goods_no)">
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png"></image> {{ currentGG.goods_no }}
<image
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png"
></image>
</div> </div>
</div> </div>
<div class="Msg_Item"> <div class="Msg_Item">
@ -61,43 +84,75 @@
</div> </div>
<div class="GoosMsg"> <div class="GoosMsg">
<image v-for="item in currentGG.goods_detail_pic" :src="picUrl + item" mode="widthFix"></image> <image
v-for="item in currentGG.goods_detail_pic"
:src="picUrl + item"
mode="widthFix"
></image>
</div> </div>
<!-- 底部购物车 --> <!-- 底部购物车 -->
<div class="Car"> <div class="Car">
<div class="car_left"> <div class="car_left">
<div class="share" @click="share"> <div class="share" @click="share">
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share.png" <image
mode="widthFix"></image> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share.png"
mode="widthFix"
></image>
分享 分享
</div> </div>
<div class="cars" @click="car"> <div class="cars" @click="car">
<u-badge numberType="limit" :type="type" max="99" :value="carNum"></u-badge> <u-badge
numberType="limit"
:type="type"
max="99"
:value="carNum"
></u-badge>
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car.png" <image
mode="widthFix"></image> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car.png"
mode="widthFix"
></image>
购物车 购物车
</div> </div>
</div> </div>
<div class="car_right" <div
v-if="!info.commodity_goods_info_list[currentGGIndex].cart_count || info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0" class="car_right"
@click="addCar"> v-if="
!info.commodity_goods_info_list[currentGGIndex].cart_count ||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0
"
@click="addCar"
>
加入购物车 加入购物车
</div> </div>
<div class="car_right" v-if="info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0"> <div
class="car_right"
<u-number-box v-model="info.commodity_goods_info_list[currentGGIndex].cart_count.count" v-if="
@change="changeCar" min="0"> info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0
"
>
<u-number-box
v-model="
info.commodity_goods_info_list[currentGGIndex].cart_count.count
"
@change="changeCar"
min="0"
>
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="36" bold></u-icon> <u-icon name="minus" size="36" bold></u-icon>
</view> </view>
<text slot="input" style="width: 200rpx;text-align: center;" class="input"> <text
{{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }}</text> slot="input"
style="width: 200rpx; text-align: center"
class="input"
>
{{
info.commodity_goods_info_list[currentGGIndex].cart_count.count
}}</text
>
<view slot="plus" class="plus"> <view slot="plus" class="plus">
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon> <u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
</view> </view>
@ -109,13 +164,17 @@
<div class="shadow" @click.stop="changeShadow" v-if="boxshadow1"> <div class="shadow" @click.stop="changeShadow" v-if="boxshadow1">
<div class="shadowBox1"> <div class="shadowBox1">
<div class="shadowBox1Item" @click="shareFriend"> <div class="shadowBox1Item" @click="shareFriend">
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png" <image
mode="aspectFill"></image> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
mode="aspectFill"
></image>
微信好友 微信好友
</div> </div>
<div class="shadowBox1Item" @click="openSave"> <div class="shadowBox1Item" @click="openSave">
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png" <image
mode="aspectFill"></image> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png"
mode="aspectFill"
></image>
生成海报 生成海报
</div> </div>
</div> </div>
@ -127,7 +186,8 @@
<div class="boxshadow_tit">今日商品推荐</div> <div class="boxshadow_tit">今日商品推荐</div>
<div class="boxshadow_img"> <div class="boxshadow_img">
<image <image
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png"> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png"
>
</image> </image>
</div> </div>
<div class="line"></div> <div class="line"></div>
@ -136,35 +196,28 @@
<div class="shadowboxInfo_right"> <div class="shadowboxInfo_right">
<div class="shadowboxInfo_right_1">正鲜生</div> <div class="shadowboxInfo_right_1">正鲜生</div>
<div class="shadowboxInfo_right_2"> <div class="shadowboxInfo_right_2">
长按识别小程序 <br> 长按识别小程序 <br />
数量有限马上抢购</div> 数量有限马上抢购
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="shadowBox_btn" @click.stop="saveImg">保存海报</div> <div class="shadowBox_btn" @click.stop="saveImg">保存海报</div>
</div> </div>
</div> </div>
</view> </view>
</template> </template>
<script> <script>
import { import { apiArr } from "../../../api/shop";
apiArr import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils";
} from '../../../api/shop';
import {
picUrl,
menuButtonInfo,
request,
NavgateTo
} from '../../../utils';
export default { export default {
data() { data() {
return { return {
picUrl, picUrl,
top: "", top: "",
localHeight: "", localHeight: "",
carNum: '', carNum: "",
prevCarNum: "", prevCarNum: "",
currentNum: "0", // currentNum: "0", //
type: "error", type: "error",
@ -178,120 +231,116 @@ export default {
currentGGIndex: "", //index currentGGIndex: "", //index
carOrderList: [], carOrderList: [],
} };
}, },
methods: { methods: {
changeIndex(e) { changeIndex(e) {
this.currentIndex = e.detail.current + 1 this.currentIndex = e.detail.current + 1;
}, },
back() { back() {
uni.navigateBack({ uni.navigateBack({
delta: 1 delta: 1,
}); });
}, },
// //
shareFriend() { shareFriend() {
this.boxshadow2 = false this.boxshadow2 = false;
return return;
// uniapp // uniapp
uni.share({ uni.share({
provider: 'weixin', provider: "weixin",
type: 'link', type: "link",
scene: 'session', scene: "session",
link: 'https://uniapp.dcloud.net.cn/', link: "https://uniapp.dcloud.net.cn/",
title: '商品名称', title: "商品名称",
imageUrl: '', imageUrl: "",
success: (res) => { success: (res) => {
uni.showToast({ uni.showToast({
title: '分享成功', title: "分享成功",
icon: 'success', icon: "success",
duration: 2000 duration: 2000,
}); });
this.boxshadow1 = false this.boxshadow1 = false;
}, },
fail: (err) => { fail: (err) => {
console.log('分享失败', err); console.log("分享失败", err);
this.boxshadow1 = false this.boxshadow1 = false;
} },
}); });
}, },
changeShadow() { changeShadow() {
this.boxshadow1 = false this.boxshadow1 = false;
}, },
openSave() { openSave() {
this.boxshadow1 = false this.boxshadow1 = false;
this.boxshadow2 = true this.boxshadow2 = true;
}, },
// //
saveImg() { saveImg() {
this.boxshadow2 = false this.boxshadow2 = false;
// //
uni.downloadFile({ uni.downloadFile({
url: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png', url: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png",
success: (res) => { success: (res) => {
if (res.statusCode === 200) { if (res.statusCode === 200) {
uni.saveImageToPhotosAlbum({ uni.saveImageToPhotosAlbum({
filePath: res.tempFilePath, filePath: res.tempFilePath,
success: (res) => { success: (res) => {
uni.showToast({ uni.showToast({
title: '保存成功', title: "保存成功",
icon: 'success', icon: "success",
duration: 2000 duration: 2000,
}); });
}, },
fail: (err) => { fail: (err) => {
console.log('保存失败', err); console.log("保存失败", err);
} },
}); });
} }
}, },
fail: (err) => { fail: (err) => {
console.log('下载失败', err); console.log("下载失败", err);
} },
}); });
}, },
changeShadow2() { changeShadow2() {
this.boxshadow2 = false this.boxshadow2 = false;
}, },
// //
share() { share() {
this.boxshadow1 = true this.boxshadow1 = true;
}, },
// //
getGoodsInfo() { getGoodsInfo() {
request(apiArr.getGoodsInfo, "POST", { request(apiArr.getGoodsInfo, "POST", {
id: this.id id: this.id,
}).then(res => { }).then((res) => {
console.log(res); console.log(res);
// //
res.commodity_goods_info_list.forEach(item => { res.commodity_goods_info_list.forEach((item) => {
item.goods_detail_pic = item.goods_detail_pic.split(',') item.goods_detail_pic = item.goods_detail_pic.split(",");
item.goods_carousel = item.goods_carousel.split(',') item.goods_carousel = item.goods_carousel.split(",");
item.commodity_pic = item.commodity_pic.split(',') item.commodity_pic = item.commodity_pic.split(",");
}); });
// //
if (this.carOrderList) { if (this.carOrderList) {
this.carOrderList.forEach(items => { this.carOrderList.forEach((items) => {
res.commodity_goods_info_list.forEach(item => { res.commodity_goods_info_list.forEach((item) => {
if (items.goods_id == item.id) { if (items.goods_id == item.id) {
item.cart_count = {count:0} item.cart_count = { count: 0 };
item.cart_count.count = items.count item.cart_count.count = items.count;
} }
}) });
}) });
} }
this.info = res this.info = res;
this.currentGG = res.commodity_goods_info_list[0] this.currentGG = res.commodity_goods_info_list[0];
this.currentGGIndex = 0 this.currentGGIndex = 0;
});
})
}, },
copys(e) { copys(e) {
@ -299,122 +348,134 @@ export default {
data: e, data: e,
success: (res) => { success: (res) => {
uni.showToast({ uni.showToast({
title: '复制成功', title: "复制成功",
icon: 'success', icon: "success",
duration: 2000 duration: 2000,
}); });
} },
}); });
}, },
// //
changeGG(item, index) { changeGG(item, index) {
this.currentGG = item this.currentGG = item;
this.currentGGIndex = index this.currentGGIndex = index;
if (this.currentGG.cart_count) { if (this.currentGG.cart_count) {
this.currentNum = this.currentGG.cart_count.count this.currentNum = this.currentGG.cart_count.count;
} else { } else {
this.currentGG.cart_count = { count: 0 } this.currentGG.cart_count = { count: 0 };
} }
}, },
car() { car() {
NavgateTo('../shopCar/index') NavgateTo("../shopCar/index");
}, },
// //
getShopCar() { getShopCar() {
request(apiArr.getCarCount, 'POST', {}).then(res => { request(apiArr.getCarCount, "POST", {}).then((res) => {
this.carNum = res.total this.carNum = res.total;
this.prevCarNum = res.total this.prevCarNum = res.total;
}) });
}, },
getShopCarList() { getShopCarList() {
request(apiArr.getCar, 'POST', {}).then(res => { request(apiArr.getCar, "POST", {}).then((res) => {
this.carOrderList = res.commodity_cart_list this.carOrderList = res.commodity_cart_list;
}) });
}, },
addCar() { addCar() {
let that = this let that = this;
// //
let goods_id_and_count = [] let goods_id_and_count = [];
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 } this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {
this.info.commodity_goods_info_list.forEach(item => { count: 1,
};
this.info.commodity_goods_info_list.forEach((item) => {
console.log(item.cart_count); console.log(item.cart_count);
goods_id_and_count.push({ goods_id_and_count.push({
goods_id: item.id, goods_id: item.id,
count: item.cart_count ? item.cart_count.count : 0 count: item.cart_count ? item.cart_count.count : 0,
}) });
}) });
console.log(goods_id_and_count); console.log(goods_id_and_count);
// update // update
request(apiArr.updateCar, "POST", { request(apiArr.updateCar, "POST", {
goods_id_and_count goods_id_and_count,
}).then(res => { }).then((res) => {
that.getShopCar() that.getShopCar();
that.getShopCarList() that.getShopCarList();
}) });
}, },
// //
changeCar(newValue) { changeCar(newValue) {
// // //
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value // this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value
// // //
this.carOrderList.forEach(item => { // this.carOrderList.forEach(item => {
if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) { // if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) {
item.count = newValue.value // item.count = newValue.value
} // }
}) // })
// // //
let carNum = 0 // let carNum = 0
this.carOrderList.forEach(item => { // this.carOrderList.forEach(item => {
carNum += item.count // carNum += item.count
}) // })
this.carNum = carNum // this.carNum = carNum
//
const params = {
user_id: uni.getStorageSync("userId"),
goods_id_and_count: [
{
goods_id: this.info.commodity_goods_info_list[this.currentGGIndex].id,
count: newValue.value,
},
],
};
request(apiArr.updateCar, "POST", params).then((res) => {
console.log(res);
this.getShopCarList();
uni.showToast({
title: "操作成功!",
success() {},
});
});
}, },
}, },
onLoad(options) { onLoad(options) {
const itemObj = JSON.parse(decodeURIComponent(options.item));
const meun = menuButtonInfo(); const meun = menuButtonInfo();
this.top = meun.top; this.top = meun.top;
this.localHeight = meun.height; this.localHeight = meun.height;
this.id = options.id this.id = itemObj.id;
},
onReachBottom() {
}, },
onReachBottom() {},
onShow() { onShow() {
this.getShopCarList() this.getShopCarList();
this.getGoodsInfo() this.getGoodsInfo();
this.getShopCar() this.getShopCar();
}, },
//( id count 0 ) //( id count 0 )
onHide() { onHide() {
let goods_id_and_count = [] let goods_id_and_count = [];
this.info.commodity_goods_info_list.forEach(item => { this.info.commodity_goods_info_list.forEach((item) => {
goods_id_and_count.push({ goods_id_and_count.push({
goods_id: item.id, goods_id: item.id,
count: item.cart_count ? item.cart_count.count : 0 count: item.cart_count ? item.cart_count.count : 0,
}) });
}) });
request(apiArr.updateCar, "POST", { request(apiArr.updateCar, "POST", {
goods_id_and_count goods_id_and_count,
}) });
return return;
}, },
};
}
</script> </script>
<style> <style>

View File

@ -90,7 +90,8 @@
<div class="Con"> <div class="Con">
<div class="Con_left"> <div class="Con_left">
<div <div
class="CateItem" :class="item.id === currentLeftCateId ? 'CateItem_active' : ''" class="CateItem"
:class="item.id === currentLeftCateId ? 'CateItem_active' : ''"
v-for="item in leftCateList" v-for="item in leftCateList"
:key="item.id" :key="item.id"
@click="changeLeftCate(item.id)" @click="changeLeftCate(item.id)"
@ -148,19 +149,19 @@
:key="items.id" :key="items.id"
> >
<div class="CateInfo_Item_Box"> <div class="CateInfo_Item_Box">
<div class="CateInfo_Item_left" @click="goods(items.id)"> <div class="CateInfo_Item_left" @click="goods(items)">
<image <image
:src="picUrl + items.commodity_pic" :src="picUrl + items.commodity_pic"
mode="aspectFill" mode="aspectFill"
></image> ></image>
</div> </div>
<div class="CateInfo_Item_right" :class="GGshow ? 'noneBor' : ''"> <div class="CateInfo_Item_right" :class="GGshow ? 'noneBor' : ''">
<div class="CateInfo_Item_right_Tit" @click="goods(items.id)"> <div class="CateInfo_Item_right_Tit" @click="goods(items)">
{{ items.commodity_name }} {{ items.commodity_name }}
</div> </div>
<div <div
class="CateInfo_Item_right_subtit" class="CateInfo_Item_right_subtit"
@click="goods(items.id)" @click="goods(items)"
> >
{{ items.commodity_intro }} {{ items.commodity_intro }}
</div> </div>
@ -175,7 +176,7 @@
> >
<u-number-box <u-number-box
:min="0" :min="0"
v-model="items.quantity" v-model="items.commodity_goods_info_list[0].quantity"
@change="(value) => handleQuantityChange(value, items)" @change="(value) => handleQuantityChange(value, items)"
> >
<view slot="minus" class="minus"> <view slot="minus" class="minus">
@ -185,7 +186,11 @@
slot="input" slot="input"
style="width: 50px; text-align: center" style="width: 50px; text-align: center"
class="input" class="input"
>{{ items.quantity ? items.quantity : 0 }}</text >{{
items.commodity_goods_info_list[0].quantity
? items.commodity_goods_info_list[0].quantity
: 0
}}</text
> >
<view slot="plus" class="plus"> <view slot="plus" class="plus">
<u-icon name="plus" color="#FFFFFF" size="20"></u-icon> <u-icon name="plus" color="#FFFFFF" size="20"></u-icon>
@ -226,7 +231,7 @@
<div <div
class="GGItem" class="GGItem"
v-for="ite in items.commodity_goods_info_list" v-for="ite in items.commodity_goods_info_list"
@click="goods(items.id)" @click="goods(items)"
> >
<div class="GGItem_Image"> <div class="GGItem_Image">
<image <image
@ -369,6 +374,8 @@ currentLeftCateId: null,
tagList: [], tagList: [],
carNum: "", carNum: "",
goodsDetail: [],
}; };
}, },
methods: { methods: {
@ -404,7 +411,7 @@ currentLeftCateId: null,
}, },
// //
goods(e) { goods(e) {
NavgateTo(`../goods/index?id=${e}`); NavgateTo(`../goods/index?item=${JSON.stringify(e)}`);
}, },
// //
@ -417,7 +424,8 @@ currentLeftCateId: null,
console.log(res); console.log(res);
this.CateList = res.commodity_category_list; this.CateList = res.commodity_category_list;
this.firstId = res.commodity_category_list[0].id; this.firstId = res.commodity_category_list[0].id;
this.leftCateList = res.commodity_category_list[0].level_two_category || []; this.leftCateList =
res.commodity_category_list[0].level_two_category || [];
if (this.leftCateList.length > 0) { if (this.leftCateList.length > 0) {
this.currentLeftCateId = this.leftCateList[0].id; this.currentLeftCateId = this.leftCateList[0].id;
this.secondId = this.leftCateList[0].id; this.secondId = this.leftCateList[0].id;
@ -440,10 +448,18 @@ currentLeftCateId: null,
}).then((res) => { }).then((res) => {
res.commodity_list.forEach((item) => { res.commodity_list.forEach((item) => {
item.commodity_info_list.forEach((item) => { item.commodity_info_list.forEach((item) => {
item.commodity_goods_info_list.forEach((param) => {
this.goodsDetail.forEach((goods) => {
if (goods.goods_id === param.id) {
param.quantity = goods.count;
}
});
});
item.isShow = false; item.isShow = false;
}); });
}); });
this.tagList = res.commodity_list; this.tagList = res.commodity_list;
console.log("🚀 ~ getGoodsList ~ this.tagList:", this.tagList)
}); });
}, },
@ -451,6 +467,7 @@ currentLeftCateId: null,
request(apiArr.getCar, "POST").then((res) => { request(apiArr.getCar, "POST").then((res) => {
console.log(res); console.log(res);
this.carNum = res.total; this.carNum = res.total;
this.goodsDetail = res.commodity_cart_list;
}); });
}, },
@ -461,7 +478,10 @@ currentLeftCateId: null,
}, },
// //
handleQuantityChange(val, item) { handleQuantityChange(val, item) {
if (item.commodity_goods_info_list.length) { if (
item.commodity_goods_info_list &&
item.commodity_goods_info_list.length
) {
this.goodsId = item.commodity_goods_info_list[0].id; this.goodsId = item.commodity_goods_info_list[0].id;
} else { } else {
this.goodsId = item.id; this.goodsId = item.id;
@ -480,8 +500,7 @@ currentLeftCateId: null,
this.getShopCarList(); this.getShopCarList();
uni.showToast({ uni.showToast({
title: "操作成功!", title: "操作成功!",
success() { success() {},
},
}); });
}); });
}, },
@ -495,6 +514,7 @@ currentLeftCateId: null,
}, },
onShow() { onShow() {
this.getShopCarList(); this.getShopCarList();
this.getGoodsList();
}, },
onReachBottom() { onReachBottom() {
if (this.flag) { if (this.flag) {

View File

@ -1,7 +1,10 @@
<template> <template>
<view> <view>
<div class="header"> <div class="header">
<div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }"> <div
class="searchBox"
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }"
>
<div class="searchBox_left" @click="back"> <div class="searchBox_left" @click="back">
<u-icon name="arrow-left" size="20px" color="#000"></u-icon> <u-icon name="arrow-left" size="20px" color="#000"></u-icon>
</div> </div>
@ -18,10 +21,20 @@
</div> </div>
<div class="goodsList"> <div class="goodsList">
<div class="goodsItem" v-for="item, index in shopCarList" :key="item.id"> <div
class="goodsItem"
v-for="(item, index) in shopCarList"
:key="item.id"
>
<div class="goodsItem_left" @click="changeChecked(item, index)"> <div class="goodsItem_left" @click="changeChecked(item, index)">
<image v-if="!item.checked" src="http://192.168.0.172:5500/7.15/shop_checked1.png"></image> <image
<image v-if="item.checked" src="http://192.168.0.172:5500/7.15/shop_checked2.png"></image> v-if="!item.checked"
src="http://192.168.0.172:5500/7.15/shop_checked1.png"
></image>
<image
v-if="item.checked"
src="http://192.168.0.172:5500/7.15/shop_checked2.png"
></image>
</div> </div>
<div class="goodsItem_right"> <div class="goodsItem_right">
<div class="goodsItem_msg"> <div class="goodsItem_msg">
@ -30,23 +43,43 @@
</image> </image>
</div> </div>
<div class="goodsItem_msg_right"> <div class="goodsItem_msg_right">
<div class="goodsItem_msg_right_tit">{{ item.commodity_goods_info.goods_name }}</div> <div class="goodsItem_msg_right_tit">
<div class="goodsItem_msg_right_subTit">{{ item.commodity_goods_info.goods_intro }} {{ item.commodity_goods_info.goods_name }}
</div>
<div class="goodsItem_msg_right_subTit">
{{ item.commodity_goods_info.goods_intro }}
</div> </div>
<div class="goodsItem_msg_right_msg"> <div class="goodsItem_msg_right_msg">
<div class="goodsItem_msg_right_msg_left"> <div class="goodsItem_msg_right_msg_left">
<span></span>{{ item.commodity_goods_info.sales_price }} <span>/{{ <span></span>{{ item.commodity_goods_info.sales_price }}
item.commodity_goods_info.goods_unit }}</span> <span>/{{ item.commodity_goods_info.goods_unit }}</span>
</div> </div>
<div class="goodsItem_msg_right_msg_right"> <div class="goodsItem_msg_right_msg_right">
<u-number-box v-model="item.count" :asyncChange="true" min="0"> <u-number-box
<view slot="minus" class="minus" @click="minus(item, index)"> v-model="item.count"
:asyncChange="true"
min="0"
>
<view
slot="minus"
class="minus"
@click="minus(item, index)"
>
<u-icon name="minus" size="32" bold></u-icon> <u-icon name="minus" size="32" bold></u-icon>
</view> </view>
<text slot="input" style="width: 80rpx;text-align: center;" class="input">{{ <text
item.count }}</text> slot="input"
style="width: 80rpx; text-align: center"
class="input"
>{{ item.count }}</text
>
<view slot="plus" class="plus" @click="add(item, index)"> <view slot="plus" class="plus" @click="add(item, index)">
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon> <u-icon
name="plus"
color="#FFFFFF"
size="32"
bold
></u-icon>
</view> </view>
</u-number-box> </u-number-box>
</div> </div>
@ -60,11 +93,15 @@
<div class="footer"> <div class="footer">
<div class="footer_left"> <div class="footer_left">
<div class="footer_all" @click="allChecked"> <div class="footer_all" @click="allChecked">
<image v-if="!isAllchecked" <image
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png"> v-if="!isAllchecked"
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png"
>
</image> </image>
<image v-if="isAllchecked" <image
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png"> v-if="isAllchecked"
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png"
>
</image> </image>
全选 全选
</div> </div>
@ -73,34 +110,23 @@
{{ shopMoney }} {{ shopMoney }}
</div> </div>
</div> </div>
<div class="footer_right" @click="submitOrder"> <div class="footer_right" @click="submitOrder">结算</div>
结算
</div>
</div> </div>
</div> </div>
<div class="empty" v-if="false"> <div class="empty" v-if="false">
<image src="http://192.168.0.172:5500/7.15/shop_empty.png"></image> <image src="http://192.168.0.172:5500/7.15/shop_empty.png"></image>
<div> <div>
啥也没有 <br> 啥也没有 <br />
赶紧去shopping吧~ 赶紧去shopping吧~
</div> </div>
</div> </div>
</view> </view>
</template> </template>
<script> <script>
import { import { apiArr } from "../../../api/shop";
apiArr import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils";
} from '../../../api/shop';
import {
picUrl,
menuButtonInfo,
request,
NavgateTo
} from '../../../utils';
export default { export default {
data() { data() {
return { return {
@ -112,120 +138,140 @@ export default {
shopCarList: [], shopCarList: [],
shopCarTotal: 0, shopCarTotal: 0,
shopMoney: 0, shopMoney: 0,
isAllchecked: false isAllchecked: false,
} };
}, },
methods: { methods: {
back() { back() {
NavgateTo("1") NavgateTo("1");
}, },
submitOrder() { submitOrder() {
let arr = [];
let arr = [] this.shopCarList.forEach((item) => {
this.shopCarList.forEach(item => {
if (item.checked) { if (item.checked) {
arr.push(item) arr.push(item);
} }
}) });
NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`) NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`);
}, },
getShopCar() { getShopCar() {
request(apiArr.getCar, 'POST', {}).then(res => { request(apiArr.getCar, "POST", {}).then((res) => {
res.commodity_cart_list.forEach(item => { res.commodity_cart_list.forEach((item) => {
item.checked = false item.checked = false;
});
this.shopCarTotal = res.total;
this.shopCarList = res.commodity_cart_list;
}); });
this.shopCarTotal = res.total
this.shopCarList = res.commodity_cart_list
})
}, },
// //
changeChecked(item, index) { changeChecked(item, index) {
this.shopCarList[index].checked = !this.shopCarList[index].checked this.shopCarList[index].checked = !this.shopCarList[index].checked;
this.calcTotal() this.calcTotal();
// //
this.isAllchecked = this.shopCarList.every(item => item.checked) this.isAllchecked = this.shopCarList.every((item) => item.checked);
}, },
// //
allChecked() { allChecked() {
this.isAllchecked = !this.isAllchecked this.isAllchecked = !this.isAllchecked;
// Bug !this.allChecked !this.isAllchecked // Bug !this.allChecked !this.isAllchecked
if (this.isAllchecked) { if (this.isAllchecked) {
this.shopCarList.forEach(item => { this.shopCarList.forEach((item) => {
item.checked = true item.checked = true;
}); });
} else { } else {
this.shopCarList.forEach(item => { this.shopCarList.forEach((item) => {
item.checked = false item.checked = false;
}); });
} }
this.calcTotal() this.calcTotal();
}, },
// //
calcTotal() { calcTotal() {
let total = 0;
let total = 0 this.shopCarList.forEach((item) => {
this.shopCarList.forEach(item => {
console.log(item); console.log(item);
if (item.checked) { if (item.checked) {
total += item.commodity_goods_info.sales_price * item.count total += item.commodity_goods_info.sales_price * item.count;
} }
}); });
this.shopMoney = total this.shopMoney = total;
}, },
minus(item, index) { minus(item, index) {
let that = this let that = this;
if (item.count === 1) { if (item.count === 1) {
request(apiArr.deleteCar, "POST", { request(apiArr.deleteCar, "POST", {
ids: [item.id] ids: [item.id],
}).then(res => { }).then((res) => {
that.shopCarList.splice(index, 1) that.shopCarList.splice(index, 1);
that.calcTotal() that.calcTotal();
}) });
} }
this.shopCarList[index].count = this.shopCarList[index].count - 1 this.shopCarList[index].count = this.shopCarList[index].count - 1;
this.calcTotal() this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index])
this.calcTotal();
}, },
add(item, index) { add(item, index) {
this.shopCarList[index].count = this.shopCarList[index].count + 1 this.shopCarList[index].count = this.shopCarList[index].count + 1;
this.calcTotal() this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index])
this.calcTotal();
}, },
deleteItem() { deleteItem() {
let that = this let that = this;
uni.showModal({ uni.showModal({
title: '提示', title: "提示",
content: '确定删除所选商品吗', content: "确定删除所选商品吗",
success: function (res) { success: function (res) {
if (res.confirm) { if (res.confirm) {
let ids = [] let ids = [];
that.shopCarList.forEach(item => { that.shopCarList.forEach((item) => {
if (item.checked) { if (item.checked) {
ids.push(item.id) ids.push(item.id);
item.checked = false item.checked = false;
} }
})
request(apiArr.deleteCar, "POST", {
ids
}).then(res => {
uni.showToast({
title: '删除成功',
duration: 2000
}); });
that.getShopCar() request(apiArr.deleteCar, "POST", {
that.calcTotal() ids,
}).catch(err => {
console.log(err);
}) })
.then((res) => {
uni.showToast({
title: "删除成功",
duration: 2000,
});
that.getShopCar();
that.calcTotal();
})
.catch((err) => {
console.log(err);
});
} else if (res.cancel) { } else if (res.cancel) {
console.log('用户点击取消'); console.log("用户点击取消");
}
} }
},
});
},
//
handleQuantityChange(val, item) {
const params = {
user_id: uni.getStorageSync("userId"),
goods_id_and_count: [
{
goods_id: item.goods_id,
count: val,
},
],
};
request(apiArr.updateCar, "POST", params).then((res) => {
console.log(res);
uni.showToast({
title: "操作成功!",
success() {},
});
}); });
}, },
}, },
@ -233,12 +279,10 @@ export default {
const meun = menuButtonInfo(); const meun = menuButtonInfo();
this.top = meun.top; this.top = meun.top;
this.localHeight = meun.height; this.localHeight = meun.height;
this.getShopCar() this.getShopCar();
}, },
onReachBottom() { onReachBottom() {},
};
},
}
</script> </script>
<style> <style>