Compare commits

..

No commits in common. "2866332d274de0962c009ad99bf2bb4d971c861f" and "2419b031d3b6af9581bfc85c44a11fa117b7a7b0" have entirely different histories.

3 changed files with 624 additions and 749 deletions

View File

@ -1,481 +1,420 @@
<template> <template>
<view> <view>
<div class="header"> <div class="header">
<div <div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
class="searchBox" <div class="searchBox_left" @click="back">
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }" <u-icon name="arrow-left" size="20px" color="#000"></u-icon>
> </div>
<div class="searchBox_left" @click="back"> </div>
<u-icon name="arrow-left" size="20px" color="#000"></u-icon> </div>
</div> <div class="swiper">
</div> <swiper :indicator-dots="false" :autoplay="true" :interval="3000" :duration="1000" @change="changeIndex">
</div> <swiper-item v-for="(item, index) in currentGG.goods_carousel" :key="index">
<div class="swiper"> <image :src="picUrl + item"></image>
<swiper </swiper-item>
:indicator-dots="false" </swiper>
: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"> <div class="NumDot">
{{ currentIndex }} /{{ currentGG.goods_carousel.length }} {{ currentIndex }} /{{ currentGG.goods_carousel.length }}
</div> </div>
</div> </div>
<div class="Money"> <div class="Money">
<div class="MoneyMark"></div> <div class="MoneyMark"></div>{{ currentGG.sales_price }} <div class="MoneyUnit">/{{ currentGG.goods_unit }}
{{ currentGG.sales_price }} </div>
<div class="MoneyUnit">/{{ currentGG.goods_unit }}</div>
<div class="oldMoney">{{ currentGG.market_price }}</div> <div class="oldMoney">{{ currentGG.market_price }}</div>
</div> </div>
<!-- 规格 --> <!-- 规格 -->
<!-- @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 <div class="GG_Item" v-for="(item, index) in info.commodity_goods_info_list" :key="item.id"
class="GG_Item" @click="changeGG(item, index)" :class="index == currentGGIndex ? 'active' : ''">
v-for="(item, index) in info.commodity_goods_info_list" {{ item.goods_spec }} / {{ item.goods_unit }}
:key="item.id" </div>
@click="changeGG(item, index)" </div>
:class="index == currentGGIndex ? 'active' : ''" <div class="GG_rigth">{{ info.commodity_goods_info_list.length }}<u-icon size="26rpx"
> name="arrow-right"></u-icon></div>
{{ item.goods_spec }} / {{ item.goods_unit }} </div>
</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="Tit">{{ currentGG.goods_name }}</div>
<div class="Msg">{{ currentGG.commodity_brief }}</div> <div class="Msg">{{ currentGG.commodity_brief }}</div>
<div class="GoodsMsg">商品详情</div> <div class="GoodsMsg">
商品详情
</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)"> <div class="Msg_ItemCon" @click="copys(currentGG.goods_no)">{{ currentGG.goods_no }} <image
{{ currentGG.goods_no }} src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png"></image>
<image </div>
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_copy.png" </div>
></image> <div class="Msg_Item">
</div> <div class="Msg_ItemTit">规格说明</div>
</div> <div class="Msg_ItemCon">{{ currentGG.goods_spec }}</div>
<div class="Msg_Item"> </div>
<div class="Msg_ItemTit">规格说明</div> <div class="Msg_Item">
<div class="Msg_ItemCon">{{ currentGG.goods_spec }}</div> <div class="Msg_ItemTit">售卖单位</div>
</div> <div class="Msg_ItemCon">{{ currentGG.goods_unit }}</div>
<div class="Msg_Item"> </div>
<div class="Msg_ItemTit">售卖单位</div>
<div class="Msg_ItemCon">{{ currentGG.goods_unit }}</div>
</div>
<div class="GoosMsg"> <div class="GoosMsg">
<image <image v-for="item in currentGG.goods_detail_pic" :src="picUrl + item" mode="widthFix"></image>
v-for="item in currentGG.goods_detail_pic" </div>
: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_right" <div class="Car">
v-if=" <div class="car_left">
!info.commodity_goods_info_list[currentGGIndex].cart_count || <div class="share" @click="share">
info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0 <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share.png"
" mode="widthFix"></image>
@click="addCar" 分享
> </div>
加入购物车 <div class="cars" @click="car">
</div> <u-badge numberType="limit" :type="type" max="99" :value="carNum"></u-badge>
<div <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_car.png"
class="car_right" mode="widthFix"></image>
v-if=" 购物车
info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0 </div>
" </div>
>
<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"
<div class="shadow" @click.stop="changeShadow" v-if="boxshadow1"> v-if="!info.commodity_goods_info_list[currentGGIndex].cart_count || info.commodity_goods_info_list[currentGGIndex].cart_count.count == 0"
<div class="shadowBox1"> @click="addCar">
<div class="shadowBox1Item" @click="shareFriend"> 加入购物车
<image </div>
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
mode="aspectFill" <div class="car_right" v-if="info.commodity_goods_info_list[currentGGIndex].cart_count.count > 0">
></image>
微信好友 <u-number-box v-model="info.commodity_goods_info_list[currentGGIndex].cart_count.count"
</div> @change="changeCar" min="0">
<div class="shadowBox1Item" @click="openSave"> <view slot="minus" class="minus">
<image <u-icon name="minus" size="36" bold></u-icon>
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png" </view>
mode="aspectFill" <text slot="input" style="width: 200rpx;text-align: center;" class="input">
></image> {{ info.commodity_goods_info_list[currentGGIndex].cart_count.count }}</text>
生成海报 <view slot="plus" class="plus">
</div> <u-icon name="plus" color="#FFFFFF" size="36" bold></u-icon>
</div> </view>
</div> </u-number-box>
<!-- 海报 --> </div>
<div class="shadow" @click="changeShadow2" v-if="boxshadow2"> </div>
<div class="shadowBox2">
<div class="shadowBox_img"> <!-- 分享 -->
<div class="boxshadow_tit">今日商品推荐</div> <div class="shadow" @click.stop="changeShadow" v-if="boxshadow1">
<div class="boxshadow_img"> <div class="shadowBox1">
<image <div class="shadowBox1Item" @click="shareFriend">
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png" <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_WX.png"
> mode="aspectFill"></image>
</image> 微信好友
</div> </div>
<div class="line"></div> <div class="shadowBox1Item" @click="openSave">
<div class="shadowBoxInfo"> <image src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_saveImg.png"
<div class="shadowboxInfo_left">二维码</div> mode="aspectFill"></image>
<div class="shadowboxInfo_right"> 生成海报
<div class="shadowboxInfo_right_1">正鲜生</div> </div>
<div class="shadowboxInfo_right_2"> </div>
长按识别小程序 <br /> </div>
数量有限马上抢购 <!-- 海报 -->
</div> <div class="shadow" @click="changeShadow2" v-if="boxshadow2">
</div> <div class="shadowBox2">
</div> <div class="shadowBox_img">
</div> <div class="boxshadow_tit">今日商品推荐</div>
<div class="shadowBox_btn" @click.stop="saveImg">保存海报</div> <div class="boxshadow_img">
</div> <image
</div> src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/shop_share_img.png">
</view> </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> </template>
<script> <script>
import { apiArr } from "../../../api/shop"; import {
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils"; apiArr
} 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",
boxshadow1: false, boxshadow1: false,
boxshadow2: false, boxshadow2: false,
id: "", id: "",
info: "", info: "",
currentIndex: "1", // currentIndex: "1",//
currentGG: "", // currentGG: "", //
currentGGIndex: "", //index currentGGIndex: "", //index
carOrderList: [], carOrderList: [],
}; }
}, },
methods: { methods: {
changeIndex(e) {
this.currentIndex = e.detail.current + 1;
},
back() { changeIndex(e) {
uni.navigateBack({ this.currentIndex = e.detail.current + 1
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() {
share() { uni.navigateBack({
this.boxshadow1 = true; delta: 1
}, });
// },
getGoodsInfo() { //
request(apiArr.getGoodsInfo, "POST", { shareFriend() {
id: this.id, this.boxshadow2 = false
}).then((res) => { return
console.log(res); // 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
},
// //
res.commodity_goods_info_list.forEach((item) => { share() {
item.goods_detail_pic = item.goods_detail_pic.split(","); this.boxshadow1 = true
item.goods_carousel = item.goods_carousel.split(","); },
item.commodity_pic = item.commodity_pic.split(","); //
}); getGoodsInfo() {
request(apiArr.getGoodsInfo, "POST", {
id: this.id
}).then(res => {
console.log(res);
// //
if (this.carOrderList) { res.commodity_goods_info_list.forEach(item => {
this.carOrderList.forEach((items) => { item.goods_detail_pic = item.goods_detail_pic.split(',')
res.commodity_goods_info_list.forEach((item) => { item.goods_carousel = item.goods_carousel.split(',')
if (items.goods_id == item.id) { item.commodity_pic = item.commodity_pic.split(',')
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");
},
// //
getShopCar() { if (this.carOrderList) {
request(apiArr.getCarCount, "POST", {}).then((res) => { this.carOrderList.forEach(items => {
this.carNum = res.total; res.commodity_goods_info_list.forEach(item => {
this.prevCarNum = res.total; 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
getShopCarList() { })
request(apiArr.getCar, "POST", {}).then((res) => { },
this.carOrderList = res.commodity_cart_list;
});
},
addCar() { copys(e) {
let that = this; uni.setClipboardData({
// data: e,
let goods_id_and_count = []; success: (res) => {
this.info.commodity_goods_info_list[this.currentGGIndex].cart_count = { uni.showToast({
count: 1, title: '复制成功',
}; icon: 'success',
this.info.commodity_goods_info_list.forEach((item) => { duration: 2000
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) { changeGG(item, index) {
// // this.currentGG = item
// this.info.commodity_goods_info_list[this.currentGGIndex].cart_count.count = newValue.value this.currentGGIndex = index
// // if (this.currentGG.cart_count) {
// this.carOrderList.forEach(item => { this.currentNum = this.currentGG.cart_count.count
// if (item.commodity_goods_info.id == this.info.commodity_goods_info_list[this.currentGGIndex].id) { } else {
// item.count = newValue.value this.currentGG.cart_count = { count: 0 }
// } }
// }) },
// // car() {
// let carNum = 0 NavgateTo('../shopCar/index')
// 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;
this.id = itemObj.id; //
}, getShopCar() {
onReachBottom() {}, request(apiArr.getCarCount, 'POST', {}).then(res => {
onShow() { this.carNum = res.total
this.getShopCarList(); this.prevCarNum = res.total
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", { getShopCarList() {
goods_id_and_count, request(apiArr.getCar, 'POST', {}).then(res => {
}); this.carOrderList = res.commodity_cart_list
return; })
}, },
};
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
},
}
</script> </script>
<style> <style>

View File

@ -90,8 +90,7 @@
<div class="Con"> <div class="Con">
<div class="Con_left"> <div class="Con_left">
<div <div
class="CateItem" class="CateItem" :class="item.id === currentLeftCateId ? 'CateItem_active' : ''"
: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)"
@ -149,19 +148,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)"> <div class="CateInfo_Item_left" @click="goods(items.id)">
<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)"> <div class="CateInfo_Item_right_Tit" @click="goods(items.id)">
{{ items.commodity_name }} {{ items.commodity_name }}
</div> </div>
<div <div
class="CateInfo_Item_right_subtit" class="CateInfo_Item_right_subtit"
@click="goods(items)" @click="goods(items.id)"
> >
{{ items.commodity_intro }} {{ items.commodity_intro }}
</div> </div>
@ -176,8 +175,8 @@
> >
<u-number-box <u-number-box
:min="0" :min="0"
v-model="items.commodity_goods_info_list[0].quantity" v-model="items.quantity"
@change="(value) => handleQuantityChange(value, items)" @change="(value) => handleQuantityChange(value,items)"
> >
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -186,11 +185,7 @@
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>
@ -231,7 +226,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)" @click="goods(items.id)"
> >
<div class="GGItem_Image"> <div class="GGItem_Image">
<image <image
@ -249,7 +244,7 @@
<u-number-box <u-number-box
v-model="ite.quantity" v-model="ite.quantity"
:min="0" :min="0"
@change="(value) => handleQuantityChange(value, ite)" @change="(value) => handleQuantityChange(value,ite)"
> >
<view slot="minus" class="minus"> <view slot="minus" class="minus">
<u-icon name="minus" size="20"></u-icon> <u-icon name="minus" size="20"></u-icon>
@ -361,7 +356,7 @@ export default {
], ],
rightTopActive: 0, rightTopActive: 0,
currentLeftCateId: null, currentLeftCateId: null,
topShow: false, topShow: false,
GGshow: false, GGshow: false,
@ -374,8 +369,6 @@ export default {
tagList: [], tagList: [],
carNum: "", carNum: "",
goodsDetail: [],
}; };
}, },
methods: { methods: {
@ -411,7 +404,7 @@ export default {
}, },
// //
goods(e) { goods(e) {
NavgateTo(`../goods/index?item=${JSON.stringify(e)}`); NavgateTo(`../goods/index?id=${e}`);
}, },
// //
@ -424,8 +417,7 @@ export default {
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 = this.leftCateList = res.commodity_category_list[0].level_two_category || [];
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;
@ -448,18 +440,10 @@ export default {
}).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)
}); });
}, },
@ -467,7 +451,6 @@ export default {
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;
}); });
}, },
@ -477,11 +460,8 @@ export default {
this.getGoodsList(); this.getGoodsList();
}, },
// //
handleQuantityChange(val, item) { handleQuantityChange(val,item) {
if ( if (item.commodity_goods_info_list.length) {
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;
@ -500,7 +480,8 @@ export default {
this.getShopCarList(); this.getShopCarList();
uni.showToast({ uni.showToast({
title: "操作成功!", title: "操作成功!",
success() {}, success() {
},
}); });
}); });
}, },
@ -514,7 +495,6 @@ export default {
}, },
onShow() { onShow() {
this.getShopCarList(); this.getShopCarList();
this.getGoodsList();
}, },
onReachBottom() { onReachBottom() {
if (this.flag) { if (this.flag) {

View File

@ -1,288 +1,244 @@
<template> <template>
<view> <view>
<div class="header"> <div class="header">
<div <div class="searchBox" :style="{ height: localHeight + 'px', paddingTop: top + 'px' }">
class="searchBox" <div class="searchBox_left" @click="back">
:style="{ height: localHeight + 'px', paddingTop: top + 'px' }" <u-icon name="arrow-left" size="20px" color="#000"></u-icon>
>
<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>
</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>
<div class="goodsItem_msg_right_subTit"> <div class="searchBox_mid">购物车({{ shopCarTotal }}) </div>
{{ item.commodity_goods_info.goods_intro }} <div class="searchBox_right">
<u-icon name="arrow-left" size="20px" color="#000"></u-icon>
</div> </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>
</div>
<div class="footer"> <div class="main">
<div class="footer_left"> <div class="deleteIcon" @click="deleteItem">
<div class="footer_all" @click="allChecked"> <u-icon name="trash" size="50rpx"></u-icon>
<image </div>
v-if="!isAllchecked"
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check1.png" <div class="goodsList">
> <div class="goodsItem" v-for="item, index in shopCarList" :key="item.id">
</image> <div class="goodsItem_left" @click="changeChecked(item, index)">
<image <image v-if="!item.checked" src="http://192.168.0.172:5500/7.15/shop_checked1.png"></image>
v-if="isAllchecked" <image v-if="item.checked" src="http://192.168.0.172:5500/7.15/shop_checked2.png"></image>
src="https://wechat-img-file.oss-cn-beijing.aliyuncs.com/property-img-file/com_check2.png" </div>
> <div class="goodsItem_right">
</image> <div class="goodsItem_msg">
全选 <div class="goodsItem_msg_img">
</div> <image :src="picUrl + item.commodity_goods_info.commodity_pic">
<div class="footer_total"> </image>
<span>合计</span> </div>
{{ shopMoney }} <div class="goodsItem_msg_right">
</div> <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> </div>
<div class="footer_right" @click="submitOrder">结算</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 { apiArr } from "../../../api/shop"; import {
import { picUrl, menuButtonInfo, request, NavgateTo } from "../../../utils"; apiArr
} from '../../../api/shop';
import {
picUrl,
menuButtonInfo,
request,
NavgateTo
} from '../../../utils';
export default { export default {
data() { data() {
return { return {
picUrl, picUrl,
top: "", top: "",
localHeight: "", localHeight: "",
value: 3, value: 3,
type: "error", type: "error",
shopCarList: [], shopCarList: [],
shopCarTotal: 0, shopCarTotal: 0,
shopMoney: 0, shopMoney: 0,
isAllchecked: false, 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: {
getShopCar() { back() {
request(apiArr.getCar, "POST", {}).then((res) => { NavgateTo("1")
res.commodity_cart_list.forEach((item) => { },
item.checked = false; submitOrder() {
});
this.shopCarTotal = res.total; let arr = []
this.shopCarList = res.commodity_cart_list; this.shopCarList.forEach(item => {
}); if (item.checked) {
}, arr.push(item)
}
// })
changeChecked(item, index) {
this.shopCarList[index].checked = !this.shopCarList[index].checked; NavgateTo(`../submitOrder/index?shopCarList=${JSON.stringify(arr)}`)
this.calcTotal(); },
//
this.isAllchecked = this.shopCarList.every((item) => item.checked); getShopCar() {
}, request(apiArr.getCar, 'POST', {}).then(res => {
// res.commodity_cart_list.forEach(item => {
allChecked() { item.checked = false
this.isAllchecked = !this.isAllchecked; });
// Bug !this.allChecked !this.isAllchecked this.shopCarTotal = res.total
if (this.isAllchecked) { this.shopCarList = res.commodity_cart_list
this.shopCarList.forEach((item) => { })
item.checked = true; },
});
} else { //
this.shopCarList.forEach((item) => { changeChecked(item, index) {
item.checked = false; this.shopCarList[index].checked = !this.shopCarList[index].checked
}); this.calcTotal()
} //
this.calcTotal(); this.isAllchecked = this.shopCarList.every(item => item.checked)
}, },
// //
calcTotal() { allChecked() {
let total = 0; this.isAllchecked = !this.isAllchecked
this.shopCarList.forEach((item) => { // Bug !this.allChecked !this.isAllchecked
console.log(item); if (this.isAllchecked) {
this.shopCarList.forEach(item => {
if (item.checked) { item.checked = true
total += item.commodity_goods_info.sales_price * item.count; });
} } else {
}); this.shopCarList.forEach(item => {
this.shopMoney = total; item.checked = false
}, });
}
minus(item, index) { this.calcTotal()
let that = this; },
if (item.count === 1) { //
request(apiArr.deleteCar, "POST", { calcTotal() {
ids: [item.id],
}).then((res) => { let total = 0
that.shopCarList.splice(index, 1); this.shopCarList.forEach(item => {
that.calcTotal(); console.log(item);
});
} if (item.checked) {
this.shopCarList[index].count = this.shopCarList[index].count - 1; total += item.commodity_goods_info.sales_price * item.count
this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index]) }
this.calcTotal(); });
}, this.shopMoney = total
add(item, index) { },
this.shopCarList[index].count = this.shopCarList[index].count + 1;
this.handleQuantityChange(this.shopCarList[index].count , this.shopCarList[index]) minus(item, index) {
this.calcTotal(); let that = this
}, if (item.count === 1) {
request(apiArr.deleteCar, "POST", {
deleteItem() { ids: [item.id]
let that = this; }).then(res => {
uni.showModal({ that.shopCarList.splice(index, 1)
title: "提示", that.calcTotal()
content: "确定删除所选商品吗", })
success: function (res) { }
if (res.confirm) { this.shopCarList[index].count = this.shopCarList[index].count - 1
let ids = []; this.calcTotal()
that.shopCarList.forEach((item) => { },
if (item.checked) { add(item, index) {
ids.push(item.id); this.shopCarList[index].count = this.shopCarList[index].count + 1
item.checked = false; this.calcTotal()
} },
});
request(apiArr.deleteCar, "POST", {
ids, deleteItem() {
}) let that = this
.then((res) => { uni.showModal({
uni.showToast({ title: '提示',
title: "删除成功", content: '确定删除所选商品吗',
duration: 2000, success: function (res) {
}); if (res.confirm) {
that.getShopCar(); let ids = []
that.calcTotal(); that.shopCarList.forEach(item => {
}) if (item.checked) {
.catch((err) => { ids.push(item.id)
console.log(err); item.checked = false
}); }
} else if (res.cancel) { })
console.log("用户点击取消"); 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) {
handleQuantityChange(val, item) { const meun = menuButtonInfo();
const params = { this.top = meun.top;
user_id: uni.getStorageSync("userId"), this.localHeight = meun.height;
goods_id_and_count: [ this.getShopCar()
{
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> </script>
<style> <style>