<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 inProfitList" :key="index">
					<uni-list-item showArrow clickable :title="item.createTime+'@'+item.scanCode"
						:note="item.appType+'&'+item.platform+'&'+item.type" :thumb="item.url" thumb-size="lg"
						:rightText="'￥'+item.profit" @click="targetToOrder(item.id)" />
				</uni-list>
			</view>
			<view v-if="typeId === 1">
				<uni-list border-full v-for="(item,index) in inProfitList" :key="index">
					<uni-list-item showArrow clickable :title="item.createTime+'@'+item.scanCode"
						:note="item.appType+'&'+item.platform+'&'+item.type" :thumb="item.url" thumb-size="lg"
						:rightText="'￥'+item.profit" @click="targetToOrder(item.id)" />
				</uni-list>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		queryFrontInProfitAmt
	} from '@/api/profit.js'
	export default {
		data() {
			return {
				items: ['广告', '邀请'],
				typeId: 0,
				activeColor: '#007aff',
				styleType: 'text',
				inProfitList: [],
				userInfo: {}
			}
		},
		created() {
			const userInfoSync = uni.getStorageSync('userInfo')
			this.userInfo = userInfoSync
			const typeProfitId = uni.getStorageSync('typeId')
			this.typeId = typeProfitId
			if (typeProfitId) {
				this.queryFrontInProfitAmt()
			} else {
				this.queryFrontInProfitAmt()
			}
		},
		methods: {

			// 查询指定艺术家已入账收益列表
			async queryFrontInProfitAmt() {
				const res = await queryFrontInProfitAmt({
					creatorId: this.userInfo.id,
					type: this.typeId
				})
				if (res.data.code === 200) {
					this.inProfitList = res.data.data
				} else {
					uni.showModal({
						content: '已入账列表数据加载失败！',
						showCancel: false
					});
				}
			},

			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
							}
							queryFrontInProfitAmt(param).then(res => {
								if (res.data.code === 200) {
									that.inProfitList = res.data.data
								} else {
									uni.showModal({
										content: '已入账列表数据加载失败！',
										showCancel: false
									});
								}
							})
						},
						complete() {
							uni.hideLoading();
						}
					});

				}
			},

			targetToOrder(id) {
				console.log('id', id)
				if (id) {
					uni.navigateTo({
						url: '../profit/profitInOrder?id=' + id
					})
				}
			}
		}
	}
</script>

<style>

</style>
