<template>
	<view class="zd_container" :class="{'en_class': applicationLocale === 'en'}">
		<!-- 作业管理 -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view>
					<view class="filter_label">{{$t('label.Keyword')}}</view>
					<search-box v-model="val1"/>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>{{$t('label.CarrierCode')}}</th>
								<th>{{$t('th.Startpoint')}}</th>
								<th>{{$t('th.Endpoint')}}</th>
								<th>{{$t('th.Status')}}</th>
								<th>{{$t('th.Jobnumber')}}</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @tap="toChek(e)" :class="{'checked': pkId === e.task_code}">
								<td>{{e.vehicle_code}}</td>
								<td>{{e.point_code1}}</td>
								<td>{{e.point_code2}}</td>
								<td>{{e.task_status}}</td>
								<td>{{e.task_code}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="zd-row submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">{{$t('button.clear')}}</button>
			<button class="zd-col-5 button-primary" @tap="_schTaskQueryTask">{{$t('button.search')}}</button>
			<button class="zd-col-6 button-primary" :class="{'button-info': !pkId}" :disabled="disabled" @tap="_schTaskAgainTask">{{$t('button.Reissue')}}</button>
			<button class="zd-col-6 button-primary" :class="{'button-info': !pkId}" :disabled="disabled" @tap="_forceConfirm">{{$t('button.Forcecompletion')}}</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {schTaskQueryTask, schTaskAgainTask, forceConfirm} from '@/utils/getData.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1:  '',
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled: false,
				applicationLocale: ''
			};
		},
		onLoad (options) {
			this.title = options.title
			this.applicationLocale = uni.getLocale()
		},
		methods: {
			toEmpty () {
				this.val1 = ''
				this.dataList = []
			},
			async _schTaskQueryTask () {
				try {
					let res = await schTaskQueryTask(this.val1)
					if (res.status === '200') {
						this.dataList = [...res.data]
					}
				} catch(e) {
					this.dataList = []
				}
			},
			toChek (e) {
				this.pkId = this.pkId === e.task_code ? '' : e.task_code
				this.pkObj = this.pkId === e.task_code ? e : {}
			},
			async _schTaskAgainTask () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await schTaskAgainTask(this.pkId)
					if (res.status === '200') {
						this._schTaskQueryTask()
					}
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			async _forceConfirm () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await forceConfirm(this.pkId)
					if (res.status === '200') {
						this._schTaskQueryTask()
					}
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>
