Compare commits

...

4 Commits

2 changed files with 432 additions and 10 deletions

View File

@ -0,0 +1,403 @@
<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>
<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="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>
<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="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_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>
</template>
<script>
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",//
currentGG: "", //
currentGGIndex: "", //index
carOrderList: [],
}
},
methods: {
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
},
//
share() {
this.boxshadow1 = true
},
//
getGoodsInfo() {
request(apiArr.getGoodsInfo, "POST", {
id: this.id
}).then(res => {
console.log(res);
this.info = 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(',')
});
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() {
request(apiArr.getCarCount, 'POST', {}).then(res => {
this.carNum = res.total
this.prevCarNum = res.total
})
},
//( id )
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);
goods_id_and_count.push({
goods_id: item.id,
count: 1
})
})
// 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.getGoodsInfo()
this.getShopCar()
this.getShopCarList()
},
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.count
})
})
request(apiArr.updateCar, "POST", {
goods_id_and_count
})
return
},
}
</script>
<style>
@import url("./index.css");
</style>

View File

@ -266,15 +266,31 @@ export default {
id: this.id id: this.id
}).then(res => { }).then(res => {
console.log(res); console.log(res);
this.info = 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) {
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.currentGG = res.commodity_goods_info_list[0]
this.currentGGIndex = 0 this.currentGGIndex = 0
}) })
}, },
@ -314,7 +330,7 @@ export default {
}) })
}, },
//( id )
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
@ -327,12 +343,14 @@ export default {
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 = { count: 1 }
this.info.commodity_goods_info_list.forEach(item => { this.info.commodity_goods_info_list.forEach(item => {
console.log(item); console.log(item.cart_count);
goods_id_and_count.push({ goods_id_and_count.push({
goods_id: item.id, goods_id: item.id,
count: 1 count: item.cart_count ? item.cart_count.count : 0
}) })
}) })
console.log(goods_id_and_count);
// update // update
request(apiArr.updateCar, "POST", { request(apiArr.updateCar, "POST", {
goods_id_and_count goods_id_and_count
@ -374,17 +392,18 @@ export default {
}, },
onShow() { onShow() {
this.getShopCarList()
this.getGoodsInfo() this.getGoodsInfo()
this.getShopCar() this.getShopCar()
this.getShopCarList()
}, },
onHide() {
//( id count 0 )
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.count count: item.cart_count ? item.cart_count.count : 0
}) })
}) })