<template>
	<view>
		<!-- 顶部导航栏 -->
		<view class="select_warp">
			<view class="manage_tab">
				<view class="tab_array">
					<image :src="BASE_IMG_URL+'ss.png'" mode="scaleToFill"></image>
					<input type="text" :class="name ? 'valueactive' : '' " @input="searchName" v-model="name"
						placeholder="线索名称" class="li_box" />
				</view>
				<view class="tab_screen" @click="toSearch">
					<image :src="BASE_IMG_URL+'shaixuan.png'" mode="scaleToFill"></image>
				</view>
			</view>
		</view>
		
		<scroll-view scroll-x="true" style="width:750rpx;padding:0 24rpx;box-sizing: border-box;background:#fff">
			<view class="tabbox">
				<view class="tabli" v-for="(item,index) in tabList" :key="index" :class="{'tabactive': status == index}"
					@click="changeTab(index)">
					<view class="tabname">{{item}}</view>
					<view class="tabot"></view>
				</view>
			</view>
		</scroll-view>

		<!-- 内容模块 -->
		<view class="clues_content">
			<view class="clues_item" v-for="(item,index) in list" :key="index">
				<view class="info_head">
					<view style="width: #333333; font-size: 34rpx;">{{item.name ? item.name : '--'}}</view>
				</view>
				<view class="info_main" @click="moreClick(item)">
					<view class="main_left">
						<view class="left_followUp">
							<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 class="left_foot">
							<view class="l_box">
								<span>{{item.source ? item.source : '--'}}</span>
							</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 ? item.owner_staff.name : '--'}}</view>
					</view>
				</view>
				<view class="info_footer">
					<view class="footer_content" @click="newFollowClick(item.id,4)">
						<image :src="BASE_IMG_URL+'morebtn.png'" mode="scaleToFill"></image>
						<view>跟进</view>
					</view>
					<view class="footer_content" @click="getaddCustomer(item.id)">
						<image :src="BASE_IMG_URL+'tj.png'" mode="scaleToFill"></image>
						<view>转客</view>
					</view>
					<view class="footer_content" @click="toCall(item.mobile)">
						<image :src="BASE_IMG_URL+'dh.png'" mode="scaleToFill"></image>
						<view>电话</view>
					</view>

				</view>
			</view>
			<view style="height: 200rpx;"></view>
			<u-empty margin-top="500rpx" v-if="list.length == 0" text="暂无更多"></u-empty>
		</view>

		<view class="btn_fix" @click="newCluesClick">
			<image :src="BASE_IMG_URL+'1.png'" mode="scaleToFill"></image>
		</view>
		
		<screen-pop ref="screenChild" 
			@sureParams="sureParams" 
			:searchForm="searchForm" 
			@changeSearchData="changeSearchData"
			@resetForm="resetForm"
		></screen-pop>
	</view>
</template>

<script>
	import screenPop from './screen.vue'
	import {
		netCluesList
	} from '@/api/clues.js'
	import {
		netSearchStaffList,
		netAddkehu
	} from '@/api/kehu.js'
	import {
		BASE_IMG_URL
	} from '@/util/api.js'
	export default {
		components:{
			screenPop
		},
		data() {
			return {
				page: 1,
				limit: 10,
				totalPage: 1,
				list: [],
				BASE_IMG_URL: BASE_IMG_URL,
				name: '',
				tabList: ['全部', '我负责的', '下属负责的', '今日待跟进', '今日已联系', '从未跟进的'],
				status: 0,
				queryParams:{},
				searchForm:[]
			}
		},
		onLoad(options) {
			if (options.startTime) {
				this.start_time = options.startTime
				this.end_time = options.endTime
			}
			if(options.stime){
				this.status = options.status
				this.start_time = options.stime
				this.end_time = options.etime
			}
			//获取搜索表单
			this.getSearchForm()
		},
		onShow() {
			this.init()
		},
		onReachBottom() {
			if (this.page >= this.totalPage) {
				return
			}
			this.page++
			this.getList()
		},
		methods: {
			getSearchForm() {
				this.handleSearchForm('leads',(data)=>{
					this.searchForm = data
				})
			},
			changeSearchData(type,key,value){
				let arr = this.searchForm
				arr.forEach((ele,index)=>{
					if(ele.field == type){
						ele[key] = value
						this.$set(this.searchForm, index, ele)
					}
				})
			},
			resetForm() {
				this.searchForm = this.handleResetSearch(this.searchForm)
			},
			toSearch() {
				let obj = {
					type:'DatePicker',
					start_time:this.start_time,
					end_time:this.end_time
				}
				this.$refs.screenChild.init(obj)
			},
			sureParams(params){
				this.queryParams = params
				this.init()
			},
			changeTab(status) {
				this.status = status
				this.init()
			},
			init() {
				this.page = 1
				this.totalPage = 1
				this.list = []
				setTimeout(()=>{
					this.getList()
				},200)
			},
			//搜索
			searchName(e) {
				this.name = e.detail.value
				this.init()
			},
			//线索 列表 
			getList() {
				let params = {
					page: this.page,
					limit: this.limit,
					name: this.name,
					createtime: (this.start_time && this.end_time) ? (this.start_time + ',' + this.end_time) : '',
					staff_id: this.staffObj?this.staffObj.id:'',
					team: this.status,
					...this.queryParams,
					...this.handleSureSearch(this.searchForm)
				}
				netCluesList(params).then(res => {
					this.list = this.list.concat(res.data.data)
					this.totalPage = res.data.last_page
				})
			},
			// 跟进
			newFollowClick(id, type) {
				uni.navigateTo({
					url: '/pagesA/crm/customerManagement/newFllow/newFllow?id=' + id + '&type=' + type
				})
			},
			//转客
			getaddCustomer(id) {
				uni.navigateTo({
					url: '/pagesA/crm/createCustomer/createCustomer?leads_id=' + id
				})
			},
			// 更多
			moreClick(item) {
				uni.navigateTo({
					url: '/pagesA/crm/cluesManagement/cluesMore/cluesMore?id=' + item.id
				})
			},
			// 新建线索
			newCluesClick() {
				uni.navigateTo({
					url: '/pagesA/crm/cluesManagement/newClues/newClues'
				})
			},
			
			// 电话
			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">
	.tabbox {
		height: 80rpx;
		display: flex;
		justify-content: flex-start;
		background: #fff;

		.tabli {
			padding-top: 20rpx;
			flex-shrink: 0;
			margin-right: 35rpx;
			position: relative;

			.tabname {
				font-size: 26rpx;
				color: #666;
				text-align: center;
				margin-bottom: 15rpx;
			}

			.tabot {
				width: 80rpx;
				height: 8rpx;
				border-radius: 4rpx;
				background: #fff;
				position: absolute;
				left: 50%;
				transform: translateX(-50%);
				bottom: 0;
			}
		}

		.tabactive {
			.tabot {
				background: $uni-text-color;
			}
		}
	}


	.left_foot {
		padding-bottom: 20rpx;
		margin: 20rpx 0;

		.l_box {
			margin-right: 35rpx;
			float: left;

			span {
				background: $uni-text-color-opcity;
				padding: 5rpx 12rpx;
				font-size: 26rpx;
				color: $uni-text-color;
				border-radius: 5rpx;
			}
		}
	}

	.valueactive {
		color: #333;
	}

	.select_warp {
		z-index: 9;
		position: relative;
	}

	.searchbox {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: $uni-text-color;
		display: flex;
		justify-content: space-around;
		margin-bottom: 40rpx;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1;

		.tab_array {
			display: flex;
			background: #fff;
			border-radius: 34rpx;
			height: 68rpx;
			width: 467rpx;

			image {
				width: 50rpx;
				height: 50rpx;
				margin: 8rpx 15rpx 0 28rpx;
			}

			input {
				line-height: 68rpx;
				height: 68rpx;
			}
		}

		.searchtext {
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 30rpx;
			color: #999;
			margin-right: 55rpx;
		}
	}

	.manage_tab {
		width: 100%;
		height: 80rpx;
		line-height: 80rpx;
		background-color: $uni-text-color;
		display: flex;
		justify-content: space-around;
		z-index: 1;

		.tab_array {
			display: flex;
			background: #fff;
			border-radius: 34rpx;
			height: 68rpx;
			width: 467rpx;
			overflow: hidden;

			image {
				width: 50rpx;
				height: 50rpx;
				margin: 8rpx 15rpx 0 28rpx;
			}

			input {
				line-height: 68rpx;
				height: 68rpx;
			}
		}

		.tab_screen {
			display: flex;

			image {
				width: 43rpx;
				height: 44rpx;
				margin-top: 10rpx;
			}
		}
	}

	.clues_content {

		// margin: 0 24rpx;
		// margin-top: 100rpx;
		.clues_item {
			background-color: #fff;
			border-radius: 10rpx;
			margin-top: 20rpx;
			padding: 20rpx 24rpx;
			box-shadow: 2rpx 2rpx 50rpx rgba(0, 0, 0, 0.1);

			.info_head {
				display: flex;
				justify-content: space-between;

				:first-child {
					font-size: 28rpx;
					font-weight: 700;
					color: #333;
				}

			}

			.info_main {
				display: flex;
				justify-content: space-between;
				padding-bottom: 20rpx;
				border-bottom: 1px solid #ededed;

				.main_left {
					.left_followUp {
						display: flex;
						padding: 20rpx 0;
						font-size: 30rpx;
						color: #666;
						margin: 20rpx 0;
					}

					.left_star {
						display: flex;
						padding-bottom: 20rpx;
						font-size: 30rpx;
						color: #666;
					}
				}

				.main_right {
					text-align: center;
					padding: 20rpx 20rpx 0 0;

					image {
						width: 129rpx;
						height: 129rpx;
						margin-bottom: 5rpx;
						border-radius: 50%;
					}
				}
			}

			.info_footer {
				display: flex;
				justify-content: space-around;
				padding-top: 30rpx;
				height: 80rpx;

				.footer_content {
					line-height: 80rpx;
					display: flex;
					justify-content: center;
					align-items: center;

					image {
						width: 48rpx;
						height: 48rpx;
						margin-right: 15rpx;
					}

					.icon-iconmore-copy,
					.icon-follow {
						font-size: 22rpx;
					}

					.icon-follow,
					.icon-task,
					.icon-tel {
						margin-right: 5rpx;
					}

					.icon-iconmore-copy {
						margin-left: 5rpx;
						margin-top: 2rpx;
					}
				}
			}
		}
	}

	.btn_fix {
		position: fixed;
		bottom: 100rpx;
		right: 80rpx;

		image {
			width: 80rpx;
			height: 80rpx;

			background-color: #fff;
			border-radius: 40rpx;
		}
	}
</style>
