<template>
	<app-layout :haveBackground="false">
	<view class="page">
		<view class="search main-left cross-center">
			<image style="margin-right: 15rpx;" src="https://t17.9026.com/web/statics/image/sale/search_icon.png"
				mode=""></image><input type="text" v-model="searchVal" @input="search" placeholder-class="search_plh_class" placeholder="客户名、楼盘名">
		</view>
		<view class="list">
			<view class="main-between cross-center item" v-for="(item,index) in dataList" :key="index"
				@click="navCusmterInfo(item.id,item.name,item.mobile,item.user_id)">
				<view class="main-left">
					<view>
						<image style="width: 94rpx;height: 94rpx;border-radius: 50%;margin-right: 26rpx;"
							:src="item.avatar" mode=""></image>
					</view>
					<view class="main-between-y ">
						<view class="name cross-center">{{item.name}}
							<image style="width: 96rpx; height: 32rpx;margin-left: 10rpx;"
								:src="item.is_verify==1?'https://t17.9026.com/web/statics/image/index/ysm.png':''"
								mode=""></image>
						</view>
						<view class="addr t-omit">{{item.estate.name}} {{item.estate.estate_no}}{{item.estate.room_no}}
						</view>
					</view>
				</view>
				<image style="width: 13rpx;height: 21rpx;"
					src="https://t17.9026.com/web/statics/image/sale/arrow_right.png" mode=""></image>
			</view>
			<view class="no-more" v-if="noMore && dataList.length>0">没有更多了...</view>
			<view style="height: 200rpx;"></view>
			<app-no-goods v-if="dataList.length === 0" :title="'暂无数据'" background="#ffffff"></app-no-goods>
		</view>
		<navigator url="/pages/sale/cusmter/addCustomer" hover-class="navigator-hover" v-if="why!='select_customer'">
			<button class="addPro" type="default">添加客户</button>
		</navigator>
	</view>
	</app-layout>
</template>

<script>
	import appNoGoods from '@/components/page-component/app-no-goods/app-no-goods.vue';
	export default {
		components:{
			appNoGoods
		},
		data() {
			return {
				searchVal:"",
				dataList: [],
				page:1,
				
				noMore:false,
				why:'',
				dk:0,
			};
		},
		onLoad(option) {
			this.why=option.why
			this.dk = option.dk
			console.log(this.dk)
		},
		onShow() {
			this.getData()
		},
		onReachBottom() {
			if(!this.noMore){
				this.page++
				this.getData()
			}
		},
		methods: {
			search(){
				this.$utils.debounce(()=>{
					this.page=1
					this.getData()
				},800)
			},
			getData(){
				this.$showLoading()
				this.$request({
					url: this.$api.sale.customer_list,
					data: {
						page: this.page,
						keyword: this.searchVal,
					},
					method: 'post'
				}).then(res => {
					if (res.code === 0) {
						if(this.page===1){
							this.dataList = res.data.list
						}else{
							this.dataList=this.dataList.concat(res.data.list)
						}
						if(res.data.list.length<20){
							this.noMore=true
						}
					}
					this.$hideLoading()
				})
			},
			navCusmterInfo(id,name,mobile,user_id) {
				if(this.why==='select_customer'){
					if(user_id==0){
						uni.showModal({
						    title: '提示',
						    content: '客户暂未绑定，请联系',
						    success: (res)=> {
						        if (res.confirm) {
						            return
						        } else if (res.cancel) {
									return
						        }
						    }
						});
						return
					}
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2]; //上一个页面
					prevPage.$vm.customerInfo={user_id:user_id,name:name,mobile:mobile}
					uni.navigateBack()
				}else{
					uni.navigateTo({
						url: `/pages/sale/cusmter/info?id=${id}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		background-color: #fff;
		padding-top: 20rpx;
	}

	.search {
		width: 678rpx;
		height: 77rpx;
		background: #F8F8F8;
		border-radius: 39rpx;
		margin: auto;
		padding: 0 43rpx;

		input {
			width: 100%;
		}

		image {
			width: 24rpx;
			height: 27rpx;
		}
	}

	/deep/.search_plh_class {
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
	}

	.list {margin-top: 20rpx;
		.item {
			background-color: #fff;
			height: 145rpx;
			width: 678rpx;
			margin: 0 auto;
			border-bottom: 1rpx solid #EEEEEE;

			.name {
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #222222;
			}

			.addr {
				width: 490rpx;
				font-size: 24rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #999999;
			}
		}
	}

	.addPro {
		position: fixed;
		bottom: 0;
		width: 100%;
		height: 100rpx;
		background: #A18353;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #FFFFFF;
	}
	.no-more {
		font-size: 24rpx;
		font-weight: 500;
		color: #666666;
		margin-top: 37rpx;
		text-align: center;
	}
</style>
