<template>
	<view>
		<view class="dataInfo">
			<view class="dataList" v-for="(item,index) in list" :key="index">
				<view class="info-upper">
					<!-- <checkbox-group 
						@change="checkClick(item)" 
						style="margin-right: 15rpx;"
						v-show="item.status == '0'"
					>
						<checkbox :checked="item.checked" />
					</checkbox-group> -->
					<view class="details">
						<view class="text">
							<text><span style="padding-right: 20rpx; color: #a6a6a6;">类型名称</span>{{item.typeName}}</text>
							<text><span style="padding-right: 20rpx; color: #a6a6a6;">规格型号</span>{{item.specificationType}}</text>
							<text><span style="padding-right: 20rpx; color: #a6a6a6;">待入库数量</span>{{item.checkNum}}</text>
							<text><span style="padding-right: 20rpx; color: #a6a6a6;">机具编号</span>{{item.maCode == null ? '无' : item.maCode}}</text>
						</view>
					</view>
				</view>
				<view class="lower-btns">
					<!-- <view
						style="background-color: #3888ff;"
					>
						<uni-icons style="color: #fff;" type="eye" size="36"></uni-icons>
						查看	
					</view> -->
					<!-- <view
						style="background-color: #1bd30b;"
						@click="openPopup"
					>
						<uni-icons style="color: #fff;" type="cart" size="36"></uni-icons>
						入库
					</view> -->
				</view>
			</view>
		</view>
		<!-- <button @click="delCart">删除</button> -->
		<!-- <view 
			class="buy"
		>
			<view class="checked">
				<checkbox-group @tap="checkAll">
					<checkbox :checked="allChecked" />
				</checkbox-group>
				<text>全选</text>
			</view>
			<view style="display: flex;">
				<view class="total" style="margin-right: 15rpx;">
					<view class="bill" @click="bindCode">
						<text>绑定</text>
					</view>
				</view>
				<view class="total">
					<view class="bill" @click="finishCart">
						<text>审核</text>
					</view>
				</view>
			</view>
			
		</view> -->
		<uni-popup
			ref="popup" 
			type="center"
			:mask-click="false"
		>
			<view class="popup">
				<view class="pop-top">
					<h4>入库</h4>
					<uni-icons 
						style="color: #AAAAAA; font-weight: bold;" 
						type="closeempty" 
						size="32"
						@click="closePopup"
					>
					</uni-icons>
				</view>
				<h5 style="width: 85%; margin: 2vh auto; font-weight: normal; text-align: center;">请选择入库方式</h5>
				<view class="select-area">
					<uni-data-checkbox 
						v-model="scanType" 
						:localdata="scanRange"
						@change="scanChange"
					></uni-data-checkbox>
				</view>
			</view>
		</uni-popup>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				taskId: '',
				allChecked: false,
				inputs: "",
				list: [
					
				],
				totalFine: '',
				totalGoods: [],
				scanType: '',
				scanRange: [
					{ text: '二维码', value: '1' },
					{ text: 'RFID', value: '2' }
				],
				subObj: '',
				codeList: []
			}
		},
		methods: {
			// 单个商品的选择
			checkClick(item) {
				item.checked = !item.checked
				if (!item.checked) {
					this.allChecked = false
				} else {
					// 判断每一个商品是否是被选择的状态
					const goods = this.list.every(item => {
						return item.checked === true
					})
					if (goods) {
						this.allChecked = true
					} else {
						this.allChecked = false
					}
				}
			},
			//全选、全不选
			checkAll() {
				this.allChecked = !this.allChecked
				console.log(this.list);
				if (this.allChecked) {
					this.list.map(item => {
						if (item.status == '0') {
							item.checked = true
						}
					})
				} else {
					this.list.map(item => {
						if (item.status == '0') {
							item.checked = false
						}
					})
				}
			},
			finishCart () {
				let that = this
				that.totalGoods = that.list.filter((item) => {
					return item.checked == true
				}).map((subItem) => {
					return {
						typeId: subItem['typeId'],
						maId: subItem['maId'],
						maCode: subItem['maCode'],
						inputNum: subItem['checkNum'],
						companyId: subItem['companyId']
					}
				})
				if (that.totalGoods.length == 0) {
					uni.showToast({
						icon: 'none',
						title: '未选中审核项！'
					})
				} else {
					uni.showModal({
						title: '新购明细审核',
						content: '是否确定审核通过？',
						confirmText: '通过',
						// cancelText: '驳回',
						success: (res) => {
							if (res.confirm) {
								// 通过
								that.subObj = {
									taskId: that.taskId,
									checkResult: '1',
									inputRecordList: that.totalGoods
								}
								console.log(that.subObj);
								that.subNewBuy(that.subObj)
							} /* else if (res.cancel) {
								// 驳回
								that.subObj = {
									taskId: that.taskId,
									checkResult: '2',
									inputRecordList: that.totalGoods
								}
								that.subNewBuy(that.subObj)
							} */
						}
					})
				}
			},
			bindCode () {
				let that = this
				that.codeList = that.list.filter(item => {
					return item.checked == true
				})
				if (that.codeList.length > 1 || that.codeList.length == 0) {
					uni.showToast({
						icon: 'none',
						title: '一次只可选择一种机具进行绑定！'
					})
				} else {
					console.log(that.codeList);
				}
			},
			openPopup () {
				this.$refs.popup.open()
			},
			closePopup () {
				this.$refs.popup.close()
			},
			scanChange (e) {
				let that = this
				console.log(e);
				if (e.detail.value == '1') {
					that.closePopup()
					that.scanType = ''
					uni.scanCode({
						success: (res) => {
							console.log(res);
							uni.navigateTo({
								url: `/pages/newInAfterScan/newInAfterScan?result=${res.result}`
							})
						}
					})
				} else {
					console.log('id');
				}
			},
			subNewBuy (obj) {
				let that = this
				that.$api.newInStore.subNewBuy(obj).then(res => {
					console.log(res);
					if (res.data.code == 200) {
						uni.showToast({
							icon: 'none',
							title: res.data.msg,
							success: () => {
								uni.navigateBack()
							}
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: res.data.msg
						})
					}
				}).catch(err => {
					console.log(err);
				})
			}
		},
		onLoad(params) {
			let that = this
			console.log(params.taskId);
			that.taskId = params.taskId
			// 初始化请求新购入库详情
			that.$api.newInStore.fetchNewBuyDetail({
				taskId: params.taskId
			}).then(res => {
				console.log(res);
				if (res.data.code == 200) {
					/* for (let i = 0; i < res.data.data.length; i++) {
						if (res.data.data[i].status == '0') {
							res.data.data[i].checked = false
						}
					} */
					that.list = res.data.data/* .filter(item => {
						return item.maCode != null
					}) */
				} else {
					uni.showToast({
						icon: 'none',
						title: res.data.msg
					})
				}
			}).catch(err => {
				console.log(err);
			})
		}
	}
</script>
 
 
<style lang="scss">
	body{
		box-sizing: border-box;
		padding-bottom: 25%;
	}
	
	/deep/uni-checkbox .uni-checkbox-input {
		border-radius: 50%;
	}
 
	/deep/uni-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
		border-color: #ddd;
		color: #fff !important;
		background-color: #2DCF8C !important;
	}
 
	/deep/uni-checkbox .uni-checkbox-input {
		border-color: #ddd;
	}
 
	/deep/uni-checkbox .uni-checkbox-input:hover {
		border-color: #ddd;
	}
 
	.search {
		padding-top: 20rpx;
	}
 
	.search .searchIput {
		background-color: #e6e6e6;
		width: 95%;
		margin: 0 auto;
		height: 72rpx;
		line-height: 72rpx;
		border-radius: 50rpx;
		padding: 0 32rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}
 
	.search .searchIput input {
		font-size: 26rpx;
		width: 100%;
		color: grey;
	}
 
	.search .searchIput image {
		width: 34rpx;
		height: 34rpx;
	}
 
 
 
	.dataInfo {
		width: 95%;
		margin: 0 auto;
	}
	
	
 
	.dataInfo .dataList {
		display: flex;
		flex-direction: column;
		align-items: center;
		border-bottom: 2px solid #F1F1F1;
		padding: 10rpx 0;
	}
	
	.info-upper{
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.lower-btns{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
	}
	
	.lower-btns>view{
		box-sizing: border-box;
		padding: 10rpx 20rpx;
		border-radius: 15rpx;
		color: #fff;
		font-size: 14px;
		margin-right: 15rpx;
	}
 
	.dataInfo .dataList .details {
		display: flex;
		align-items: center;
		flex: 1;
		font-size: 0;
	}
 
	.dataInfo .dataList .details .img image {
		width: 200rpx;
		height: 140rpx;
		padding: 0 20rpx;
	}
 
	.dataInfo .dataList .details .text text {
		color: #000;
		font-size: 27rpx;
		display: block;
		padding: 10rpx 0;
	}
 
	.dataInfo .dataList .details .text  {
		color: red;
		font-size: 32rpx;
	}
 
	.dataInfo .dataList .action text {
		font-size: 25rpx;
		color: #000;
		border: 1px solid #C8C7CC;
		display: inline-block;
		line-height: 50rpx;
		width: 60rpx;
		text-align: center;
		box-sizing: border-box;
	}
 
	.dataInfo .dataList .action text:nth-child(2) {
		border-left: none;
		border-right: none;
	}
 
	.buy {
		display: flex;
		align-items: center;
		justify-content: space-between;
		position: fixed;
		left: 50%;
		bottom: 0;
		width: 95%;
		background-color: #fff;
		transform: translate(-50%, 0);
	}
 
	.buy .checked {
		display: flex;
		align-items: center;
	}
 
	.buy .checked text {
		font-size: 25rpx;
		color: #000;
		padding: 0 12rpx;
	}
 
	.buy .total {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}
 
	.buy .total .price {
		padding-right: 20rpx;
 
	}
 
	.buy .total .price text {
		font-size: 27rpx;
		color: #C8C7CC;
		display: inline-block;
	}
 
	.buy .total .price text:last-child {
		color: red;
		font-weight: bold;
	}
 
	.buy .total .bill text {
		font-size: 25rpx;
		color: #fff;
		display: inline-block;
		background-color: red;
		line-height: 70rpx;
		width: 150rpx;
		text-align: center;
	}
	
	.popup{
		width: 80vw;
		height: 20vh;
		background-color: #fff;
		border-radius: 15rpx;
		overflow: hidden;
		background: linear-gradient(#D9E7FE, #fff, #fff, #fff);
	}
	
	.popup>.pop-top{
		width: 100%;
		height: 5vh;
		box-sizing: border-box;
		padding: 0 25rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.popup>.select-area{
		width: 85%;
		margin: 40rpx auto;
		.uni-data-checklist .checklist-group[data-v-84d5d996]{
			justify-content: center;
		}
	}
</style>