<template>
	<view>
		<view>
			<u-row style="padding: 10px;border-bottom: 1px solid #000000;">
				<u-col span="4">
					<view class="viewCent">
						<u-text text="日期" size="14"></u-text>
					</view>
				</u-col>
				<u-col span="6" v-if="type == 'sc'">
					<view class="viewCent">
						<u-text text="运行时间" size="14"></u-text>
					</view>
				</u-col>
				<u-col span="6" v-if="type == 'nh'">
					<view class="viewCent">
						<u-text text="电量消耗 (预估)" size="14"></u-text>
					</view>
				</u-col>
				<u-col span="2">
				</u-col>
			</u-row>
		</view>
		<view v-for="item in dataList">
			<u-row style="padding: 10px;border-bottom: 1px solid #aaaaaa;">
				<u-col span="4">
					<view class="viewCent">
						<u-text :text="item.createTimeVo" size="18"></u-text>
					</view>
				</u-col>
				<u-col span="6" v-if="">
					<view class="viewCent">
						<u-text v-if="item.isStat === 0 && type == 'sc'" :text="item.dosage" size="18"></u-text>
						<u-text v-if="item.isStat === 0 && type == 'nh'"
							:text="(parseFloat(item.remark) * nhBz).toFixed(2) +' kWh'" size="18"></u-text>
						<u-text v-if="item.isStat === 1" text="统计中" color="#1c81df" size="18"></u-text>
						<u-text v-if="item.isStat === 2" text="未使用" color="#ffaa00" size="18"></u-text>
					</view>
				</u-col>
				<u-col span="2" @click="toStatDayPage(item)">
					<view class="viewCent">
						<u-text text="日志" size="12" color="#26a495"></u-text>
					</view>
				</u-col>
			</u-row>
		</view>
		<u-popup :show="show" @close="close" @open="open">
			<view style="padding: 20px 20px 0 20px;">
				<view>
					<u-row style="padding: 10px;border-bottom: 1px solid #aaaaaa;">
						<u-col span="9">
							<view class="viewCent">
								<u-text text="时间" size="18"></u-text>
							</view>
						</u-col>
						<u-col span="3">
							<view class="viewCent">
								<u-text text="操作" size="18"></u-text>
							</view>
						</u-col>
					</u-row>
					<view v-if="logList.length === 0" style="text-align: center;margin-top: 40px;">
						暂无数据
					</view>
					<view>
						<u-list style="height:400px;">
							<u-list-item v-for="item in logList">
								<view>
									<u-row style="padding: 10px;border-bottom: 1px solid #aaaaaa;">
										<u-col span="9">
											<view class="viewCent">
												<u-text :text="item.createTime" size="16"></u-text>
											</view>
										</u-col>
										<u-col span="3">
											<view class="viewCent">
												<u-text v-if="item.useDescribe === '打开'" :text="item.useDescribe"
													color="#00cb62" size="18"></u-text>
												<u-text v-else color="#cf0000" :text="item.useDescribe" size="18">
												</u-text>
											</view>
										</u-col>
									</u-row>
								</view>
							</u-list-item>
						</u-list>
					</view>
				</view>
				<view style="text-align: center; margin-top: 20px;position: absolute;top: -10px;right: 15px;">
					<view @click="show = false;">
						<u-icon name="close" size="18"></u-icon>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				dataList: [],
				logList: [],
				type: '',
				nhBz: 0
			}
		},
		onLoad(option) {
			if (option && option.type) {
				console.log(option.type)
				this.type = option.type
			}
			this.nhBz = parseFloat(uni.getStorageSync('deviceInfo').energyConsumption)
			console.log(this.nhBz)
			this.getList()
		},
		methods: {
			async getList() {
				const {
					data: res
				} = await this.$httpRequest({
					url: '/api/control/statDayList?useNoId=' + uni.getStorageSync('deviceInfo').deviceUseNo +
						'&yearMonth=' + uni.getStorageSync('yearMonth'),
					method: 'get'
				});
				if (res.code === 200) {
					this.dataList = res.data
					console.log(this.dataList)
				} else {

				}
			},
			toStatDayPage(item) {
				this.show = true
				this.getLogList(item)
			},
			async getLogList(item) {
				this.logList = []
				const {
					data: res
				} = await this.$httpRequest({
					url: '/api/control/useLogList?useNoId=' + item.useNoId +
						'&date=' + item.createTime.substr(0, 10),
					method: 'get'
				});
				if (res.code === 200) {
					this.logList = res.data
					console.log(this.logList)
				} else {

				}
			},
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	}
</script>

<style scoped>
	.viewCent {
		margin: 0 auto;
	}
</style>