<template>
	<view>
		<mescroll-body top="30" bottom="40" @init="mescrollInit" @down="downCallback" @up="upCallback" :option="{}">
			<view class="common-list">
				<view class="common-item" v-for="(item,index) in list" :key="item.id"
					@click="$navigateTo('/pages/orderDetail/orderDetail?orderId='+item.id)">
					<view class="title">{{item.name}}</view>
					<view class="date">{{item.date}}</view>
					<view>
						<view class="space" v-for="(node,index) in item.roomMap" :key="index">{{node}}</view>
					</view>
					<view class="other">
						<view class="item" v-if="type === 3">
							<view class="label">合同编码</view>
							<view class="value">{{item.contractCode}}</view>
						</view>
						<view class="item" v-if="type !== 3">
							<view class="label">关联租客</view>
							<view class="value">{{item.tenantType === 1 ? item.merchantName: item.clientName}}</view>
						</view>
						<view class="item" v-if="type !== 3">
							<view class="label">服务方式</view>
							<view class="value">
								{{type === 1?$field.findTypeName('serviceWorkWay',item.workWay):$field.findTypeName('clearWorkWay',item.workWay)}}
							</view>
						</view>
					</view>
					<view class="state">
						<view class="create">
							<uni-icons class="inherit-icons" type="staff-filled" color="#08979c" size="18"></uni-icons>
							<text class="name hui-ellipsis">{{item.followUpPersonName || '-'}}</text>
						</view>
						<view class="tag">
							<view class="status-tag info" v-if="!item.status">待提交</view>
							<view class="status-tag primary" v-else-if="item.status === 1">待处理</view>
							<view class="status-tag warning" v-else-if="item.status === 2">处理中</view>
							<view class="status-tag success" v-else>已处理</view>
						</view>
					</view>
					<view class="icon">
						<uni-icons custom-prefix="iconfont" :type="menu.iconClass" color="#08979c" size="30">
						</uni-icons>
					</view>
				</view>
			</view>
		</mescroll-body>
	</view>
</template>

<script>
	import {
		getOrderPageListByQuery
	} from '@/request/api/order.js'
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				list: [],
				type: '',
				menu: {}
			}
		},
		onLoad(body) {
			this.type = parseInt(body.type);
			this.menu = this.title();
			uni.setNavigationBarTitle({
				title: this.menu.title
			});
			uni.$on('reloadOrder', () => {
				this.mescroll.resetUpScroll(false);
			})
		},
		methods: {
			title() {
				let str = {
					title: '',
					iconClass: 'icon-weixiugongdan'
				};
				switch (this.type) {
					case 1:
						str = {
							title: '维修工单',
							iconClass: 'icon-weixiugongdan'
						};
						break;
					case 2:
						str = {
							title: '保洁工单',
							iconClass: 'icon-jinribaojie'
						};
						break;
					case 3:
						str = {
							title: '运维工单',
							iconClass: 'icon-yunwei-jiancebaogao'
						};
						break;
					default:
						break;
				}
				return str;
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				getOrderPageListByQuery({
					currPage: page.num,
					pageSize: 10,
					organizationId: this.$store.getters.organization.id,
					projectId: this.$store.getters.project.id,
					type: this.type
				}).then(res => {
					if (res.code === 200) {
						this.mescroll.endBySize(res.data.dataList.length, res.data.totalCount);
						if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
						let data = res.data.dataList;
						this.list = this.list.concat(data); //追加新数据
					} else {
						this.mescroll.endErr();
					}
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},
		}
	}
</script>

<style>

</style>