<template>
	<view class="my_duty">
		<uni-nav-bar @clickLeft="goBack()" height="110rpx" leftWidth="200rpx" leftText="我的代办" leftIcon="left" border
			backgroundColor="#2cade8" color="#fff" fixed statusBar shadow></uni-nav-bar>
		<view class="my-top-search-nav">
			<view class="search-wrap">
				<view class="search-body">
					<image class="left-img" src="../../../static/home/searchIcon.png" mode=""></image>
					<input class="search-input" type="text" v-model="search" placeholder="请输入" />
					<image class="right-img" src="../../../static/my/my_apply/zuofei.png" mode="" @click="resetSearch">
					</image>
					<view class="right-btn" @click="searchHandle">搜索</view>
				</view>
			</view>
		</view>
		<view class="empty-view"></view>
		<view class="content">
			<view class="item-wrap" v-for="(val,index) in ticketList" :key="val.id">
				<view class="duty-item">
					<view class="top-info">
						<view class="info-title">{{val.title}}</view>
					</view>
					<view class="center-info">
						<view class="info-details">所属工作流：{{val.workflow_.name}}</view>
						<view class="info-details">工单状态：{{val.state_.name}}</view>
						<view class="info-details">提交时间：{{val.create_time}} </view>
						<view class="info-details">更新时间：{{val.update_time}} </view>
					</view>
					<view class="bottom-btns">
						<view class="shenhezhong shenhe-status" @click="ticketHandle(val)">
							<image src="../../../static/my/my_apply/blue-time.png" mode=""></image>
							处理
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'ticket',
		data() {
			return {
				search: '',
				pageSize: 10,
				pageNum: 1,
				totalNum: 0,
				ticketList: [],
			}
		},
		//上拉加载
		onReachBottom() {
			const totalPage = Math.ceil(this.totalNum / this.pageSize);
			if (this.pageNum < totalPage) {
				this.pageNum += 1;
				this._getMyApplyList(false);
			} else {
				uni.showToast({
					title: "已全部加载",
					icon: 'none'
				})
			}
		},
		onShow() {
			this.ticketList = [];
			this.getTicketLists();
		},
		//下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1;
			this.ticketList = [];
			this.getTicketLists();
		},
		methods: {
			getTicketLists() {
				let that = this;
				let obj = {};
				obj.category = 'all';
				obj.pageNum = this.pageNum;
				obj.pageSize = this.pageSize;
				if (that.search !== '') {
					obj.search = that.search;
				}
				obj.pageSize = this.pageSize;
				that.$u.api.getTickets(obj).then(res => {
					that.ticketList = that.ticketList.concat(res.results);
					this.totalNum = res.count;
				})
			},
			ticketHandle(val) {
				let projectId = val.ticket_data.opl;//项目、许可证Id
				let catetype = val.workflow_.key;
				const params = `?ticketId=${val.id}&projectId=${projectId}&cateType=${catetype}&type='handle'`;
				uni.navigateTo({
					url: '../detail/ticketHandle' + params,
				})
			},
			
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			searchHandle() {
				this.pageNum = 1;
				this.ticketList = [];
				this.getTicketLists()
			},
			resetSearch() {
				this.pageNum = 1;
				this.search = "";
				this.ticketList = [];
				this.getTicketLists();
			},
		}
	}
</script>

<style scoped>
	.empty-view {
		height: 120rpx;
	}

	>>>.uni-navbar__header,
	>>>.uni-status-bar {
		background-image: linear-gradient(254deg,
				#0ca7ee 0%,
				#005aff 100%,
				#2a8cff 100%,
				#54bdff 100%),
			linear-gradient(#e60012,
				#e60012);
	}

	.my_duty {
		background-color: #f3fbff;
	}

	.my_duty>>>.uni-navbar-btn-text text {
		font-size: 32rpx !important;
	}

	.content {
		padding: 14rpx;
	}

	.item-wrap {
		margin-bottom: 14rpx;
	}

	.duty-item {
		width: 720rpx;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin: 0 auto;
		padding: 24rpx 21rpx;
		box-sizing: border-box;
	}

	.info-title {
		font-family: PingFang-SC-Medium;
		font-size: 30rpx;
		line-height: 72rpx;
		color: #3d3d3d;
		flex: 1;
	}

	.right-time {
		font-size: 24rpx;
		line-height: 72rpx;
		color: #ababab;
	}

	.center-info {
		padding-bottom: 30rpx;
		border-bottom: 1rpx solid #eeeeee;
	}

	.info-details {
		font-size: 28rpx;
		line-height: 40rpx;
		color: #5b5b5b;
	}

	.bottom-btns {
		text-align: center;
		font-family: PingFang-SC-Medium;
		font-size: 28rpx;
		line-height: 83rpx;
	}

	.shenhezhong {
		color: #2c6fd9;
	}

	.shenhe-status image {
		width: 26rpx;
		height: 26rpx;
		margin-right: 10rpx;
		vertical-align: middle;
	}

	.my-top-search-nav {
		position: fixed;
		left: 0;
		right: 0;
		z-index: 999;
	}

	.search-wrap {
		background-blend-mode: normal,
			normal;
		padding-bottom: 44rpx;
		padding-top: 20rpx;
	}

	.search-body {
		width: 715rpx;
		height: 78rpx;
		background-color: #ffffff;
		border-radius: 39rpx;
		margin: 0 auto;
		padding: 13rpx;
		padding-left: 25rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
	}

	.search-body .search-input {
		height: 100%;
		flex: 1;
		padding-left: 12rpx;
		box-sizing: border-box;
	}

	.left-img {
		width: 26rpx;
		height: 26rpx;

	}

	.right-img {
		width: 30rpx;
		height: 30rpx;
		margin-right: 10rpx;
	}

	.right-btn {
		width: 110rpx;
		height: 58rpx;
		line-height: 58rpx;
		background-image: linear-gradient(0deg,
				#2da0f3 0%,
				#54bcff 100%);
		border-radius: 29rpx;
		font-size: 28rpx;
		color: #ffffff;
		text-align: center;
	}
</style>
