<template>
	<view>
		<view class="promoter-order">
			<view class='promoterHeader bg-color'>
				<view class='headerCon acea-row row-between-wrapper'>
					<view>
						<view class='name' v-if="type==1">累积未结算订单</view>
						<view class='name' v-else>累积已结算推广订单</view>
						<view><text class='num'>{{recordCount || 0}}</text>单</view>
					</view>
					<view class='iconfont icon-2'>
						<image v-if="type==1" src="https://hy.liuniu946.com/app/img/dsh.png" mode=""></image>
						<image v-if="type==0" src="https://hy.liuniu946.com/app/img/ysh.png" mode=""></image>
					</view>
				</view>
			</view>
			<view class='list' v-if="recordList.length>0">
				<block v-for="(item,index) in recordList" :key="index">
					<view class='item'>
						<view class='listn'>
							<view class='itenm'>
								<view class='top acea-row row-between-wrapper'>
									<view class='pictxt acea-row row-between-wrapper'>
										<view class='pictrue'>
											<image v-if="item.avatar" :src='item.avatar'></image>
											<image v-else class="avatar" src="/static/images/f.png"></image>
										</view>
										<view class='text line1'>{{item.nickname}}</view>
									</view>
									<view class='money' v-if="item.type== 'brokerage'">返佣：<text
											class='font-color'>￥{{item.number}}</text></view>
									<view class='money' v-else>订单总额：<text class='font-color'>￥{{item.number}}</text>
									</view>
								</view>
								<view class='bottom'>
									<view><text class='name'>订单编号：</text>{{item.order_id}}</view>
									<view><text class='name'>下单时间：</text>{{item.time}}</view>
								</view>
								<view class="shop-box">
									<view class="title">
										{{item.order_info[0].cart_info.productInfo.store_name}}
									</view>
									<view class="shop-img">
										<image :src="item.order_info[0].cart_info.productInfo.image" mode=""></image>
									</view>
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
			<view v-if="recordList.length == 0">
				<emptyPage title="暂无推广订单～"></emptyPage>
			</view>
		</view>
		<!-- #ifdef MP -->
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
		<!-- #endif -->
	</view>
</template>

<script>
	import {
		spreadOrder,
		spreadInfo
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	import emptyPage from '@/components/emptyPage.vue'
	export default {
		components: {
			emptyPage
		},
		data() {
			return {
				page: 1,
				limit: 8,
				status: false,
				recordList: [],
				recordCount: 0,
				userInfo: '',
				type: 0,
			};
		},
		computed: mapGetters(['isLogin']),
		onLoad(e) {
			console.log(e)
			this.type = e.type;
			this.getRecordOrderList();
		},
		methods: {
			spreadInfo() {
				spreadInfo().then(res => {
					this.userInfo = res.data
				});
			},
			getRecordOrderList: function() {
				let that = this;
				let page = that.page;
				let limit = that.limit;
				let status = that.status;
				let recordList = that.recordList;
				console.log(recordList,'22222');
				let recordListNew = [];
				let lst = [];
				let sum = 0;
				if (status == true) return;
				spreadOrder({
					page: page,
					limit: limit
				}).then(res => {
					console.log(res,'ere')
					let len = res.data.list ? res.data.list.length : 0;
					let recordListData = res.data.list;
					let list = res.data.list
					console.log(list)
					for (let i = 0; i < list.length; i++) {
						for (let j = 0; j < res.data.list[i].child.length; j++) {
							if (res.data.list[i].child[j].type == 'pay_money' && that.type == 1) {
								sum = sum + 1;
								lst.push(res.data.list[i].child[j])
							}
							if (res.data.list[i].child[j].type == 'brokerage' && that.type == 0) {
								sum = sum + 1;

								lst.push(res.data.list[i].child[j])
							}
						}

					}
					that.recordCount = sum || 0;
					recordListNew = recordList.concat(lst);
					
					that.status = limit > len;
					that.page += 1;
					that.$set(that, 'recordList', recordListNew);
					// console.log(recordListNew,'recordList');
				});
			}
		},
		onReachBottom() {
			this.getRecordOrderList();
		}
	}
</script>

<style scoped lang="scss">
	.iconfont image {
		opacity: 0.8;
		width: 120rpx;
		height: 120rpx;
	}

	.money {
		color: red;
	}
	.shop-box {
		margin-top: -20rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		// text-align: center;
		.title {
			text-overflow:ellipsis;
			white-space: nowrap;
			overflow: hidden;
			width: 550rpx;
		}

		.shop-img {
			margin-top: -80rpx;
			margin-right: 50rpx;
			width: 80rpx;
			height: 80rpx;
			border-radius: 20%;
			overflow: hidden;
			image {
				width: 100%;
				height: 100%;
			}
		}
	}

	.item {
		overflow: hidden;
		border-radius: 20rpx;
		margin: 10rpx;
	}

	.headerCon .name {
		margin-bottom: 10rpx;
		font-size: 32rpx;
	}

	.headerCon {
		padding: 20rpx;
		color: #fff;
		border-bottom-left-radius: 20rpx;
		border-bottom-right-radius: 20rpx;
		background-color: #f75022;
		height: 240rpx;
	}

	.promoter-order .list .item {
		margin-bottom: 20rpx;
	}

	.promoter-order .list .item .title {
		height: 133rpx;
		padding: 0 30rpx;
		font-size: 26rpx;
		color: #999;
	}

	.promoter-order .list .item .title .data {
		font-size: 28rpx;
		color: #282828;
		margin-bottom: 5rpx;
	}

	.promoter-order .list .item .listn .itenm {
		background-color: #fff;
	}

	.promoter-order .list .item .listn .itenm~.itenm {
		margin-top: 12rpx;
	}

	.promoter-order .list .item .listn .itenm .top {
		margin-left: 30rpx;
		padding-right: 30rpx;
		border-bottom: 1rpx solid #eee;
		height: 100rpx;
	}

	.promoter-order .list .item .listn .itenm .top .pictxt {
		width: 320rpx;
	}

	.promoter-order .list .item .listn .itenm .top .pictxt .text {
		width: 230rpx;
		font-size: 30rpx;
		color: #282828;
	}

	.promoter-order .list .item .listn .itenm .top .pictxt .pictrue {
		width: 66rpx;
		height: 66rpx;
	}

	.promoter-order .list .item .listn .itenm .top .pictxt .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 50%;
		border: 3rpx solid #fff;
		box-sizing: border-box;
		box-shadow: 0 0 15rpx #aaa;
	}

	.promoter-order .list .item .listn .itenm .top .money {
		font-size: 28rpx;
	}

	.promoter-order .list .item .listn .itenm .bottom {
		padding: 20rpx 30rpx;
		font-size: 28rpx;
		color: #666;
		line-height: 1.6;
	}

	.promoter-order .list .item .listn .itenm .bottom .name {
		color: #999;
	}
</style>
