<template>
	<view class="container" v-if="isShow">
		<view class="headerBox">
			<view class="searchBox">
				<icon class="icon-small searchIcon" type="search" size="14"></icon>
				<input type="text" data-code="code" v-model="CodeTitle" class="fway-form-input searchInput" placeholder="请输入编号或者标题搜索" />
				<text class="searchBtn" @tap="onTapSearch">搜索</text>
			</view>
			<view class="tabBox">
				<view class="tabItem" :class="tabIndex == '1' ? 'active' : ''" @tap="onChangeState('1')">全部</view>
				<view class="tabItem" :class="tabIndex == '2' ? 'active' : ''" @tap="onChangeState('2')">未回复</view>
				<view class="tabItem" :class="tabIndex == '3' ? 'active' : ''" @tap="onChangeState('3')">已回复</view>
				<view class="tabItem" :class="tabIndex == '4' ? 'active' : ''" @tap="onChangeState('4')">已评价</view>
			</view>
		</view>
		<view class="contentBox">
			<z-paging ref="paging" v-model="listData" @query="onGetOrderList" refresher-update-time-key="list">
				<view class="listInfoBox">
					<view class="listInfo" v-for="(item, index) in listData" :key="index" @tap="onOrderViewTo(item.id)">
						<view class='listCode'>
							<view class="codeTextBox">
								<text>编号：</text>
								<text class="codeText">{{item.orderNo}}</text>
								<text class="codeType" v-if="item.industryName">{{item.industryName}}</text>
							</view>
							<rich-text :nodes="item.statusText" class="codeStatus" :class="item.statusClass"></rich-text>
						</view>
						<rich-text :nodes="item.title" class="listTitle"></rich-text>
						<view class="listDetailBox">
							<text class="listArea">{{item.area}}</text>
							<text class="listDate">{{item.creationTime}}</text>
						</view>
					</view>
				</view>
			</z-paging>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow: false,
				tabIndex: '1',
				State: '',
				CodeTitle: '',
				listData: [],
				isReLoad: false,
			}
		},
		onLoad(options) {
			let that = this;
			if (options.tabIndex){
				that.tabIndex = options.tabIndex;
			}
			that.isShow = true;
		},
		methods: {
			onGetOrderList(pageNo, pageSize) {
				let that = this;
				switch(that.tabIndex) {
					case '1': 
						that.State = 0;
						break;
					case '2':
						that.State = 1;
						break;
					case '3':
						that.State = 2;
						break;
					case '4':
						that.State = 3;
						break;
					default: break;
				}
				that.$admin.req({
					method: 'GET',
					url: '/api/v1/Snapshot/order?KeyWords=' + that.CodeTitle + '&Status=' + that.State + '&QueryIndex=' + (pageNo - 1) + '&QueryCount=' + pageSize,
				}).then(res => {
					if (res && res.length > 0) {
						res.forEach((item, index) => {
							item.creationTime = that.$util.formatTime(new Date(item.creationTime));
							switch (item.statusText) {
								case '办理完成':
									item.statusClass = 'greenText';
									break;
								case '办理中':
									item.statusClass = 'redText';
									break;
								case '待受理':
									item.statusClass = 'yellowText';
									break;
								case '':
									item.statusClass = 'grayText';
									break;
								default:
									item.statusClass = 'blueText';
									break;
							}
						})
						that.$refs.paging.complete(res);
					} else if (res && res.length == 0) {
						that.$refs.paging.complete([]);
					} else {
						that.$util.msg('网络出错！');
						that.$refs.paging.complete(false);
					}
					typeof fun === 'function' && fun();
				}, err => {
					if (!that.isReLoad) {
						that.isReLoad = true;
						that.onGetOrderList(pageNo, pageSize);
					} else {
						that.$util.msg(err);
						that.$refs.paging.complete(false);
					}
				})
			},
			// 点击查询按钮
			onTapSearch() {
				let that = this;
				that.$refs.paging.reload();
			},
			// 切换工单状态
			onChangeState(tabIndex) {
				let that = this;
				if (that.tabIndex != tabIndex){
					that.tabIndex = tabIndex;
					that.$refs.paging.reload();
				}
			},
			onOrderViewTo(id) {
				uni.navigateTo({
					url: '/pagesBase/Order/View?type=mine&id=' + encodeURIComponent(id)
				})
			},
		}
	}
</script>

<style lang="less">
	.container {
		background-color: #F6F7F8;
	}

	.headerBox {
		line-height: 0;
		background-color: #fff;
	}

	.searchBox {
		padding: 20rpx;
		position: relative;
	}

	.searchIcon {
		position: absolute;
		top: 40rpx;
		left: 50rpx;
	}

	.searchInput {
		background-color: #F6F7F8;
		border-radius: 30rpx;
		padding: 10rpx 110rpx 10rpx 80rpx;
		width: calc(100% - 190rpx);
		height: 46rpx;
		line-height: 46rpx;
	}

	.searchBtn {
		position: absolute;
		line-height: 48rpx;
		top: 28rpx;
		right: 28rpx;
		background-color: #E5F7FF;
		color: #3e6ffd;
		font-size: 28rpx;
		padding: 2rpx 20rpx;
		border-radius: 30rpx;
	}

	.tabBox {
		padding: 0;
		line-height: 48rpx;
	}

	.tabItem {
		padding: 20rpx 0 30rpx;
		display: inline-block;
		width: calc(25%);
		text-align: center;
		color: #333333;
		font-size: 28rpx;
		position: relative;
	}

	.active {
		color: #3e6ffd;
	}

	.active::after {
		content: " ";
		width: 52rpx;
		height: 6rpx;
		background-color: #3e6ffd;
		position: absolute;
		bottom: 0;
		left: calc(50% - 26rpx);
	}

	.contentBox {
		position: relative;
		height: calc(100% - 180rpx);
	}

	.listInfo {
		margin: 20rpx;
		padding: 30rpx 20rpx;
		border-radius: 20rpx;
		background-color: #fff;
	}

	.listCode {
		padding-bottom: 30rpx;
		border-bottom: 2rpx #EEEEEE solid;
	}

	.codeTextBox {
		width: calc(100% - 120rpx);
		display: inline-block;
		font-size: 28rpx;
		color: #666666;
		vertical-align: middle;
	}

	.codeText {
		color: #000006;
	}
	
	.codeType{
		padding: 2rpx 6rpx 4rpx;
		margin-left: 20rpx;
		border: 2rpx #3e6ffd solid;
		border-radius: 10rpx;
		color: #3e6ffd;
		font-size: 24rpx;
	}

	.codeStatus {
		width: calc(120rpx);
		display: inline-block;
		color: #3e6ffd;
		font-size: 28rpx;
		text-align: right;
		vertical-align: middle;
	}

	.listTitle {
		color: #000405;
		font-size: 32rpx;
		line-height: 46rpx;
		white-space: pre-line;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		/*行向垂直排列*/
		-webkit-line-clamp: 2;
		width: 100%;
		padding-top: 20rpx;
	}

	.listDetailBox {
		color: #666666;
		font-size: 24rpx;
		padding-top: 30rpx;
		display: block;
	}

	.listArea {
		font-size: 24rpx;
		margin-right: 20rpx;
	}

	.listDate {
		font-size: 24rpx;
	}
</style>