<template>
	<view class="zd_container">
		<!-- <nav-bar title="烘烤区域母卷详情"></nav-bar> -->
		<nav-bar :title="title"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="filter_item">
					<view class="filter_label">{{$t('filter.area')}}</view>
					<view class="filter_input_wraper">
						<uni-data-select v-model="index" :placeholder="$t('uni.dataSelect.placeholder')" :emptyTips="$t('uni.dataSelect.emptyTips')" :localdata="options"></uni-data-select>
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('grid.point-code')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val1" />
					</view>
				</view>
				<view class="filter_item">
					<view class="filter_label_wraper">
						<span class="filter_label">{{$t('grid.mother-roll-number')}}</span>
					</view>
					<view class="filter_input_wraper">
						<search-box v-model="val2" />
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>{{$t('grid.point-code')}}</th>
								<th>{{$t('grid.mother-roll-number')}}</th>
								<th>{{$t('filter.area')}}</th>
								<th>{{$t('grid.mother-roll-status')}}</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" @click="toCheck(e)" :class="{'checked': e.container_name === pkId}">
								<td>{{e.point_code}}</td>
								<td>{{e.container_name}}</td>
								<td>{{e.product_area}}</td>
								<td>{{e.roll_status}}</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="zd-row submitbar">
			<button class="zd-col-7 btn-submit btn-success" @tap="searchList">{{$t('button.search')}}</button>
			<button class="zd-col-7 btn-submit btn-success" :class="{'btn-info': !pkId}" :disabled="disabled1" @tap="_inCoolIvt">{{$t('button.quality-approved')}}</button>
			<button class="zd-col-7 btn-submit btn-success" :class="{'btn-info': !pkId}" :disabled="disabled2" @tap="_inCoolOrOven">质检不合格</button>
		</view>
		<view class="msg_wrapper" :class="active ? 'popshow' : 'pophide'" style="height: auto">
			<view class="pop-line"></view>
			<view class="msg_content">
				<view class="zd_wrapper zd_wrapper-1">
					<view class="filter_item">
						<view class="filter_label">{{$t('filter.temperature')}}</view>
						<view class="filter_input_wraper">
							<NumberInput
							v-model="val3"
							input-class="filter_input"
							mode="mixed"
							:decimalLength="3"
							/>
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label">{{$t('filter.time')}}({{$t('unit.minute')}})</view>
						<view class="filter_input_wraper">
							<NumberInput
							v-model="val4"
							input-class="filter_input"
							mode="integer"
							/>
						</view>
					</view>
					<view class="filter_item">
						<view class="filter_label">去向</view>
						<view class="filter_input_wraper">
							<uni-data-select v-model="index1" :placeholder="$t('uni.dataSelect.placeholder')" :emptyTips="$t('uni.dataSelect.emptyTips')" :localdata="options1" placement="top"></uni-data-select>
						</view>
					</view>
				</view>
			</view>
			<view class="zd-row submitbar">
				<button class="zd-col-11 btn-submit btn-default letter-30" @tap="cancleModal">{{$t('button.cancel')}}</button>
				<button class="zd-col-11 btn-submit btn-success letter-30" @tap="modalToSure">{{$t('button.confirm')}}</button>
			</view>
		</view>
		<view v-if="active" class="msg_mask"></view>
		<up-top ref="UT" :scrollTop="top"></up-top>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import NumberInput from '@/components/NumberInput.vue'
	import UpTop from '@/components/upTop.vue'
	import {queryProductArea, inCoolIvt, inCoolOrOven} from '@/utils/getData1.js'
	import {queryHotPoints} from '@/utils/getData3.js'
	export default {
		components: {
			NavBar,
			SearchBox,
			NumberInput,
			UpTop
		},
		data() {
			return {
				title: '',
				top: 0,
				val1: '',
				val2: '',
				options: [],
				index: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				reload: false,
				status: 'more',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				totalCount: 0,
				pageNum: 1,
				pageSize: 10,
				disabled1: false,
				disabled2: false,
				active: false,
				val3: '',
				val4: '',
				index1: '',
				options1: [{value: '1', text: '入冷却'}, {value: '2', text: '入烘箱'}]
			};
		},
		onPageScroll(e) {
			this.$refs.UT.topData(e.scrollTop)
		},
		onLoad (options) {
			this.title = options.title
		},
		created () {
			this._queryHotPoints()
			this._queryProductArea()
		},
		methods: {
			searchList () {
				this.dataList = []
				this.pageNum = 1
				this._queryHotPoints()
			},
			/** 生产区域下拉框查询 */
			async _queryProductArea () {
				let res = await queryProductArea()
				this.options = [...res.data]
			},
			/** 初始化查询 */
			async _queryHotPoints () {
				let res = await queryHotPoints(this.val1, this.val2, this.index, this.pageNum + '', this.pageSize + '')
				this.totalCount = res.size
				if (res.size > 0) {
					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._queryHotPoints()
					}, 1000)
				} else { //停止加载
					this.status = 'noMore'
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.container_name ? '' : e.container_name
				this.pkObj = this.pkId === e.container_name ? e : {}
			},
			async _inCoolIvt () {
				this.disabled1 = true
				if (!this.pkId) {
					this.disabled1 = false
					return
				}
				try {
					let res = await inCoolIvt(this.pkObj.point_code, this.pkObj.container_name)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.searchList()
					this.disabled1 = false
				} catch (e) {
					this.disabled1 = false
				}
			},
			_inCoolOrOven () {
				if (this.pkId) {
					this.active = true
					this.disabled2 = true
				}
			},
			cancleModal () {
				this.val3 = ''
				this.val4 = ''
				this.index1 = ''
				this.active = false
				this.disabled2 = false
			},
			async modalToSure () {
				try {
					let res = await inCoolOrOven(this.pkObj.point_code, this.pkObj.container_name, this.val3, this.val4, this.index1)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					this.cancleModal()
					this.searchList()
				} catch (e) {
					this.disabled2 = false
				}
			}
		}
	}
</script>

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