<template>
	<view class="wrap">
		<page-nav :desc="desc" :title="title"></page-nav>
		<view class="container">
			<uni-list>
				<uni-list-item v-for="(item, index) in list" :key="index">
					<!-- 自定义 body -->
					<template v-slot:body>
						<view style="height: 200px;width: 100%;display: flex;flex-direction: column;">
							<view style="display: flex;flex-direction: row;width: 100%;justify-content: flex-start;">
								<view style="font-size: 18px;font-weight: bold;width: 88%;">问题编号:{{item.failureCheckNo}}
								</view>
								<view style="width: 10%;" @click="delRecord(item.failureCheckNo)">
									<uni-icons type="trash" size="30"></uni-icons>
								</view>
							</view>
							<view>
								<text
									style="margin-right: 10px;font-weight: bolder;">检查点位:</text><text>{{item.failureCheckPointDesc}}</text>
							</view>
							<view>
								<text style="margin-right: 10px;font-weight: bolder;">问题描述:</text>
								<view style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
									{{item.failureHiddenDangerDesc}}
								</view>
							</view>
							<view style="display: flex;flex-direction: row;min-height: 30px;">
								<view style="width: 200px;">{{item.createTime}}</view>
								<view style="color: #18B566;">{{item.createUserName}}</view>
							</view>
							<view style="margin-top: 5px;padding-left: 0px;padding-right: 0px;">
								<button type="default" @click="openPage(item.failureCheckNo)">编辑</button>
							</view>
						</view>
					</template>
				</uni-list-item>

			</uni-list>
		</view>

		<!-- 		<view class="list-wrap">
			<u-cell-item :titleStyle="{fontWeight: 500}" @click="openPage(item.failureCheckNo)"
				:title="item.failureCheckNo" v-for="(item, index) in list" :key="index">
				
			</u-cell-item>
		</view> -->
		<u-gap height="70"></u-gap>
	</view>
</template>

<script>
	import pageNav from '@/components/page-nav/page-nav.vue';
	import http from '@/http/api.js';
	export default {
		components: {
			pageNav
		},
		onLoad(option) {
			var reportList = [];
			var list = uni.getStorageSync('check_report_storage_index');
			if (list != null && list.length > 0) {
				list.forEach(itemKey => {
					var data = uni.getStorageSync('check_report_storage_' + itemKey);
					if (data != null) {
						reportList.push(data);
					}
				});
			}
			this.list = reportList;
		},
		data() {
			return {
				list: [],
				title: '缓存问题列表管理',
				desc: ''
			}
		},
		computed: {
			getIcon() {
				return path => {
					return 'https://cdn.uviewui.com/uview/example/' + path + '.png';
				}
			},
		},
		onShow() {
			uni.setNavigationBarTitle({
				title: ""
			});
			var reportList = [];
			var list = uni.getStorageSync('check_report_storage_index');
			if (list != null && list.length > 0) {
				list.forEach(itemKey => {
					var data = uni.getStorageSync('check_report_storage_' + itemKey);
					if (data != null) {
						reportList.push(data);
					}
				});
			}
			this.list = reportList;
		},
		created() {

		},
		methods: {
			openPage(checkNo) {
				uni.navigateTo({
					url: '/pages/checkReport/editCacheCheckReport?checkNo=' + checkNo
				})
			},
			delRecord(checkNo) {
				const that = this;
				uni.showModal({
					content: '确定删除记录？',
					showCancel: true,
					success(res) {
						if (res.confirm) {
							var reportList = [];
							var reportIndexList = [];
							var list = uni.getStorageSync('check_report_storage_index');
							if (list != null && list.length > 0) {
								list.forEach(itemKey => {
									if (checkNo !== itemKey) {
										var data = uni.getStorageSync('check_report_storage_' + itemKey);
										if (data != null) {
											reportList.push(data);
										}
										reportIndexList.push(itemKey);
									} else {
										uni.removeStorageSync('check_report_storage_' + itemKey);
										uni.removeStorageSync('check_report_storage_image_' + itemKey);
									}
								});
							}
							uni.setStorageSync('check_report_storage_index', reportIndexList);
							that.list = reportList;
						}
					}
				});
			}
		}
	}
</script>

<style>
	/* page {
		background-color: rgb(240, 242, 244);
	} */
</style>

<style lang="scss" scoped>
	.u-cell-icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 8rpx;
	}

	.slot-box {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		align-items: center;
	}

	.slot-image {
		/* #ifndef APP-NVUE */
		display: block;
		/* #endif */
		margin-right: 10px;
		width: 30px;
		height: 30px;
	}

	.slot-text {
		flex: 1;
		font-size: 14px;
		color: #4cd964;
		margin-right: 10px;
	}
</style>
