<template>
	<view id="page">
		<view class="Width100 Box BorderBox">
			<view class="Content BorderBox Width100">
				<top-title :is-show-left="false" :title="'审批'" :rightWidth='120' class="custom_bg">
					<!-- <template slot="right">
            <image :src="$.imgSrc + '/mine/search.png'" @click="$.open('/pages/mine/setting')" mode="aspectFit" class="InlineBlock imgIcon"></image>
            <image :src="$.imgSrc + '/mine/plus.png'" mode="aspectFit" @click="$.open('/pages/mine/notice')" class="InlineBlock imgIcon"></image>
          </template> -->
				</top-title>
			</view>
			<view class="query-form" :class="approve==2?'query-form2':''">
				<view class="search-box">
					<u-search placeholder="请输入名称" v-model="searchValue" actionText="" :showAction="false"
						@search="handleSearch" @clear="handleSearch"></u-search>
				</view>
				<view class="tab">
					<view v-for="tabItem in tabList" :key="tabItem.active" :class="{
							'tab-item': true,
							'active': tabItem.active == approve
						}" @click="handleTabChange(tabItem.active)">
						<text>{{tabItem.name}}</text>
						<text class="number">{{tabItem.number}}</text>
					</view>
				</view>
				<dateSearch :startDate.sync="startDate" :endDate.sync="endDate" @handleSearch="handleSearch"
					v-if="approve == 2" />
				<!-- <view class="type-box" v-show="approve==2">
					<view v-for="item in tabTypeList" :key="item.active" :class="{
						'type-item': true,
						'type-active': classification == item.active
					}" @click="queryTypeChange(item.active)">
						{{item.name}}
					</view>
				</view> -->
			</view>
			<view class="Content MarginAuto BorderBox">
				<no-data v-if="isEmpty" />
				<view v-else class="List Width100 BorderBox">
					<view class="Unit FontBold BorderBox Width100 MarginT_30rpx BG_FFFFFF" v-for="item in list"
						:key='item.id' @click='handleClick(item)'>
						<!-- <image class="imgleft" :src="item.imgurl" mode="widthFix"></image> -->
						<view class="right">
							<view class="title">{{ item.name }}</view>
							<view class="type">
								<!-- <text v-if="tab === 1">排查</text>
								<text v-if="tab === 3">治理</text> -->
								<text>{{ item.enumname || '--' }}</text>
								<text v-show="approve!=2">{{ item.deadlineStatus || '--' }}</text>
							</view>
						</view>
						<!-- 	<view class="trapezoidal" v-if="item.deadlineType == 1&& approve == 1">
							超期
						</view>
						<view class="trapezoidal lin" v-if="item.deadlineType == 2&& approve == 1">
							临期
						</view> -->
					</view>
				</view>
				<u-loadmore :status="loadmorestatus" v-show="!isEmpty" />
			</view>
		</view>
		<Tabbar name="审批" v-if="tabbarShow"></Tabbar>
	</view>
</template>

<script>
	import NoData from "../../components/no-data.vue";
	import TopTitle from "../../components/top-title";
	import tabFun from '@/libs/function/tabbar.js'
	import Tabbar from "../../components/tabbar.vue";
	import dateSearch from "./date-search.vue";
	export default {
		// 组件
		components: {
			NoData,
			TopTitle,
			Tabbar,
			dateSearch
		},
		data() {
			return {
				// 公用的js
				list: [],
				isEmpty: false,
				isMore: true,
				pageNum: 1,
				pageSize: 10,
				searchValue: '',
				classification: '1',
				approve: '1',
				status: '60',
				startDate: '',
				endDate: '',
				tabbarShow: true,
				tabList: [{
						name: '待审批',
						active: '1',
						number: 0
					},
					{
						name: '已完成',
						active: '2',
						number: 0
					},
				],
				tabTypeList: [{
						name: '全部',
						active: '1'
					},
					{
						name: '人工上报',
						active: '2'
					},
					{
						name: '系统下发',
						active: '3'
					},
				],
				loadmorestatus: 'loading'
			}
		},
		// 页面加载
		onLoad(e) {
			// this.getList()
		},
		onShow() {
			const approve = uni.getStorageSync('MySPtabIndex')
			if (approve) {
				this.approve = Number(approve)
				uni.setStorageSync('MySPtabIndex', '')
			}
			uni.hideTabBar() //隐藏官方的tabBar
			this.pageNum = 1
			this.list = [];
			this.getList()

			// tabFun.tabbar()
			// this.tabbarShow = false
			// this.$nextTick(() => {
			// 	this.tabbarShow = true
			// })
		},
		// 计算属性
		computed: {},
		// 方法
		methods: {
			handleSearch() {
				this.pageNum = 1
				this.list = []
				this.getList()
			},
			queryTypeChange(tabKey) {
				if (this.classification != tabKey) {
					this.classification = tabKey
					this.pageNum = 1
					this.list = []
					this.getList()
				}
			},
			handleTabChange(tabKey) {
				if (this.approve != tabKey) {
					this.approve = tabKey
					this.pageNum = 1
					this.list = []
					this.getList()
				}
			},
			getQueryStr(query) {
				let myQuery = {
					...query
				}
				if (myQuery.approve == 2) {
					myQuery.startTime = this.startDate
					myQuery.endTime = this.endDate
				}
				return Object.entries(myQuery).reduce((str, keyValue, index, self) => {
					const [key, value] = keyValue
					str += `${key}=${value}${index !== self.length - 1 ? '&' : ''}`
					return str
				}, '')
			},
			getList() {
				const data = {
					nuserid: this.$.getData('token'),
					status: this.status
				}
				const queryStr = this.getQueryStr({
					pageNum: this.pageNum,
					pageSize: this.pageSize,
					search: this.searchValue,
					approve: this.approve,
				})
				this.loadmorestatus = 'loading'
				this.isMore = true
				this.$request.globalRequest(`/hiddenDanger/highDanger/getHigDangerDealt?${queryStr}`, data,
					'post').then((
					res) => {
					this.loadmorestatus = 'loadmore'
					uni.stopPullDownRefresh();
					this.$set(this.tabList[this.approve - 1], 'number', res.result.total)
					if (res.code === 200) {
						if (res.result.total === 0) {
							this.isEmpty = true;
						} else {
							this.isEmpty = false;
							this.list.push(...res.result.list)
						}
						if (this.list.length >= res.result.total) {
							this.loadmorestatus = 'nomore'
							this.isMore = false
						}
						console.log(res)
					} else {
						this.$.toast(res.message)
					}
				}).catch((err) => {
					this.loadmorestatus = 'nomore'
					uni.stopPullDownRefresh();
				})
				if (this.pageNum == 1) {
					this.$request.globalRequest(`/hiddenDanger/highDanger/getHigDangerDealt?${this.getQueryStr({
						pageNum: this.pageNum,
						pageSize: 1,
						search: this.searchValue,
						approve: this.approve == 1 ? 2 : 1,
					})}`, data, 'post').then(res => {
						this.$set(this.tabList[this.approve == 1 ? 1 : 0], 'number', res.result.total)
					})
				}

			},
			handleClick(row) {
				this.$.open("/pages/investigation/complete" + "?id=" + row.businessId + '&sectionId=' + row
					.sectionCode +
					'&operator=' + row.operator + '&deptId=' + row.handleDept + '&taskName=' + row.name +
					'&pcType' + row.pcType + '&sectionName=' + row.sectionName + '&sectionCode=' + row
					.sectionCode + '&sectionType=' + (row.ifCross || '1') + '&pageName=' + '审批' + '&approveStatus=' +
					row.status + '&isSP=' + this.approve);
			},
			// 跳转页面
			skipPage(even) {
				// this.$.open(even)
			},
		},
		onReady() {},
		// 页面卸载
		onUnload() {

		},
		// 触发下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1
			this.list = [];
			this.getList()
		},
		// 页面上拉触底事件的处理函数
		onReachBottom() {
			if (this.isMore) {
				this.pageNum++
				this.getList()
			}
		},
	}
</script>

<style>
</style>
<style lang="scss" scoped>
	page {
		background: #F6F8FA;
	}

	.imgIcon {
		width: 40rpx;
		height: 100%;
	}

	.imgIcon:nth-of-type(2) {
		margin-left: 40rpx;
	}

	.img {
		width: 40rpx;
		height: 40rpx;
		margin-left: 30rpx;
	}

	.trapezoidal {
		position: relative;
		display: inline-block;
		min-width: 2em;
		text-align: center;
		padding: 3rpx 20rpx 3rpx 18rpx;
	}

	.trapezoidal::before,
	.trapezoidal::after {
		content: '';
		position: absolute;
		top: 0;
		left: 0%;
		width: 100%;
		height: 100%;
		border-radius: 0rpx 0 0 0;
		background: #FF1111;
		z-index: -1;
		transform-origin: bottom;
		transform: skew(18deg);
		border: 0rpx solid #333;
		box-sizing: border-box;
	}

	.trapezoidal::after {
		left: auto;
		right: 0;
		transform: skew(-0deg);
		border-radius: 0 0rpx 0 0;
		background-color: #FF1111;
		border-left: 0 none;
	}

	.query-form {

		font-size: 16px;
		height: 91px;
		background: #ffffff;
		box-shadow: 3px 0px 10px #ccc;
		color: #666666;
		position: sticky;
		// top: var(--status-bar-height + 88rpx);
		top: calc(var(--status-bar-height) + 88rpx);
		z-index: 10;

		.tab {
			display: flex;
			align-items: center;
			justify-content: space-around;

			.tab-item {
				position: relative;
				height: 41px;
				line-height: 41px;
				padding: 0 30rpx 0 30rpx;
				border-bottom: 3px solid #fff;
				display: flex;
				align-items: center;

				&.active {
					color: rgb(60, 109, 195);
					border-color: rgb(60, 109, 195);
				}

				.number {
					font-weight: bold;
					font-size: 18px;
					margin-left: 10rpx;
				}
			}
		}

		.search-box {
			padding: 10px 10px 3px;
		}
	}

	.query-form2 {
		height: 146px;

		.date-content {
			display: flex;
			align-items: center;
			padding: 15px 10px;
			justify-content: space-between;

			.date-item {
				display: flex;
				align-items: center;

				&-label {
					margin-right: 10px;
				}

				&-value {
					width: 185rpx;
					text-align: right;
				}
			}
		}
	}


	.Box {
		padding-top: var(--status-bar-height);

		.Content {
			width: calc(100% - 48rpx);
			padding-bottom: 88rpx;
		}

		.Unit {
			padding: 24rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: relative;
			box-shadow: 1px 1px 3px #ccc;

			.trapezoidal {
				position: absolute;
				top: 0px;
				right: 0px;
				color: #ffffff;
				font-size: 14px;
				font-weight: normal;
				z-index: 1;
			}

			image {
				width: 140rpx;
			}

			.right {
				flex: 1;
				padding-left: 30rpx;

				.title {
					font-size: 16px;
				}

				.type {
					font-size: 14px;
					color: #666;
					font-weight: normal;

					text {
						margin-right: 20rpx;
					}
				}
			}
		}
	}
</style>