|
@@ -32,12 +32,12 @@
|
|
|
</sticky-header>
|
|
|
<productItem
|
|
|
v-for="(item, index) in list"
|
|
|
- :key="item.id"
|
|
|
+ :key="index"
|
|
|
:index="index"
|
|
|
:list="item"
|
|
|
@changeQty="changeQty"
|
|
|
@check="chooseItem"
|
|
|
- @remove="removeChoose">
|
|
|
+ @remove="removeCart">
|
|
|
</productItem>
|
|
|
<!-- loading -->
|
|
|
<view class="loading-bar" v-if="list.length==0 && status!='loading'">{{noDataText}}</view>
|
|
@@ -68,9 +68,9 @@
|
|
|
<text>¥{{totalAmount}}</text>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view class="cart-head-btton red" v-if="editFlag" @click="clearAll">
|
|
|
+ <!-- <view class="cart-head-btton red" v-if="editFlag" @click="clearAll">
|
|
|
<text>清空购物车</text>
|
|
|
- </view>
|
|
|
+ </view> -->
|
|
|
<view class="cart-footer-right-button">
|
|
|
<button class="btns" v-if="!editFlag" type="warn" size="mini" @click="settlement">去结算</button>
|
|
|
<button v-else class="btns" type="warn" plain size="mini" @click="batchRemove">删除</button>
|
|
@@ -89,6 +89,8 @@
|
|
|
mapMutations,
|
|
|
} from 'vuex'
|
|
|
import productItem from '@/pagesB/cart/productitem.vue'
|
|
|
+ import { getCartList, updateCart, deleteCart } from '@/api/cart.js'
|
|
|
+
|
|
|
export default {
|
|
|
components:{
|
|
|
productItem
|
|
@@ -99,11 +101,7 @@
|
|
|
this.screenWidth = uni.getSystemInfoSync().windowWidth
|
|
|
this.screenHeight = uni.getSystemInfoSync().windowHeight
|
|
|
this.safeAreaBottom = uni.getSystemInfoSync().safeAreaInsets.bottom
|
|
|
-
|
|
|
- this.cacheList = this.getCacheList()
|
|
|
- this.cacheList.forEach(key => {
|
|
|
- this.total += key.length // 总款数
|
|
|
- })
|
|
|
+ // 获取列表数据
|
|
|
this.pageInit()
|
|
|
},
|
|
|
data() {
|
|
@@ -116,14 +114,13 @@
|
|
|
},
|
|
|
// 查询条件
|
|
|
pageNo: 1,
|
|
|
- pageSize: 3,
|
|
|
+ pageSize: 5,
|
|
|
list: [],
|
|
|
total: 0,
|
|
|
totalAmount: 0,
|
|
|
totalNum: 0,
|
|
|
editFlag: false,
|
|
|
allChecked: false,
|
|
|
- cacheList: [],
|
|
|
screenWidth: 325,
|
|
|
screenHeight: 0,
|
|
|
statusBarHeight: 44,
|
|
@@ -140,11 +137,6 @@
|
|
|
goBack(){
|
|
|
uni.navigateBack()
|
|
|
},
|
|
|
- // 从缓存获取数据
|
|
|
- getCacheList(){
|
|
|
- const cacheList = this.$store.state.vuex_cartList.find(k => k.sn == '693459699332595712')
|
|
|
- return cacheList ? JSON.parse(JSON.stringify(cacheList.list)) : []
|
|
|
- },
|
|
|
pageInit(){
|
|
|
this.pageNo = 1
|
|
|
this.list = []
|
|
@@ -161,34 +153,22 @@
|
|
|
pageSize: this.pageSize,
|
|
|
queryWord: this.queryWord
|
|
|
}
|
|
|
- const storeShelf = this.$store.state.vuex_storeShelf
|
|
|
this.status = "loading"
|
|
|
- setTimeout(()=>{
|
|
|
- let list = this.cacheList.slice(this.list.length,this.pageNo*this.pageSize)||[]
|
|
|
+ getCartList(params).then(res => {
|
|
|
+ if (res.status == 200) {
|
|
|
+ const list = res.data.list
|
|
|
list.forEach(key => {
|
|
|
- key.forEach(s => {
|
|
|
- s.checked = this.allChecked
|
|
|
- })
|
|
|
+ key.checked = this.allChecked
|
|
|
})
|
|
|
- this.list = this.list.concat(list)
|
|
|
- this.status = this.total>=this.list.length ? "nomore" : 'loadmore'
|
|
|
+ _this.list.push(list)
|
|
|
+ _this.total = res.data.count || 0
|
|
|
+ } else {
|
|
|
+ _this.list = []
|
|
|
+ _this.total = 0
|
|
|
+ _this.noDataText = res.message
|
|
|
+ }
|
|
|
+ _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
|
|
|
})
|
|
|
- // promoTerminalListByPage(params).then(res => {
|
|
|
- // if (res.code == 200 || res.status == 204 || res.status == 200) {
|
|
|
- // const list = res.data.list
|
|
|
- // if(_this.pageNo>1){
|
|
|
- // _this.list = _this.list.concat(list)
|
|
|
- // }else{
|
|
|
- // _this.list = list
|
|
|
- // }
|
|
|
- // _this.total = res.data.count || 0
|
|
|
- // } else {
|
|
|
- // _this.list = []
|
|
|
- // _this.total = 0
|
|
|
- // _this.noDataText = res.message
|
|
|
- // }
|
|
|
- // _this.status = _this.total>=_this.list.length ? "nomore" : 'loadmore'
|
|
|
- // })
|
|
|
},
|
|
|
// scroll-view到底部加载更多
|
|
|
onreachBottom() {
|
|
@@ -199,25 +179,32 @@
|
|
|
this.status = "nomore"
|
|
|
}
|
|
|
},
|
|
|
- // 根据id查找
|
|
|
- getItemById(id){
|
|
|
- const a = this.list.findIndex(k => k.find(s=> s.id == id))
|
|
|
- const b = a>=0 ? this.list[a].findIndex(s=> s.id == id) : -1
|
|
|
+ // 根据cartSn查找
|
|
|
+ getItemById(cartSn){
|
|
|
+ const a = this.list.findIndex(k => k.find(s=> s.cartSn == cartSn))
|
|
|
+ const b = a>=0 ? this.list[a].findIndex(s=> s.cartSn == cartSn) : -1
|
|
|
return {p:a,s:b}
|
|
|
},
|
|
|
// 已选产品变更数量
|
|
|
- changeQty(val,id){
|
|
|
- const crow = this.getItemById(id)
|
|
|
- if(crow.p>=0&&crow.s>=0){
|
|
|
- this.list[crow.p][crow.s].qty = val
|
|
|
- this.list[crow.p].splice()
|
|
|
- // 合计
|
|
|
- this.getChooseHeji()
|
|
|
- }
|
|
|
+ changeQty(val,cartSn){
|
|
|
+ updateCart({
|
|
|
+ cartSn: cartSn,
|
|
|
+ qty: val
|
|
|
+ }).then(res => {
|
|
|
+ if(res.status == 200){
|
|
|
+ const crow = this.getItemById(cartSn)
|
|
|
+ if(crow.p>=0&&crow.s>=0){
|
|
|
+ this.list[crow.p][crow.s].qty = val
|
|
|
+ this.list[crow.p].splice()
|
|
|
+ // 合计
|
|
|
+ this.getChooseHeji()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
// 选择
|
|
|
- chooseItem(id){
|
|
|
- const crow = this.getItemById(id)
|
|
|
+ chooseItem(cartSn){
|
|
|
+ const crow = this.getItemById(cartSn)
|
|
|
if(crow.p>=0&&crow.s>=0){
|
|
|
this.list[crow.p][crow.s].checked = !this.list[crow.p][crow.s].checked
|
|
|
// 合计
|
|
@@ -248,15 +235,11 @@
|
|
|
confirmText: '确定',
|
|
|
success(res) {
|
|
|
if(res.confirm){
|
|
|
- // uni.showLoading({
|
|
|
- // title: '正在清空...',
|
|
|
- // mask: true
|
|
|
- // })
|
|
|
- _this.list = []
|
|
|
- _this.cacheList = []
|
|
|
- _this.allChecked = false
|
|
|
- _this.editFlag = false
|
|
|
- _this.getChooseHeji()
|
|
|
+ uni.showLoading({
|
|
|
+ title: '正在清空...',
|
|
|
+ mask: true
|
|
|
+ })
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
})
|
|
@@ -273,9 +256,9 @@
|
|
|
this.getChooseHeji()
|
|
|
},
|
|
|
//单个删除
|
|
|
- removeChoose(id,isBatch){
|
|
|
+ removeChoose(cartSn,isBatch){
|
|
|
// 删除项
|
|
|
- const crow = this.getItemById(id)
|
|
|
+ const crow = this.getItemById(cartSn)
|
|
|
if(crow.p>=0&&crow.s>=0){
|
|
|
this.list[crow.p].splice(crow.s, 1);
|
|
|
this.total = this.total - 1
|
|
@@ -301,24 +284,42 @@
|
|
|
confirmText: '确定',
|
|
|
success(res) {
|
|
|
if(res.confirm){
|
|
|
- // 如果是全选
|
|
|
- if(_this.allChecked){
|
|
|
- _this.list = []
|
|
|
- _this.cacheList = []
|
|
|
- _this.allChecked = false
|
|
|
- }else{
|
|
|
- _this.list.forEach(item => {
|
|
|
- item.filter(k=>k.checked).forEach(s=>{
|
|
|
- _this.removeChoose(s.id,true)
|
|
|
- })
|
|
|
+ const snList = []
|
|
|
+ _this.list.forEach(item => {
|
|
|
+ item.filter(k=>k.checked).forEach(s=>{
|
|
|
+ snList.push(s.cartSns)
|
|
|
})
|
|
|
- }
|
|
|
- // 合计
|
|
|
- _this.getChooseHeji()
|
|
|
+ })
|
|
|
+ // 删除购物车
|
|
|
+ this.removeCart(snList)
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
},
|
|
|
+ // 删除商品
|
|
|
+ removeCart(snList){
|
|
|
+ const _this = this
|
|
|
+ deleteCart({cartSns:snList}).then(ret => {
|
|
|
+ if(ret.status == 200){
|
|
|
+ uni.showToast({
|
|
|
+ title: '删除成功',
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ // 如果全选
|
|
|
+ if(_this.allChecked){
|
|
|
+ _this.list = []
|
|
|
+ _this.allChecked = false
|
|
|
+ }
|
|
|
+ snList.forEach(sn => {
|
|
|
+ _this.removeChoose(sn,snList.length>1)
|
|
|
+ })
|
|
|
+ // 合计
|
|
|
+ if(snList.length>1){
|
|
|
+ _this.getChooseHeji()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
// 去结算
|
|
|
settlement(){
|
|
|
if(this.totalAmount>0){
|