feat : 使商城列表 商品详情 购物车 的商品数量保持一致
This commit is contained in:
parent
7b1dc4a1fa
commit
cc1d99ad1c
@ -1,420 +1,481 @@
|
||||
<template>
|
||||
<view>
|
||||
<div class="header">
|
||||
<div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
|
||||
<div class="searchBox_left" @click="back">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="swiper">
|
||||
<swiper :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>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view>
|
||||
<div class="header">
|
||||
<div
|
||||
class="searchBox"
|
||||
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }"
|
||||
>
|
||||
<div class="searchBox_left" @click="back">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="swiper">
|
||||
<swiper
|
||||
: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>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
|
||||
<div class="NumDot">
|
||||
{{ currentIndex }} /{{ currentGG.goods_carousel.length }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="NumDot">
|
||||
{{ currentIndex }} /{{ currentGG.goods_carousel.length }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="Money">
|
||||
<div class="MoneyMark">¥</div>{{ currentGG.sales_price }} <div class="MoneyUnit">/{{ currentGG.goods_unit }}
|
||||
</div>
|
||||
<div class="Money">
|
||||
<div class="MoneyMark">¥</div>
|
||||
{{ currentGG.sales_price }}
|
||||
<div class="MoneyUnit">/{{ currentGG.goods_unit }}</div>
|
||||
|
||||
<div class="oldMoney">¥{{ currentGG.market_price }}</div>
|
||||
</div>
|
||||
<div class="oldMoney">¥{{ currentGG.market_price }}</div>
|
||||
</div>
|
||||
|
||||
<!-- 规格 -->
|
||||
<!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> -->
|
||||
<div class="GGBox">
|
||||
<div class="GG_left">
|
||||
<div 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 }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="GG_rigth">共{{ info.commodity_goods_info_list.length }}款<u-icon size="26rpx"
|
||||
name="arrow-right"></u-icon></div>
|
||||
</div>
|
||||
<!-- 规格 -->
|
||||
<!-- @click="changeGG2(item, index)" :class="index == currentGGIndex ? 'active' : ''"> -->
|
||||
<div class="GGBox">
|
||||
<div class="GG_left">
|
||||
<div
|
||||
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 }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="GG_rigth">
|
||||
共{{ info.commodity_goods_info_list.length }}款<u-icon
|
||||
size="26rpx"
|
||||
name="arrow-right"
|
||||
></u-icon>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="Tit">{{ currentGG.goods_name }}</div>
|
||||
<div class="Msg">{{ currentGG.commodity_brief }}</div>
|
||||
<div class="GoodsMsg">
|
||||
商品详情
|
||||
</div>
|
||||
<div class="Tit">{{ currentGG.goods_name }}</div>
|
||||
<div class="Msg">{{ currentGG.commodity_brief }}</div>
|
||||
<div class="GoodsMsg">商品详情</div>
|
||||
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">商品编号</div>
|
||||
<div class="Msg_ItemCon" @click="copys(currentGG.goods_no)">{{ currentGG.goods_no }} <image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png"></image>
|
||||
</div>
|
||||
</div>
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">规格说明</div>
|
||||
<div class="Msg_ItemCon">{{ currentGG.goods_spec }}</div>
|
||||
</div>
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">售卖单位</div>
|
||||
<div class="Msg_ItemCon">{{ currentGG.goods_unit }}</div>
|
||||
</div>
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">商品编号</div>
|
||||
<div class="Msg_ItemCon" @click="copys(currentGG.goods_no)">
|
||||
{{ currentGG.goods_no }}
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png"
|
||||
></image>
|
||||
</div>
|
||||
</div>
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">规格说明</div>
|
||||
<div class="Msg_ItemCon">{{ currentGG.goods_spec }}</div>
|
||||
</div>
|
||||
<div class="Msg_Item">
|
||||
<div class="Msg_ItemTit">售卖单位</div>
|
||||
<div class="Msg_ItemCon">{{ currentGG.goods_unit }}</div>
|
||||
</div>
|
||||
|
||||
<div class="GoosMsg">
|
||||
<image v-for="item in currentGG.goods_detail_pic" :src="picUrl + item" mode="widthFix"></image>
|
||||
</div>
|
||||
<div class="GoosMsg">
|
||||
<image
|
||||
v-for="item in currentGG.goods_detail_pic"
|
||||
:src="picUrl + item"
|
||||
mode="widthFix"
|
||||
></image>
|
||||
</div>
|
||||
|
||||
<!-- 底部购物车 -->
|
||||
<div class="Car">
|
||||
<div class="car_left">
|
||||
<div class="share" @click="share">
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share.png"
|
||||
mode="widthFix"
|
||||
></image>
|
||||
分享
|
||||
</div>
|
||||
<div class="cars" @click="car">
|
||||
<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"
|
||||
mode="widthFix"
|
||||
></image>
|
||||
购物车
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 底部购物车 -->
|
||||
<div class="Car">
|
||||
<div class="car_left">
|
||||
<div class="share" @click="share">
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share.png"
|
||||
mode="widthFix"></image>
|
||||
分享
|
||||
</div>
|
||||
<div class="cars" @click="car">
|
||||
<u-badge numberType="limit" :type="type" max="99" :value="carNum"></u-badge>
|
||||
<div
|
||||
class="car_right"
|
||||
v-if="
|
||||
!info.commodity_goods_info_list[currentGGIndex].cart_count ||
|
||||
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0
|
||||
"
|
||||
@click="addCar"
|
||||
>
|
||||
加入购物车
|
||||
</div>
|
||||
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car.png"
|
||||
mode="widthFix"></image>
|
||||
购物车
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="car_right"
|
||||
v-if="
|
||||
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">
|
||||
<u-icon name="minus" size="36" bold></u-icon>
|
||||
</view>
|
||||
<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">
|
||||
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="car_right"
|
||||
v-if="!info.commodity_goods_info_list[currentGGIndex].cart_count || info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0"
|
||||
@click="addCar">
|
||||
加入购物车
|
||||
</div>
|
||||
|
||||
<div class="car_right" v-if="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">
|
||||
<u-icon name="minus" size="36" bold></u-icon>
|
||||
</view>
|
||||
<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">
|
||||
<u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 分享 -->
|
||||
<div class="shadow" @click.stop="changeShadow" v-if="boxshadow1">
|
||||
<div class="shadowBox1">
|
||||
<div class="shadowBox1Item" @click="shareFriend">
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
|
||||
mode="aspectFill"></image>
|
||||
微信好友
|
||||
</div>
|
||||
<div class="shadowBox1Item" @click="openSave">
|
||||
<image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png"
|
||||
mode="aspectFill"></image>
|
||||
生成海报
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 海报 -->
|
||||
<div class="shadow" @click="changeShadow2" v-if="boxshadow2">
|
||||
<div class="shadowBox2">
|
||||
<div class="shadowBox_img">
|
||||
<div class="boxshadow_tit">今日商品推荐</div>
|
||||
<div class="boxshadow_img">
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png">
|
||||
</image>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<div class="shadowBoxInfo">
|
||||
<div class="shadowboxInfo_left">二维码</div>
|
||||
<div class="shadowboxInfo_right">
|
||||
<div class="shadowboxInfo_right_1">正鲜生</div>
|
||||
<div class="shadowboxInfo_right_2">
|
||||
长按识别小程序 <br>
|
||||
数量有限马上抢购</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shadowBox_btn" @click.stop="saveImg">保存海报</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</view>
|
||||
<!-- 分享 -->
|
||||
<div class="shadow" @click.stop="changeShadow" v-if="boxshadow1">
|
||||
<div class="shadowBox1">
|
||||
<div class="shadowBox1Item" @click="shareFriend">
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
微信好友
|
||||
</div>
|
||||
<div class="shadowBox1Item" @click="openSave">
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
生成海报
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 海报 -->
|
||||
<div class="shadow" @click="changeShadow2" v-if="boxshadow2">
|
||||
<div class="shadowBox2">
|
||||
<div class="shadowBox_img">
|
||||
<div class="boxshadow_tit">今日商品推荐</div>
|
||||
<div class="boxshadow_img">
|
||||
<image
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png"
|
||||
>
|
||||
</image>
|
||||
</div>
|
||||
<div class="line"></div>
|
||||
<div class="shadowBoxInfo">
|
||||
<div class="shadowboxInfo_left">二维码</div>
|
||||
<div class="shadowboxInfo_right">
|
||||
<div class="shadowboxInfo_right_1">正鲜生</div>
|
||||
<div class="shadowboxInfo_right_2">
|
||||
长按识别小程序 <br />
|
||||
数量有限马上抢购
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="shadowBox_btn" @click.stop="saveImg">保存海报</div>
|
||||
</div>
|
||||
</div>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
apiArr
|
||||
} from '../../../api/shop';
|
||||
import {
|
||||
picUrl,
|
||||
menuButtonInfo,
|
||||
request,
|
||||
NavgateTo
|
||||
} from '../../../utils';
|
||||
import { apiArr } from "../../../api/shop";
|
||||
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
carNum: '',
|
||||
prevCarNum: "",
|
||||
currentNum: "0",//当前商品的数量
|
||||
type: "error",
|
||||
boxshadow1: false,
|
||||
boxshadow2: false,
|
||||
id: "",
|
||||
info: "",
|
||||
currentIndex: "1",//当前轮播图
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
carNum: "",
|
||||
prevCarNum: "",
|
||||
currentNum: "0", //当前商品的数量
|
||||
type: "error",
|
||||
boxshadow1: false,
|
||||
boxshadow2: false,
|
||||
id: "",
|
||||
info: "",
|
||||
currentIndex: "1", //当前轮播图
|
||||
|
||||
currentGG: "", //当前选中规格
|
||||
currentGGIndex: "", //当前规格index
|
||||
currentGG: "", //当前选中规格
|
||||
currentGGIndex: "", //当前规格index
|
||||
|
||||
carOrderList: [],
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
carOrderList: [],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
changeIndex(e) {
|
||||
this.currentIndex = e.detail.current + 1;
|
||||
},
|
||||
|
||||
changeIndex(e) {
|
||||
this.currentIndex = e.detail.current + 1
|
||||
},
|
||||
back() {
|
||||
uni.navigateBack({
|
||||
delta: 1,
|
||||
});
|
||||
},
|
||||
// 分享微信
|
||||
shareFriend() {
|
||||
this.boxshadow2 = false;
|
||||
return;
|
||||
// uniapp 分享微信好友
|
||||
uni.share({
|
||||
provider: "weixin",
|
||||
type: "link",
|
||||
scene: "session",
|
||||
link: "https://uniapp.dcloud.net.cn/",
|
||||
title: "商品名称",
|
||||
imageUrl: "",
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: "分享成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
this.boxshadow1 = false;
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("分享失败", err);
|
||||
this.boxshadow1 = false;
|
||||
},
|
||||
});
|
||||
},
|
||||
changeShadow() {
|
||||
this.boxshadow1 = false;
|
||||
},
|
||||
openSave() {
|
||||
this.boxshadow1 = false;
|
||||
this.boxshadow2 = true;
|
||||
},
|
||||
// 保存海报
|
||||
saveImg() {
|
||||
this.boxshadow2 = false;
|
||||
// 微信小程序保存图片
|
||||
uni.downloadFile({
|
||||
url: "https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png",
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: "保存成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("保存失败", err);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log("下载失败", err);
|
||||
},
|
||||
});
|
||||
},
|
||||
changeShadow2() {
|
||||
this.boxshadow2 = false;
|
||||
},
|
||||
|
||||
back() {
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
});
|
||||
},
|
||||
// 分享微信
|
||||
shareFriend() {
|
||||
this.boxshadow2 = false
|
||||
return
|
||||
// uniapp 分享微信好友
|
||||
uni.share({
|
||||
provider: 'weixin',
|
||||
type: 'link',
|
||||
scene: 'session',
|
||||
link: 'https://uniapp.dcloud.net.cn/',
|
||||
title: '商品名称',
|
||||
imageUrl: '',
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: '分享成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
this.boxshadow1 = false
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('分享失败', err);
|
||||
this.boxshadow1 = false
|
||||
}
|
||||
});
|
||||
},
|
||||
changeShadow() {
|
||||
this.boxshadow1 = false
|
||||
},
|
||||
openSave() {
|
||||
this.boxshadow1 = false
|
||||
this.boxshadow2 = true
|
||||
},
|
||||
// 保存海报
|
||||
saveImg() {
|
||||
this.boxshadow2 = false
|
||||
// 微信小程序保存图片
|
||||
uni.downloadFile({
|
||||
url: 'https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png',
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: '保存成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('保存失败', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.log('下载失败', err);
|
||||
}
|
||||
});
|
||||
},
|
||||
changeShadow2() {
|
||||
this.boxshadow2 = false
|
||||
},
|
||||
// 点分享按钮
|
||||
share() {
|
||||
this.boxshadow1 = true;
|
||||
},
|
||||
//商品详情
|
||||
getGoodsInfo() {
|
||||
request(apiArr.getGoodsInfo, "POST", {
|
||||
id: this.id,
|
||||
}).then((res) => {
|
||||
console.log(res);
|
||||
|
||||
// 点分享按钮
|
||||
share() {
|
||||
this.boxshadow1 = true
|
||||
},
|
||||
//商品详情
|
||||
getGoodsInfo() {
|
||||
request(apiArr.getGoodsInfo, "POST", {
|
||||
id: this.id
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
// 分割图片
|
||||
res.commodity_goods_info_list.forEach((item) => {
|
||||
item.goods_detail_pic = item.goods_detail_pic.split(",");
|
||||
item.goods_carousel = item.goods_carousel.split(",");
|
||||
item.commodity_pic = item.commodity_pic.split(",");
|
||||
});
|
||||
|
||||
// 分割图片
|
||||
res.commodity_goods_info_list.forEach(item => {
|
||||
item.goods_detail_pic = item.goods_detail_pic.split(',')
|
||||
item.goods_carousel = item.goods_carousel.split(',')
|
||||
item.commodity_pic = item.commodity_pic.split(',')
|
||||
});
|
||||
//根据购物车列表 和 当前商品列表 来更新当前商品列表在购物车中的数量
|
||||
if (this.carOrderList) {
|
||||
this.carOrderList.forEach((items) => {
|
||||
res.commodity_goods_info_list.forEach((item) => {
|
||||
if (items.goods_id == item.id) {
|
||||
item.cart_count = { count: 0 };
|
||||
item.cart_count.count = items.count;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
this.info = res;
|
||||
this.currentGG = res.commodity_goods_info_list[0];
|
||||
this.currentGGIndex = 0;
|
||||
});
|
||||
},
|
||||
|
||||
copys(e) {
|
||||
uni.setClipboardData({
|
||||
data: e,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: "复制成功",
|
||||
icon: "success",
|
||||
duration: 2000,
|
||||
});
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
// 切换规格
|
||||
changeGG(item, index) {
|
||||
this.currentGG = item;
|
||||
this.currentGGIndex = index;
|
||||
if (this.currentGG.cart_count) {
|
||||
this.currentNum = this.currentGG.cart_count.count;
|
||||
} else {
|
||||
this.currentGG.cart_count = { count: 0 };
|
||||
}
|
||||
},
|
||||
car() {
|
||||
NavgateTo("../shopCar/index");
|
||||
},
|
||||
|
||||
//根据购物车列表 和 当前商品列表 来更新当前商品列表在购物车中的数量
|
||||
if (this.carOrderList) {
|
||||
this.carOrderList.forEach(items => {
|
||||
res.commodity_goods_info_list.forEach(item => {
|
||||
if (items.goods_id == item.id) {
|
||||
item.cart_count = {count:0}
|
||||
item.cart_count.count = items.count
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
this.info = res
|
||||
this.currentGG = res.commodity_goods_info_list[0]
|
||||
this.currentGGIndex = 0
|
||||
//获取购物车数量
|
||||
getShopCar() {
|
||||
request(apiArr.getCarCount, "POST", {}).then((res) => {
|
||||
this.carNum = res.total;
|
||||
this.prevCarNum = res.total;
|
||||
});
|
||||
},
|
||||
|
||||
})
|
||||
},
|
||||
getShopCarList() {
|
||||
request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
this.carOrderList = res.commodity_cart_list;
|
||||
});
|
||||
},
|
||||
|
||||
copys(e) {
|
||||
uni.setClipboardData({
|
||||
data: e,
|
||||
success: (res) => {
|
||||
uni.showToast({
|
||||
title: '复制成功',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
addCar() {
|
||||
let that = this;
|
||||
//如果没有当前商品 直接添加一个
|
||||
let goods_id_and_count = [];
|
||||
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = {
|
||||
count: 1,
|
||||
};
|
||||
this.info.commodity_goods_info_list.forEach((item) => {
|
||||
console.log(item.cart_count);
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count ? item.cart_count.count : 0,
|
||||
});
|
||||
});
|
||||
|
||||
console.log(goods_id_and_count);
|
||||
//因为是当前商品没有 调用update就是增加商品。增加商品之后再获取购物车数量
|
||||
request(apiArr.updateCar, "POST", {
|
||||
goods_id_and_count,
|
||||
}).then((res) => {
|
||||
that.getShopCar();
|
||||
that.getShopCarList();
|
||||
});
|
||||
},
|
||||
|
||||
// 切换规格
|
||||
changeGG(item, index) {
|
||||
this.currentGG = item
|
||||
this.currentGGIndex = index
|
||||
if (this.currentGG.cart_count) {
|
||||
this.currentNum = this.currentGG.cart_count.count
|
||||
} else {
|
||||
this.currentGG.cart_count = { count: 0 }
|
||||
}
|
||||
},
|
||||
car() {
|
||||
NavgateTo('../shopCar/index')
|
||||
},
|
||||
// 购物车更改
|
||||
changeCar(newValue) {
|
||||
// // 修改当前商品在购物车中的数量
|
||||
// this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value
|
||||
// // 修改购物车列表中的数量
|
||||
// this.carOrderList.forEach(item => {
|
||||
// if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) {
|
||||
// item.count = newValue.value
|
||||
// }
|
||||
// })
|
||||
// // 计算购物车数量
|
||||
// let carNum = 0
|
||||
// this.carOrderList.forEach(item => {
|
||||
// carNum += item.count
|
||||
// })
|
||||
// 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) {
|
||||
const itemObj = JSON.parse(decodeURIComponent(options.item));
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
|
||||
//获取购物车数量
|
||||
getShopCar() {
|
||||
request(apiArr.getCarCount, 'POST', {}).then(res => {
|
||||
this.carNum = res.total
|
||||
this.prevCarNum = res.total
|
||||
})
|
||||
},
|
||||
this.id = itemObj.id;
|
||||
},
|
||||
onReachBottom() {},
|
||||
onShow() {
|
||||
this.getShopCarList();
|
||||
this.getGoodsInfo();
|
||||
this.getShopCar();
|
||||
},
|
||||
|
||||
//离开页面的时候直接更新购物车数量(目前接口是 传入商品id 数量。如果有当前商品就更新数量。如果没有就增加商品。如果删除某个商品 count 为0 就删除)
|
||||
onHide() {
|
||||
let goods_id_and_count = [];
|
||||
this.info.commodity_goods_info_list.forEach((item) => {
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count ? item.cart_count.count : 0,
|
||||
});
|
||||
});
|
||||
|
||||
getShopCarList() {
|
||||
request(apiArr.getCar, 'POST', {}).then(res => {
|
||||
this.carOrderList = res.commodity_cart_list
|
||||
})
|
||||
},
|
||||
|
||||
addCar() {
|
||||
let that = this
|
||||
//如果没有当前商品 直接添加一个
|
||||
let goods_id_and_count = []
|
||||
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { count: 1 }
|
||||
this.info.commodity_goods_info_list.forEach(item => {
|
||||
console.log(item.cart_count);
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count ? item.cart_count.count : 0
|
||||
})
|
||||
})
|
||||
|
||||
console.log(goods_id_and_count);
|
||||
//因为是当前商品没有 调用update就是增加商品。增加商品之后再获取购物车数量
|
||||
request(apiArr.updateCar, "POST", {
|
||||
goods_id_and_count
|
||||
}).then(res => {
|
||||
that.getShopCar()
|
||||
that.getShopCarList()
|
||||
})
|
||||
},
|
||||
|
||||
// 购物车更改
|
||||
changeCar(newValue) {
|
||||
// 修改当前商品在购物车中的数量
|
||||
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value
|
||||
// 修改购物车列表中的数量
|
||||
this.carOrderList.forEach(item => {
|
||||
if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) {
|
||||
item.count = newValue.value
|
||||
}
|
||||
})
|
||||
// 计算购物车数量
|
||||
let carNum = 0
|
||||
this.carOrderList.forEach(item => {
|
||||
carNum += item.count
|
||||
})
|
||||
this.carNum = carNum
|
||||
},
|
||||
|
||||
|
||||
},
|
||||
onLoad(options) {
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
|
||||
this.id = options.id
|
||||
|
||||
},
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
onShow() {
|
||||
this.getShopCarList()
|
||||
this.getGoodsInfo()
|
||||
this.getShopCar()
|
||||
},
|
||||
|
||||
//离开页面的时候直接更新购物车数量(目前接口是 传入商品id 数量。如果有当前商品就更新数量。如果没有就增加商品。如果删除某个商品 count 为0 就删除)
|
||||
onHide() {
|
||||
let goods_id_and_count = []
|
||||
this.info.commodity_goods_info_list.forEach(item => {
|
||||
goods_id_and_count.push({
|
||||
goods_id: item.id,
|
||||
count: item.cart_count ? item.cart_count.count : 0
|
||||
})
|
||||
})
|
||||
|
||||
request(apiArr.updateCar, "POST", {
|
||||
goods_id_and_count
|
||||
})
|
||||
return
|
||||
},
|
||||
|
||||
|
||||
}
|
||||
request(apiArr.updateCar, "POST", {
|
||||
goods_id_and_count,
|
||||
});
|
||||
return;
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
@ -90,7 +90,8 @@
|
||||
<div class="Con">
|
||||
<div class="Con_left">
|
||||
<div
|
||||
class="CateItem" :class="item.id === currentLeftCateId ? 'CateItem_active' : ''"
|
||||
class="CateItem"
|
||||
:class="item.id === currentLeftCateId ? 'CateItem_active' : ''"
|
||||
v-for="item in leftCateList"
|
||||
:key="item.id"
|
||||
@click="changeLeftCate(item.id)"
|
||||
@ -148,19 +149,19 @@
|
||||
:key="items.id"
|
||||
>
|
||||
<div class="CateInfo_Item_Box">
|
||||
<div class="CateInfo_Item_left" @click="goods(items.id)">
|
||||
<div class="CateInfo_Item_left" @click="goods(items)">
|
||||
<image
|
||||
:src="picUrl + items.commodity_pic"
|
||||
mode="aspectFill"
|
||||
></image>
|
||||
</div>
|
||||
<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 }}
|
||||
</div>
|
||||
<div
|
||||
class="CateInfo_Item_right_subtit"
|
||||
@click="goods(items.id)"
|
||||
@click="goods(items)"
|
||||
>
|
||||
{{ items.commodity_intro }}
|
||||
</div>
|
||||
@ -175,8 +176,8 @@
|
||||
>
|
||||
<u-number-box
|
||||
:min="0"
|
||||
v-model="items.quantity"
|
||||
@change="(value) => handleQuantityChange(value,items)"
|
||||
v-model="items.commodity_goods_info_list[0].quantity"
|
||||
@change="(value) => handleQuantityChange(value, items)"
|
||||
>
|
||||
<view slot="minus" class="minus">
|
||||
<u-icon name="minus" size="20"></u-icon>
|
||||
@ -185,7 +186,11 @@
|
||||
slot="input"
|
||||
style="width: 50px; text-align: center"
|
||||
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">
|
||||
<u-icon name="plus" color="#FFFFFF" size="20"></u-icon>
|
||||
@ -226,7 +231,7 @@
|
||||
<div
|
||||
class="GGItem"
|
||||
v-for="ite in items.commodity_goods_info_list"
|
||||
@click="goods(items.id)"
|
||||
@click="goods(items)"
|
||||
>
|
||||
<div class="GGItem_Image">
|
||||
<image
|
||||
@ -244,7 +249,7 @@
|
||||
<u-number-box
|
||||
v-model="ite.quantity"
|
||||
:min="0"
|
||||
@change="(value) => handleQuantityChange(value,ite)"
|
||||
@change="(value) => handleQuantityChange(value, ite)"
|
||||
>
|
||||
<view slot="minus" class="minus">
|
||||
<u-icon name="minus" size="20"></u-icon>
|
||||
@ -356,7 +361,7 @@ export default {
|
||||
],
|
||||
|
||||
rightTopActive: 0,
|
||||
currentLeftCateId: null,
|
||||
currentLeftCateId: null,
|
||||
topShow: false,
|
||||
|
||||
GGshow: false,
|
||||
@ -369,6 +374,8 @@ currentLeftCateId: null,
|
||||
|
||||
tagList: [],
|
||||
carNum: "",
|
||||
|
||||
goodsDetail: [],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
@ -404,7 +411,7 @@ currentLeftCateId: null,
|
||||
},
|
||||
//商品详情页
|
||||
goods(e) {
|
||||
NavgateTo(`../goods/index?id=${e}`);
|
||||
NavgateTo(`../goods/index?item=${JSON.stringify(e)}`);
|
||||
},
|
||||
|
||||
// 购物车
|
||||
@ -417,7 +424,8 @@ currentLeftCateId: null,
|
||||
console.log(res);
|
||||
this.CateList = res.commodity_category_list;
|
||||
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) {
|
||||
this.currentLeftCateId = this.leftCateList[0].id;
|
||||
this.secondId = this.leftCateList[0].id;
|
||||
@ -440,10 +448,18 @@ currentLeftCateId: null,
|
||||
}).then((res) => {
|
||||
res.commodity_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;
|
||||
});
|
||||
});
|
||||
this.tagList = res.commodity_list;
|
||||
console.log("🚀 ~ getGoodsList ~ this.tagList:", this.tagList)
|
||||
});
|
||||
},
|
||||
|
||||
@ -451,6 +467,7 @@ currentLeftCateId: null,
|
||||
request(apiArr.getCar, "POST").then((res) => {
|
||||
console.log(res);
|
||||
this.carNum = res.total;
|
||||
this.goodsDetail = res.commodity_cart_list;
|
||||
});
|
||||
},
|
||||
|
||||
@ -460,8 +477,11 @@ currentLeftCateId: null,
|
||||
this.getGoodsList();
|
||||
},
|
||||
//商品数量变化
|
||||
handleQuantityChange(val,item) {
|
||||
if (item.commodity_goods_info_list.length) {
|
||||
handleQuantityChange(val, item) {
|
||||
if (
|
||||
item.commodity_goods_info_list &&
|
||||
item.commodity_goods_info_list.length
|
||||
) {
|
||||
this.goodsId = item.commodity_goods_info_list[0].id;
|
||||
} else {
|
||||
this.goodsId = item.id;
|
||||
@ -480,8 +500,7 @@ currentLeftCateId: null,
|
||||
this.getShopCarList();
|
||||
uni.showToast({
|
||||
title: "操作成功!",
|
||||
success() {
|
||||
},
|
||||
success() {},
|
||||
});
|
||||
});
|
||||
},
|
||||
@ -495,6 +514,7 @@ currentLeftCateId: null,
|
||||
},
|
||||
onShow() {
|
||||
this.getShopCarList();
|
||||
this.getGoodsList();
|
||||
},
|
||||
onReachBottom() {
|
||||
if (this.flag) {
|
||||
|
||||
@ -1,244 +1,288 @@
|
||||
<template>
|
||||
<view>
|
||||
<div class="header">
|
||||
<div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
|
||||
<div class="searchBox_left" @click="back">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
<div class="searchBox_mid">购物车({{ shopCarTotal }}) </div>
|
||||
<div class="searchBox_right">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
</div>
|
||||
<view>
|
||||
<div class="header">
|
||||
<div
|
||||
class="searchBox"
|
||||
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }"
|
||||
>
|
||||
<div class="searchBox_left" @click="back">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
|
||||
<div class="main">
|
||||
<div class="deleteIcon" @click="deleteItem">
|
||||
<u-icon name="trash" size="50rpx"></u-icon>
|
||||
</div>
|
||||
|
||||
<div class="goodsList">
|
||||
<div class="goodsItem" v-for="item, index in shopCarList" :key="item.id">
|
||||
<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 v-if="item.checked" src="http://192.168.0.172:5500/7.15/shop_checked2.png"></image>
|
||||
</div>
|
||||
<div class="goodsItem_right">
|
||||
<div class="goodsItem_msg">
|
||||
<div class="goodsItem_msg_img">
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</div>
|
||||
<div class="goodsItem_msg_right">
|
||||
<div class="goodsItem_msg_right_tit">{{ item.commodity_goods_info.goods_name }}</div>
|
||||
<div class="goodsItem_msg_right_subTit">{{ item.commodity_goods_info.goods_intro }}
|
||||
</div>
|
||||
<div class="goodsItem_msg_right_msg">
|
||||
<div class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }} <span>/{{
|
||||
item.commodity_goods_info.goods_unit }}</span>
|
||||
</div>
|
||||
<div class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box 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>
|
||||
</view>
|
||||
<text slot="input" style="width: 80rpx;text-align: center;" class="input">{{
|
||||
item.count }}</text>
|
||||
<view slot="plus" class="plus" @click="add(item, index)">
|
||||
<u-icon name="plus" color="#FFFFFF" size="32" bold></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<div class="footer_left">
|
||||
<div class="footer_all" @click="allChecked">
|
||||
<image v-if="!isAllchecked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png">
|
||||
</image>
|
||||
<image v-if="isAllchecked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png">
|
||||
</image>
|
||||
全选
|
||||
</div>
|
||||
<div class="footer_total">
|
||||
<span>合计</span>
|
||||
¥{{ shopMoney }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer_right" @click="submitOrder">
|
||||
结算
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="searchBox_mid">购物车({{ shopCarTotal }})</div>
|
||||
<div class="searchBox_right">
|
||||
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="empty" v-if="false">
|
||||
<image src="http://192.168.0.172:5500/7.15/shop_empty.png"></image>
|
||||
<div>
|
||||
啥也没有 <br>
|
||||
赶紧去shopping吧~
|
||||
<div class="main">
|
||||
<div class="deleteIcon" @click="deleteItem">
|
||||
<u-icon name="trash" size="50rpx"></u-icon>
|
||||
</div>
|
||||
|
||||
<div class="goodsList">
|
||||
<div
|
||||
class="goodsItem"
|
||||
v-for="(item, index) in shopCarList"
|
||||
:key="item.id"
|
||||
>
|
||||
<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
|
||||
v-if="item.checked"
|
||||
src="http://192.168.0.172:5500/7.15/shop_checked2.png"
|
||||
></image>
|
||||
</div>
|
||||
<div class="goodsItem_right">
|
||||
<div class="goodsItem_msg">
|
||||
<div class="goodsItem_msg_img">
|
||||
<image :src="picUrl + item.commodity_goods_info.commodity_pic">
|
||||
</image>
|
||||
</div>
|
||||
<div class="goodsItem_msg_right">
|
||||
<div class="goodsItem_msg_right_tit">
|
||||
{{ item.commodity_goods_info.goods_name }}
|
||||
</div>
|
||||
<div class="goodsItem_msg_right_subTit">
|
||||
{{ item.commodity_goods_info.goods_intro }}
|
||||
</div>
|
||||
<div class="goodsItem_msg_right_msg">
|
||||
<div class="goodsItem_msg_right_msg_left">
|
||||
<span>¥</span>{{ item.commodity_goods_info.sales_price }}
|
||||
<span>/{{ item.commodity_goods_info.goods_unit }}</span>
|
||||
</div>
|
||||
<div class="goodsItem_msg_right_msg_right">
|
||||
<u-number-box
|
||||
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>
|
||||
</view>
|
||||
<text
|
||||
slot="input"
|
||||
style="width: 80rpx; text-align: center"
|
||||
class="input"
|
||||
>{{ item.count }}</text
|
||||
>
|
||||
<view slot="plus" class="plus" @click="add(item, index)">
|
||||
<u-icon
|
||||
name="plus"
|
||||
color="#FFFFFF"
|
||||
size="32"
|
||||
bold
|
||||
></u-icon>
|
||||
</view>
|
||||
</u-number-box>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</view>
|
||||
<div class="footer">
|
||||
<div class="footer_left">
|
||||
<div class="footer_all" @click="allChecked">
|
||||
<image
|
||||
v-if="!isAllchecked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png"
|
||||
>
|
||||
</image>
|
||||
<image
|
||||
v-if="isAllchecked"
|
||||
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png"
|
||||
>
|
||||
</image>
|
||||
全选
|
||||
</div>
|
||||
<div class="footer_total">
|
||||
<span>合计</span>
|
||||
¥{{ shopMoney }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="footer_right" @click="submitOrder">结算</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="empty" v-if="false">
|
||||
<image src="http://192.168.0.172:5500/7.15/shop_empty.png"></image>
|
||||
<div>
|
||||
啥也没有 <br />
|
||||
赶紧去shopping吧~
|
||||
</div>
|
||||
</div>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
apiArr
|
||||
} from '../../../api/shop';
|
||||
import {
|
||||
picUrl,
|
||||
menuButtonInfo,
|
||||
request,
|
||||
NavgateTo
|
||||
} from '../../../utils';
|
||||
import { apiArr } from "../../../api/shop";
|
||||
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
value: 3,
|
||||
type: "error",
|
||||
shopCarList: [],
|
||||
shopCarTotal: 0,
|
||||
shopMoney: 0,
|
||||
isAllchecked: false
|
||||
data() {
|
||||
return {
|
||||
picUrl,
|
||||
top: "",
|
||||
localHeight: "",
|
||||
value: 3,
|
||||
type: "error",
|
||||
shopCarList: [],
|
||||
shopCarTotal: 0,
|
||||
shopMoney: 0,
|
||||
isAllchecked: false,
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
back() {
|
||||
NavgateTo("1");
|
||||
},
|
||||
submitOrder() {
|
||||
let arr = [];
|
||||
this.shopCarList.forEach((item) => {
|
||||
if (item.checked) {
|
||||
arr.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`);
|
||||
},
|
||||
methods: {
|
||||
back() {
|
||||
NavgateTo("1")
|
||||
},
|
||||
submitOrder() {
|
||||
|
||||
let arr = []
|
||||
this.shopCarList.forEach(item => {
|
||||
if (item.checked) {
|
||||
arr.push(item)
|
||||
}
|
||||
})
|
||||
getShopCar() {
|
||||
request(apiArr.getCar, "POST", {}).then((res) => {
|
||||
res.commodity_cart_list.forEach((item) => {
|
||||
item.checked = false;
|
||||
});
|
||||
this.shopCarTotal = res.total;
|
||||
this.shopCarList = res.commodity_cart_list;
|
||||
});
|
||||
},
|
||||
|
||||
NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`)
|
||||
},
|
||||
// 单个修改
|
||||
changeChecked(item, index) {
|
||||
this.shopCarList[index].checked = !this.shopCarList[index].checked;
|
||||
this.calcTotal();
|
||||
// 计算是否全选
|
||||
this.isAllchecked = this.shopCarList.every((item) => item.checked);
|
||||
},
|
||||
// 全选
|
||||
allChecked() {
|
||||
this.isAllchecked = !this.isAllchecked;
|
||||
// Bug 修复:将 !this.allChecked 改为 !this.isAllchecked
|
||||
if (this.isAllchecked) {
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = true;
|
||||
});
|
||||
} else {
|
||||
this.shopCarList.forEach((item) => {
|
||||
item.checked = false;
|
||||
});
|
||||
}
|
||||
this.calcTotal();
|
||||
},
|
||||
// 计算金额
|
||||
calcTotal() {
|
||||
let total = 0;
|
||||
this.shopCarList.forEach((item) => {
|
||||
console.log(item);
|
||||
|
||||
getShopCar() {
|
||||
request(apiArr.getCar, 'POST', {}).then(res => {
|
||||
res.commodity_cart_list.forEach(item => {
|
||||
item.checked = false
|
||||
});
|
||||
this.shopCarTotal = res.total
|
||||
this.shopCarList = res.commodity_cart_list
|
||||
})
|
||||
},
|
||||
if (item.checked) {
|
||||
total += item.commodity_goods_info.sales_price * item.count;
|
||||
}
|
||||
});
|
||||
this.shopMoney = total;
|
||||
},
|
||||
|
||||
// 单个修改
|
||||
changeChecked(item, index) {
|
||||
this.shopCarList[index].checked = !this.shopCarList[index].checked
|
||||
this.calcTotal()
|
||||
// 计算是否全选
|
||||
this.isAllchecked = this.shopCarList.every(item => item.checked)
|
||||
},
|
||||
// 全选
|
||||
allChecked() {
|
||||
this.isAllchecked = !this.isAllchecked
|
||||
// Bug 修复:将 !this.allChecked 改为 !this.isAllchecked
|
||||
if (this.isAllchecked) {
|
||||
this.shopCarList.forEach(item => {
|
||||
item.checked = true
|
||||
});
|
||||
} else {
|
||||
this.shopCarList.forEach(item => {
|
||||
item.checked = false
|
||||
});
|
||||
}
|
||||
this.calcTotal()
|
||||
},
|
||||
// 计算金额
|
||||
calcTotal() {
|
||||
minus(item, index) {
|
||||
let that = this;
|
||||
if (item.count === 1) {
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids: [item.id],
|
||||
}).then((res) => {
|
||||
that.shopCarList.splice(index, 1);
|
||||
that.calcTotal();
|
||||
});
|
||||
}
|
||||
this.shopCarList[index].count = this.shopCarList[index].count - 1;
|
||||
this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index])
|
||||
this.calcTotal();
|
||||
},
|
||||
add(item, index) {
|
||||
this.shopCarList[index].count = this.shopCarList[index].count + 1;
|
||||
this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index])
|
||||
this.calcTotal();
|
||||
},
|
||||
|
||||
let total = 0
|
||||
this.shopCarList.forEach(item => {
|
||||
console.log(item);
|
||||
|
||||
if (item.checked) {
|
||||
total += item.commodity_goods_info.sales_price * item.count
|
||||
}
|
||||
});
|
||||
this.shopMoney = total
|
||||
},
|
||||
|
||||
minus(item, index) {
|
||||
let that = this
|
||||
if (item.count === 1) {
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids: [item.id]
|
||||
}).then(res => {
|
||||
that.shopCarList.splice(index, 1)
|
||||
that.calcTotal()
|
||||
})
|
||||
}
|
||||
this.shopCarList[index].count = this.shopCarList[index].count - 1
|
||||
this.calcTotal()
|
||||
},
|
||||
add(item, index) {
|
||||
this.shopCarList[index].count = this.shopCarList[index].count + 1
|
||||
this.calcTotal()
|
||||
},
|
||||
|
||||
|
||||
deleteItem() {
|
||||
let that = this
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '确定删除所选商品吗',
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
let ids = []
|
||||
that.shopCarList.forEach(item => {
|
||||
if (item.checked) {
|
||||
ids.push(item.id)
|
||||
item.checked = false
|
||||
}
|
||||
})
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids
|
||||
}).then(res => {
|
||||
uni.showToast({
|
||||
title: '删除成功',
|
||||
duration: 2000
|
||||
});
|
||||
that.getShopCar()
|
||||
that.calcTotal()
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
} else if (res.cancel) {
|
||||
console.log('用户点击取消');
|
||||
}
|
||||
}
|
||||
deleteItem() {
|
||||
let that = this;
|
||||
uni.showModal({
|
||||
title: "提示",
|
||||
content: "确定删除所选商品吗",
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
let ids = [];
|
||||
that.shopCarList.forEach((item) => {
|
||||
if (item.checked) {
|
||||
ids.push(item.id);
|
||||
item.checked = false;
|
||||
}
|
||||
});
|
||||
request(apiArr.deleteCar, "POST", {
|
||||
ids,
|
||||
})
|
||||
.then((res) => {
|
||||
uni.showToast({
|
||||
title: "删除成功",
|
||||
duration: 2000,
|
||||
});
|
||||
that.getShopCar();
|
||||
that.calcTotal();
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
} else if (res.cancel) {
|
||||
console.log("用户点击取消");
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
onLoad(options) {
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
this.getShopCar()
|
||||
//商品数量变化
|
||||
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() {},
|
||||
});
|
||||
});
|
||||
},
|
||||
onReachBottom() {
|
||||
|
||||
},
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
const meun = menuButtonInfo();
|
||||
this.top = meun.top;
|
||||
this.localHeight = meun.height;
|
||||
this.getShopCar();
|
||||
},
|
||||
onReachBottom() {},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user