<template>
	<view class="index">
		<view class="index-cent" v-for="v in findInviteList" :key="v.userId">
			<view class="index-cent-top">
				<view class="">
					订单号:{{v.contractNo}}
				</view>
				<view class="index-cent-top-rig">
					{{v.contractStatusIng | filterOrderStatus}}
				</view>
			</view>
			<view class="index-cent-xian"></view>
			<view class="index-cent-ct">
				<image :src="v.url" mode=""></image>
				<view class="index-cent-ct-right">
					<view class="">
						{{v.businessName}}
					</view>
					<view class="tp">
						公司名称:{{v.companyName}}
					</view>
					<view class="tp">
						营业地址:{{v.businessAddressContent}}{{v.businessAddressInfo}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import apiBaseConfig from '@/config/index.js';
	import {
		findInviteContractGET
	} from '@/api/workbench/index.js';
	export default {
		data() {
			return {
				imgBgUrl: apiBaseConfig.imgBgUrl,
				globalData: getApp().globalData,
				findInviteList: [],
				totalSize: 0,
				pageNum: 1,
				userId: "",
				currentRole: 'app_user'
			};
		},
		filters: {
			filterOrderStatus(val) {
				// -1=定金待支付 0=待签约,1=待确认,2=待付款,3=图纸待上传,4=图纸待确认,5=材料待到厂,6=到厂待验收,7=材料待到家,8=到家待验收,9=待安装,10=完成待验收,11=已完成,12=终止待退款,13=终止已退款
				switch (val) {
					case '-1':
						return '定金待支付';
						break;
					case '0':
						return '合同待签约';
						break;
					case '1':
						return '合同待确认';
						break;
					case '2':
						return '待付款';
						break;
					case '3':
						return '图纸待上传';
						break;
					case '4':
						return '图纸待确认';
						break;
					case '5':
						return '材料待到厂';
						break;
					case '6':
						return '到厂待验收';
						break;
					case '7':
						return '材料待到家';
						break;
					case '8':
						return '到家待验收';
						break;
					case '9':
						return '待完成安装';
						break;
					case '10':
						return '完成待验收';
						break;
					case '11':
						return '已完成';
						break;
					case '12':
						return '终止待退款';
						break;
					case '13':
						return '终止已退款';
						break;
					case '14':
						return '待评价';
						break;
					default:
						return val;
						break;
				}
			}
		},
		onLoad(option) {
			this.userId = option.userId
			console.log(option.role, 'role===')
			this.currentRole = option.role
			this.pageNum = 1
			this.findInviteList = []
			this.findInvite()
		},
		onReachBottom() {
			console.log('触底了-------')
			if (this.totalSize > this.pageNum) {
				this.pageNum++
				this.findInvite()
			}
		},
		methods: {
			findInvite(userId) {
				let self = this
				let roleData = {}
				switch (self.currentRole) {
					case 'merchant':
						roleData = {
							businessId: self.userId
						}
						break;
					case 'app_user':
					case 'promoter':
						roleData = {
							userId: self.userId
						}
						break
					default:
						roleData = {
							userId: self.userId
						}
				}
				findInviteContractGET({
					...roleData,
					pageSize: 10,
					pageNum: this.pageNum
				}).then((res) => {
					self.findInviteList = self.findInviteList.concat(res.rows)
					self.findInviteList.forEach((item) => {
						item.url = JSON.parse(item.businessImg)[0].url
						// console.log(JSON.parse(item.businessImg),'item.url=====')
					})
					self.totalSize = Math.ceil(Number(res.total) / 10)
					// console.log(self.totalSize,'触底了-------111')
				})
			},
		}
	};
</script>

<style>
	page {
		background-color: #F7F8FA;
	}
</style>
<style lang="scss" scoped>
	.index {
		padding: 22rpx 30rpx;

		&-cent {
			padding: 24rpx 30rpx;
			background-color: #fff;
			border-radius: 20rpx;
			margin-bottom: 22rpx;

			&-top {
				display: flex;
				align-items: center;
				justify-content: space-between;
				font-weight: 400;
				font-size: 24rpx;
				color: #666666;

				&-rig {
					font-weight: 400;
					font-size: 24rpx;
					color: #1572FF;
				}
			}

			&-xian {
				width: 100%;
				height: 1rpx;
				background: #ECECEC;
				margin: 20rpx 0;
			}

			&-ct {
				display: flex;
				align-items: center;

				>image {
					width: 156rpx;
					height: 156rpx;
					margin-right: 16rpx;
				}

				&-right {
					width: calc(100% - 172rpx);
					font-weight: 400;
					font-size: 24rpx;
					color: #1A1A1A;

					>view:nth-child(1) {
						font-weight: 500;
						font-size: 26rpx;
						color: #1A1A1A;
					}
				}
			}
		}
	}

	.tp {
		margin-top: 20rpx;
	}
</style>