<template>
	<view class="group_company">
		<view class="group_head">
			<view class="group_item">
				<view>线索名称</view>
				<view class="text">{{info && info.name}}</view>
			</view>
			<view class="group_item">
				<view>线索来源</view>
				<view class="text">{{info && info.source}}</view> 
			</view>
			<view class="group_item">
				<view>下次跟进时间</view>
				<view class="text">{{info && info.next_time ? info.next_time : '--'}}</view>
			</view>
		</view>
		<!-- 标签栏 -->
		<view class="group_tab"> 
			<u-tabs name="cate_name" :list="list" :is-scroll="false" active-color="#008EFF" :current="current"
				@change="change"></u-tabs>
			<view class="processing_title" v-if="current == 0">
				<customer-dynamic v-if="info && info.id" :kehuid="info.id" :type="4"></customer-dynamic>
			</view>
			<view class="processing_title" v-if="current == 1">
				<info-detail v-if="info" :info="info"></info-detail>
			</view>
			<view class="processing_title" v-if="current == 2">
				<cust-detail v-if="info" :kehuid="info.id"></cust-detail>
			</view>
		</view>
		<view style="height:100rpx"></view>
		<!-- 底部导航栏 -->
		<view class="bottom_nav">
			<view class="bottom_item" @click="newFollowClick">
				<image :src="BASE_IMG_URL+'edit.png'" class="botimg" mode=""></image>
				<view>写新跟进</view>
			</view>
			<view class="bottom_item" @click="getaddCustomer">
				<image :src="BASE_IMG_URL+'tj.png'" class="botimg" mode=""></image>
				<view>转客</view>
			</view>
			<view class="bottom_item" @click="toCall(info.mobile)">
				<image :src="BASE_IMG_URL+'dh.png'" class="botimg" mode=""></image>
				<view>拨打电话</view>
			</view>
			<view class="bottom_item" @click="toLookMore">
				<image :src="BASE_IMG_URL+'morebtn.png'" class="botimg" mode=""></image>
				<view>更多</view>
			</view>
		</view>
		<uni-popup ref="morePopup" type="bottom" background-color="#fff">
			<view class="pull_head">更多操作</view>
			<view class="more_operation">
				<view class="more_btn" @click="editClues">编辑线索</view>
				<view class="more_btn" @click="toTransfer">更换负责人</view>
				<view class="more_btn" @click="deleteClueClick">删除线索</view>
			</view>
		</uni-popup>
		
	</view>
</template>

<script>
	import customerDynamic from 'components/content/customerDynamic/customerDynamic.vue';
	import infoDetail from './baseInfo.vue';
	import custDetail from './relateInfo.vue';
	import { netCluesDetail, netDelClues } from '@/api/clues.js'
	import { BASE_IMG_URL } from '@/util/api.js'
	export default {
		data() {
			return {
				BASE_IMG_URL:BASE_IMG_URL,
				id:'',   //线索
				info:null,
				current: 0,
				list: [{
						name: '跟进记录',
						status: 0
					},
					{
						name: '基本信息',
						status: 1
					},
					{
						name: '相关信息',
						status: 2
					},
				],
			}
		},
		onLoad(options) {
			this.id = options.id
		},
		onShow() {
			this.info = null
			this.getInfo()
		},
		onHide() {
			this.$refs.morePopup.close()
		},
		created() {
			
		},
		components: {
			customerDynamic,
			infoDetail,
			custDetail,
		},
		methods: {
			//查看更多操作
			toLookMore() {
				this.$refs.morePopup.open()
			},
			change(index) {
				this.current = index;
			},
			tabs_change(e) {
				this.current = e;
				this.mescroll.resetUpScroll();
			},
			//获取客户信息
			getInfo() {
				netCluesDetail({id:this.id}).then(res=>{
					this.info = res.data
					uni.setNavigationBarTitle({
						title:res.data.name
					})
				})
			},
			//写  新跟进
			newFollowClick() {
				uni.navigateTo({
					url:'/pagesA/crm/customerManagement/newFllow/newFllow?id='+this.info.id+'&type=4'
				})
			},
			//编辑 线索
			editClues() {
				uni.navigateTo({
					url:'/pagesA/crm/cluesManagement/cluesMore/editInfo?id='+this.id
				})
			},
			//拨打电话
			selectPhone(e) {
				let obj = e.detail
				// #ifdef MP-ALIPAY
				dd.showCallMenu({
				    phoneNumber: obj.mobile, 
				    code: '+86'
				})
				// #endif
				// #ifndef MP-ALIPAY || APP-PLUS
				uni.makePhoneCall({
					phoneNumber: obj.mobile
				})
				// #endif
				// #ifdef APP-PLUS
				plus.device.dial(obj.mobile, true);
				// #endif
			},
			
			// 任务
			taskClick() {
				this.taskShow = true;
				this.show = false;
			},
			// 取消底部弹出框
			onCancel() {
				this.taskShow = false;
				this.statusShow = false;
				this.telShow = false;
				this.show = false;
			},
			// 变更状态
			statusClick() {
				this.statusShow = true;
				this.show = false;
			},
			// 电话
			telClick() {
				this.telShow = true;
				this.show = false;
			},
			// 领取线索
			getCluesClick() {
				this.show = false;
				uni.showModal({
					title: '是否确定领取公池客户',
					content: '领取后长时间未跟进，客户将自动转为公共客户',
					cancelColor: "#008EFF",
					confirmColor: "#008EFF",
					success: function(res) {
						if (res.confirm) {
							netReceiveKehu().then(res=>{
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
								setTimeout(()=>{
									uni.navigateTo({
										url: '/pages/index/groupCompany/groupCompany?id='+res.data.id
									})
								},1000)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			// 删除线索
			deleteClueClick() {
				uni.showModal({
					title: '提示',
					content: '请确认是否删除吗？',
					cancelColor: "#008EFF",
					confirmColor: "#008EFF",
					success: (res) => {
						if (res.confirm) {
							netDelClues({id:this.id}).then(res=>{
								uni.showToast({
									title:res.msg,
									icon:'none'
								})
								this.$refs.morePopup.close()
								setTimeout(()=>{
									uni.navigateBack({
										delta:1
									})
								},2000)
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			// 隐藏遮罩层
			onClickHide() {
				this.overShow = false;
			},
			//更换负责人
			toTransfer() {
				uni.navigateTo({
					url:'/pagesA/crm/cluesManagement/cluesMore/transfer?id='+this.id
				})
			},
			//转客
			getaddCustomer() {
				uni.navigateTo({
					url: '/pagesA/crm/createCustomer/createCustomer?leads_id=' + this.id
				})
			},
			// 电话
			toCall(phone) {
				// #ifdef MP-ALIPAY
				dd.showCallMenu({
					phoneNumber: phone, // 期望拨打的电话号码
					code: '+86', // 国家代号，中国是+86
				})
				// #endif
				// #ifndef MP-ALIPAY || APP-PLUS
				uni.makePhoneCall({
					phoneNumber: phone
				})
				// #endif
				// #ifdef APP-PLUS
				plus.device.dial(phone, true);
				// #endif
			},
		}
	}
</script>

<style lang="scss">
	.pull_head {
		font-size: 34rpx;
		color: #999;
		padding: 30rpx 0;
		text-align: center;
	}
	.more_operation{
		width:750rpx;
		padding:40rpx 45rpx 100rpx;
		background:#fff;
		display: flex;
		justify-content: flex-start;
		flex-wrap:wrap;
		.more_btn{
			font-size:24rpx;
			padding:5rpx 15rpx;
			border:1rpx solid #ededed;
			margin-right:35rpx;
			margin-bottom:45rpx;
			&:nth-child(4n){
				margin-right:0;
			}
		}
	}
	.group_head {
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx 0;
		background-color: #fff;
		text-align: center;

		.group_item {
			width: 33.33%;
			color: #ccc;
			margin-bottom:15rpx;
			.text{
				line-height:48rpx;
				color: #999;
			}
			.group_htz{
				margin-top: 8rpx;
			}
		}
	}

	.group_tab {
		margin: 20rpx 0;
	}

	.bottom_nav {
		position: fixed;
		display: flex;
		bottom: 0;
		left: 0;
		right: 0;
		padding: 20rpx 0;
		background-color: #fff;
		text-align: center;
		color: #999;
		display: flex;
		justify-content: space-around;
		align-items: center;
		z-index: 2;
		.bottom_item {
			.botimg{
				width:40rpx;
				height:40rpx;
				margin-bottom:5rpx;
			}
		}
	}

	.pull_con {
		padding: 40rpx 0 10rpx;
		display: flex;
		flex-wrap: wrap;
		text-align: center;
		color: #999;

		.pull_item {
			width: 25%;

			:first-child {
				padding-bottom: 10rpx;
			}

			:last-child {
				padding-bottom: 50rpx;
			}
		}
	}
</style>
