<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 class="select-list">
				<uni-data-select
					v-model="selectValue"
					:localdata="range"
					:clear="false"
					@change="changeSelect"
				></uni-data-select>
			</view> -->
		</view>
		<view class="attr-item-right">
			<view class="attr-value item-line" v-show="charShow">
				<qiun-data-charts
					type="line"
					:opts="opts"
					:chartData="chartData"
					:canvas2d="true"
					:reshow="charShow"
					:canvasId="canvasId"
				/>
			</view>
			<view class="attr-value item-line" v-show="!charShow">
				<u-empty ></u-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import uniDataSelect from "../../uni-data-select/uni-data-select.vue"
	export default{
		name: 'iots-line',
		props:{
			// 选择值
			value: {
				type: [String,Number],
				default: 0
			},
			time: {
				type: [Number],
				default: 0
			},
			// 图标
			icon: {
				type: [String],
				default: 'icon-tubiao-zhexiantu'
			},
			name: {
				type: [String],
				default: ''
			},
			logShow:{
				type: [Boolean],
				default: true
			}
		},
		components:{
			uniDataSelect
		},
		data() {
		  return {
		    chartData: {},
				dataList:{
					categories:[],
					series:[{
						name:'',
						data:[]
					}]
				},
				selectValue:this.value,
				charShow: true,
				canvasId:this.$u.guid(32),
				opts: {
					color: ["#1890FF","#91CB74","#FAC858","#EE6666","#73C0DE","#3CA272","#FC8452","#9A60B4","#ea7ccc"],
					padding: [15,15,0,5],
					enableScroll: false,
					legend: {show:false},
					xAxis: {
						disableGrid: true,
						// format: "xAxisDemo2"
					},
					yAxis: {
						gridType: "dash",
						dashLength: 2,
						splitNumber:3,
						data:[{tofix:2,min:0}]
					},
					extra: {
						line: {
							type: "straight",
							width: 2,
							activeType: "hollow"
						}
					},
					update:true
				},
				range: [
          { value: 0, text: "近1小时" },
          { value: 1, text: "近1天" },
          { value: 2, text: "近1周" },
        ],
				
		  };
		},
		watch: {
		  value(newValue) {
				if(newValue!==null){
					// this.selectValue = newValue;
					this.getServerData();
				}
		  }
		},
		mounted() {
			// this.getServerData();
			this.canvasId=this.$u.guid(32);
		},
		methods:{
			getServerData() {
					// this.chartData = JSON.parse(this.dataList);
					this.dataList.categories.push(this.$u.timeFormat(this.time,'hh:MM:ss'));
					// this.dataList.categories.push(this.time);
					this.dataList.series[0].name = this.name;
					this.dataList.series[0].data.push(this.value)
					this.chartData = this.dataList;
					
			},
			// 点击步进器
			changeSelect(e) {
				console.log("e",e)
				this.$emit('input', e);
				this.$emit('change',e);
			},
			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;
			// }
			.select-list{
				margin-left: auto;
				width: 160rpx;
			}
		}
		.attr-item-right{
			// flex: 1;
			display: flex;
			// flex-wrap: wrap;
			align-items: center;
			justify-content: center;
			.attr-value{
				width: 100%;
				height: 600rpx;
				box-sizing: border-box;
				padding-top: 40rpx;
			}
		}
	}
</style>
