<template>
	<view class="content">
		<view class="top">
			<u-search placeholder="输入名称搜索" v-model="searchKey" @custom="search()" @search="search()"></u-search>
		</view>
		<mescroll-body top="88rpx" bottom="0" ref="mescrollRef" @init="mescrollInit"    :down="downOption" :up="upOption" @down="downCallback" @up="upCallback">
		<view class="customer-list">
			<view class="customer-item"  v-for="(item) in dataList"  @click="navTo('/pages/user/crm/customerDetails?customerId='+item.customerId)" >
				<view class="name-box">
					<view class="name">{{item.customerName}}</view>
					<view class="btns">
						<image class="btn" src="../../../static/images/sms.png"></image>
						<image class="btn" src="../../../static/images/phone.png"></image>
					</view>
				</view>
				<view class="desc-box">
					<view class="label">最后跟进：</view>
					<view class="value">{{item.startTime}}</view>
				</view>
				<view class="desc-box">
					<view class="label">所在地区：</view>
					<view class="value">{{item.address}}</view>
				</view>
				<view class="desc-box">
					<view class="label">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注：</view>
					<view class="value">{{item.remark}}</view>
				</view>
				 
			</view>
		</view>
		</mescroll-body>
	</view>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	
	import {getMyCustomerList} from '@/api/crm.js'
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				searchKey:"",
				mescroll:null,
				downOption: {
					auto:false//不要自动加载
				},
				upOption: {
					onScroll:false,
					use: true, // 是否启用上拉加载; 默认true
					page: {
						num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
						size: 10 // 每页数据的数量,默认10
					},
					noMoreSize: 10, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
					textNoMore:"已经到底了",
					empty: {
						icon:'/static/images/empty.png',
						tip: '暂无数据'
					}
				},
				dataList: []
			}
		},
		onShow() {
		},
		methods: {
			search(){
				this.mescroll.resetUpScroll()
			}, 
			navTo(url){
				uni.navigateTo({
					url: url
				})
			},
			mescrollInit(mescroll) {
				this.mescroll = mescroll;
			},
			/*下拉刷新的回调 */
			downCallback(mescroll) {
				mescroll.resetUpScroll()
			},
			upCallback(page) {
				//联网加载数据
				var that = this;
				var data={
					customerName:this.searchKey,
					pageNum: page.num,
					pageSize: page.size
				};
				uni.showLoading({
					title:"加载中..."
				})
				getMyCustomerList(data).then(res => {
					uni.hideLoading()
					if(res.code==200){
						//设置列表数据
						if (page.num == 1) {
							that.dataList = res.data.list; 
							
						} else {
							that.dataList = that.dataList.concat(res.data.list);
							 
						}
						that.mescroll.endBySize(res.data.list.length, res.data.total);
						
					}else{
						uni.showToast({
							icon:'none',
							title: "请求失败",
						});
						that.dataList = null;
						that.mescroll.endErr();
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		
		height: 100%;
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.content{
		height: 100%;
		padding: 0rpx;
		position: relative;
		.top{
			z-index: 10000;
			width: 100%;
			position: absolute;
			top:0rpx;
			left:0rpx;
			height: 88rpx;
			background-color: #fff;
			padding: 0rpx 15rpx;
		}
		.customer-list{
			display: flex;
			flex-direction: column;
			padding: 15rpx;
			.customer-item{
				padding: 15rpx;
				border-radius: 15rpx;
				background-color: #fff;
				margin-bottom: 15rpx;
				width: 100%;
				.name-box{
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					.name{
						flex: 1;
						font-size: 38rpx;
						color:#111;
					}
					.btns{
						.btn{
							margin-left: 10rpx;
							width: 45rpx;
							height:45rpx;
						}
					}
				}
				.desc-box{
					margin-top: 15rpx;
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: flex-start;
					.label{
						font-size: 28rpx;
						color: #a8a8a8;
					}
					.value{
						font-size: 28rpx;
						color: #a8a8a8;
					}
					
					
				}
			}
		}
		
	}
	 
</style>
