You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

188 lines
5.2 KiB

<template>
<view class="wishlist_body">
<view class="status_bar"></view>
<uni-nav-bar left-icon="left" :rightText="isDelete?'Done':'Delete'" title="Wishlist" color="#000000" @clickLeft="back" @clickRight="clickRight()"/>
<view class="wishlist">
<view class="wishlist_item" v-for="(item,index) in goodsList" :key="index" >
<view class="wishlist_item_img"@click="isDelete?selectGoods(item.goods_id,index): goDetails(item.goods_id)">
<image :src="item.goods_img" mode="" class="wishlist_item_img_goods"></image>
<image src="../../static/img/select1.png" @click="deleteTap(item)" mode=" " class="select" v-if="isDelete && item.goods_id==goods_id || isAll"></image>
<image src="../../static/img/select.png" mode="" class="select" v-else-if="isDelete && item.goods_id!=goods_id"></image>
<!-- <image :src="Src" @click="deleteTap(item)" mode=" " v-model="item.goods_id" class="select" v-if="isDelete || item.goods_id==goods_id"></image> -->
</view>
<view class="wishlist_item_bottom">
<text>US${{item.promote_price?item.promote_price:item.shop_price}}</text>
<image src="../../static/img/delete1.png" mode="" class="wishlist_item_bottom_icon" @click="removeL(item)"></image>
</view>
</view>
</view>
<view class="wishlist_foot" v-show="isDelete">
<view class="wishlist_foot_left" @click="isAllTap()">
<image src="../../static/img/select2.png" mode="" v-if="!isAll"></image>
<image src="../../static/img/select1.png" mode="" v-else></image>
<text>All</text>
</view>
<view class="wishlist_foot_right">
<button :disabled="!isAll || !goods_id" @click="$refs.alertDialog.open()" :class="(isAll||goods_id)?'wishlist_foot_right_button':''">DELETE</button>
</view>
</view>
<uni-popup ref="alertDialog" type="dialog">
<uni-popup-dialog type="error" cancelText="Close" confirmText="Sure" title="Tips" content="Cancel the collection of this product?"
@confirm="removeLike()" ></uni-popup-dialog>
</uni-popup>
</view>
</template>
<script>
import {defaultRequest2} from '../../api/index.js'
export default {
data() {
return {
isDelete:false,
goodsList:[],
goods_id:'',
isAll:false,
Src:'../../static/img/select.png',
deletelist:[]
}
},
methods:{
selectGoods(id,index){
if(id==this.goods_id){
this.goods_id=''
}else{
this.goods_id=id
}
if(this.isAll ==true){
this.isDelete=true
}
let i = index
let list = ({
id:this.goodsList[i].goods_id,
index:i
})
console.log(list)
// let str = []
if(!this.deletelist.includes(list)){
this.deletelist.push(list)
console.log(this.deletelist)
}
else if(this.deletelist.includes(list)){
let i = this.deletelist.indexOf(list)
this.deletelist = this.deletelist.splice(i,1)
console.log(this.deletelist)
}
// this.$store.commit('addSave', list)
// if(this.$store.state.goodslist.includes(list)){
// const i = this.$store.state.goodslist.indexOf(list)
// this.$store.state.goodslist = this.$store.state.goodslist.splice(i,1)
// console.log(i)
// }
},
deleteTap(u){
this.goods_id = item.goods_id
// if(this.Src.includes('select.png')){
// this.Src = '../../static/img/select1.png'
// }else{
// this.Src = '../../static/img/select.png'
// }
},
isAllTap(){
this.goods_id = ''
this.isAll=!this.isAll
if(this.Src.includes('select.png')&&this.isAll==true){
this.Src = '../../static/img/select1.png'
}else{
this.Src = '../../static/img/select.png'
}
},
removeL(e){
console.log(e.goods_id)
let data={_action:'unsetfaviouritegoods',goods_id:e.goods_id}
defaultRequest2(data).then(res=>{
console.info(res)
if(res.error==0){
uni.showToast({
title:'ok!',
icon:'none'
})
this.getList()
}
})
},
goDetails(id){
uni.navigateTo({
url:"../productDetails/index?goodid="+id
})
},
getList(){
let data={_action:'getfaviouritegoods',page_index:1,page_size:30}
defaultRequest2(data).then(res=>{
console.info(res)
if(res.error==0){
this.goodsList=res.data
}
})
},
// 添加收藏
addLike(id){
let data={_action:'setfaviouritegoods',goods_id:id}
defaultRequest2(data).then(res=>{
console.info(res)
if(res.error==0){
uni.showToast({
title:res.message,
icon:'none'
})
}
})
},
// 取消收藏
removeLike(){
let data={_action:'unsetfaviouritegoods',goods_id:this.goods_id}
if(this.isAll)data.goods_id=0
defaultRequest2(data).then(res=>{
console.info(res)
if(res.error==0){
uni.showToast({
title:res.message,
icon:'none'
})
this.isAll = false
this.isDelete = false
this.getList()
}
})
},
back(){
uni.navigateBack()
},
clickRight(){
// this.isDelete=!this.isDelete
// this.isAll=false
if(this.goodsList){
this.isAll= false
this.isDelete=!this.isDelete
}
}
},
onLoad() {
this.getList()
}
}
</script>
<style lang="scss" scoped>
page{
}
.uni-navbar{
font-size: 32rpx;
font-weight: bold;
}
</style>