<template>
	<view class="warpper">
		<uni-nav-bar  :fixed="true" color="#ffffff" background-color="#ffffff" :status-bar="true">
			<view slot="left" class="left-title">购物车</view>
			<view slot="right" v-if="pageShow"  class="right-title" @tap="delTap">删除</view>
		</uni-nav-bar>
		<view class="" v-if="pageShow">
		<scroll-list ref="list" :option="option" @load="upCallback" @refresh="downCallback" style="background-color: #FFFFFF;">
			<view class="group-box" v-for="(item, index) in list" :key="index">
				<uGap></uGap>
				<view class="group-checkbox">
					<view class="checkbox">
						<checkbox-group @change="onCheck"><checkbox value="cb" :checked="checked" color="#000000" style="transform: scale(0.7)" /></checkbox-group>
					</view>
					<view class="">{{item.supplierName}}</view>
				</view>
				<view class="list-box" v-for="(subItem, subIndex) in item.carItemList" :key="subIndex">
					<view class="checkbox">
						<checkbox-group @change="onCheck"><checkbox value="cb" :checked="checked" color="#000000" style="transform: scale(0.7)" /></checkbox-group>
					</view>
					<view class="list-row">
						<image class="image" src="https://qncloud.oss-cn-shenzhen.aliyuncs.com/ztb_pic/testPic.jfif" mode=""></image>
						<view class="right">
							<view class="name">{{subItem.productName}}</view>
							<view class="measure">{{subItem.gramWeight}}g｜{{subItem.width}}*{{subItem.length}}</view>
							<view class="weight">预估重量：{{subItem.weight}}吨</view>
							<view class="price-row">
								<view class="value">¥{{subItem.price}}</view>
								<view class=""><qnInputNumber @change="change" /></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</scroll-list>
		<view class="footer-box">
			<view class="row">
				<view class="left">
					<view class="">
						<checkbox-group @change="onCheck"><checkbox value="cb" :checked="checked" color="#000000" style="transform: scale(0.7)"></checkbox></checkbox-group>
					</view>
					<view class=""><text class="check-text">全选</text></view>
				</view>
				<view class="right">
					<view class="">
						<text class="name">应付：</text>
						<text class="value">¥7200.00</text>
					</view>
					<view class="right-balance-btn">结算</view>
				</view>
			</view>
		</view>	
		</view>
		<uni-popup ref="popup" type="center" :mask-click="false">
			<view class="popup-box">
				<view class="tip-title">
					确定将当前纸品删除吗？
				</view>
				<view class="operation-row">
					<view class="cancel-text" @tap="cancelTap">
						取消
					</view>
					<view class="line">
						
					</view>
					<view class="confirm-text" @tap="confirmTap">
						确定
					</view>
				</view>
			</view>
			</uni-popup>
			<no-data v-if="!pageShow"></no-data>
	</view>
</template>

<script>
import uGap from '@/components/u-gap/u-gap.vue'
import qnFooter from '@/components/qn-footer/qn-footer.vue'
import { back, go2 } from '@/utils/hook.js'
import qnInputNumber from '@/components/qn-input-number/qn-input-number.vue'
import { getShoppingCarList, removeShoppingCar } from '@/apis/cartApi.js'
import noData from './no-data.vue'
export default {
	components: { uGap, qnInputNumber, qnFooter, noData },
	data() {
		return {
			pageShow: true,
			option: {
				size: 10,
				auto: true,
				// height: '90%',
				emptyText: '暂无数据~',
				background: '#F7F8FA',
				disabled: false
			},
			params: {
				userId : this.$store.state.userInfo.userId || null,
				
			},
			pagination: {
				pageNum: 0, // 初始会执行一次下拉加载
				pageSize: 10
			},
			checked: false,
			list: [],
		}
	},
	created() {
		let that = this
		uni.getSystemInfo({
			success: function(res) {
				console.log('状态栏的高', res.statusBarHeight)
				that.option.height = res.windowHeight * (750 / res.windowWidth) - 180
			}
		})
	},
	onLoad() {},
	methods: {
		getList() {
			return new Promise((resolve, reject) => {
				getShoppingCarList({ ...this.params, ...this.pagination })
					.then(res => {
						// console.log('购物车', res)
						if (res) {
							if(res.records.length == 0) {
								this.pageShow = false
								return
							}
							if (this.pagination.pageNum == 1) {
								this.list = res.records
							} else {
								this.list = this.list.concat(res.records)
							}
							// this.list = []
							// this.list = [...this.list, ...[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]
							resolve({ list: this.list, total: res.total })
						}
					})
					.catch(err => {
						reject(err)
					})
			})
		},
		downCallback() {
			this.pagination.pageNum = 1
			this.getList()
				.then(({ list, total }) => {
					this.$refs.list.refreshSuccess({ list, total })
				})
				.catch(() => {
					this.$refs.list.refreshFail()
				})
		},
		upCallback() {
			this.pagination.pageNum++
			this.getList()
				.then(({ list, total }) => {
					this.$refs.list.loadSuccess({ list, total })
				})
				.catch(() => {
					this.$refs.list.loadFail()
				})
		},
		delTap() {
			this.$refs.popup.open('center')
		},
		confirmTap() {
			this.$refs.popup.close()
		},
		cancelTap() {
			this.$refs.popup.close()
		},
		/**
		 * @param {Number} num
		 * 计数器返回值
		 */
		change(num) {}
	}
}
</script>

<style lang="scss">
.warpper {
	.left-title {
		font-size: 40rpx;
		color: #000000;
		letter-spacing: 0;
		font-weight: 500;
	}
	.right-title {
		font-size: 28rpx;
		color: #f5222d;
		text-align: right;
		font-weight: 500;
		float: right;
	}
	.group-box {
		// padding: 0rpx 32rpx;
		.group-checkbox {
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 88rpx;
			background: #ffffff;
			padding: 0rpx 32rpx;
		}
	}
	.checkbox {
		flex: 0 0 35rpx;
		margin-right: 20rpx;
	}
	.list-box {
		width: 100%;
		display: flex;
		flex-direction: row;
		align-items: center;
		border-top: 2rpx solid #d8d8d8;
		padding: 28rpx 32rpx 40rpx 32rpx;
		.list-row {
			flex: 1;
			display: flex;
			flex-direction: row;
			.image {
				flex: 0 0 180rpx;
				width: 180rpx;
				height: 180rpx;
				border-radius: 8px;
				margin-right: 16rpx;
			}
			.right {
				flex: 1;
				width: 100%;
			}
			.name {
				font-size: 34rpx;
				color: #333333;
				letter-spacing: 0;
				text-align: left;
				font-weight: 600;
				padding-top: 10rpx;
			}
			.measure {
				font-size: 24rpx;
				color: #333333;
				letter-spacing: 0;
				text-align: left;
				font-weight: 500;
				margin-top: 16rpx;
			}
			.weight {
				text-align: center;
				font-size: 24rpx;
				color: #888888;
				font-weight: 400;
				text-align: right;
				padding-top: 4rpx;
			}
			.price-row {
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: space-between;
				padding-top: 12rpx;
				.value {
					font-size: 30rpx;
					color: #f5222d;
					letter-spacing: 0;
					text-align: left;
					font-weight: 500;
				}
			}
		}
	}
	.footer-box {
		left: 0;
		right: 0;
		.check-text {
			font-size: 24rpx;
			color: #333333;
			letter-spacing: 0;
			text-align: center;
			font-weight: 400;
		}
		.row {
			display: flex;
			flex-direction: row;
			align-items: center;
			height: 96rpx;
			background: #ffffff;
			padding: 0rpx 32rpx;
			.left {
				flex: 0 0 200rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
			}
			.right {
				flex: 1;
				// width: 100%;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				.name {
					font-size: 28rpx;
					color: rgba(0, 0, 0, 0.85);
					text-align: right;
					font-weight: 400;
				}
				.value {
					font-size: 36rpx;
					color: #f5222d;
					letter-spacing: 0;
					text-align: left;
					font-weight: 500;
				}
			}
			.right-balance-btn {
				width: 201rpx;
				height: 76rpx;
				line-height: 76rpx;
				background: #007aff;
				border-radius: 38rpx;
				font-size: 32rpx;
				color: #ffffff;
				letter-spacing: 0;
				text-align: center;
				font-weight: 400;
			}
		}
	}
	.popup-box {
		width: 540rpx;
		height: 226rpx;
		background: #FFFFFF;
		border-radius: 14rpx;
		.tip-title {
			display: flex;
			flex-direction: row;
			justify-content: center;
			align-items: center;
			height: 126rpx;
			font-size: 32rpx;
			color: #333333;
			letter-spacing: 0;
			text-align: center;
			font-weight: 400;
		}
		.operation-row {
			display: flex;
			flex-direction: row;
			justify-content: space-around;
			align-items: center;
			height: 100rpx;
			background: #FFFFFF;
			border-top: 2rpx solid #DDDDDD;
			.cancel-text {
				flex-grow: 1;
				flex-shrink: 1;
				font-size: 36rpx;
				color: #000000;
				letter-spacing: 0;
				text-align: center;
				font-weight: 400;
			}
			.line {
				flex-grow: 0;
				flex-shrink: 0;
				width: 2rpx;
				height: 100rpx;
				border-left: 2rpx solid #DCDEE3;
			}
			.confirm-text{
				flex-grow: 1;
				flex-shrink: 1;
				font-size: 36rpx;
				color: #108EE9;
				letter-spacing: 0;
				text-align: center;
				font-weight: 400;
			}
		}
	}
}
</style>
