<template>
	<view class="data-detail detail">
		<house-items :house="detail" v-if="detail.id"></house-items>
		<view class="detail-box">
			<view class="sub-title">
				<uni-icons class="inherit-icons" type="icon-hetongwendang" custom-prefix="iconfont" color="#08979c"
					size="26">
				</uni-icons>
				<text class="sub-label">房源合同</text>
			</view>
			<view class="other-list">
				<mescroll-empty :option="{tip:'暂未签订合同'}" v-if="contract.length === 0"></mescroll-empty>
				<view class="other">
					<view class="contarct-item hui-ellipsis" v-for="(item,index) in contract" :key="item.id"
						@click="$navigateTo('/pages/contractDetail/contractDetail?contractId='+item.id)">
						<view class="contarct-content">
							<view class="content-item content-title">{{item.code}}</view>
							<view class="content-item right">
								<view class="status-tag info" v-if="!item.status">待发送</view>
								<view class="status-tag warning" v-else-if="item.status === 1">待确认</view>
								<view class="status-tag success" v-else-if="item.status === 2">已生效</view>
							</view>
						</view>
						<view class="contarct-content last">
							<view class="content-item">
								<view class="content-label">出租方:</view>
								<view class="content-value hui-ellipsis">{{item.organizationName}}</view>
							</view>
							<view class="content-item right">
								<view class="content-label">租赁方:</view>
								<view class="content-value hui-ellipsis">
									{{item.tenantType === 1 ? item.merchantName: item.clientName}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="detail-box">
			<view class="sub-title">
				<uni-icons class="inherit-icons" type="icon-weixiugongdan" custom-prefix="iconfont" color="#08979c"
					size="26">
				</uni-icons>
				<text class="sub-label">房源工单</text>
			</view>
			<view class="other-list">
				<mescroll-empty :option="{tip:'暂未有工单数据'}" v-if="order.length === 0"></mescroll-empty>
				<view class="other">
					<view class="contarct-item hui-ellipsis" v-for="(item,index) in order" :key="item.id"
						@click="$navigateTo('/pages/orderDetail/orderDetail?orderId='+item.id)">
						<view class="contarct-content">
							<view class="content-item content-title">{{item.name}}</view>
							<view class="content-item right">
								<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="contarct-content last">
							<view class="content-item">
								<view class="content-label">跟进者:</view>
								<view class="content-value hui-ellipsis">{{item.followUpPersonName || '-'}}</view>
							</view>
							<view class="content-item right">
								<view class="content-label">租客:</view>
								<view class="content-value hui-ellipsis">
									{{(item.tenantType === 1 ? item.merchantName: item.clientName) || '-'}}
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import houseItems from "@/components/house/houseItems.vue";
	import {
		getHouseDetailById
	} from '@/request/api/house.js'
	import {
		getContractList
	} from '@/request/api/contract.js'
	import {
		getOrderPageListByQuery
	} from '@/request/api/order.js'
	export default {
		data() {
			return {
				houseId: '',
				detail: {},
				contract: [],
				order: []
			}
		},
		onLoad(body) {
			if (body.houseId) this.houseId = body.houseId;
			this.init();
		},
		components: {
			houseItems
		},
		methods: {
			init() {
				getHouseDetailById(this.houseId).then(res => {
					if (res.code === 200) {
						this.detail = res.data;
						this.getContract();
						this.getOrder();
					}
				})
			},
			getContract() {
				getContractList({
					projectItemTargetRoomIds: this.houseId
				}).then(res => {
					if (res.code === 200) {
						this.contract = res.data;
					}
				})
			},
			getOrder() {
				getOrderPageListByQuery({
					currPage: 1,
					pageSize: 100,
					projectItemTargetRoomIds: this.houseId
				}).then(res => {
					if (res.code === 200) {
						this.order = res.data.dataList;
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.data-detail {
		// padding: 30rpx;
	}
</style>