<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 endProfitList" :key="index">
					<uni-list-item showArrow clickable :title="item.walletTime+'@'+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 endProfitList" :key="index">
					<uni-list-item showArrow clickable :title="item.walletTime+'@'+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 {
		queryFrontEndProfitAmt
	} from '@/api/profit.js'
	export default {
		data() {
			return {
				items: ['广告', '邀请'],
				typeId: 0,
				activeColor: '#007aff',
				styleType: 'text',
				endProfitList: [],
				userInfo: {}
			}
		},
		created() {
			const userInfoSync = uni.getStorageSync('userInfo')
			this.userInfo = userInfoSync
			const typeProfitId = uni.getStorageSync('typeId')
			this.typeId = typeProfitId
			if (typeProfitId) {
				this.queryFrontEndProfitAmt()
			} else {
				this.queryFrontEndProfitAmt()
			}
		},
		methods: {

			// 查询指定艺术家转入钱包收益列表
			async queryFrontEndProfitAmt() {
				const res = await queryFrontEndProfitAmt({
					creatorId: this.userInfo.id,
					type: this.typeId
				})
				if (res.data.code === 200) {
					this.endProfitList = 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
							}
							queryFrontEndProfitAmt(param).then(res => {
								//console.log('res', res)
								if (res.data.code === 200) {
									that.endProfitList = res.data.data
								} else {
									uni.showModal({
										content: '转入钱包列表数据加载失败！',
										showCancel: false
									});
								}
							})
						},
						complete() {
							uni.hideLoading();
						}
					});

				}
			},

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

<style>

</style>
