<template>
	<view class="iots-component-box">
		<view class="attr-item-left">
			<view class="iconfont" :class="icon"></view>
			<view class="attr-name">{{name}}</view>
			<view v-if="logShow" class="iconfont icon-unordered-list" @click="clickLog"></view>
		</view>
		<view class="attr-item-right">
			<view class="attr-value item-color-select" @click="changeColor()">
				<view class="color-box" :style="{background:value?value:'#f4f5f6'}">
					{{value?"":"选择颜色"}}
				</view>
				<view class="iconfont icon-xiangyou1"></view>
			</view>
		</view>
		<u-popup v-model="colorShow" :closeable="true" mode="bottom" border-radius="10" :safe-area-inset-bottom="true">
			<view class="">
				<view class="" style="display: flex;justify-content: center;align-items: center;height: 40rpx;margin: 24rpx 0;font-weight: bold;font-size: 34rpx;">
					选择颜色
				</view>
				<zebra-color-picker v-model="colors"></zebra-color-picker>
				<!-- <view style="padding: 0 10rpx;">
					<u-button type="primary" @click="selectColor">确认颜色</u-button>
				</view> -->
				<view class="btn-box"  @click="selectColor">
					<button>确认颜色</button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	/**
	 * 该组件依赖zebra-color-picker组件（https://ext.dcloud.net.cn/plugin?id=9905）需要引入uni——modules
	 * **/
	export default{
		name: 'iots-color-select',
		props:{
			// 选择值或默认值
			value: {
				type: [String, Number],
				default: ''
			},
			// 图标处理后
			icon: {
				type: [String],
				default: 'icon-gongnengdingyi'
			},
			name: {
				type: [String],
				default: ''
			},
			logShow:{
				type: [Boolean],
				default: true
			}
		},
		data(){
			return {
				colorShow: false,
				colors:{
					hex: '#7ED321'
				},
			}
		},
		methods:{
			changeColor() {
				this.colorShow = true;
			},
			selectColor() {
				this.$emit('input', this.colors.hex);
				this.$emit('change',this.colors);
				this.colorShow = false;
			},
      clickLog(){
        this.$emit('clickLog');
      }

		}
	}
</script>

<style lang="scss" scoped>
	@import '../common.css';
	.iots-component-box{
		padding: 20rpx 20rpx;
		background: #fff;
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-top: 20rpx;
		border-radius: 10rpx;
		// .attr-item-left{
		// 	display: flex;
		// 	align-items: center;
		// 	font-size: 28rpx;
		// 	color: #000;
		// 	.iconfont{
		// 		margin-right: 20rpx;
		// 		font-size: 40rpx;
		// 	}
		// }
		.attr-item-right{
			flex: 1;
			display: flex;
			flex-wrap: wrap;
			align-items: center;
			justify-content: flex-end;
			.attr-value{
				display: flex;
				align-items: center;
				justify-content: flex-end;
				flex: 1;
				&.item-color-select {
					display: flex;
					align-items: center;
					justify-content: flex-end;
					color: #ccc;
					.color-box{
						color: #606266;
						width: 120rpx;
						height: 120rpx;
						border-radius: 10rpx;
						font-size: 26rpx;
						display: flex;
						align-items: center;
						justify-content: center;
					}
					.iconfont{
						margin-left: 10rpx;
					}
				}
			}
		}
	}
	.btn-box{
		position: absolute;
		left: 0;
		right: 0;
		bottom: 0rpx;
		padding: 10rpx;
		text-align: center;
		background: #fff;
		z-index: 10076;
		button{
			height: 100rpx;
			line-height: 100rpx;
			background-color: $mainColor;
			color: #fff;
		}
	}
</style>
