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.
184 lines
4.4 KiB
184 lines
4.4 KiB
1 year ago
|
<template>
|
||
|
<view class="page">
|
||
|
<ul class="list">
|
||
|
<li v-for="(item, i) in list">
|
||
|
<uni-data-checkbox v-if="item.check" class="check" multiple :value="[1]" :localdata="item.checkData" @change="e => checkChange(e, i)"></uni-data-checkbox>
|
||
|
<uni-data-checkbox v-else class="check" multiple v-model="item.check" :localdata="item.checkData" @change="e => checkChange(e, i)"></uni-data-checkbox>
|
||
|
<image class="icon" :src="$util.getIcon(item)" mode="widthFix"></image>
|
||
|
{{ item.productName }}
|
||
|
</li>
|
||
|
</ul>
|
||
|
<uni-load-more :status="status" />
|
||
|
|
||
|
<view class="btn-wrap">
|
||
|
<uni-data-checkbox class="check" multiple v-model="checkAll" :localdata="checkAllData" @change="allChange"></uni-data-checkbox>
|
||
|
<view class="btn" @click="submit">生成订单</view>
|
||
|
</view>
|
||
|
</view>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
import { shoppingCartList, delCart } from '@/apis/modules/product.js'
|
||
|
export default {
|
||
|
data() {
|
||
|
return {
|
||
|
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
|
||
|
status: 'more', // 上拉加载状态 more|loading|noMore
|
||
|
searchTimer: null,
|
||
|
list: [],
|
||
|
page: 1,
|
||
|
pageSize: 10,
|
||
|
check: [1],
|
||
|
noCheck: [],
|
||
|
checkData: [{
|
||
|
text: '',
|
||
|
value: 1
|
||
|
}],
|
||
|
checkAll: [],
|
||
|
checkAllData: [{
|
||
|
text: '全部',
|
||
|
value: 1
|
||
|
}],
|
||
|
checked: [], // 已经勾选的集合
|
||
|
}
|
||
|
},
|
||
|
// 下拉刷新
|
||
|
onPullDownRefresh() {
|
||
|
this.initList()
|
||
|
setTimeout(() => {
|
||
|
uni.stopPullDownRefresh()
|
||
|
}, 1500)
|
||
|
},
|
||
|
// 上拉加载
|
||
|
onReachBottom() {
|
||
|
if (this.reachBottom >= 0) {
|
||
|
this.reachBottom = 1
|
||
|
this.status = 'loading'
|
||
|
this.getList()
|
||
|
}
|
||
|
},
|
||
|
onShow() {
|
||
|
this.getList()
|
||
|
},
|
||
|
methods: {
|
||
|
// 购物车列表
|
||
|
getList() {
|
||
|
uni.showLoading({
|
||
|
title: '加载中'
|
||
|
})
|
||
|
shoppingCartList({
|
||
|
pageNum: this.page,
|
||
|
pageSize: this.pageSize,
|
||
|
}).then(({ data }) => {
|
||
|
const { records } = data
|
||
|
const all = this.checkAll.length // 是否勾选了全选
|
||
|
const pageChange = this.reachBottom > 0 // 是否是翻页
|
||
|
const { checked } = this // 已选数据
|
||
|
// 添加选择框字段
|
||
|
records.forEach(e => {
|
||
|
e.check = 0
|
||
|
e.checkData = [{
|
||
|
text: '',
|
||
|
value: 1
|
||
|
}]
|
||
|
})
|
||
|
|
||
|
// 未加载完所有数据,并且不是筛选,则拼接list,否则直接赋值
|
||
|
this.list = pageChange ? [...this.list, ...records] : records
|
||
|
this.page++ // 每次获取了数据后page+1
|
||
|
const noMore = this.list.length === data.total // 是否加载完所有数据
|
||
|
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
|
||
|
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
|
||
|
uni.hideLoading()
|
||
|
}).catch(e => {
|
||
|
uni.hideLoading()
|
||
|
})
|
||
|
},
|
||
|
initList() {
|
||
|
this.page = 1
|
||
|
this.reachBottom = 0
|
||
|
this.getList()
|
||
|
},
|
||
|
// 选择框回调
|
||
|
checkChange(e, i) {
|
||
|
const { checked } = this
|
||
|
const item = this.list[i]
|
||
|
const { id } = item
|
||
|
const include = checked.findIndex(e => e.id === id)
|
||
|
// 选中的情况下,该产品如果没有push到已选数组里,则push
|
||
|
if (e.detail.value.length) {
|
||
|
include === -1 && checked.push(item)
|
||
|
} else {
|
||
|
// 取消选中的情况下,如果已选数组里存在该产品,则移除
|
||
|
if (include !== -1) {
|
||
|
checked.splice(include, 1)
|
||
|
this.checkAll = []
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
// 全选
|
||
|
allChange(e) {
|
||
|
const isCheck = !!e.detail.value.length // 是否选中
|
||
|
const { list } = this
|
||
|
this.checked = isCheck ? list.map(e => e.id) : []
|
||
|
list.forEach(e => {
|
||
|
e.check = isCheck ? 1 : 0
|
||
|
})
|
||
|
},
|
||
|
// 确定
|
||
|
submit() {
|
||
|
const list = this.checked // 已选产品
|
||
|
if (list.length) {
|
||
|
|
||
|
} else {
|
||
|
this.$util.errMsg('请选择产品!')
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped lang="scss">
|
||
|
.page {
|
||
|
padding-bottom: 130rpx;
|
||
|
}
|
||
|
.list {
|
||
|
li {
|
||
|
display: flex;
|
||
|
align-items: center;
|
||
|
padding: 30rpx 24rpx;
|
||
|
margin: 16rpx 24rpx;
|
||
|
font-size: 30rpx;
|
||
|
color: #333;
|
||
|
background-color: #fff;
|
||
|
border-radius: 16rpx;
|
||
|
}
|
||
|
.icon {
|
||
|
width: 80rpx;
|
||
|
margin: 0 20rpx;
|
||
|
}
|
||
|
}
|
||
|
/deep/.check {
|
||
|
.checklist-box {
|
||
|
margin: 0 !important;
|
||
|
}
|
||
|
.checkbox__inner {
|
||
|
width: 40rpx !important;
|
||
|
height: 40rpx !important;
|
||
|
border-radius: 50% !important;
|
||
|
}
|
||
|
.checkbox__inner-icon {
|
||
|
top: 8rpx !important;
|
||
|
left: 14rpx !important;
|
||
|
}
|
||
|
}
|
||
|
.btn-wrap {
|
||
|
position: fixed;
|
||
|
justify-content: space-between;
|
||
|
.btn {
|
||
|
width: 340rpx;
|
||
|
margin-left: 27rpx;
|
||
|
}
|
||
|
}
|
||
|
</style>
|