<template>
	<view>
		<view>
			<u-row style="padding: 10px;border-bottom: 1px solid #9c9c9c;">
				<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="type == 'sc'">
					<view class="viewCent">
						<u-text :text="item.dosage" size="18"></u-text>
					</view>
				</u-col>
				<u-col span="6" v-if="type == 'nh'">
					<view class="viewCent">
						<u-text :text="(parseFloat(item.remark) * nhBz).toFixed(2) +' kWh'" 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>
	</view>
</template>

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

				} else {

				}
			},
			toStatDayPage(item) {
				uni.setStorageSync('yearMonth', item.createTimeVo)
				this.$goto('statDay?type=' + this.type)
			}
		}
	}
</script>

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