<template>
	<view class="zd_container">
		<nav-bar :inner2="true" @goIn="goIn" title="点检填报"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">设备</span>
					</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input filter_input_disabled" disabled v-model="val1">
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">点检单</span>
					</view>
					<view class="filter_input_wraper">
						<input type="text" class="filter_input filter_input_disabled" disabled v-model="val2">
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="grid_new">
					<view class="grid_l">
						<table>
							<thead>
								<tr>
									<th>是否完成</th>
								</tr>
							</thead>
							<tbody>
								<tr v-for="(el, i) in dataList" :key="i">
									<td>
										<uni-data-select v-model="el.isfinish" :localdata="options" @change="selectChange($event, el)"></uni-data-select>
									</td>
								</tr>
							</tbody>
						</table>
					</view>
					<view class="grid_r">
						<table>
							<thead>
								<tr>
									<th>点检项目编号</th>
									<th>点检项目名称</th>
									<th>点检等级</th>
									<th>点检内容</th>
									<th>要求</th>
								</tr>
							</thead>
							<tbody>
								<tr v-for="(e, i) in dataList" :key="i">
									<td>{{e.maint_item_code}}</td>
									<td>{{e.maint_item_name}}</td>
									<td>{{['日常', '一级', '二级'][Number(e.item_level) - 1]}}</td>
									<td>{{e.contents}}</td>
									<td>{{e.requirement}}</td>
								</tr>
							</tbody>
						</table>
					</view>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !active}" :disabled="disabled" @tap="toSure">确认</button>
			<button class="submit-button" @tap="toCancle">取消</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {sportcheckgetDtl, sportcheckconfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: this.$store.getters.publicObj !== '' ? this.$store.getters.publicObj.device_code : '',
				val2: this.$store.getters.publicObj !== '' ? this.$store.getters.publicObj.maint_code : '',
				val3: this.$store.getters.publicObj !== '' ? this.$store.getters.publicObj.maint_id : '',
				options: [{text: '否', value: '0'}, {text: '是', value: '1'}],
				dataList: [],
				disabled: false
			};
		},
		computed: {
			active () {
				let t = false
				let arr = this.dataList.filter(el => el.isfinish === '1')
				if (this.dataList.length > 0 && this.dataList.length === arr.length) {
					t = true
				}
				return t
			}
		},
		created () {
			this._sportcheckgetDtl()
		},
		methods: {
			/** 选择器 */
			selectChange($event, el) {
				el.isfinish = $event
			},
			/** grid查询 */
			async _sportcheckgetDtl () {
				let res = await sportcheckgetDtl(this.val1, this.val2, this.val3)
				this.dataList = [...res.data]
			},
			/** 确认 */
			async toSure () {
				this.disabled = true
				if (!this.active) {
					this.disabled = false
					return
				}
				try {
					let res = await sportcheckconfirm(this.val1, this.val2, this.dataList)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.goIn()
				} catch (e) {
					this.disabled = false
				}
			},
			toCancle () {
			  this.goIn()
			},
			goIn () {
				this.$store.dispatch('setPublicObj', '')
				uni.navigateBack()
			}
		}
	}
</script>

<style lang="stylus">
</style>
