215 lines
6.3 KiB
Plaintext
215 lines
6.3 KiB
Plaintext
<template>
|
|
<view>
|
|
<view>
|
|
<!-- 购物车列表数据 -->
|
|
<view class="w-710 pb-165 ml-20 pt-20">
|
|
<view v-if="shopList&&shopList[0]">
|
|
<view @tap="select(index,item.onindex)" v-for="(item,index) in shopList" :key="index"
|
|
class="rows rowsm mb-20 pt-50 pb-30 bgff br-20 pl-25 pr-25">
|
|
<image v-if="item.onindex!=1" src="/static/index/duih.png"
|
|
class="w-34 h-34 mr-26"></image>
|
|
<image v-else src="/static/index/xuanzedui.png"
|
|
class="w-34 h-34 mr-26"></image>
|
|
<image :src="URL + item.good_image" class="w-172 h-172 mr-18" />
|
|
<view class="rowsbl h-172">
|
|
<view class="fs-32 two_overflow">{{ item.good_name }}</view>
|
|
<view class="lh-50 rowsb w-400">
|
|
<view class="fs-34 fn-kt fw-600"><text class="fs-26">¥</text>{{ item.good_price }}
|
|
</view>
|
|
<lxc-count @handleCount="numChange" :index="index" :minValue="1" :min="1"
|
|
:value="item.num"></lxc-count>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view v-else class="tct pt-200">
|
|
<image class="w-60 h-60 mb-20" src="/static/top_gouwuche_moren.png"></image>
|
|
<view class="col999" v-if="islogin">购物车暂无内容</view>
|
|
<view class="col999" v-else>请先登录</view>
|
|
</view>
|
|
</view>
|
|
</view>
|
|
<view class="w-750 h-100 bgff fixed" style="bottom: 0;">
|
|
<view class="h-10 bgf1 w-750"></view>
|
|
<view class="rowsb rowsm pl-30 pr-10 pt-10 pb-13">
|
|
<view class="rows rowsm">
|
|
<image @tap="select('1',0)" v-if="!iconShow" src="/static/index/duih.png" class="w-34 h-34 mr-10"
|
|
style="vertical-align: middle;"></image>
|
|
<image @tap="select('1',1)" v-else src="/static/index/xuanzedui.png" class="w-34 h-34 mr-10"
|
|
style="vertical-align: middle;"></image>
|
|
<text class="fs-28 ml-10">全选</text>
|
|
</view>
|
|
<view class="rows rowsm">
|
|
<view class="fs-26 mr-20">
|
|
合计: <text class="fw-600 fn-kt fs-34 col_FF0000"><text
|
|
class="fs-23">¥</text>{{ totalSum }}</text>
|
|
</view>
|
|
<view @tap="ifOrder()" v-if="cartModel===0" class="w-220 lh-76 h-76 br-47 colfff tct bg">结算</view>
|
|
<view @tap="detTap()" v-else class="w-220 lh-76 h-76 br-47 colfff tct bg">删除商品</view>
|
|
</view>
|
|
</view>
|
|
|
|
|
|
</view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
const app = getApp().globalData
|
|
export default {
|
|
data() {
|
|
return {
|
|
addressId: null,
|
|
islogin: false,
|
|
shopList: [],
|
|
current: 0,
|
|
cartModel: 0, //购物车模式0,正常下单, 1是删除商品
|
|
}
|
|
},
|
|
onShow() {
|
|
let userInfo = uni.getStorageSync('userInfo')
|
|
let token = uni.getStorageSync('token')
|
|
if (userInfo && userInfo.id && token) { //判断是否登录
|
|
this.getUserCart()
|
|
this.islogin = true
|
|
} else {
|
|
// this.$tools.showtt('请先登录','error')
|
|
}
|
|
},
|
|
methods: {
|
|
tabChange(e) {
|
|
console.log(e, '11')
|
|
this.current = e
|
|
this.shopList = []
|
|
this.getUserCart()
|
|
},
|
|
setModel() {
|
|
this.cartModel = this.cartModel == 1 ? 0 : 1
|
|
},
|
|
ifOrder() { //判断是否满足提交订单条件
|
|
if (this.shopList && this.shopList[0]) { //判断购物车是否有数据
|
|
let arr = this.shopList.filter(val => val.onindex === 1)
|
|
if (arr.length !== 0) { //判断是否选择了数据
|
|
this.goConfirmOrder(arr)
|
|
} else this.$tools.showtt('请先选择商品')
|
|
} else this.$tools.showtt('购物车无商品')
|
|
|
|
},
|
|
goConfirmOrder(arr) { //确认订单
|
|
let sectelArr = []
|
|
arr.forEach(val => sectelArr.push(val.id))
|
|
app.cartList = arr
|
|
this.goNext(`/pages/index/pagesOne/goodsList/confirmOrderCart?type=${this.current+1}`)
|
|
},
|
|
//点击编辑字样
|
|
editTap() {
|
|
this.isedit = true
|
|
},
|
|
//点击完成字样
|
|
okTap() {
|
|
this.isedit = false
|
|
},
|
|
//点击删除
|
|
detTap() {
|
|
let arr = []
|
|
let detarr = []
|
|
arr = this.shopList.filter(val => val.onindex === 1)
|
|
detarr = this.shopList.filter(val => val.onindex !== 1)
|
|
let sectelArr = arr.map(val => val.id)
|
|
if (arr.length !== 0) {
|
|
this.$tools.axiosFromToken('POST', 'shop_cart/delCart', {
|
|
user_token: app.token,
|
|
ids: sectelArr.join(','),
|
|
}).then(res => {
|
|
this.shopList = detarr
|
|
this.cartModel = 0
|
|
this.$tools.showtt('删除成功', 'succec')
|
|
})
|
|
} else {
|
|
this.$tools.showtt('请选择商品,再进行操作')
|
|
}
|
|
|
|
},
|
|
numChange(val, index, type) {
|
|
this.shopList[index].num = val
|
|
this.getcartNumber(index, type)
|
|
},
|
|
//获取用户购物车
|
|
getUserCart() {
|
|
this.$tools.axiosFromToken('POST', 'shop_cart/getCartList', {
|
|
type: this.current + 1
|
|
}, '加载中').then(res => {
|
|
if (res.data && res.data[0]) {
|
|
res.data.forEach(val => {
|
|
val.onindex = 0
|
|
})
|
|
}
|
|
this.shopList = res.data
|
|
console.log(res)
|
|
})
|
|
},
|
|
//编辑商品购买数量
|
|
getcartNumber(index) {
|
|
this.$tools.axiosFromToken('POST', 'shop_cart/editCartNum', {
|
|
id: this.shopList[index].id,
|
|
count: this.shopList[index].num
|
|
})
|
|
},
|
|
select(index, type) { //选中
|
|
if (type == 0) {
|
|
if (index === '1') {
|
|
for (let i = 0; i < this.shopList.length; i++) {
|
|
this.shopList[i].onindex = 1
|
|
}
|
|
} else {
|
|
this.shopList[index].onindex = 1
|
|
}
|
|
} else {
|
|
if (index === '1') {
|
|
for (let i = 0; i < this.shopList.length; i++) {
|
|
this.shopList[i].onindex = 0
|
|
}
|
|
} else {
|
|
this.shopList[index].onindex = 0
|
|
}
|
|
}
|
|
|
|
}
|
|
},
|
|
computed: {
|
|
totalSum() { //计算总金额
|
|
if (this.shopList.length >= 1) {
|
|
let arr = this.shopList.filter(val => val.onindex === 1)
|
|
let totalToo = 0
|
|
for (let i = 0; i < arr.length; i++) {
|
|
totalToo += arr[i].num * arr[i].good_price
|
|
}
|
|
console.log('1111', totalToo)
|
|
return totalToo.toFixed(2)
|
|
} else {
|
|
return 0
|
|
}
|
|
},
|
|
iconShow() { //判断是否全选
|
|
if (this.shopList.length > 0) {
|
|
let arr = []
|
|
this.shopList.forEach(val => {
|
|
arr.push(val.onindex)
|
|
})
|
|
if (arr.every(value => value === 1)) {
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
} else return false
|
|
}
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
page {
|
|
background: #f7f6fa;
|
|
}
|
|
</style>
|