收藏功能

This commit is contained in:
jqtmviyu@gmail.com 2021-02-27 18:52:32 +08:00
parent 610af145d7
commit ea34fe93f5

View File

@ -14,7 +14,7 @@
<view class="iconfont icon-zhuanfa open_type_button_wrap"> <view class="iconfont icon-zhuanfa open_type_button_wrap">
<button class="open_type_button" open-type="share">分享按钮</button> <button class="open_type_button" open-type="share">分享按钮</button>
</view> </view>
<view class="iconfont icon-shoucang1"></view> <view class="iconfont icon-shoucang1" @tap="collectHandle" :class="isCollect?'icon-shoucang':'icon-shoucang1'"></view>
</view> </view>
<view class="title"> <view class="title">
{{goods_name}} {{goods_name}}
@ -40,7 +40,7 @@
<view class="iconfont icon-gouwuche"></view> <view class="iconfont icon-gouwuche"></view>
<text class="icon_btn_text">购物车</text> <text class="icon_btn_text">购物车</text>
</navigator> </navigator>
<view class="button">加入购物车</view> <view class="button" @tap="addToCartHandle">加入购物车</view>
<view class="button">立即购买</view> <view class="button">立即购买</view>
</view> </view>
@ -56,14 +56,19 @@ export default {
goods_name: "商品名称", goods_name: "商品名称",
goods_price: "0", goods_price: "0",
goods_introduce: "", goods_introduce: "",
isCollect: false
} }
}, },
onLoad( {goods_id} ){ onLoad( {goods_id} ){
console.log(goods_id) console.log(goods_id)
this.goods_id = goods_id this.goods_id = goods_id
this.getGoodsDetail() this.getGoodsDetail()
//
const collectList = uni.getStorageSync("collectList") || [];
this.isCollect = collectList.some((item) => item.goods_id === goods_id)
}, },
methods: { methods: {
//
async getGoodsDetail(){ async getGoodsDetail(){
const { pics, goods_name, goods_price, goods_introduce } = (await this.$u.api.getGoodsDetail({ goods_id: this.goods_id })).message const { pics, goods_name, goods_price, goods_introduce } = (await this.$u.api.getGoodsDetail({ goods_id: this.goods_id })).message
this.pics = pics this.pics = pics
@ -81,10 +86,46 @@ export default {
this.goods_introduce = htmlStr this.goods_introduce = htmlStr
} }
}, },
//
showBigImgHandle(current){ showBigImgHandle(current){
const urls = this.pics.map(item => item.pics_big) const urls = this.pics.map(item => item.pics_big)
uni.previewImage({ urls, current }) uni.previewImage({ urls, current })
//Array.<string> //Array.<string>
},
// .
collectHandle(){
const goodsObj = {
goods_id: this.goods_id,
goods_small_logo: this.goods_small_logo,
goods_price: this.goods_price,
goods_name: this.goods_name,
}
//
const collectList = uni.getStorageSync("collectList") || [];
const index = collectList.findIndex(
(item) => item.goods_id === this.goods_id
)
if(index === -1) {
// 便
collectList.push(goodsObj)
}else{
// 便
// splice()
// ,
//
collectList.splice(index, 1)
}
//
uni.setStorageSync("collectList", collectList)
//
this.isCollect = !this.isCollect
},
//
addToCartHandle(){
console.log('加入购物车')
} }
}, },
@ -106,6 +147,9 @@ export default {
} }
.info { .info {
padding: 20rpx 30rpx; padding: 20rpx 30rpx;
.icon-shoucang {
color: #fcaa23;
}
.info_head { .info_head {
display: flex; display: flex;
.price { .price {