<template>
	<z-paging ref="paging" @query="queryList" v-model="dataList" :default-page-size="queryParams.pageSize"
		:auto-show-system-loading="true" empty-view-text="抱歉，暂时还没有相关数据！">
		<template #top>
			<custom-nav-bar :left="true" title="操作日志"></custom-nav-bar>
			<view class="search">
				<u-search v-model="queryParams.searchValue" @search="queryList" shape="square"/>
			</view>
		</template>
		<view class="card" v-for="item in dataList">
			<uni-collapse>
				<uni-collapse-item title-border="none" :border="false" :show-arrow="false" :open="true">
					<template v-slot:title>
						<view class="cards-title">
							<view>
								<view class="text">
									<view>出水口：{{ item.woName}}</view>
								</view>
							</view>
							<view class="title-r">
								<uni-tag v-hasPermi="['system:land:edit']" class="bg-green" :circle="true" text="发送成功" />
							</view>
						</view>
					</template>
					<view class="content">
						<view class="cards-content">
							<view class="txt-list" @click="openStepPop(item)">
								<view class="list1">
									<view><text>设备名称：</text>{{ item.operSubject}}</view>
									<view><text>执行内容：</text>{{ item.operContent}}</view>
									<view><text>操作人员：</text>{{ item.operUser}}</view>
									<view><text>操作时间：</text>{{ item.occurTime}}></view>
								</view>
								<view class="right">
									<view class="iconfont icon-you">
									</view>
								</view>
							</view>
						</view>
					</view>
				</uni-collapse-item>
			</uni-collapse>
		</view>
		<!-- 
				<view style="display: flex; align-items: center; justify-content: space-between;">
					<view style="margin-right: 5px;" v-hasPermi="['system:land:edit']">
						<u-button type="primary" plain plainFill>
							{{ item.operResult}}
						</u-button>
					</view>
				</view>
			 -->
	</z-paging>

	<!-- 图层弹出 -->
	<u-popup mode="center" :show="openPop" @close="openPop = false">
		<view class="popup-content" style="width: 70vw;" :style="`height:${this.stepList.length * 45}px`">
			<u-steps direction="column" :current="stepCurrent">
				<u-steps-item v-for="item in this.stepList" :title="item.title" :desc="item.description"></u-steps-item>
			</u-steps>
		</view>
	</u-popup>
</template>
<script>
	import * as userlog from "@/api/iotlog/userlog.js"

	export default {
		data() {
			return {
				dataList: [],
				queryParams: {
					pageNum: 1,
					pageSize: 20,
					logType: 1, //1:设备,2:系统
					landId: -1, //地块id
					operType: "control", //控制
					operSource: 1, //用户
					searchValue: "", //出水口，设备code
				},
				openPop: false,
				stepCurrent: 0,
				stepList: [],
			}
		},
		onLoad(par) {
			if (par.queryParams) {
				let queryParams = JSON.parse(par.queryParams);
				this.queryParams = Object.assign(this.queryParams, queryParams)
			} else {
				if (getApp().ijs.land) {
					this.queryParams.landId = getApp().ijs.land.id;
				}
			}
		},
		onShow() {},
		mounted() {},
		methods: {
			queryList(pageNo, pageSize) {
				this.queryParams.pageNum = pageNo;
				userlog.getlist(this.queryParams).then(res => {
					this.$refs.paging.completeByTotal(res.rows, res.total);
				});
			},
			async openStepPop(item) {
				let stepList = userlog.getSeqlistTemp();
				let stepCurrent = 0;
				this.stepList = [];
				userlog.getSeqlist({
					traceId: item.traceId
				}).then(response => {
					if (response.rows.length) {
						response.rows.forEach(item => {
							if (item.eventType > stepCurrent) {
								if (item.eventType == 9) {
									stepList.splice(stepCurrent, 0, {
										title: '中断',
										description: item.occurTime,
										status: 'success'
									});
								} else {
									stepCurrent = item.eventType;
									stepList[stepCurrent - 1].description = item.occurTime;
									stepList[stepCurrent - 1].status = 'success';

									if (item.eventType == 5 && stepList[3].status == "") {
										stepList[3].description = item.occurTime;
										stepList[3].status = 'success';
									}
								}
							}
						});
					}
					this.stepList = stepList;
					this.stepCurrent = stepCurrent;
					this.openPop = true;
				});
			},
			// 数据排序
			compareDataNew(file1) {
				return function(b, a) {
					if (b[file1] < a[file1]) {
						return -1;
					} else if (b[file1] > a[file1]) {
						return 1;
					}
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.popup-content{padding: 10px;}
	.u-search{padding: 10px;}
</style>