<template>
	<view>
		<view v-for="item in dataList" :key="item.id" class="content" :class="{'choosedColor': packageId===item.id}"
			@click="chooseGoods(item)">
			<u-icon size="60" class="icon" name="../../../static/icon/success.png" v-if="packageId===item.id"></u-icon>
			<view class="item">
				<span class="name">业主名称</span>
				<span class="value">{{item.baseConsignorVo.consignorName}}</span>
			</view>
			<view class="item">
				<span class="name">商品编号</span>
				<span class="value">{{ item.baseGoodsVo.goodNo }}</span>
			</view>
			<view class="item">
				<span class="name">商品名称</span>
				<span class="value">{{ item.baseGoodsVo.goodName }}</span>
			</view>
			<view class="item">
				<span class="name">生产厂家</span>
				<span class="value">{{ item.factory }}</span>
			</view>
			<view class="item">
				<span class="name">产地</span>
				<span class="value">{{ item.waster }}</span>
			</view>
			<view class="item">
				<span class="name">包装单位</span>
				<span class="value">{{ transUnit(item.unit) }}</span>
			</view>
			<view class="item">
				<span class="name">件装量</span>
				<span class="value">{{ item.packageQty }}</span>
			</view>
		</view>
		<view class="footer">
			<u-button type="primary" @click="confirmChoose" :disabled="isShowChoose">确定选择</u-button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				dataList: [],
				goodId: null,
				packageId: null, //包装id
				dicOptions: [],
				consignorName: "", //业主名称
				isShowChoose: true,
				packageQty: null, //件装量
			};
		},
		onLoad: function(option) {
			this.goodId = option.goodId;
			this.loadList();
			this.getDic(); //获取字典
		},
		methods: {
			loadList() {
				this.$u.api.recevie.queryBasPackageByGoodId({
					goodId: this.goodId
				}).then(res => {
					this.dataList = res.data;
				});
			},
			confirmChoose() {
				this.$u.route({
					url: 'pages/receive/receiveHomeWork/receiveHomeWork',
					type: 'navigateTo',
					params: {
						packageQty: this.packageQty,
						packageId: this.packageId
					}
				})
			},
			chooseGoods(item) {
				this.packageId = item.id;
				this.packageQty = item.packageQty;
				this.isShowChoose = false;
			},
			getDic() {
				this.$u.api.getByDicType().then(res => {
					this.dicOptions = res.data;
				});
			},
			transUnit(unit) {
				for (let dic in this.dicOptions) {
					if (this.dicOptions[dic].dictValue === unit) {
						return this.dicOptions[dic].dictLabel;
					}
				}
			}
		}
	}
</script>

<style lang="scss">
	.content {
		width: 90%;
		margin: 0 auto;
		border: 0.5px solid #797979;
		border-radius: 10rpx;
		margin-top: 20rpx;
		padding: 10rpx 20rpx;
		position: relative;

		.icon {
			position: absolute;
			top: 20rpx;
			right: 20rpx;
		}

		.item {
			display: flex;
			align-items: center;
			font-size: 28rpx;
			line-height: 60rpx;
		}

		.name {
			color: #555555;
			width: 130rpx;
			text-align: left;
		}

		.value {
			color: #666666;
			margin-left: 20rpx;
		}
	}

	.choosedColor {
		background-color: #f2f2f2;
	}

	.footer {
		width: 50%;
		margin: 0 auto;
		margin-top: 40rpx;
	}
</style>
