<template>
	<view>
		<view class="cu-bar search bg-gray">
			<view class="search-form round text-center">
				<text class="cuIcon-search"></text>
				<input v-model="searchval" :adjust-position="false" type="text" placeholder="搜索昵称或手机号" confirm-type="search" @confirm="pageRefresh()"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-white shadow-blur round" @click="pageRefresh()">搜索</button>
			</view>
		</view>
		<!-- <scroll-view scroll-x class="bg-white nav text-center solid-bottom">
			<block v-for="(item,index) in followstatusarr" :key="index">
			<view class="cu-item" :class="followstatus==index?'text-blue cur':''" @tap="tabSelect" :data-followstatus="index">{{item}}</view>
			</block>
		</scroll-view> -->
		
		<view class="cu-list menu-avatar">
			<view class="cu-item" v-for="(item,index) in plist" :key="index">
				<view class="cu-avatar round lg" :style="'background-image:url('+item.avatar+');'"></view>
				<view class="content">
					<view class="text-grey">{{item.nickname}}<text class="text-sm">({{item.mobile}})</text></view>
					<view class="text-orange text-sm text-cut">{{ item.userFollow.length == 0 ? followstatusarr[item.followstatus] : item.userFollow[0].remark }}</view>
					<view class="text-gray text-sm" v-if="item.userFollow.length == 0">注册时间：{{item.createtime}}</view>
					<view class="text-gray text-sm" v-else>最近跟进：{{item.userFollow[0].createtime}}</view>
				</view>
				<view class="action basis-xs">
					<view class="text-grey text-sm">{{followstatusarr[item.followstatus]}}</view>
					<view class="cu-tag bg-blue margin-top-xs" @tap="goLPage('/pages/broker/setfollow?userid='+item.id)">我要跟进</view>
				</view>
			</view>
		</view>
		
		<uni-load-more :status="pstatus"></uni-load-more>

		
	</view>
</template>

<script>
	import uniLoadMore from "@/components/uni-load-more/uni-load-more.vue";
	var _this;
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				brokerinfo: {},
				searchval: "",
				
				pstatus: 'more',
				ppage: 1,
				psize: 20,
				plist: [],
				
				followstatus: 0,
				followstatusarr: ['全部','未跟进', '未面试', '面试通过', '面试未通过', '用户放弃', '已入职', '已离职']
			};
		},
		onLoad: function(){
			_this = this;
			_this.brokerinfo = uni.getStorageSync('brokerinfo') || false;
			if (_this.brokerinfo===false){
				uni.reLaunch({
					url: "/pages/my/my"
				});
				return false;
			}
			_this.getMore();
		},
		onPullDownRefresh: function() {
			_this.ppage = 1;
			_this.pstatus = 'more';
			_this.plist = [];
			_this.getMore();
		},
		onReachBottom: function() {
			if (_this.pstatus !== 'more') {
				return;
			}
			_this.getMore();
		},
		methods: {
			getMore: function() {
				_this.$req.ajax({
					path: "broker/listuser",
					data: {
						ppage: _this.ppage,
						psize: _this.psize,
						brokerid: _this.brokerinfo.id,
						followstatus: _this.followstatus,
						keyword: _this.searchval,
					}
				}).then((data) => {
					_this.pstatus = data.pstatus;
					_this.plist = _this.plist.concat(data.plist);
					_this.ppage += 1;
					uni.stopPullDownRefresh();
				}).catch((err) => {
					uni.showModal({
						title: '信息提示',
						content: err,
						showCancel: false
					});
				});
			},
			
			pageRefresh: function() {
				_this.pstatus = 'more';
				_this.ppage = 1;
				_this.plist = [];
				_this.getMore();
			},
			tabSelect: function(e) {
				_this.followstatus = e.currentTarget.dataset.followstatus;
				_this.pageRefresh();
			},
			
			goLPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.navigateTo({
					url: pageurl,
					fail: function(){
						uni.switchTab({
						    url: pageurl
						});
					}
				});
			},
			
			goNavPage: function(pageurl) {
				_this.userinfo = _this.checkLogin("/pages/my/my");
				if (_this.userinfo===false){
					return false;
				}
				uni.redirectTo({
					url: pageurl
				});
			},
		}
	}
</script>

<style>
	.cu-list.menu-avatar .cu-item{ height: 170rpx !important; }
</style>
