<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" style="background: #F8F8F8;margin-top: 15rpx;border: 1px transparent solid;">
			<view class="main-between cross-center item dklist" v-for="(item,index) in dataList" :key="index">
				<view class="main-left" style="align-items: center;" @click="navCusmterInfo(item.id,item.name,item.mobile,item.user_id)">
					<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>
				</view>				
				<!-- <image style="width: 13rpx;height: 21rpx;"
					src="https://t17.9026.com/web/statics/image/sale/arrow_right.png" mode=""></image> -->
				<view class="check-lp">
					<view class="check-lp-text">选择楼盘下单</view>
					<view class="off-open-sider off-open-sider-show" v-if="!item.show||item.show==false" style="display: flex;"  @click="off_show(index)">
						展开
						<image class="off-open-sider-img" style="transform: rotate(90deg);"
						src="/static/image/icon/order-submit/dkorder.png" mode=""></image>
					</view>
					<view class="off-open-sider off-open-sider-hide"  v-else  style="display: flex;"  @click="off_show(index)">
						收起
						<image class="off-open-sider-img" style="transform: rotate(-90deg);"
						src="/static/image/icon/order-submit/dkorder.png" mode=""></image>
					</view>
					
				</view>
				<view class="lp-list" v-if="item.show">
					<view class="lp-list-item" v-for="(lpitem,lpindex) in item.user_estates" v-if="item.user_estates">
						<view class="lp-item-title">{{lpitem.estate.name}}</view>
						<view class="lp-item-do" @click="gotoOrder(lpitem.estate_id,item.sale_id)" style="color: #A18353;">去下单
							<image class="off-open-sider-img" style="width: 13rpx;height: 21rpx;"
							src="/static/image/icon/order-submit/dkorder.png" mode=""></image>
						</view>						
					</view>
					
				</view>
				
			</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>
	
	</view>
	
	<template>
		<view class="safe-area-inset-bottom">
			<view :style="{height: '110rpx'}" class="nav-margin "
				:class="haveBackground ? 'app-layout-background' : ''"></view>
		</view>
		<app-tab-bar :page-count="0"></app-tab-bar>
	</template>
	</app-layout>
</template>

<script>
	import appNoGoods from '@/components/page-component/app-no-goods/app-no-goods.vue';
	import AppTabBar from '@/components/basic-component/app-tab-bar/app-tab-bar.vue';
	export default {
		components:{
			appNoGoods,
			AppTabBar
		},
		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) {
						for(var i=0;i<res.data.list.length;i++){
							res.data.list[i].show = false
						}						
						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}`
					})
				}
			}, 
			off_show(index){				
				if(this.dataList[index].show){					
					this.dataList[index].show = false					
				}else{
					this.dataList[index].show = true			
				}
				
			},	
			
			//去分类下单
			gotoOrder(estate_id,sale_id){
				console.log(estate_id)
				try{
					uni.setStorageSync('dk_estate_id', estate_id);
					uni.setStorageSync('dk_sale_id', sale_id);
				}catch(e){
					console.log(e)				  
				};
				
				// 同步方式获取数据， 阻塞形式，如果做完了的话代码才会向下进行
				try{
					const dk_estate_id = uni.getStorageSync('dk_estate_id');					
					const dk_user_id = uni.getStorageSync('dk_sale_id');
					console.log("const value = uni.getStorageSync('dk_estate_id,dk_sale_id') 同步获取 = " + dk_estate_id,dk_sale_id)
				}catch(e){
					console.log(e)
					//TODO handle the exception
				};				
				uni.navigateTo({
					url: `/pages/cats/cats`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100vh;
		background-color: #fff;
		padding-top: 20rpx;
	}
	
	.dklist{
		display: inherit;
		padding: 30rpx;
		height: inherit !important;
		margin: 15rpx auto !important;
		border-radius: 15rpx;
	}
	.check-lp{
		font-size: 24rpx;
		font-weight: 500;
		color: #333;
		margin-top: 37rpx;
		display: flex;
	}
	.check-lp-text{
		flex: 1;
	}
	.off-open-sider{
		width: 80rpx;
		align-items: center;
		color: #A18353;
	}
	.off-open-sider-img{
		width: 6px;
		height: 10px;
		margin-left: 10rpx;
		position: relative;
		
	}
	.lp-list{
		font-size: 24rpx;
		font-weight: 500;
		color: #333;
		margin-top: 20rpx;
		background: #F8F8F8;
		padding: 15rpx 20rpx;
		border-radius: 15rpx;
	}
	.lp-list-item{
		display: flex;
		align-items: center;
		margin: 25rpx 0;
	}
	.lp-item-title{
		flex: 1;
	}

	.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>
