<template>
	<view class="enterprise-list">
		<view class="list-wrap">
			<u-sticky bgColor="#fff" class="main-sticky">
				<view class="search-wrap">
					<view class="input-wrap">
						<u-search bgColor='#fff' :showAction='false' :placeholder="$t('base.common.inputPlaceholder')"
							@search="searchList" @clear='searchList' v-model="keyword">
						</u-search>
						<view class="sx-btn" @click="searchList">{{$t("customer_meter.search")}}</view>
					</view>
				</view>
			</u-sticky>
			<template v-if="vehicleList.length">
				<view class="business-card" v-for="(item, index) in vehicleList" :key="index">
					<view class="business-card-info" @click="onClickDriver(item)">
						<view class="info-line" v-if="item.vehicleType!=1">
							<text class="lebel">{{item.driver}} {{item.vehicle || ''}}</text>
						</view>
						<view class="info-line" v-if="item.vehicleType==1">
							<text class="lebel">{{item.vehicle}} {{item.driver || ''}}</text>
							<text class="info">{{$t("driver.fleet")}} {{item.fleetName || ''}}</text>
						</view>
						<view class="businessStatus-info">
							<u--image width="100rpx" height="88rpx"
								:src="item.vehicleType==1?'/subpages/static/czzn-img/state/fleet_vehicle.png':'/subpages/static/czzn-img/state/private-vehicle.png'">
							</u--image>
						</view>
					</view>

				</view>
			</template>
			<template v-else>
				<u-empty mode="list" icon="https://cdn.uviewui.com/uview/empty/list.png">
				</u-empty>
			</template>
		</view>
		<uni-fab ref="fab" buttonColor="#3c9cff" @trigger="trigger" @fabClick="onClickRight" />
	</view>
</template>

<script>
	import {
		saveRunVehicle,
		getVehicleListByCondition,
	} from '../../api/driver'
	export default {
		data() {
			return {
				vehicleList: [],
				keyword: '',
				status: undefined,
			}
		},
		onShow() {
			this.bindDriver()
		},
		onLoad(option) {
			this.status = option.status;
		},
		methods: {
			//点击司机返回
			onClickDriver(item) {
				saveRunVehicle(item).then(res => {
				})
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2]; //上一个页面
				prevPage.$vm.currentVehicleInfo = item; //重点$vm
				uni.navigateBack();
			},
			//获取车辆选项列表
			bindDriver() {
				let data = {
					keyword: this.keyword || '',
				}
				getVehicleListByCondition(data).then(res => {
					if (res.statusCode == 200) {
						this.vehicleList = res.data.data
					}
				})
			},
			//搜索列表
			searchList() {
				this.bindDriver()
			},
			//跳转添加司机表单
			onClickRight() {
				uni.navigateTo({
					url: '/subpages/driver/add'
				})
			}
		},

	}
</script>

<style lang="scss" scoped>
	@import '../../common/css/public.scss';
</style>
