<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='工单待办'></cus-header>
		<div class="tab">
			<div class="pre" :class="{'active':params.status==1}" @tap="changeType(1)">待指派</div>
			<div class="pre" :class="{'active':params.status==2}" @tap="changeType(2)">已指派(待维修)</div>
			<div class="pre" :class="{'active':params.status==3}" @tap="changeType(3)">已维修</div>
		</div>
		<div class="boxs" v-if="list.length">
			<div class="box" v-for="(item,index) in list" :key="index" @tap="toDetail(item)">
				<div class="place">{{item.repairPosition||''}}</div>
				<div class="pre">报修类型<span>{{RepairType[item.repairType]||''}}</span></div>
				<div class="pre">报修时间<span>{{item.createDate||''}}</span></div>
				<div class="type" :class="colorCfg[item.urgency]||'mr'" v-if="params.status!==1">{{typeCfg[item.urgency]||'未知'}}</div>
			</div>
		</div>
		<template v-else>
			<page-empty :height="'calc(100vh - 100px)'"></page-empty>
		</template>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{
			pageEmpty
		},
		data(){
			return {
				typeCfg:{
					3:'普通',
					2:'紧急',
					1:'非常紧急'
				},
				colorCfg:{
					3:'pt',
					2:'jj',
					1:'fcjj'
				},
				RepairType:{},
				params:{
					page:1,
					limit:10,
					status:1
				},
				list:[]
			}
		},
		async onShow() {
			let pages = getCurrentPages();
			let last = pages[pages.length-1];
			let status = last.options?.status;
			if(status) this.params.status = status;
			this.getRepairTypeData();
			this.getList();
		},
		async onReachBottom() {
			if(this.isOver) return
			this.getRepairTypeData();
			this.getList();
		},
		methods:{
			changeType(status){
				this.params.page = 1;
				this.params.status = status;
				this.list = [];
				this.getList();
			},
			async getRepairTypeData(){
				let res = await this.$api.get('/sys/dict/data/getListByType/RepairType');
				if(res.data.code===0){
					res.data.data.forEach(d=>{
						this.RepairType[d.dictValue]=d.dictLabel;
					})
				}else this.$showToast(res.data.msg)
			},
			getList(){
				this.$api.get('/repairorder/page',this.params).then(res=>{
					if(res.data.code===0){
						if(this.list.length<res.data.data.total){
							this.params.page++;
							this.list = [...this.list,...res.data.data.list];
						}else this.isOver = true
					}else this.$showModal(res.data.msg)
				});
			},
			toDetail(item){
				uni.navigateTo({
					url:'/pagesInspection/waitOrder/detail?id='+item.id
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		background: #F4F8FB;
		padding-bottom: 20rpx;
		box-sizing: border-box;
		.tab{
			width: 100%;
			height: 102rpx;
			background: #FFFFFF;
			display: flex;
			.pre{
				width: calc(100% / 3);
				height: 100%;
				display: flex;
				align-items: center;
				justify-content: center;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 28rpx;
				color: #1D2129;
				line-height: 40rpx;
				position: relative;
				&.active{
					font-weight: bold;
					font-size: 32rpx;
					color: #198CFF;
					line-height: 45rpx;
					&::after{
						content: '';
						width: 36rpx;
						height: 8rpx;
						background: #198CFF;
						border-radius: 4rpx;
						position: absolute;
						left: 50%;
						margin-left: -18rpx;
						bottom: 8rpx;
					}
				}
			}
		}
		
		.boxs{
			width: 100%;
			padding: 0 24rpx;
			box-sizing: border-box;
			.box{
				margin-top: 20rpx;
				background: #FFFFFF;
				border-radius: 16rpx;
				padding: 36rpx 24rpx;
				position: relative;
				.place{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 32rpx;
					color: #1D2129;
					line-height: 36rpx;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}
				.pre{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #86909C;
					line-height: 24rpx;
					margin-top: 24rpx;
					span{
						font-size: 26rpx;
						color: #1D2129;
						margin-left: 40rpx;
					}
				}
				.type{
					height: 48rpx;
					padding: 0 19rpx;
					border-radius: 0rpx 16rpx 0rpx 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					line-height: 48rpx;
					position: absolute;
					top: 0;
					right: 0;
					&.pt{
						background: rgba(20,204,140,.14);
						color: #14CC8C;
					}
					&.jj{
						background: rgba(254,164,0,.14);
						color: #FEA400;
					}
					&.fcjj{
						background: rgba(249,80,80,.14);
						color: #F95050;
					}
					&.mr{
						background: rgba(153,153,153,.14);
						color: #999999;
					}
				}
			}
		}
	}
</style>