<template>
	<view>
		<view class="search">
			<u-search 
				v-model="keyword" 
				show-action placeholder="请输入搜索关键词" 
				@change="onSearch" 
				:show-action="false"/>
		</view>
		<!-- 客户 -->
		<view v-if="type == 1 || type == 0">
			<view class="tablabel">
				<image :src="BASE_IMG_URL+'/kehu1.png'" mode="scaleToFill"></image>
				<view class="item_content">
					<view>客户</view>
					<view class="number">共{{customer.length}}个客户</view>
				</view>
			</view>
			<view class="clineInfo" v-for="(item,index) in customer" :key="index">
				<view class="info_head">
					<view>{{item.name}}</view>
					<view>{{item.follow ? item.follow : '--'}}</view>
				</view>
				<view class="info_main">
					<view class="main_left">
						<view class="left_followUp">
							<view>下次跟进时间：</view>
							<view>{{item.next_time}}</view>
						</view>
						<view class="left_star">
							<view>客户星级：</view>
							<view>
								<u-rate :count="5" v-model="item.level" disabled active-color="#FFD049" inactive-color="#b2b2b2" :size="30" :gutter="10"></u-rate>
							</view>
						</view>
					</view>
					<view class="main_right">
						<image :src="item.owner_staff.img ? item.owner_staff.img : BASE_IMG_URL+'headImg.png'" mode=""></image>
						<view>{{item.owner_staff.name}}</view>
					</view>
				</view>
				<view class="info_footer">
					<view class="footer_content" @click="followClick(item.id,1)">
						<image :src="BASE_IMG_URL+'tj.png'"  mode="scaleToFill"></image>
						<view>跟进</view>
					</view>
					<view class="footer_content" @click="linkmanClick(item.id)">
						<image :src="BASE_IMG_URL+'rq.png'"  mode="scaleToFill"></image>
						<view>联系人</view>
					</view>
					<view class="footer_content" @click="toCall(item.contacts)">
						<image :src="BASE_IMG_URL+'dh.png'"  mode="scaleToFill"></image>
						<view>电话</view>
					</view>	
					<view class="footer_content" @click="toKehuMore(item.id)">
						<view>更多</view>
						<view class="iconfont icon-iconmore-copy"></view>
					</view>
				</view>
			</view>
			<view style="height: 100rpx;"></view>
			<u-empty v-if="customer.length == 0" text="暂无更多"></u-empty>
			<view style="height: 100rpx;"></view>
		</view>
		<!-- 线索 -->
		 <view v-if="type == 2 || type == 0">
			<view class="tablabel">
				<image :src="BASE_IMG_URL+'xiansuo1.png'" mode="scaleToFill"></image>
				<view class="item_content">
					<view>线索</view>
					<view class="number">共{{leads.length}}条线索</view>
				</view>
			</view>
			<view class="clineInfo" v-for="(item,index) in leads" :key="index">
				<view class="info_head">
					<view>{{item.name}}</view>
					<view>{{item.follow ? item.follow : '--'}}</view>
				</view>
				<view class="info_main">
					<view class="main_left">
						<view class="left_followUp">
							<view>下次跟进时间：</view>
							<view>{{item.next_time?item.next_time:''}}</view>
						</view>
						<view class="left_star">
							<view>客户星级：</view>
							<view>
								<u-rate :count="5" v-model="item.level" disabled active-color="#FFD049" inactive-color="#b2b2b2" :size="30" :gutter="10"></u-rate>
							</view>
						</view>
					</view>
					<view class="main_right">
						<image :src="item.owner_staff.img ? item.owner_staff.img : BASE_IMG_URL+'headImg.png'"  mode="scaleToFill"></image>
						<view>{{item.owner_staff.name}}</view>
					</view>
				</view>
				<view class="info_footer">
					<view class="footer_content" @click="followClick(item.id,4)">
						<image :src="BASE_IMG_URL+'tj.png'"  mode="scaleToFill"></image>
						<view>跟进</view>
					</view>
					<view class="footer_content" @click="toCall(item)">
						<image :src="BASE_IMG_URL+'dh.png'"  mode="scaleToFill"></image>
						<view>电话</view>
					</view>
					<view class="footer_content" @click="moreClick(item)">
						<view>更多</view>
						<view class="iconfont icon-iconmore-copy"></view>
					</view>
				</view>
			</view>
			<view style="height: 100rpx;"></view>
			<u-empty v-if="leads.length == 0" text="暂无更多"></u-empty>
			<view style="height: 100rpx;"></view>
		</view>
		<!-- 联系人 -->
		<view v-if="type == 3 || type == 0">
			<view class="tablabel">
				<image :src="BASE_IMG_URL+'dh.png'" mode="scaleToFill"></image>
				<view class="item_content">
					<view>联系人</view>
					<view class="number">共{{contacts.length}}个联系人</view>
				</view>
			</view>
			<view class="clineInfo" v-for="(item,index) in contacts" :key="index">
				<view class="info_head_con">
					<view class="head_name">
						{{item.name}} 
					</view>
					<view class="head_import" v-if="item.is_major == 1">首联系人</view>
				</view>
				<view class="info_main_con">
					<view class="left_star">
						<view>职务：</view>
						<view>{{item.post ? item.post : '--' }}</view>
					</view>
					<view class="left_star">
						<view>角色：</view>
						<view>{{item.role ? item.role : '--'}}</view>
					</view>
				
					<view class="left_star">
						<view>手机：</view>
						<view>{{item.mobile ? item.mobile : '--'}}</view>
					</view>
				
					<view class="left_star">
						<view>生日：</view>
						<view>{{item.birthday ? item.birthday : '--'}}</view>
					</view>
				</view>
				<view class="info_footer">
					<view class="footer_content" @click="followClick(item.id,2)">
						<image :src="BASE_IMG_URL+'tj.png'"  mode="scaleToFill"></image>
						<view>跟进</view>
					</view>
					<view class="footer_content" @click="ToCall(item)">
						<image :src="BASE_IMG_URL+'dh.png'"  mode="scaleToFill"></image>
						<view>电话</view>
					</view>
					<view class="footer_content" @click="toMore(item.id)">
						<view>更多</view>
						<view class="iconfont icon-iconmore-copy"></view>
					</view>
				</view>
			</view>
			<view style="height: 100rpx;"></view>
			<u-empty v-if="contacts.length == 0" text="暂无更多"></u-empty>
			<view style="height: 100rpx;"></view>
		</view>
	
	</view>
</template>

<script>
	import { BASE_IMG_URL } from '@/util/api.js'
	import { netQueryData } from '@/api/kehu.js'
	
	export default{
		data() {
			return{
				BASE_IMG_URL:BASE_IMG_URL,
				type:0,   //0全部   1客户   2线索    3联系人
				keyword:'',
				customer:[],
				leads:[],
				contacts:[],
				telShow: true,
				description:'',
			}
		},
		onLoad(options) {
			this.type = options.type
			this.keyword = options.word
			if(this.keyword){
				this.getList()
			}
		},
		methods:{
			onInputCancel() {
				uni.navigateBack({
					delta:1
				})
			},
			onSearch(e) {
				if(!e){
					return
				}
				this.keyword = e
				let searlist = uni.getStorageSync('searchword')
				if(searlist){
					if(searlist.indexOf(this.keyword) != -1) {
						let index = searlist.indexOf(this.keyword)
						searlist.splice(index,1)
					}
					if(searlist.length >= 10) {
						searlist.shift()
						searlist.push(this.keyword)
					}else{
						searlist.push(this.keyword)
					}
				}else{
					searlist = []
					searlist.push(this.keyword)
				}
				uni.setStorageSync('searchword',searlist)
				this.getList()
			},
			getList() {
				let params = {
					keywords: this.keyword
				}
				netQueryData(params).then(res=>{
					this.leads = res.data.leads
					this.customer = res.data.customer
					this.contacts = res.data.contacts
				})
			},
			// 跟进
			followClick(id,type) {
				uni.navigateTo({
					url:'/pagesA/crm/customerManagement/newFllow/newFllow?id='+id+'&type='+type
				})
			},
			// 联系人
			linkmanClick(id) {
				uni.navigateTo({
					url:'/pagesA/crm/linkman/newLinkman/newLinkman?id='+id
				})
			},
			//客户 更多
			toKehuMore(id) {
				uni.navigateTo({
					url: '/pages/index/groupCompany/groupCompany?id='+id
				})
			},
			// 电话
			toCall(item) {
				// #ifdef MP-ALIPAY
				dd.showCallMenu({
				    phoneNumber: item.mobile, 
				    code: '+86'
				})
				// #endif
				// #ifndef MP-ALIPAY || APP-PLUS
				uni.makePhoneCall({
					phoneNumber: item.mobile
				})
				// #endif
				// #ifdef APP-PLUS
				plus.device.dial(item.mobile, true);
				// #endif
			},
			// 线索  更多
			moreClick(item) {
				uni.navigateTo({
					url:'/pagesA/crm/cluesManagement/cluesMore/cluesMore?id='+item.id
				})
			},
			// 联系人 更多
			toMore(id) {
				uni.navigateTo({
					url: "/pages/index/groupCompany/contact/contactDetail?id=" + id
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.tablabel{
		padding:20rpx 30rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		background:#fff;
		image {
			width: 50rpx;
			height: 50rpx;
			background-color: #fff;
		}
		.item_content{
			font-size:28rpx;
			color:#333;
			margin-left:15rpx;
			.number{
				font-size:24rpx;
				color:#999;
				margin-top:10rpx;
			}
		}
	}
	.clineInfo {
		margin: 0 30rpx;
		background-color: #fff;
		padding: 30rpx 24rpx;
		margin-top: 20rpx;
		border-radius: 10rpx;
		.info_head {
			display: flex;
			justify-content: space-between;
			:first-child {
				font-size: 28rpx;
				font-weight: 700;
				color: #999;
			}
			:last-child {
				&::before {
					position: relative;
					display: block;
					content: '';
					width: 10rpx;
					height: 10rpx;
					top: 24rpx;
					left: -22rpx;
					background-color: #52c1f5;
					border-radius: 5rpx;
				}
			}
		}
		.info_head_con{
			display: flex;
			justify-content: space-between;
			margin-bottom:20rpx;
			.head_name{
				.head_name {
					font-size: 28rpx;
					font-weight: 700;
					color: #999;
				}
			}
			.head_import {
				color: #f95e5a;
				border: 1rpx solid #f95e5a;
				padding: 4rpx 10rpx;
				border-radius: 10rpx;
			}
		}
		.info_main_con {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			color: #666;
			padding: 0 30rpx 20rpx;
			border-bottom:1rpx solid #CCC;
			margin-bottom:15rpx;
			.left_star {
				display: flex;
				width: 50%;
				line-height: 60rpx;
			}
		}
		.info_main {
			display: flex;
			justify-content: space-between;
			flex-wrap: wrap;
			.left_star {
				display: flex;
				padding-bottom: 20rpx;
			}
			.main_left {
				.left_followUp {
					display: flex;
					padding: 20rpx 0;
				}
	
				.left_star {
					display: flex;
					padding-bottom: 20rpx;
				}
			}
	
			.main_right {
				text-align: center;
				padding: 20rpx 20rpx 0 0;
				image {
					width: 44rpx;
					height: 44rpx;
					border-radius: 50%;
					margin-bottom: 5rpx;
				}
			}
		}
	
		.info_footer {
			display: flex;
			justify-content: space-between;
			padding-top: 10rpx;
			height: 28rpx;
	
			.footer_content {
				// width: 25%;
				line-height: 28rpx;
				display: flex;
				justify-content: center;
				align-items: center;
				image{
					width: 48rpx;
					height: 48rpx;
					margin-right: 15rpx;
				}
				.icon-iconmore-copy {
					font-size: 22rpx;
					margin-left: 5rpx;
					margin-top: 2rpx;
				}
				
			}
		}
	}
</style>
