<template>
	<view class="center">
		<view class="row1">
			<u--image class="flex-end" :showLoading="true" src="../../static/images/mine/saoma.png" width="30px"
				height="30px" @click="myPage"></u--image>
		</view>
		<view class="flex center_top">
			<u-button :type="indexbtn == 1? 'primary':''" @click="changebtn(1)">司机</u-button>
			<u-button :type="indexbtn == 2? 'primary':''" @click="changebtn(2)">车队</u-button>
		</view>
		<view class="driver" v-if="indexbtn == 1">
			<view class="flex" >
				<!-- <regionPicker :multiIndex_="selections1" @region_="regionChange1" custom_="请选择"
					@selecteRegion_="selecteRegion1" title_="全国" /> -->
					<!-- <view > -->
						<view @click="addressChange(1)">{{title1 ? title1 : "请选择地址"}}</view>
						<Linkage @conceal="conceal1" class="flex" v-show="show1" ref="uDropdown"></Linkage>
					<!-- </view> -->
					<view @click="replace">--></view>
					<!-- <view style="margin-left: 60px;"> -->
						<view @click="addressChange(2)">{{title2 ? title2 : "请选择地址"}}</view>
					<Linkage @conceal="conceal2" class="flex" v-show="show2" ref="uDropdown"></Linkage>
					<!-- </view> -->
			</view>
			<view class="" v-for="(item,index) in routeData">
				<view>{{item.driverNickname}}</view>
				<view>{{item.sendCity ? item.sendCity: item.sendProvince }}{{item.sendArea}} ----->
					{{item.unloadCity ? item.unloadCity: item.unloadCity }}{{item.unloadArea}} </view>
			</view>

		</view>
		<view class="driver" v-if="indexbtn == 2">
		<!-- 	<view @click="show = true">sss</view> -->
			<!-- <u-picker :show="show" ref="uPicker" :columns="fprovincelist" @confirm="confirm" @change="changeHandler"></u-picker> -->
		</view>
	</view>
</template>

<script>
	import regionPicker from "@/components/region/region-picker";
	import dataList from "@/components/region/data.js";
	import Linkage from '@/components/gaojianghua-linkage/linkage.vue'
	import {
		address,
	} from '@/components/data/data.js'
	export default {
		components: {
			regionPicker,
			Linkage
		},
		data() {
			return {
				indexbtn: 1,
				// fprovincelist: [],
				// sprovincelist: [],
				// show: false,
				selections1: [],
				selections2: [],
				// sendregion: [],
				// unloaddregion: [],
				routeData: [], //列表
				//
				show1:false,
				show2:false,
				title1:"",
				title2:"",
				sendInfo: {},
				unloadInfo: {},
			}
		},
		created() {},
		onShow() {
			this.sendInfo = uni.getStorageSync("sendInfo")
			this.unloadInfo = uni.getStorageSync("unloadInfo")
			if (this.sendInfo) {
				this.title1 = this.sendInfo.sendProvince + this.sendInfo.sendCity + this.sendInfo.sendArea
			}
			if (this.unloadInfo) {
				this.title2 = this.unloadInfo.unloadProvince + this.unloadInfo.unloadCity + this.unloadInfo.unloadArea
			}
			this.getList()
		},
		onLoad() {},
		methods: {
			addressChange(num){
				if(num == 1){
					this.show1 = true
					this.show2 = false
				}else{
					this.show1 = false
					this.show2 = true
				}
			},
			getList() {
				
				this.$request.baseRequest('get', '/commonRoute/select', {
						pageSize: 10,
						currentPage: 1,
						sendProvince: this.sendInfo.sendProvince,
						sendCity: this.sendInfo.sendCity,
						sendArea: this.sendInfo.sendArea,
						unloadProvince: this.unloadInfo.unloadProvince,
						unloadCity: this.unloadInfo.unloadCity,
						unloadArea: this.unloadInfo.unloadArea
					}).then(res => {
						if (res.code == 200) {
							this.routeData = res.data.records
						}
					})
					.catch(res => {
						uni.$u.toast(res.message);
					});
			},
			changebtn(num) {
				this.indexbtn = num
			},
			// 回调参数为包含columnIndex、value、values
			confirm(e) {
				console.log('confirm', e)
				this.show = false
			},
			replace(){
				let _obj = {}
				_obj = this.sendInfo
				this.sendInfo = this.unloadInfo
				this.unloadInfo = _obj
				let text = ""
				text = this.title1
				this.title1 = this.title2
				this.title2 = text
				this.getList()
			},
			conceal1(param) {
				const {
					chooseprovince,
					choosecity,
					choosearea
				} = param
				// 获取到传过来的 省 市 区 县数据
				this.sendInfo.sendProvince = chooseprovince
				this.sendInfo.sendCity = choosecity == '全部' ? "" : choosecity
				this.sendInfo.sendArea = choosearea == '全部' ? "" : choosearea
				uni.setStorageSync("sendInfo", this.sendInfo)
				this.title1 = chooseprovince + choosecity + choosearea
				if (chooseprovince == '全国') {
					this.succeed(1)
				}
				if (choosecity == '全部') {
					this.succeed(1)
				} else if (choosearea != '') {
					this.succeed(1)
				}
			},
			conceal2(param) {
				const {
					chooseprovince,
					choosecity,
					choosearea
				} = param
				// 获取到传过来的 省 市 区 县数据
				this.unloadInfo.unloadProvince = chooseprovince
				this.unloadInfo.unloadCity = choosecity == '全部' ? "" : choosecity
				this.unloadInfo.unloadArea = choosearea == '全部' ? "" : choosearea
				uni.setStorageSync("unloadInfo", this.unloadInfo)
				this.title2 = chooseprovince + choosecity + choosearea
				if (chooseprovince == '全国') {
					this.succeed(2)
				}
				if (choosecity == '全部') {
					this.succeed(2)
				} else if (choosearea != '') {
					this.succeed(2)
				}
			},
			//筛选框关闭
			succeed(num) {
				// this.$refs.uDropdown.close();
				if (num == 1) {
					this.show1 = false
				} else if (num == 2) {
					this.show2 = false
				}
				this.getList()
			},
			myPage(){
			    uni.$u.route("/pages/riders/myTeam")	
			}
			// regionChange1(value) {
			// 	this.sendregion = value
			// 	this.sendInfo.sendProvince = this.sendregion[0] == '请选择' ? '' : this.sendregion[0]
			// 	this.sendInfo.sendCity = this.sendregion[1] == '请选择' ? '' : this.sendregion[1]
			// 	this.sendInfo.sendArea = this.sendregion[2] == '请选择' ? '' : this.sendregion[2]
			// },
			// regionChange2(value) {
			// 	this.unloaddregion = value
			// 	this.unloadInfo.unloadProvince = this.unloaddregion[0] == '请选择' ? '' : this.unloaddregion[0]
			// 	this.unloadInfo.unloadCity = this.unloaddregion[1] == '请选择' ? '' : this.unloaddregion[1]
			// 	this.unloadInfo.unloadArea = this.unloaddregion[2] == '请选择' ? '' : this.unloaddregion[2]

			// },
			// selecteRegion1(value) {
			// 	this.selections1 = value;
			// 	this.sendInfo.sendNum = this.selections1 ? this.selections1.toString() : ""
			// 	this.getList()
			// },
			// selecteRegion2(value) {
			// 	this.selections2 = value;
			// 	this.unloadInfo.unloadNum = this.selections2 ? this.selections2.toString() : ""
			// 	this.getList()
			// },
		}
	}
</script>

<style lang="scss" scoped>
	.center {
		.row1 {
			display: flex;
			justify-content: flex-end;
			margin-top: 46rpx;
			margin: 40rpx 30rpx 0 0;
		}
		.center_top{
			margin-top: 30rpx;
			padding: 0 30rpx;
		}
	}
</style>
