//车队管理
<template>
	<view class="center">
		<view class="fleetInfo">
			<view class="fleetInfo_name">队长身份</view>
			<view class="fleetInfo_phone" v-if="fleetInfo.status">{{fleetInfo.status}}</view>
			<view class="fleetInfo_phone" v-else>去认证</view>
		</view>
		<view class="btn_css">
			<view class="btn_item" v-if="!fleetInfo">
				<u-button type="primary" text="去认证" @click="operation(1)"></u-button>
			</view>
			<view class="btn_item" v-else>
				<u-button type="primary" text="编辑" @click="operation(2)"></u-button>
			</view>
		</view>
		<u-divider></u-divider>
		<view class="list_css" v-for="(item,index) in formList">
			<view class="list_left">{{item.driverName}}({{item.accountNumber}})</view>
			<view class="list_right">
				<view class="list_text" v-if="item.status == '待确认'" @click="audit(item,1)">拒绝</view>
				<view class="list_text" v-if="item.status == '待确认'" @click="audit(item,2)">接受</view>
				<view class="list_text" v-if="item.status == '已绑定'">{{item.status}}</view>
				<view class="list_text"
					v-if="item.status == '已绑定'||item.status == '已解绑'||item.status == '已接受'||item.status == '已拒绝'"
					@click="next(item)">删除</view>
			</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: "",
				formList: [],
				distinguish: "",
				id: "",
				sign:"",
			}
		},
		onLoad() {
			this.getInfo()
		},
		onShow() {

		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onNavigationBarButtonTap(e) {
			this.$u.route("/pages/mine/fleet/fleetBill")
		},
		methods: {
			solution() {
				let that = this
				uni.showLoading({
					mask: true,
					title: '加载中'
				})
				this.tipsShow = false
				this.$request.baseRequest('post', '/hyBindCarCaptainInfo/api/deleteBind', {
					id: this.id
				}).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.$refs.uToast.show({
							type: 'success',
							message: "删除成功！",
							complete() {
								that.getInfo()
							}
						})
					} else {
						uni.hideLoading()
						uni.$u.toast(res.message);
					}
				}).catch(res => {
					uni.hideLoading()
					uni.$u.toast(res.message);
				});
			},
			next(obj) {
				this.tipsShow = true
				this.alertTitle = "确定删除" + obj.driverName + "信息？"
				this.id = obj.id
				this.sign="删除"
			},
			audit(obj, val) {
				if (val == 1) {
					this.alertTitle = "确定拒绝" + obj.driverName + "加入车队？"
					this.distinguish = "2"
				} else if (val == 2) {
					this.alertTitle = "确定接受" + obj.driverName + "加入车队？"
					this.distinguish = "1"
				}
				this.id = obj.id
				this.tipsShow = true
			},
			operation(val) {
				if (val == 1) {
					uni.$u.route('/pages/mine/fleet/carCaptainAuthentication');
				} else {
					uni.$u.route('/pages/mine/fleet/carCaptainAuthentication', {
						data: JSON.stringify(this.fleetInfo),
					});
				}
			},
			leave() {
				this.tipsShow = true
			},
			cancelClick() {
				this.tipsShow = false
			},
			confirmClick() {
				let that = this
				if(this.sign == "删除"){ //删除操作
					this.solution()
				}else{
					uni.showLoading({
						mask: true,
						title: '加载中'
					})
					this.tipsShow = false
					this.$request.baseRequest('post', '/hyBindCarCaptainInfo/api/examine', {
							id: this.id,
							examineFlag: this.distinguish
						}).then(res => {
							if (res.code == 200) {
								uni.hideLoading()
								if (this.distinguish == 1) {
									this.$refs.uToast.show({
										type: 'success',
										message: "接受成功！",
										complete() {
											that.getInfo()
										}
									})
								} else {
									this.$refs.uToast.show({
										type: 'success',
										message: "拒绝成功！",
										complete() {
											that.getInfo()
										}
									})
								}
							} else {
								uni.hideLoading()
								uni.$u.toast(res.message);
							}
						})
						.catch(res => {
							uni.hideLoading()
							uni.$u.toast(res.message);
						});
				}
				
			},
			getInfo() {
				this.$request.baseRequest('get', '/hyCarCaptainInfo/getCarCaptain', {
						commonId: this.userInfo.id
					}).then(res => {
						if (res.code == 200) {
							if (res.data) {
								this.fleetInfo = res.data
								//车队人员
								this.$request.baseRequest('get', '/hyBindCarCaptainInfo/api/selectPage', {
										carCaptainCommonId: this.fleetInfo.commonId,
										pageSize: 10,
										currentPage: 1
									}).then(res => {
										if (res.code == 200) {
											this.formList = res.data.records
											// if(res.data.total == 0){
											// 	this.status = 'nomore'
											// }else{
											// 	this.status = 'loadmore'
											// }
										}
									})
									.catch(res => {
										uni.$u.toast(res.message);
									});
							}
						} else {
							uni.$u.toast(res.message);
						}
					})
					.catch(res => {
						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;
		}
	}

	.list_css {
		display: flex;
		margin: 10rpx 0;

		.list_left {
			width: 50%;
		}

		.list_right {
			display: flex;
			justify-content: flex-end;
			width: 50%;

			.list_text {
				margin: 0 10rpx;
			}
		}
	}
</style>
