<template>
	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
		<cus-header title='运维服务' bgColor="transparent" :showback="false"></cus-header>
		<image class="topbg" :src="imgBase+'operation/top_bg.png'" mode="widthFix"></image>
		<div class="order">
			<div class="pre">
				<div class="top">
					<div class="left">
						<p>本月巡检次数</p>
						<p>{{xjData.abnormalNum}}/{{xjData.normalNum}}</p>
					</div>
					<div class="right">
						<p>异常：<span>{{xjData.abnormalNum}}</span></p>
						<p>正常：<span>{{xjData.normalNum}}</span></p>
					</div>
				</div>
				<div class="bottom">
					<div class="jd" :style="{'width':xjWidth+'%'}"></div>
				</div>
			</div>
			<div class="pre">
				<div class="top">
					<div class="left">
						<p>故障工单</p>
						<p>{{gzData.normalNum}}/{{gzData.abnormalNum}}</p>
					</div>
					<div class="right">
						<p>已解决：<span>{{gzData.normalNum}}</span></p>
						<p>未解决：<span>{{gzData.abnormalNum}}</span></p>
					</div>
				</div>
				<div class="bottom">
					<div class="jd green" :style="{'width':gzWidth+'%'}"></div>
				</div>
			</div>
		</div>
		<div class="menu">
			<div class="pre" @tap="turnPage('/pagesOperation/record/add')">
				<image :src="imgBase+'operation/menu_xjtd.png'" mode="widthFix"></image>
				<p>巡检提单</p>
			</div>
			<div class="pre" @tap="turnPage('/pagesOperation/record/index')">
				<image :src="imgBase+'operation/menu_xjjl.png'" mode="widthFix"></image>
				<p>巡检记录</p>
			</div>
			<div class="pre" @tap="turnPage('/pagesOperation/repair/index')">
				<image :src="imgBase+'operation/menu_gzbx.png'" mode="widthFix"></image>
				<p>故障报修</p>
			</div>
			<div class="pre" @tap="turnPage('/pagesOperation/workorder/index')">
				<image :src="imgBase+'operation/menu_gzgd.png'" mode="widthFix"></image>
				<p>故障工单</p>
			</div>
		</div>
		<div class="list">
			<div class="title">
				<div class="left">故障工单</div>
				<div class="right" @tap="turnPage('/pagesOperation/workorder/index')">
					<span>更多</span>
					<image :src="imgBase+'operation/arrow_right.png'" mode="widthFix"></image>
				</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.description||''}}</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 - 200px)'"></page-empty>
			</template>
		</div>
	</view>
</template>

<script>
	import pageEmpty from '../../components/pageEmpty/index.vue'
	export default {
		components:{
			pageEmpty
		},
		data(){
			return {
				xjData:{
					normalNum:0,
					abnormalNum:0
				},
				gzData:{
					normalNum:0,
					abnormalNum:0
				},
				xjWidth:0,
				gzWidth:0,
				isOver:false,
				params:{
					page:1,
					limit:2
				},
				dataList:[],
				typeList:[],
			}
		},
		onShow() {
			this.getNumsInfo();
			this.getTypeList();
		},
		methods:{
			turnPage(url){
				if(!url) return
				uni.navigateTo({ url })
			},
			getNumsInfo(){
				this.$api.get('/wms/order/operation/getOperationCountInfo').then(res=>{
					if(res.data.code===0){
						let xj = res.data.data.find(d=>d.type==1);
						let gz = res.data.data.find(d=>d.type==2);
						if(xj){
							this.xjData = xj;
							this.xjWidth = xj.abnormalNum/(xj.normalNum+xj.abnormalNum)*100;
						}
						if(gz){
							this.gzData = gz;
							this.gzWidth = gz.normalNum/(gz.normalNum+gz.abnormalNum)*100;
						}
					}else this.$showToast(res.data.msg)
				})
			},
			getTypeList(){
				this.$api.get('/sys/dict/data/getListByType/wms_operation_category').then(res=>{
					if(res.data.code===0){
						this.typeList = res.data.data;
						this.getDataList();
					}else this.$showToast(res.data.msg)
				})
			},
			getDataList(){
				this.$api.get('/wms/order/operation/page',{page:1,limit:2}).then(res=>{
					if(res.data.code===0){
						if(this.dataList.length<res.data.data.total){
							this.params.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)
				});
			},
			toDetail(item){
				uni.navigateTo({
					url:'/pagesOperation/workorder/detail?id='+item?.id
				})
			}
		}
	}
</script>

<style scoped lang="less">
	.page{
		padding: 0 24rpx 40rpx;
		background: #F5F8FA;
		box-sizing: border-box;
		
		.topbg{
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 0;
		}
		
		.order{
			display: flex;
			justify-content: space-between;
			position: relative;
			margin-top: 218rpx;
			.pre{
				width: calc(50% - 9rpx);
				background: rgba(255,255,255,0.7);
				border-radius: 12rpx;
				border: 2rpx solid #FFFFFF;
				padding: 30rpx 20rpx;
				box-sizing: border-box;
				.top{
					display: flex;
					align-items: center;
					justify-content: space-between;
					.left{
						p{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 24rpx;
							color: #657588;
							line-height: 24rpx;
							&:last-child{
								font-family: DINAlternate, DINAlternate;
								font-weight: bold;
								font-size: 36rpx;
								color: #333333;
								line-height: 36rpx;
								margin-top: 20rpx;
							}
						}
					}
					.right{
						p{
							font-family: PingFangSC, PingFang SC;
							font-weight: 400;
							font-size: 20rpx;
							color: #657588;
							position: relative;
							padding-left: 16rpx;
							&::before{
								content: '';
								width: 10rpx;
								height: 10rpx;
								background: #FEA400;
								border-radius: 50%;
								position: absolute;
								left: 0;
								top: 50%;
								margin-top: -5rpx;
							}
							&:last-child{
								margin-top: 20rpx;
								&::before{
									background: #DDE0E6;
								}
							}
							span{
								color: #1D2129;
							}
						}
					}
				}
				.bottom{
					width: 100%;
					height: 6rpx;
					background: #DFE5EE;
					border-radius: 3rpx;
					margin-top: 24rpx;
					position: relative;
					.jd{
						height: 6rpx;
						background: #FEA400;
						border-radius: 3rpx;
						position: absolute;
						left: 0;
						top: 0;
						&.green{
							background: #31D1D6;
						}
					}
				}
			}
		}
	
		.menu{
			padding: 38rpx 0;
			background: #FFFFFF;
			border-radius: 12rpx;
			margin-top: 20rpx;
			display: flex;
			position: relative;
			.pre{
				width: 25%;
				display: flex;
				flex-direction: column;
				align-items: center;
				image{
					width: 64rpx;
					height: 64rpx;
				}
				p{
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #4E5969;
					line-height: 30rpx;
					text-align: center;
					margin-top: 18rpx;
				}
			}
		}
	
		.list{
			margin-top: 49rpx;
			position: relative;
			.title{
				display: flex;
				align-items: center;
				justify-content: space-between;
				.left{
					font-family: PingFang-SC, PingFang-SC;
					font-weight: bold;
					font-size: 36rpx;
					color: #1D2129;
					line-height: 50rpx;
				}
				.right{
					display: flex;
					align-items: center;
					span{
						font-family: PingFangSC, PingFang SC;
						font-weight: 400;
						font-size: 26rpx;
						color: #86909C;
						line-height: 26rpx;
					}
					image{
						width: 24rpx;
						height: 24rpx;
						margin-left: 13rpx;
					}
				}
			}
			.boxs{
				margin-top: 36rpx;
				.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>