<template>
	<view class="app-container">
		<view class="list-container">
			<block v-for="(item, index) in dataList" :key='index'>
				<view class="item" @tap="toDetail(item.workerOrder)">
					<view class="row">工单编号：{{item.workerOrder}}
						<view class="state wait">{{item | stateFilter}}</view>
					</view>
					<view class="row">订单编号：{{item.orderId}}</view>
					<view class="row">派单时间：{{item.createTime || ''}}</view>
					<view class="row">预约时间：{{item.reserveTime || ''}}</view>
					<view class="row">服务类型：{{item.serverContent || ''}}</view>
					<view class="row">服务人员：{{item.workerName || ''}}{{item.assistName ? '、'+item.assistName:''}}</view>
				</view>
			</block>
		</view>
		<no-data v-if="!dataList.length" :showText="'暂无工单信息'"></no-data>
		<loading-text v-if="dataList.length"  :loading="loading" :noMore="noMore" ></loading-text>
	</view>
</template>

<script>
	import {mapState} from 'vuex';
	
	export default {
		filters: {
			stateFilter(item) {
				let orderState = Number(item.orderState);
				if(item.serverContent == '安装服务') {
					if(orderState == 6) {
						return '服务中';
					}else if(orderState == 7 || orderState == 10) {
						return '已完工';
					}else {
						return '已派单';
					}
				}else {
					if(orderState < 7) {
						return '已派单';
					}else if(orderState == 7) {
						return '服务中';
					}else {
						return '已完工';
					}
				}
				
			}
		},
		
		data() {
			return {
				dataList: [],
				pageNum: 1,
				pageSize: 10,
				noMore: false,
				loading: false,
			}
		},
		
		computed:{
			...mapState(['userInfo', 'isLogin', 'userId'])
		},
		
		onLoad() {
			this.getProfitList();
		},
		
		// 下拉刷新
		onPullDownRefresh() {
			this.pageNum = 1;
			this.getProfitList();
		},
		
		// 上拉加载
		onReachBottom() {
			this.getProfitList(1);
		},
		
		methods: {
			// 获取列表
			getProfitList(loadMore) {
				if(this.noMore && loadMore)return;
				this.noMore = false
				if(!loadMore){
					this.pageNum = 1;
				}else{
					this.loading = true;
				}
				this.$axios({
					url: '/order/work/list',
					method: 'get',
					params: {
						pageNo: this.pageNum,
						pageSize: this.pageSize,
						userId: this.userId,
					},
					isLoading: !loadMore
				}).then(res => {
					let _list = res.data.records;
					let pageTotal = res.data.pages;
					if(this.pageNum >= pageTotal){
						this.noMore = true;
					}
					if (_list.length) {
						this.pageNum += 1
					}
					if (loadMore) {
						this.dataList = this.dataList.concat(_list);
						this.loading = false;
					} else {
						this.dataList = _list;
					}
					
					uni.stopPullDownRefresh();
				})
			},
			
			toDetail(id) {
				uni.navigateTo({
					url:'/pages/mine/workOrder/detail?id=' + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.app-container {
		background: #F4F2F2;
		padding: 20rpx;
		box-sizing: border-box;
	}
	.list-container {
		.item {
			margin-bottom: 20rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding: 15rpx 20rpx;
			.row {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 28rpx;
				color: #666666;
				height: 48rpx;
				.state {
					font-size: 28rpx;
					&.wait {
						color: #FF3F42;
					}
					&.over {
						color: #3F9EFF;
					}
					&.cancel {
						color: #999999;
					}
				}
			}
		}
	}
</style>
