<template>
	<view class="selSupplier">
		<!-- <view class="search-view">
			<u-search @custom="search()" @search="search()" @clear="search()" action-text="搜索" :clearabled="true" placeholder="客户名称/手机号" v-model="keyword"></u-search>
		</view> -->
		<view class="customer-ul" >
			<view class="gk-wrap" v-for="(item, index) in customer_list" :key="index">
				<view class="gk-top">
					<view class="top-left">
						<view class="left-name">
							<u-icon margin-left="10" name="account-fill" label-size="24" label-color="#2979ff" :label="item.name" color="#2979ff" size="28"></u-icon>
						</view>
						<view class="left-tip">
							{{item.customerType}}
						</view>
					</view>
					<view class="top-right" @click="goBf(item)">
						拜访记录<image src="../../static/img/downright.png" mode=""></image>
					</view>
				</view>
				<view class="call-wrap" @click="goCall(item.mobile)" v-if="item.mobile">
					联系客户
				</view>
				<view class="user-info">
					<view class="phone">
						{{item.mobile}}
					</view>
					<view class="brithday">
						生日：{{item.birthday?getBirthday(item.birthday): '--'}}
					</view>
					<view class="where">
						地区：{{ item.area.provinceName }}-{{ item.area.cityName }}-{{ item.area.districtName }}-{{ item.area.address }}
					</view>
				</view>
			</view>
			<!-- <view class="customer-li" v-for="(item, index) in customer_list" :key="index" @click="changeSupplier(item)">
				<view class="customer-name">{{ item.name }}</view>
				<view class="other">
					<view class="concat clearfix">
						<text class="float_left">{{ item.customerType }}</text>
						<view class="float_right" v-if="item.mobile">
							<u-icon name="phone-fill" size="26"></u-icon>
							<text class="phone-text">{{ item.mobile }}</text>
						</view>
					</view>
					<view class="address">{{ item.area.provinceName }}-{{ item.area.cityName }}-{{ item.area.districtName }}-{{ item.area.address }}</view>
				</view>
			</view> -->
		</view>
		<u-loadmore :status="load_status" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			keyword: '',
			load_status: 'nomore',
			page: 1,
			pageSize: 10,
			total: 0,
			customer_list: []
		};
	},
	onLoad() {
		this.getAllCustomer();
	},
	onPullDownRefresh() {
		this.getAllCustomer();
	},
	// 上拉加载
	onReachBottom() {
		if (this.total / this.pageSize > this.page) {
			this.page += 1;
			this.getAllCustomer();
		}
	},
	methods: {
		goBf(item) {
			uni.navigateTo({
				url:'/pagesT/customer/CommunicationLogs?id=' + item.id + '&name=' + item.name
			})
		},
		changeSupplier(item) {
			// 选择供应商返回上一页
			this._prePage().customerData = item;
			uni.navigateBack();
		},
		search() {
			this.page = 1;
			this.getAllCustomer();
		},
		getAllCustomer() {
			this.loading_status = 'loading';
			this.$u.api
				.getAllCustomer({
					page: this.page,
					pageSize: this.pageSize,
					enableStatus: 5,
					keyword: this.keyword,
					status: 2
				})
				.then(res => {
					uni.stopPullDownRefresh();
					if (this.page === 1) {
						this.customer_list = res.data;
					} else {
						this.customer_list = this.customer_list.concat(res.data);
					}
					this.total = res.pageTotal;
					this.load_status = this.$utils.loadStatus(this.page, this.pageSize, this.total);
				})
				.catch(err => {
					uni.stopPullDownRefresh();
				});
		},
		goCall(phone) {
			uni.makePhoneCall({
				phoneNumber: phone
			})
		},
		getBirthday(time) {
			let date = new Date(time*1000)
			return date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate()
		}
	}
};
</script>

<style lang="scss" scoped>
.search-view {
	position: fixed;
	z-index: 99;
	top: 0;
	left: 0;
	width: 100%;
	background-color: #ffffff;
	border-bottom: 1px solid #f5f5f5;
	padding: 20rpx;
	.input-view {
		padding: 0 24rpx;
		input {
			height: 60rpx;
			line-height: 60rpx;
			padding: 0 24rpx;
			display: inline-block;
			width: 580rpx;
			border: 1px solid #f5f5f5;
			vertical-align: middle;
			border-radius: 8rpx;
			background-color: #f7f8fa;
		}
		.add-icon {
			margin-left: 14rpx;
			display: inline-block;
			vertical-align: middle;
		}
	}
}
.customer-ul {
	// padding-top: 90rpx;
	padding-top: 20rpx;
	padding-bottom: 20rpx;
	.customer-li {
		width: 702rpx;
		margin: 0 auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		margin-top: 20rpx;
		.customer-name {
			padding: 0 20rpx;
			line-height: 80rpx;
			border-bottom: 1px solid #f5f5f5;
		}
		.other {
			font-size: 24rpx;
			padding: 10rpx 20rpx;
			line-height: 50rpx;
			.concat {
				.float_right {
					color: $uni-color-primary;
					.phone-text {
						margin-left: 10rpx;
					}
				}
			}
		}
	}
}
.gk-wrap {
	width: 710rpx;
	height: 224rpx;
	border-radius: 20rpx;
	background-color: #fff;
	margin:0 auto 20rpx;
	position: relative;
	.call-wrap {
		position: absolute;
		right: 20rpx;
		bottom: 20rpx;
		width: 126rpx;
		height: 48rpx;
		background: #4D74CF;
		border-radius: 10rpx;
		color: #fff;
		text-align: center;
		line-height: 48rpx;
		font-size: 24rpx;
		font-weight: 400;
	}
	.user-info {
		padding-left: 20rpx;
		font-size: 24rpx;
		font-weight: 500;
		color: #939393;
		.phone {
			color: #0F2447;
		}
		.brithday {
			margin: 15rpx 0;
		}
		
	}
	.gk-top {
		height: 80rpx;
		width: 100%;
		display: flex;
		justify-content: space-between;
		align-items: center;
		.top-left {
			display: flex;
			
			.left-name {
				padding: 0 20rpx;
				height: 40rpx;
				border-radius: 0 20rpx 20rpx 0;
				background-color: #ecf5ff;
				margin-right: 20rpx;
				max-width: 400rpx;
			}
			.left-tip {
				border: 1px solid #4D74CF;
				color: #4D74CF;
				height: 32rpx;
				padding: 0 10rpx;
				line-height: 32rpx;
				border-radius: 5rpx;
				font-size: 20rpx;
			}
		}
		.top-right {
			display: flex;
			align-items: center;
			padding-right: 20rpx;
			font-size: 22rpx;
			font-weight: 500;
			color: #999999;
			image {
				width: 9rpx;
				height: 17rpx;
			}
		}
	}
}
</style>
