<template>
	<view>
		<text class="iconfont icon-youjiantou zuojiantou" style="top: 20rpx;" @click="goBack()" ></text>
		<template v-if="title">
			<view style="padding-top: 50rpx;"><my-list-item :title="title" :lists="lists"></my-list-item></view>
			<view v-if="lists.length<=0" style="text-align: center;margin-top: 40rpx;">暂无{{typeName}}记录</view>
		</template>
	</view>
</template>

<script>
	// import myListItem from "@/components/my-list-item/my-list-item.vue";
	import api from "@/api/api";
	export default {
		// components:{
		// 			myListItem
		// 		},

		data() {
			return {
				title:[],
				lists:[],
				fileId:'',
				type:'1',
				userId: uni.getStorageSync('cffp_userId'),
				typeName:'',
				shareId:'',
				readId:'',
				queryDate:''
			}
		},
		methods: {
			goBack() {
				uni.navigateBack({
					delta: 1
				});
			},
			queryLists(obj){
				const params = {
					userId:this.userId,
					fileId:this.fileId,
					shareId:this.shareId?this.shareId:undefined,
					readId:this.readId?this.readId:undefined,
					queryDate:this.queryDate?this.queryDate:undefined
				}
				api[obj.req](params).then(res=>{
					if(res['success']){
						const r = res['data'][obj.result];
						if(r && r.length>0){
							for(let i=0;i<r.length;i++){
								this.lists.push({id:r[i][obj.id],readCount:r[i][obj.readCount],children:JSON.parse(JSON.stringify(obj.children))});
								for(let m=0;m<this.lists[i]['children'].length;m++){
									this.lists[i]['children'][m]['value'] = r[i][this.lists[i]['children'][m]['alias']] ? r[i][this.lists[i]['children'][m]['alias']] : this.lists[i]['children'][m]['value'];
									if(this.lists[i]['children'][m].needParam){
										this.lists[i]['children'][m]['link'] += r[i][obj.id]
										this.lists[i]['children'][m]['readCount'] += r[i][obj.readCount]
										this.lists[i]['children'][m]['buyCount'] += r[i][obj.buyCount]
									}
								}	
							}
						}
					}else{
						this.lists = []
					}
				})
			}
		},
		onLoad(option) {
			this.fileId = option.fileId;
			// type 1为分享明细 2阅读明细 3购买明细
			this.type = option.type;
			this.shareId = option.shareId;
			this.readId = option.readId;
			this.queryDate = option.queryDate;
		},
		mounted() {
			if(this.type=='1'){
				this.typeName = '分享';
				this.title = [
					{no:1,name:'分享时间',width: '40%'},
					{no:2,name:'分享链接',width: '35%'},
					{no:3,name:'阅读明细',width: '25%'},
				];
				this.queryLists(
					{
						req:'userShareLinkList',
						result:'userShareLinks',
						id:'shareId',
						readCount:'readCount',
						children:[
							{no:1,name:'分享时间',width: '40%',value:'',link:null,alias:'shareDate'},
							{no:2,name:'分享链接',width: '35%',value:'',link:null,alias:'shareUrl'},
							{no:3,name:'阅读明细',width: '25%',value:'阅读明细',link:`/pages/commonDetail/commonDetail?fileId=${this.fileId}&type=2&shareId=`,needParam:true,readCount: ''},
						]
					}
				);
			}else if(this.type=='2'){
				this.typeName = '阅读';
				this.title = [
					{no:1,name:'用户',width: '20%'},
					{no:2,name:'阅读链接',width: '30%'},
					{no:3,name:'阅读时间',width: '25%'},
					{no:4,name:'购买明细',width: '25%'}
				];
				this.queryLists(
					{
						req:'userShareReadList',
						result:'userShareReads',
						id:'readId',
						buyCount:'buyCount',
						children:[
							{no:1,name:'用户',width: '20%',value:'',link:null,alias:'readName'},
							{no:2,name:'阅读链接',width: '30%',value:'',link:null,alias:'readUrl'},
							{no:3,name:'阅读时间',width: '25%',value:'',link:null,alias:'readDate'},
							{no:3,name:'购买明细',width: '25%',value:'购买明细',link:`/pages/commonDetail/commonDetail?fileId=${this.fileId}&type=3&readId=`,needParam:true,buyCount:''},
						]
					}
				);
			}else if(this.type=='3'){
				this.typeName = '购买';
				this.title = [
					{no:1,name:'用户',width: '30%'},
					{no:2,name:'阅读链接',width: '30%'},
					{no:3,name:'购买订单',width: '40%'},
				];
				this.queryLists(
					{
						req:'userShareBuyList',
						result:'userShareBuys',
						id:'orderId',
						children:[
							{no:1,name:'用户',width: '30%',value:'',link:null,alias:'buyName'},
							{no:2,name:'阅读链接',width: '30%',value:'',link:null,alias:'buyUrl'},
							{no:3,name:'购买订单',width: '40%',value:'',link:`/pages/orderDetail/orderDetail?id=`,alias:'orderNo',needParam:true},
						]
					}
				);
			}
		}
	}
</script>

<style lang="scss" scoped>

</style>
