<template>
	<view class="zd_container">
		<!-- AGV管理 -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view class="zd-col-5">
						<span class="filter_label">车号</span>
					</view>
					<view class="zd-col-14">
						<input type="text" class="filter_input" v-model="val1">
					</view>
					<button class="mini-btn" type="primary" @tap="_queryHistoryTask">查询</button>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>序号</th>
								<th>车号</th>
								<th>电量（%）</th>
								<th>当前状态</th>
								<th>当前位置</th>
								<th>当前任务</th>
								<th>起点</th>
								<th>终点</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i">
								<td>{{i+1}}</td>
								<td>{{e.vehicle_code}}</td>
								<td>{{e.point_code1}}</td>
								<td>{{e.point_code2}}</td>
								<td>{{e.task_code}}</td>
								<td>{{e.config_name}}</td>
								<td>{{e.car_no}}</td>
								<td>{{e.remark}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">清空</button>
			<button class="zd-col-18 button-primary" :class="{'button-info': !val1}" :disabled="disabled" @tap="_createTask">强制充电</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {queryHistoryTask, createTask} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				dataList: []
			};
		},
		onLoad (options) {
			this.title = options.title
			this._queryHistoryTask()
		},
		methods: {
			toEmpty () {
				this.val1 = ''
				this.dataList = []
				this.disabled = false
			},
			async _queryHistoryTask () {
				try {
					let res = await queryHistoryTask(this.val1)
					if (res && res.data) {
						this.dataList = [...res.data]
					} else {
						this.dataList = []
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
				} catch (e) {
					this.dataList = []
				}
			},
			async _createTask () {
				this.disabled = true
				if (!this.val1) {
					this.disabled = false
					return
				}
				try {
					let res = await createTask(this.val1)
					if (res) {
						uni.showToast({
							title: res.message,
							icon: 'none'
						})
					}
					this.toEmpty()
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

<style scoped>
.filter_picker {
	text-align: center
}
</style>