<template>
	<view class="content">
		<view class="box-1">
			<view class="box-left">
				商品分类
				<text class="imp">*</text>
				：
			</view>
			<view class="list-input" v-if="choose.length == 0" @click="open()">
				请选择商品分类
			</view>
			<view class="list-input clamp" v-if="choose.length != 0" @click="open()">
				<text v-for="(item,index) in choose">{{item.label}}</text>
			</view>
		</view>
		<uni-popup ref="choose" type="bottom">
			<view class="choose-main">
				<view class="choose-top flex">
					<view class="choose-font" @click="close()">
						取消
					</view>
					<view class="choose-qd" @click="qd()">
						确定
					</view>
				</view>
				<scroll-view scroll-y="true" style="height: 600rpx;">
					<view class="choose-item flex" v-for="(item,index) in classlist" @click="xuanzhe(item)"
						:key="item.value">
						<view class="choose-item-left" :class="{ current: item.disabled == 0 }">
							{{item.label}}
						</view>
						<view class="choose-item-right" v-if="item.disabled == 1">
							<image v-if="item.xuan == 1" src="../../../static/icon/dians.png" mode=""></image>
							<image v-if="item.xuan != 1" src="../../../static/icon/dian.png" mode=""></image>
						</view>
					</view>
				</scroll-view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		name: 'classify',
		props: {
			//分类选项
			list: {
				type: Array,
				default: []
			},
			// 选择分类
			choose: {
				type: Array,
				default: []
			}
		},
		data() {
			return {
				classlist: []
			};
		},
		mounted() {
			this.loadData()
		},
		onReachBottom() {},
		onReady() {},
		methods: {
			loadData() {
				const obj = this
				this.classlist = this.list
				this.classlist.forEach(e => {
					let j = 0
					for (var i = 0; i < this.choose.length; i++) {
						if (choose[i] == e.value) {
							j = 1
						}
					}
					obj.$set(e, 'xuan', j);
				})
				console.log(this.classlist, '654852');
			},
			open() {
				this.$refs.choose.open()
			},
			close() {
				this.$refs.choose.close()
			},
			xuanzhe(opt) {
				console.log(opt, '123456');
				const obj = this;
				if (opt.xuan == 1) {
					opt.xuan = 0;
					let index = obj.choose.indexOf(opt);
					obj.choose.splice(index, 1);
				} else {
					opt.xuan = 1;
					obj.choose.push(opt);
				}
			},
			qd() {
				this.$refs.choose.close()
				this.$emit('chooseClasswc', this.choose);
			}
		}
	};
</script>

<style lang="scss">
	page,
	.content {
		min-height: 100%;
		height: auto;
	}

	.box-1 {
		background: #ffffff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		width: 100%;
		padding-top: 20rpx;

		.box-left {
			padding-left: 2rpx;
			width: 50%;
			text-align: left;
			color: #000000;

			.imp {
				color: #e63931;
			}
		}

		.list-input {
			width: 50%;
			font-size: 28rpx;
			color: #959595;
			text-align: right;
			padding-right: 24rpx;
		}
	}

	.choose-main {
		background: #ffffff;

	}

	.choose-top {
		padding: 20rpx 40rpx 20rpx;
		font-size: 32rpx;

		.choose-font {
			color: #d4c7c2;
		}

		.choose-qd {
			color: #e63931;
		}
	}

	.choose-item {
		padding: 20rpx;

		.choose-item-left {
			font-size: 28rpx;
		}

		.current {
			color: #d4c7c2;
		}

		.choose-item-right {
			width: 40rpx;
			height: 40rpx;

			image {
				width: 100%;
				height: 100%;
			}
		}
	}
</style>