<template>
	<view class="processWrapper ">
		<view style="height:98rpx"></view>
		<view class="ding">
			<scroll-view scroll-x class="bg-white nav text-center">
				<view class="cu-item" :class="index==TabCur?'text-blue cur':''" v-for="(item,index) in tabNav"
					:key="index" @tap="tabSelect" :data-id="index">
					<view v-if="TabCur==index&&!TabCur&&record_count" class="cu-tag badge">
						<block class="">{{record_count}} </block>
					</view>
					{{item}}
				</view>
			</scroll-view>
		</view>
		<block v-if="TabCur==0">
			<view class="processList">
				<view class="cu-list menu-avatar">

					<view class="cu-item" v-for="(item,index) in unporcessList" :key="index">
						<view class="cu-avatar lg">
							<image class="image-bg" src="/static/process-icon.png"/>
						</view>
						<view class="content">
							<view class="pro-title">
								<view class="cut">{{type==1?item.artificial_code:item.supervise_code}}</view>
							</view>
							<view class="pro-des  ">
								<view class="text-cut">
									{{item.content}}
								</view>
							</view>
							<view class="pro-date ">{{item.timestamp}}</view>
						</view>
						<view class="action" style="z-index:99">
							<view class="unProcess" @tap="goUnprocessDetail(item)">未处理</view>
						</view>
					</view>
					<view class=" text-center margin-top" v-if="record_count == 0">暂无数据...</view>
					<view v-show="isLoadMore&&record_count != 0&&this.page>1">
						<uni-load-more :status="loadStatus"></uni-load-more>
					</view>
				</view>
			</view>
		</block>

		<block v-if="TabCur==1">
			<view class="processList">
				<view class="cu-list menu-avatar ">
					<view class="cu-item" v-for="(item,index) in porcessedList" :key="index">
						<view class="cu-avatar lg">
							<image class="image-bg" src="/static/processed-icon.png"/>
						</view>
						<view class="content">
							<view class="pro-title">
								<view class="cut">{{type==1?item.artificial_code:item.supervise_code}}</view>
							</view>
							<view class="pro-des  ">
								<view class="text-cut">
									{{item.content}}
								</view>
							</view>
							<view class="pro-date ">{{item.timestamp}}</view>
						</view>
						<view class="action" style="z-index:99">
							<view class="processed" @tap="goProcessedDetail(item)">已处理</view>
						</view>	
					</view>
					<view class="text-center margin-top" v-if="record_count1 == 0">暂无数据...</view>
					<view v-show="isLoadMore&&record_count1 != 0&&this.page>1">
						<uni-load-more :status="loadStatus"></uni-load-more>
					</view>
				</view>
			</view>
		</block>

	</view>
</template>

<script>
	import json from '../../../data/json.js';
	export default {
		data() {
			return {
				unporcessList: [],
				porcessedList: [],
				type: 1,
				modalName: null,
				listTouchStart: 0,
				listTouchDirection: null,
				CustomBar: this.CustomBar,
				TabCur: 0,
				tabNav: ['未处理', '已处理'],
				record_count: '',
				record_count1: '',
				
				requestUrl:'',
				keyWords:'',
				
				
				page: 1,
				pageSize: 10,
				loadStatus: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore: false, //是否加载中
				bottomFlag:false


			};
		},
		
		onReachBottom() { //上拉触底函数
			if (!this.isLoadMore) { //此处判断，上锁，防止重复请求
				this.isLoadMore = true
				this.page += 1;
				
				this.getProcessData({
					"company_code": uni.getStorageSync('selectedCode'),
					"clzt":this.TabCur,
					"page": this.page,
					"pageSize": this.pageSize,
				}, this.TabCur);
				
				
				
			}
		},
		onBackPress(event) {
			uni.reLaunch({
				url: "/"
			})
			return true;
		},
		onLoad: function(option) {
			this.type=option.type;
			if(option.type==1){
				this.keyWords='人工督察单';
				uni.setNavigationBarTitle({
					title: "消防支队人工督察单",
				});
			}else{
				this.keyWords='电子督察单';
				uni.setNavigationBarTitle({
					title: "消防支队电子督察单",
				});
			}

			this.getProcessData({
				"company_code": uni.getStorageSync('selectedCode'),
				"clzt": 0,
				"page": this.page,
				"pageSize": this.pageSize,
			}, 0);


		},

		onNavigationBarButtonTap(e) {
			console.log(e)
			uni.navigateTo({
				url: '/pages/export/export?keywords='+this.keyWords,
				success: res => {},
				fail: () => {},
				complete: () => {}
			});
		},
		methods: {
			async getProcessData(params = {}, whichTab) {
				const res = await this.$myRequest({
					url: this.type==1?'FireInspector/getManualInspectorList':'FireInspector/getElectronicInspectorList',
					data: params,
					showLoading: true
				})
				// this.data_res = res.data.record_count ? 1 : 0
				if (res.data.record_count) {
					if (whichTab == 0) {
						this.unporcessList = this.unporcessList.concat(res.data.data)
						this.record_count = parseInt(res.data.record_count)
				
					} else {
						this.porcessedList = this.porcessedList.concat(res.data.data);
						this.record_count1 = parseInt(res.data.record_count)
					}
				
					if (res.data.data.length < this.pageSize) { //判断接口返回数据量小于请求数据量，则表示此为最后一页
						this.isLoadMore = true
						this.loadStatus = 'nomore'
					} else {
						this.isLoadMore = false
					}
				} else {
					this.isLoadMore = true
					this.loadStatus = 'nomore'
				}
			},

			tabSelect(e) {
				this.unporcessList = [],
					this.porcessedList = [],
					console.log(e.currentTarget);
				this.TabCur = e.currentTarget.dataset.id;
				this.scrollLeft = (e.currentTarget.dataset.id - 1) * 60;

				this.getProcessData({
					"company_code": uni.getStorageSync('selectedCode'),
					"clzt": e.currentTarget.dataset.id
				}, this.TabCur);
			},

			// 页面跳转
			goUnprocessDetail(item) {
				uni.navigateTo({
					url: '/pages/inspectList/processDetailEle/processDetailEle?id='+item.id+'&type='+this.type,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},

			goProcessedDetail(item) {
				uni.navigateTo({
					url: '/pages/inspectList/processDetailEle/processDetailEle?id='+item.id+'&type='+this.type,
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},




		
		}
	}
</script>

<style lang="scss">
	//已处理未处理消息个数样式
	.nav .cu-item.cur {
		position: relative;
		border-bottom: 8rpx solid;
	}

	.cu-tag.badge {
		top: 14rpx;
		right: 96rpx;
	}

	.nav .cu-item {
		width: 50%;
		margin: 0;

		.text-blue,
		.line-blue,
		.lines-blue {
			color: #4274E7
		}
	}
</style>
