<template>
	<view class="content">
		<view class="top-box" v-if="item!=null">
			<view class="customer-box">
				<view class="left">
					<view class="name">{{item.customerName}}</view>
					<view class="desc-box">
						<view class="label">创建时间：</view>
						<view class="value"> {{item.createTime}}</view>
					</view>
					<view class="desc-box">
						<view class="label">地址：</view>
						<view class="value">{{item.address}} </view>
					</view>
				</view>
				<view class="btns">
					<image class="btn" src="../../../static/images/sms.png"></image>
					<image class="btn" src="../../../static/images/phone.png"></image>
				</view>
			</view>
			<view class="tabs">
				<u-tabs
				 :scrollable="true"
				 :list="tabs"  
				  lineColor="#115296"
				@change="tagChange">
				</u-tabs>
			</view>
			<view class="cont-box">
				<customer-info ref="customerInfo"  v-if="tabId==1"></customer-info>
			</view>
		</view>
		<u-modal :show="show"   ref="uModal" :asyncClose="true" :showCancelButton="true" title="提示" @cancel="close" @confirm="confirm" :content='content'></u-modal>
	</view>
</template>
<script>
	import customerInfo from './components/customerInfo.vue'
	import {getCustomerDetails,editCrmCustomer} from '@/api/crm.js'
	export default {
		components:{
			customerInfo, // 基本信息
		},
		data() {
			return {
				wxNickName:null,
				show:false,
				content:"",
				customerId:null,
				tabId:1,
				item:null,
				tabs:[
					{
						id:1,
						name:'用户资料'
					},
					{
						id:2,
						name:'联系人'
					},
					{
						id:3,
						name:'跟进记录'
					},
					{
						id:4,
						name:'通话记录'
					},
					{
						id:5,
						name:'短信记录'
					}
				],
			}
		},
		onLoad(option) {
			var that=this;
			uni.$on('getWeixinId', (item) => {
				console.log(item)
				
				that.content="用户昵称:"+item.data+"，是否更新";
				that.wxNickName=item.data;
				that.show=true;
			})
			this.customerId=option.customerId
			console.log(this.customerId)
			this.getCustomerDetails()
		},
		onShow() {
			
		},
		methods: {
			close(){
				this.show=false;
			},
			confirm(){
				this.show=false;
				var data = {
					customerId:this.customerId,
					weixin:this.wxNickName
					
				};
				//更新用户昵称
				var that=this;
				editCrmCustomer(data).then(res => {
					if(res.code==200){
						uni.showToast({
							icon:'none',
							title: "操作成功",
						});
						if(this.tabId==1){
							setTimeout(function(){
								that.$refs.customerInfo.getCustomerDetails(that.customerId)
							},200);
						}
					}else{
						uni.showToast({
							icon:'none',
							title: res.msg,
						});
					}
				});
				
			},
			tagChange(item){
				this.tabId=item.id
				var that = this;
				if(this.tabId==1){
					setTimeout(function(){
						that.$refs.customerInfo.getCustomerDetails(that.customerId)
					},200);
				}
			},
			getCustomerDetails() {
				//联网加载数据
				var that = this;
				var data = {
					customerId:this.customerId
				};
				getCustomerDetails(data).then(res => {
					if(res.code==200){
						this.item=res.customer;
						setTimeout(function(){
							that.$refs.customerInfo.getCustomerDetails(that.customerId)
						},200);
						
						 
					}else{
						uni.showToast({
							icon:'none',
							title: res.msg,
						});
						setTimeout(function(){
							uni.navigateBack()
						},2000);
						
					}
				});
			},
		}
	}
</script>

<style lang="scss">
	page{
		
		height: 100%;
		background: #f6f6f6;
	}
</style>
<style scoped lang="scss">
	.content{
		height: 100%;
		padding: 20rpx;
		.top-box{
			padding: 15rpx;
			background-color: #fff;
			margin-bottom: 15rpx;
			border-radius: 15rpx;
			width: 100%;
			.customer-box{
				
				width: 100%;
				display: flex;
				align-items: flex-start;
				justify-content: flex-start;
				.left{
					flex: 1;
					font-size: 38rpx;
					color:#111;
					.name{
						flex: 1;
						font-size: 42rpx;
						color:#111;
					}
					.desc-box{
						margin-top: 15rpx;
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: flex-start;
						.label{
							font-size: 28rpx;
							color: #a8a8a8;
						}
						.value{
							font-size: 28rpx;
							color: #a8a8a8;
						}
						
						
					}
				}
				.btns{
					.btn{
						margin-left: 10rpx;
						width: 45rpx;
						height:45rpx;
					}
				}
			}
		}
		
	}
	 
</style>
