//绑定车队长
<template>
	<view class="center">
		<view class="fleetInfo">
			<view class="fleetInfo_name" v-if="fleetInfo.name">{{fleetInfo.name}}({{fleetInfo.phone}})</view>
			<view class="fleetInfo_name" v-else>队长名称</view>
			<view class="fleetInfo_phone">{{fleetInfo.status?fleetInfo.status:"未绑定"}}</view>
		</view>
		<view class="btn_css">
			<view class="btn_item" v-if="!fleetInfo.name">
				<u-button type="primary" text="去绑定" @click="operation"></u-button>
			</view>
			<view class="btn_item" v-else>
				<u-button type="primary" text="解绑" @click="leave"></u-button>
			</view>
			
		</view>
		<u-toast ref="uToast"></u-toast>
		<u-modal :show="tipsShow" :title="alertTitle" :closeOnClickOverlay='true' :showCancelButton='true'
			confirmColor='#2772FB' @confirm="$u.throttle(confirmClick, 5000)" @close="cancelClick" @cancel="cancelClick"></u-modal>
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				fleetInfo:{},
				tipsShow:false,
				alertTitle:"确定解绑车队长？"
			}
		},
		onLoad() {
			this.getInfo()
		},
		onShow() {

		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		methods: {
			operation(){
				uni.$u.route('/pages/mine/fleet/addBinding');
				// uni.$u.route('/pages/mine/fleet/addBinding', {
				// 	data: JSON.stringify(this.dataDetails),
				// });
			},
			leave(){
				this.tipsShow = true
			},
			cancelClick(){
				this.tipsShow = false
			},
			confirmClick(){
				uni.showLoading({
					mask: true,
					title: '加载中'
				})
				this.tipsShow = false
				this.$request.baseRequest('post', '', this.dataDetails).then(res => {
						if (res.code == 200) {
							uni.hideLoading()
							this.$refs.uToast.show({
								type: 'success',
								message: "解绑成功！",
								complete() {
									// uni.navigateBack({
									// 	delta: 1
									// });
									this.getInfo()
								}
							})
						} else {
							uni.hideLoading()
							uni.$u.toast(res.message);
						}
					})
					.catch(res => {
						uni.hideLoading()
						uni.$u.toast(res.message);
					});
			},
			getInfo(){
				this.$request.baseRequest('get', '/hyBindCarCaptainInfo/getBindCarCaptain', {
					commonId:this.userInfo.id
				}).then(res => {
					debugger
						if (res.code == 200) {
							if(res.data){
								this.fleetInfo = res.data
							}
						} else {
							uni.$u.toast(res.message);
						}
					})
					.catch(res => {
						uni.hideLoading()
						uni.$u.toast(res.message);
					});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.center{
		padding: 20rpx 30rpx;
		
	}
	.fleetInfo{
		display: flex;
		width: 100%;
		margin-top: 30rpx;
		.fleetInfo_name{
			width: 50%;
		}
		.fleetInfo_phone{
			width: 50%;
			text-align: right;
		}
	}
	.btn_css{
		display: flex;
		margin-top: 30rpx;
		.btn_item{
			width: 120rpx;
			margin-right: 20rpx;
		}
	}
</style>
