<template>
	<view class="container">
		<view v-if="repair.length > 0">
			<view class="details" v-for="(item, i) in repair" :key="i" @click="details(item)">
				<view class="detail_header">
					<text class="blueSign"></text>
					<text class="font-tilte">服务报修</text>
					<text :class="item.statusCode == 11 ? 'statusgr' : 'statusred'">{{ item.status }}</text>
				</view>
				<view class="detail_msg">
					<view class="info-item">
						<text>报修人：</text>
						<text class="infoSpan">{{ item.userName }}</text>
					</view>
					<view class="info-item">
						<text>处理人：</text>
						<text class="infoSpan">{{ item.disposeName }}</text>
					</view>
					<view class="info-item">
						<text>报修选项：</text>
						<text class="infoSpan">{{ item.opt > 0 ? fixList[item.opt - 1].title : '' }}</text>
					</view>
					<view class="info-item">
						<text>报修位置：</text>
						<text class="infoSpan">{{ item.repairAddr }}</text>
					</view>
					<view class="info-item">
						<text>报修描述：</text>
						<text class="infoSpan">{{ item.faultDetail }}</text>
					</view>
					<view class="info-item">
						<text class="label">报修时间：</text>
						<text class="infoSpan">{{ formatDate(item.apply_time, 'dateTime') }}</text>
					</view>
				</view>
			</view>
		</view>

		<content-none v-else :padTop="32"></content-none>
		<load-more :loadingType="loadingType" :contentText="contentText"></load-more>
	</view>
</template>

<script>
import { getDoHitchList } from '@/common/api.js';
import { callbackRequest, getStorage, alertTip, formatDate } from '@/common/util.js';
import loadMore from '@/components/loadMore.vue';
import contentNone from '@/components/contentNone.vue';
export default {
	components: {
		loadMore,
		contentNone
	},
	data() {
		return {
			formatDate: formatDate,
			//分页
			page: 1,
			pageSize: 10,
			loadingType: 0, //0-loading前；1-loading中；2-没有更多了
			contentText: {
				contentdown: '上拉加载更多',
				contentrefresh: '正在加载...',
				contentnomore: '没有更多数据了'
			},
			userInfo: getStorage('userInfo'),
			repair: [],
			fixList: [
				{
					title: '空调',
					more: '风系统'
				},
				{
					title: '给排水',
					more: '饮水、清洁、排水'
				},
				{
					title: '电',
					more: '照明、办公、生产'
				},
				{
					title: '木',
					more: '办公桌、椅、门等'
				},
				{
					title: '安保',
					more: '门禁、监控等'
				},
				{
					title: '电梯',
					more: '货运、人员等'
				},
				{
					title: '消防',
					more: '报警、逃生、灭火器'
				},
				{
					title: '其它',
					more: ''
				}
			]
		};
	},
	onShow() {
		this.page = 1;
		this.loadData();
	},
	methods: {
		details: function(item) {
			uni.navigateTo({
				url: 'repair-details2?item=' + encodeURIComponent(JSON.stringify(item))
			});
		},
		loadData() {
			let cur = this;
			let params = {
				method: getDoHitchList,
				data: {
					userId: this.userInfo.id,
					pageNum: this.page,
					pageSize: this.pageSize
				}
			};
			callbackRequest(params).then(res => {
				res = res.data;
				if (res.returnCode == '1') {
					if (cur.page == 1) {
						cur.repair = res.returnData || [];
					} else {
						if (res.returnData.length > 0) {
							cur.repair = cur.repair.concat(res.returnData);
							// console.log(cur.repair);
							this.loadingType = 0;
						} else {
							this.loadingType = 2;
						}
					}
				}
			});
		}
	},
	onReachBottom() {
		if (this.loadingType !== 0) {
			return;
		}
		this.loadingType = 1;
		this.page = this.page + 1;
		this.loadData();
	}
};
</script>

<style lang="scss">
@import '@/static/css/common.scss';

.nolist {
	font-size: 30upx;
	color: #797979;
	text-align: center;
	padding-top: 20upx;
}

.container {
	min-height: 100vh;
	background: #f8f8f8;
	font-size: 28upx;

	.details {
		height: 460upx;
		background: white;
		margin: 15upx;
		border-radius: 15upx;

		.detail_header {
			border-bottom: #f8f8f8 5upx solid;
			height: 90upx;
			line-height: 90upx;
			margin: 15upx;
			border-radius: 10upx;

			.blueSign {
				height: 28upx;
				width: 5upx;
				background: #00c277;
				display: inline-block;
				margin-left: 20upx;
				vertical-align: middle;
			}

			.font-tilte {
				font-weight: bold;
				margin-left: 20upx;
				vertical-align: middle;
			}
		}

		.statusgr {
			float: right;
			margin-right: 30upx;
			color: #00c277;
		}

		.statusred {
			float: right;
			margin-right: 30upx;
			color: red;
		}

		.detail_msg {
			margin-left: 20upx;
			border-radius: 10upx;

			view {
				height: 60upx;
				line-height: 60upx;
			}
		}
	}
}
.detail_msg .info-item {
	font-size: 28upx;
	margin-right: 30upx;
	text {
		display: inline-block;
		width: 140upx;
	}

	.infoSpan {
		width: auto;
		font-size: 28upx;
		color: #666;
		float: right;
	}
}
</style>
