<template>
	<view>
		<view class="uni-padding-wrap uni-common-mt">
			<uni-segmented-control :current="typeId" :values="items" :style-type="styleType" :active-color="activeColor"
				@clickItem="onClickItem" />
		</view>
		<view class="content">
			<view v-if="typeId === 0">
				<uni-list border-full v-for="(item,index) in preProfitList" :key="index">
					<uni-list-item :title="item.createTime+'@'+item.scanCode"
						:note="item.appType+'&'+item.platform+'&'+item.type" :thumb="item.url" thumb-size="lg"
						:rightText="item.downloadNum+'次'" />
				</uni-list>
			</view>
			<view v-if="typeId === 1">
				<uni-list border-full v-for="(item,index) in preProfitList" :key="index">
					<uni-list-item :title="item.createTime+'@'+item.scanCode"
						:note="item.appType+'&'+item.platform+'&'+item.type" :thumb="item.url" thumb-size="lg"
						:rightText="item.downloadNum+'次'" />
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		queryFrontPreProfit
	} from '@/api/profit.js'
	export default {
		data() {
			return {
				preProfitList: [],
				items: ['广告', '邀请'],
				typeId: 0,
				activeColor: '#007aff',
				styleType: 'text',
				userInfo: {}
			}
		},
		created() {
			const userInfoSync = uni.getStorageSync('userInfo')
			this.userInfo = userInfoSync
			const typeProfitId = uni.getStorageSync('typeId')
			this.typeId = typeProfitId
			const param = {
				creatorId: userInfoSync.id,
				type: typeProfitId
			}
			if (typeProfitId) {
				this.queryFrontPreProfit(param)
			} else {
				this.queryFrontPreProfit(param)
			}
		},
		methods: {
			onClickItem(e) {
				let that = this
				if (that.typeId !== e.currentIndex) {
					that.typeId = e.currentIndex
					uni.showLoading({
						title: '加载中',
						mask: true,
						success() {
							// 查询即将入账邀请收益列表
							const param = {
								creatorId: that.userInfo.id,
								type: that.typeId
							}
							queryFrontPreProfit(param).then(res => {
								if (res.data.code === 200) {
									that.preProfitList = res.data.data
								} else {
									uni.showModal({
										content: '即将到账列表数据加载失败！',
										showCancel: false
									});
								}
							})
						},
						complete() {
							uni.hideLoading();
						}
					});

				}
			},

			// 查询即将入账邀请收益列表
			async queryFrontPreProfit(param) {
				const res = await queryFrontPreProfit(param)
				if (res.data.code === 200) {
					this.preProfitList = res.data.data
				} else {
					uni.showModal({
						content: '即将到账列表数据加载失败！',
						showCancel: false
					});
				}
			},
		}
	}
</script>

<style>

</style>
