<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='故障工单'></cus-header>
		<div class="status">
			<div class="pre" :class="{'active':sidx===0}" @tap="changeStatus('',0)">全部</div>
			<div class="pre" :class="{'active':sidx===1}" @tap="changeStatus(0,1)">待解决</div>
			<div class="pre" :class="{'active':sidx===2}" @tap="changeStatus(1,2)">已解决</div>
		</div>
		<div class="query">
			<!-- <div class="pre" @tap="selectQuery(1)">
				<span>{{typeText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div> -->
			<div class="pre" @tap="selectQuery(2)">
				<span>{{timeText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div>
			<div class="pre" @tap="selectQuery(3)">
				<span>{{placeText}}</span>
				<u-icon name="arrow-down-fill" color="#C0C4CC" size="20rpx"></u-icon>
			</div>
		</div>
		<div class="boxs" v-if="dataList.length">
			<div class="item" v-for="(item,index) in dataList" :key="index">
				<div class="left">
					<div class="name">{{item.customer||''}}</div>
					<p>故障类型<span>{{item.typeName}}</span></p>
					<p>故障描述<span>{{item.repairDesc||''}}</span></p>
					<p>故障时间<span>{{item.happenDate||''}}</span></p>
				</div>
				<div class="right">
					<div class="top" :class="{'djj':item.status===0,'yjj':item.status===1}">{{item.status===0?'待解决':'已解决'}}</div>
					<div class="bottom" @tap="toDetail(item)">查看</div>
				</div>
			</div>
		</div>
		<template v-else>
			<page-empty :height="'calc(100vh - 140px)'"></page-empty>
		</template>
		<u-picker :itemHeight="88" :show="show1" :columns="columns1" keyName="label" title="故障类型"
			@cancel="show1=false" @confirm="e=>confirm(e,1)" :immediateChange="true"></u-picker>
		<u-datetime-picker :itemHeight="88" :show="show2" v-model="queryParams.month" mode="date" title="巡检时间"
			@cancel="show2=false" @confirm="e=>confirm(e,2)" :immediateChange="true" :minDate="minDate" :maxDate="maxDate"></u-datetime-picker>
		<u-picker :itemHeight="88" :show="show3" :columns="columns3" title="巡检地点"
			@cancel="show3=false" @confirm="e=>confirm(e,3)" :immediateChange="true"></u-picker>
	</view>
</template>

<script>
	import pageEmpty from '@/components/pageEmpty/index.vue'
	export default {
		components:{
			pageEmpty
		},
		data(){
			return {
				sidx:0,
				typeText:'故障类型',
				timeText:'巡检时间',
				placeText:'巡检地点',
				queryParams:{
					page:1,
					limit:10,
					createStartDate:'',
					createEndDate:'',
					customer:'',
					status:''
				},
				show1:false,
				show2:false,
				show3:false,
				columns1:[[
					{value:0,label:'类型1'},
					{value:1,label:'类型2'}
				]],
				columns3:[],
				minDate:'',
				maxDate:'',
				isOver:false,
				dataList:[]
			}
		},
		onReachBottom() {
			if(this.isOver) return
			this.getList();
		},
		async onShow() {
			this.init()
			this.getCustomerList();
			await this.getTypeList();
			this.getList();
			let d = new Date();
			this.minDate = new Date(d.getFullYear()-3,d.getMonth()+1,d.getDate()).getTime();
			this.maxDate = new Date().getTime();
		},
		methods:{
			getTypeList(){
				return new Promise((resolve,reject)=>{
					this.$api.get('/sys/dict/data/getListByType/wms_operation_category').then(res=>{
						if(res.data.code===0){
							this.typeList = res.data.data;
							resolve()
						}else this.$showToast(res.data.msg)
					})
				})
			},
			getCustomerList(){
				this.$api.get('/wms/project/getCustomerList',{page:1,limit:-1}).then(res=>{
					if(res.data.code!==0) return this.$showToast(res.data.msg)
					this.columns3 = [res.data.data]
				})
			},
			init(){
				this.sidx = 0;
				this.typeText = '故障类型';
				this.timeText = '巡检时间';
				this.placeText = '巡检地点';
				this.queryParams = {
					page:1,
					limit:10,
					createStartDate:'',
					createEndDate:'',
					customer:'',
					status:''
				};
				this.isOver = false;
				this.dataList = [];
			},
			changeStatus(status,idx){
				this.init();
				this.sidx = idx;
				this.queryParams.status = status;
				this.getList();
			},
			getList(){
				this.$api.get('/wms/order/operation/page',this.queryParams).then(res=>{
					if(res.data.code===0){
						if(this.dataList.length<res.data.data.total){
							this.queryParams.page++;
							this.dataList = [...this.dataList,...res.data.data.list];
							this.dataList.forEach(d=>{
								d.typeName = this.typeList.find(t=>t.dictValue==d.optCategory)?.dictLabel;
							})
						}else this.isOver = true
					}else this.$showModal(res.data.msg)
				});
			},
			selectQuery(type){
				this['show'+type] = true;
			},
			toDetail(item){
				uni.navigateTo({
					url:'/pagesOperation/workorder/detail?id='+item?.id
				})
			},
			confirm(e,type){
				this.init();
				if(type==1){
					this.typeText = e.value[0].label;
					this.queryParams.type = e.value[0].value;
					this.show1 = false;
				}else if(type==2){
					this.timeText = new Date(e.value).Format('yyyy-MM-dd');
					this.queryParams.createStartDate = new Date(e.value).Format('yyyy-MM-dd');
					this.queryParams.createEndDate = new Date(new Date().setDate(new Date(this.queryParams.createStartDate).getDate()+1)).Format('yyyy-MM-dd');
					this.show2 = false;
				}else if(type==3){
					this.placeText = e.value[0];
					this.queryParams.customer = e.value[0];
					this.show3 = false;
				}
				this.getList();
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding-bottom: 40rpx;
		background: #F4F8FB;
		
		.status{
			width: 100%;
			height: 90rpx;
			background: #FFFFFF;
			box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECEEF5;
			display: flex;
			.pre{
				width: calc(100% / 3);
				height: 90rpx;
				font-family: PingFang-SC, PingFang-SC;
				font-weight: bold;
				font-size: 30rpx;
				color: #1D2129;
				line-height: 90rpx;
				text-align: center;
				position: relative;
				&.active{
					font-weight: bold;
					font-size: 32rpx;
					color: #2E69EB;
					&::after{
						content: '';
						width: 59rpx;
						height: 5rpx;
						background: #2E69EB;
						position: absolute;
						bottom: 0;
						left: 50%;
						margin-left: -30rpx;
					}
				}
			}
		}
		
		.query{
			width: 100%;
			height: 88rpx;
			background: #FFFFFF;
			display: flex;
			.pre{
				width: calc(100% / 2);
				height: 88rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				span{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 26rpx;
					color: #86909C;
					line-height: 26rpx;
					margin-right: 12rpx;
				}
			}
		}
	
		.boxs{
			padding: 0 24rpx;
			margin-top: 20rpx;
			.item{
				background: #FFFFFF;
				box-shadow: inset 0rpx -1rpx 0rpx 0rpx #ECEEF5;
				padding: 36rpx 27rpx;
				display: flex;
				.left{
					width: calc(100% - 115rpx);
					padding-right: 20rpx;
					box-sizing: border-box;
					.name{
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 30rpx;
						color: #1D2129;
						line-height: 42rpx;
						text-align: left;
						white-space: nowrap;
						overflow: hidden;
						text-overflow: ellipsis;
					}
					p{
						margin-top: 36rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #86909C;
						line-height: 26rpx;
						span{
							color: #1D2129;
							margin-left: 64rpx;
						}
					}
				}
				.right{
					width: 115rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.top{
						width: 104rpx;
						height: 48rpx;
						border-radius: 6rpx;
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						line-height: 48rpx;
						text-align: center;
						&.djj{
							color: #FEA400;
							background: rgba(254,164,0,0.08);
						}
						&.yjj{
							color: #05C17F;
							background: rgba(20,204,140,0.08);
						}
					}
					.bottom{
						width: 115rpx;
						height: 64rpx;
						background: #2E69EB;
						border-radius: 16rpx;
						font-family: PingFang-SC, PingFang-SC;
						font-weight: bold;
						font-size: 28rpx;
						color: #FFFFFF;
						line-height: 64rpx;
						text-align: center;
					}
				}
			}
		}
			
	}
</style>