<template>
	<view>
		<view style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);margin-bottom: 20rpx">
			<u-tabs :list="list" :is-scroll="false" :current="current" @change="changetwo"></u-tabs>
		</view>
		<view v-for="(item,index) in dataList" :key="index"
			style="box-shadow: 0px 0px 8px 0px rgba(165, 189, 251, 0.4);width: 96%;border-top-right-radius: 10rpx;margin: 10rpx auto;padding-top: 10rpx;">
			<span
				style="width: 10rpx;height: 40rpx;background-color: #2979ff;display: block;float: left;margin-top: 10rpx;"></span>
			<h4 style="width: 140rpx;border-radius: 200rpx;text-align: center;color: #2979ff;border: 2rpx solid #1785FF;float: right;margin-right: 10rpx;margin-top: 10rpx;">{{item.fInspectorName}}</h4>
			<view style="width: 90%;margin: 0 auto;margin: 0 auto;">
				<view
					style="display: flex;justify-content: space-between;height: 60rpx;line-height: 60rpx;border-bottom: 1rpx solid #eff4ff;">
					<h4>{{item.fWarehouseName}}</h4>
				</view>
				<view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">计划日期</view>
						<view style="float: right;">{{item.fInspectionDatetime}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">最新巡查日期</view>
						<view style="float: right;">{{item.fUpdateTime}}</view>
					</view>
					<view style="width: 100%;height: 60rpx;line-height: 60rpx;">
						<view style="float: left;">备注</view>
						<view style="float: right;">{{item.fRemark}}</view>
					</view>
				</view>
				<view style="width: 100%;margin: 0 auto;height: 80rpx;margin: 0 auto;line-height: 80rpx;border-top: 1rpx solid #eff4ff;"
					@click="expenseDetails(item)">
					<view style="float: left;">
						<h3>立即巡检</h3>
					</view>
					<view style="float: right;">
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
		<u-calendar :closeable="false" v-model="show" mode="date" @change="change" :mask-close-able="false"></u-calendar>
		<u-action-sheet :list="warehouseList" @click="click" @close="close" :mask-close-able="false" v-model="warehouse"></u-action-sheet>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				status: 'loadmore',
				warehouseList:[],
				warehouse:false,
				loadText: {
					loadmore: uni.getStorageSync('deptName') == '外部用户'?'请切换选择仓库':'轻轻上拉',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				iconType: 'flower',
				dataList: [],
				list: [{
					name: '全部'
				}, {
					name: '仓库'
				}, {
					name: '计划日期'
				}, {
					name: '今日计划'
				}],
				form: {
					pageNum: 1,
					pageSize: 10,
					fInspectionDatetime: new Date().toLocaleDateString().replace(/\//g,"-")
				},
				current: 3,
				total: 0,
			}
		},
		created() {
			if(uni.getStorageSync('deptName') == '外部用户'){
				this.list = [{
					name: '选择仓库'
				}]
				delete this.form.fInspectionDatetime
			}else{
				this.query()
			}
			this.$u.get('/warehouse/check/selectTWarehouseListInCheck').then(res=>{
				console.log(res)
				for(let item in res.rows){
					this.warehouseList.push({
						text:res.rows[item].fName,
						fId:res.rows[item].fId
					})
				}
				console.log(this.warehouseList)
			})
		},
		onReachBottom() {
			this.status = 'loading'
			if (this.dataList.length < this.total) {
				this.form.pageNum++
				this.query()
			} else {
				this.status = 'nomore'
			}
		},
		methods: {
			close(){
				this.current = null
			},
			click(index){
				console.log(index)
				this.form.fWarehouseFid = this.warehouseList[index].fId
				this.dataList = []
				this.current = null
				this.query()
			},
			query() {
				// this.current = null
				if(uni.getStorageSync('deptName') == '外部用户'){
					this.$u.get('/warehouse/checkitems/appListByUser', this.form).then(res => {
						console.log(res)
						this.dataList = this.dataList.concat(res.rows)
						this.total = res.total
						if (res.total === 0) this.status = 'nomore'
					})
				}else{
					this.$u.get('/warehouse/checkitems/listByUser', this.form).then(res => {
						console.log(res)
						this.dataList = this.dataList.concat(res.rows)
						this.total = res.total
						if (res.total === 0) this.status = 'nomore'
					})
				}
			},
			change(e) {
				// console.log(e)
				this.current = null
				this.form.fInspectionDatetime = e.result
				this.dataList = []
				this.query()
			},
			changetwo(index) {
				console.log(index)
				if (index === 1) this.warehouse = true
				if (index === 2) this.show = true
				if (index === 3){
					this.form.fInspectionDatetime = new Date().toLocaleDateString().replace(/\//g,"-")
					this.dataList = []
					this.query()
				}
				if(uni.getStorageSync('deptName') == '外部用户'){
					this.warehouse = true
				}else{
					if (index === 0) {
						this.dataList = []
						this.form = {
							pageNum: 1,
							pageSize: 10
						}
						this.query()
					}
				}
				this.current = index;
			},
			expenseDetails(item) {
				this.$u.route('/pages/home/patrolInspection/patrolDetails', {
					form: JSON.stringify(item)
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.wrap {
		padding: 24rpx;
	}

	.item {
		padding: 24rpx 0;
		color: $u-content-color;
		font-size: 28rpx;
	}
</style>
