<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="slide_new">
					<table>
						<thead>
							<tr>
								<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>{{e.indexId}}</td>
								<td>
									<uni-data-select v-model="index" :localdata="options" @change="selectChange"></uni-data-select>
								</td>
								<td>{{e.maint_item_code}}</td>
								<td>{{e.item_level}}</td>
								<td>{{e.contents}}</td>
								<td>{{e.requirement}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !dataList.every(item=>item.isfinish === '1')}" :disabled="disabled"  @tap="_lubricateconfirm">确认</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 {lubricategetDtl, lubricateconfirm} from '@/utils/getData1.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				options: [{text: '否', value: '0'}, {text: '是', value: '1'}],
				index: '',
				val1: this.$store.getters.publicObj !== '' ? this.$store.getters.publicObj.device_code : '',
				val2: this.$store.getters.publicObj !== '' ? this.$store.getters.publicObj.maint_code : '',
				dataList: [],
				disabled: false
			};
		},
		created () {
			this._lubricategetDtl()
		},
		methods: {
			selectChange (e) {
				this.index = e
			},
			/** grid查询 */
			async _lubricategetDtl () {
				let res = await lubricategetDtl(this.val1, this.val2, this.$store.getters.publicObj.maint_id)
				this.dataList = [...res.data]
			},
			/** 确认 */
			async _lubricateconfirm () {
				this.disabled = true
				if (!this.val1 || !this.val2 || !this.dataList.length) {
					this.disabled = false
					return
				}
				if (this.dataList.every(item=>item.isfinish === '1')) {
					// console.log('true')
				} else {
					this.disabled = false
					return
				}
				try {
					let res = await lubricateconfirm(this.val1, this.val2, this.dataList)
					this.disabled = false
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			toCancle () {
			  this.$store.dispatch('setPublicObj', '')
			  this.goIn()
			},
			goIn () {
				uni.redirectTo({
					url: '/pages/device/LubricateWork'
				})
			}
		}
	}
</script>

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