<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.id)">
									<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.checkUserName}}</view>
							</view>
							<view style="margin-top: 5px;padding-left: 0px;padding-right: 0px;">
								<button type="default" @click="openPage(item.id)">编辑</button>
							</view>
						</view>
					</template>
				</uni-list-item>

			</uni-list>
		</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) {
			this.loadList();
			const current = 1;
			const size = 1000;
			const isSubmit = '0';

			var reportList = [];
			http.request({
				url: '/blade-business/report/failure/queryPage',
				method: 'GET',
				params: {
					current,
					size,
					isSubmit
				}
			}).then(res => {
				console.log(res.data)
				if (res.data.records != null) {
					const listSize = res.data.records['length'];
					for (var i = 0; i < listSize; i++) {
						let report = res.data.records['' + i];
						reportList.push(report);
					}
				}

			}).catch(err => {
				console.log(err)
			})

			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: "问题管理"
			});
		},
		created() {

		},
		methods: {
			openPage(id) {
				const basePath = '/pages/checkReport/editCheckReport';
				const path = basePath + '?id=' + id;
				this.$u.route({
					url: path
				})

			},
			loadList() {
				const current = 1;
				const size = 1000;
				const isSubmit = '0';

				var reportList = [];
				http.request({
					url: '/blade-business/report/failure/queryPage',
					method: 'GET',
					params: {
						current,
						size,
						isSubmit
					}
				}).then(res => {
					if (res.data.records != null) {
						const listSize = res.data.records['length'];
						for (var i = 0; i < listSize; i++) {
							let report = res.data.records['' + i];
							reportList.push(report);
						}
					}

				}).catch(err => {
					console.log(err)
				})

				this.list = reportList;
			},
			delRecord(id) {
				const that = this;
				uni.showModal({
					content: '确定删除记录？',
					showCancel: true,
					success(res) {
						if (res.confirm) {
							var ids = id;

							http.request({
								url: '/blade-business/report/failure/remove',
								method: 'POST',
								params: {
									ids
								}
							}).then(res => {
								console.log(JSON.stringify(res.data))
								if (res.success) {
									uni.showModal({
										content: '删除已成功',
										showCancel: false,
										success(res) {
											if (res.confirm) {
												that.loadList();
											}
										}
									});
								}
							}).catch(err => {
								console.log(err)
							})
						}
					}
				});
			}
		}
	}
</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>
