<template>
	<view class="zd_container">
		<nav-bar title="混碾操作"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>压机编号</th>
								<th>泥料号</th>
								<th>工单号</th>
								<th>是否上料</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @tap="toCheck(e)" :class="{'checked': e.record_id === pkId}">
								<td>{{e.device_code}}</td>
								<td>{{e.material_id}}</td>
								<td>{{e.workorder_id}}</td>
								<td>{{e.is_finish}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
		</view>
		<view class="submit-bar">
			<button class="submit-button" @tap="_mixRequestInfo">刷新</button>
			<button class="submit-button" :disabled="disabled" @tap="toSure">删除</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import {mixRequestInfo, mixDeleteInfo} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar
		},
		data() {
			return {
				dataList: [],
				pkId: '',
				pkObj: {},
				disabled: false
			};
		},
		created () {
			this._mixRequestInfo()
		},
		methods: {
			/** grid查询 */
			async _mixRequestInfo () {
				let res = await mixRequestInfo()
				this.dataList = [...res]
			},
			/** 删除 */
			async toSure () {
				this.disabled = true
				if (!this.pkId) {
					this.disabled = false
					return
				}
				try {
					let res = await mixDeleteInfo(this.pkObj)
					this.disabled = false
					this.pkId = ''
					this.pkObj = {}
					this._mixRequestInfo()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.record_id ? '' : e.record_id
				this.pkObj = this.pkId === e.record_id ? e : {}
			}
		}
	}
</script>

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