<template>
	<view>
		<view>
			<uni-search-bar :radius="100" @confirm="search" @input="input" @cancel="cancel"></uni-search-bar>
		</view>
		<uni-list>
			<uni-list-item v-for="(item, index) in listData" :key="index" @click="goDetail(item.checkCode)" clickable>
				<view slot="body" class="slot-box">
					<view class="row">
						<view class="column-left">编号：</view>
						<view class="column-right section-title">{{item.checkCode}}</view>
					</view>
					<view class="row">
						<view class="column-left">工程名称：</view>
						<view class="column-right">{{item.projectName}}</view>
					</view>
					<view class="row">
						<view class="column-left">日期：</view>
						<view class="column-right">{{item.checkDateStr}}</view>
					</view>
					<view class="row" v-show="$util.getQuery('type')=='2'">
						<view class="column-left">检查类型：</view>
						<view class="column-right">{{item.inspectType}}</view>
					</view>
					<view class="row">
						<view class="column-left">状态：</view>
						<view class="column-right">{{item.statusName}}</view>
					</view>
				</view>
			</uni-list-item>
		</uni-list>
		<view style="bottom: 15px;right:10px;position: fixed;z-index: 50;">
			<router-link :to="'/pages/template/SafeQualityCheckAdd/SafeQualityCheckAdd?type='+$util.getQuery('type')" style="text-decoration: none;" :title="titleName+'添加'">
				<uni-icons type="plus-filled" size="80" color="#5678FE"></uni-icons>
			</router-link>
		</view>

		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
		<page-foot :isShow="true" :showIndex="4"></page-foot>
	</view>
</template>

<script>
	import {
		GetSafeQualityCheckDTOs
	} from "@/common/api/SafeQualityCheckApi.js";
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';

	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				listData: [],
				searchvalue: '',
				last_id: '',
				reload: false,
				status: 'more',
				titleName: '质量安全检查',


				contentText: {
					contentdown: '上拉加载更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				}
			};
		},
		onLoad() {
			console.info("当前登录状态:" + this.$store.state.isLogin);
			//console.info(this);
			this.$util.persistLogin(this);

		},
		onPullDownRefresh() {
			this.reload = true;
			this.last_id = '';

			this.getList();
		},
		onReachBottom() {
			this.status = 'more';
			this.getList();
		},
		created: function() {
			let type = this.$util.getQuery("type") - 0;
			if (type == 1) {
				this.titleName = '质量安全检查';
				uni.setNavigationBarTitle({
					title: '安全检查'
				});
			} else if (type == 2) {
				this.titleName = '材料检查';
				uni.setNavigationBarTitle({
					title: '材料检查'
				});
			} else {
				this.titleName = '质量安全检查';
				uni.setNavigationBarTitle({
					title: '质量检查'
				});
			}
			this.getList();
		},
		methods: {
			getList() {
				let that = this;
				let type = this.$util.getQuery("type") - 0;
				let search = this.searchvalue;

				GetSafeQualityCheckDTOs(type, search).then((res) => {
					console.info(res);
					that.listData = [];
					res.forEach(function(item, index, array) {
						that.$set(that.listData, index, item);
					});
					console.info(that.listData);
				});
			},
			goDetail: function(id) {
				console.info('检查godetail', id);
				uni.navigateTo({
					url: '/pages/template/GetSafeQualityCheckDTO/GetSafeQualityCheckDTO?type=' + this.$util.getQuery("type") +
						'&id=' + id
				});
			},
			search(res) { //回车搜索
				this.searchvalue = res.value; //赋值

				this.getList(); //调用搜索方法
			},
			input(res) {
				this.searchVal = res.value
			},
			cancel(res) {
				console.info('点击取消，输入值为：' + res.value);

			},

		}
	};
</script>

<style scoped lang="scss">
	.uni-list-item{
		border-bottom: $BgColorBlue;
	} 
	
</style>
