<template>
	<view class="zd_container">
		<nav-bar 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">
						<search-box
						v-model="val1"
						@handleChange="handleChange"
						/>
					</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>
								<th>所属工序</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.checked}" @tap="toCheck(e)">
								<td>{{i + 1}}</td>
								<td>{{e.type}}</td>
								<td>{{e.order_id}}</td>
								<td>{{e.stor_id}}</td>
								<td>{{e.in_device}}</td>
								<td>{{e.out_device}}</td>
								<td>{{e.bar_code}}</td>
							</tr>
						</tbody>
					</table>
				</view>
			</view>
			<uni-load-more color="#007AFF" iconType="circle" :status="status" :icon-size="14" :content-text="contentText" v-if="dataList.length > 0"/>
		</view>
		<view class="submit-bar">
			<button class="submit-button" :class="{'btn-disabled': !checkArr.length}" :disabled="disabled" @tap="toSure">上料确认</button>
			<button class="submit-button" @tap="searchList">查询</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {hrBcpOrderList, hrBcpOrderDelete} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				val1: '',
				dataList: [],
				checkArr: [],
				disabled: false,
				reload: false,
				status: 'more',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				totalCount: 0,
				pageNum: 1,
				pageSize: 30
			};
		},
		methods: {
			handleChange (e) {
				this.dataList = []
				this.pageNum = 1
				this._hrBcpOrderList(e)
			},
			searchList () {
				this.dataList = []
				this.pageNum = 1
				this._hrBcpOrderList(this.val1)
			},
			/** grid查询 */
			async _hrBcpOrderList (e) {
				let res = await hrBcpOrderList(e, this.pageNum + '', this.pageSize + '')
				this.totalCount = res.totalCount
				if (res.totalCount > 0) {
					res.data.map(el => {
						this.$set(el, 'checked', false)
					})
					const dataMap = res.data
					this.dataList = this.reload ? dataMap : this.dataList.concat(dataMap)
					this.reload = false
				} else {
					this.dataList = []
				}
				if (this.totalCount == this.dataList.length) {
					this.reload = false
					this.status = 'noMore'
				}	
			},
			onReachBottom () {
				if (this.totalCount > this.dataList.length) {
					this.status = 'loading'
					setTimeout(() => {
						this.pageNum++
						this._hrBcpOrderList(this.val1)
					}, 1000)
				} else { //停止加载
					this.status = 'noMore'
				}
			},
			toCheck (e) {
				e.checked = !e.checked
				this.checkArr = []
				this.dataList.map(el => {
					if (el.checked === true) {
						this.checkArr.push(el.order_id)
					}
				})
			},
			/** 确认 */
			async toSure () {
				this.disabled = true
				if (!this.checkArr.length) {
					this.disabled = false
					return
				}
				try {
					let res = await hrBcpOrderDelete(this.checkArr)
					this.disabled = false
					this.dataList = []
					this._hrBcpOrderList()
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				} catch (e) {
					this.disabled = false
				}
			}
		}
	}
</script>

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