<template>
	<view class="hb column">
		<view class="topBgline plr20">
			<view class="justify-between p30 bgcolf radius12 align-center">
				<view class="ml16">
					<view class="bold fs28 justify-start align-center">
						<text>{{detailUser.nickname}}</text>
						<image class="list-item-copy ml8" :src="imgPath+'/app/images/copy_icon.png'" mode="aspectFill"
							@click="copyId(detailUser.nickname)">
					</image>
					</view>
					<view class="fs24 base-color-6 mt8" >跟进人:林新新</view>
					<view class="fs24 base-color-6">注册时间：{{detailUser.createTime}}</view>
				</view>
				<u-avatar :src='detailUser.avatar' shape="square" size='50'></u-avatar>
			</view>
		</view>
		<view class="p20">
			<view class="justify-between bgf p40 radius12">
				<view>
					<view>客户标签</view>
					<view class="base-color-6 fs24">{{detailUser.tag?detailUser.tag:'暂无'}}</view>
				</view>
				<view class="justify-start align-center base-color-6 fs24">
					<!-- <view>共{{detailUser.tag.length?detailUser.tag.length:'0'}}个</view> -->
					<view>{{detailUser.tag.length?detailUser.tag.split(",").length:'0'}}</view>
					<image :src="imgPath+'/app/images/right_arrow.png'" class="w12 h20 ml12"></image>
				</view>
			</view>
		</view>
		<view class="w100 bgf align-center justify-center">
			 <u-tabs :list="list1" @click="clicktab" lineWidth='30' activeStyle="{color:'#333';font}"></u-tabs>
		</view>
		<view class="bgf flex-1 hidden h100">
			<scroll-view scroll-y="true" class="hb" :refresher-enabled="isEnabled" :refresher-triggered="triggered"
				refresher-background="rgba(0,0,0,0)" @refresherrefresh="pullDownRefresh"
				@refresherrestore="triggered = false" :upper-threshold="100" :lower-threshold="100"
				@refresherabort="triggered = false" @scrolltolower="reachBottom">
				<view v-for="(item,index) in userlist" :key="index" class="p20">
					<view class="justify-between align-center">
						<view>{{item.operationType}}</view>
						<view class="base-color-6 fs24">{{item.createTime}}</view>
					</view>
					<view v-html="item.text"></view>
				</view>
				<u-loadmore :status="status" />
				
				<view class="h80 w100"></view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		getuserTrajectory
	} from "@/api/courseManage.js";
	export default {
		data() {
			return {
				detailUser:{},
				list1: [{
					name: '行为轨迹',
					value:1
				}],
				pageNum:1,
				pageSize:6,
				id:'',
				userlist:[],
				isEnabled:true,
				triggered: false,
				status:'loadmore'
			}
		},
		computed: {
		    imgPath() {
		      return this.$store.state.imgpath
		    },
			imgname() {
			  return this.$store.state.logoname
			}
		},
		onShow() {
			this.detailUser =uni.getStorageSync('detailUser')
			this.getuserlist()
		},
		onLoad(option) {
			this.id=option.id
		},
		methods: {
			pullDownRefresh() {
				// 下拉
				this.triggered = true; //下拉了状态为true
				setTimeout(() => {
					this.triggered = false;
					uni.stopPullDownRefresh()
					this.pageNum = 1;
					this.getuserlist('refresh') //触底  不穿执行else
				}, 1000)
			},
			reachBottom() {
				//上拉
				// status这个是加载状态
				if (this.status === 'loadmore') {
					this.status = 'loading'
					uni.showNavigationBarLoading()
					setTimeout(() => {
						this.pageNum++
						this.getuserlist() //触底  不穿执行else
						uni.hideNavigationBarLoading()
					}, 1000);
				}
			},
			getuserlist(type){
				const data={
					userId:this.id,
					pageNum:this.pageNum,
					pageSize:this.pageSize
				}
				getuserTrajectory(data).then(res=>{
					if(res.code==200){
						if (type == 'refresh') {
							this.userlist = res.data.list
						} else {
							// 加载更多 当前页和下一页合并
							this.userlist = [...this.userlist, ...res.data.list]
						}
						if (this.pageNum >= res.data.pages) {
							this.status = 'nomore'
						} else {
							this.status = 'loadmore'
						}
						console.log(res)
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			clicktab(item) {
				console.log('item', item);
			},
			copyId(id) {
				setTimeout(()=>{
					uni.setClipboardData({
						data: String(id),
						success: () => {
							uni.showToast({
								title: '复制成功',
								icon: 'none',
								duration: 2000
							});
						},
					})
				},200)
			},
		}
	}
</script>

<style lang="scss" scoped>
.topBgline {
	background: linear-gradient(to right, rgba(225, 238, 255, 1), rgba(223, 224, 254, 1));
	padding-top: 40rpx;
}
.bgcolf {
	background: rgba(255, 255, 255, 0.4);
}
.list-item-copy {
	width: 20px;
	height: 20px;
}
</style>
