<template>
	<view class="zd_container">
		<!-- 库存出库 -->
		<nav-bar :title="title" :inner="true"></nav-bar>
		<view class="zd_content">
			<view class="zd_wrapper">
				<view class="zd-row border-bottom">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'">
						<span class="filter_label">{{$t('filter.ck')}}</span>
					</view>
					<view class="filter_select" :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'">
						<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="zd-row">
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-7'">
						<span class="filter_label">{{$t('filter.wlbm')}}</span>
					</view>
					<view :class="$i18n.locale !== 'zh-Hans' ? 'zd-col-12' : 'zd-col-17'">
						<input type="text" class="filter_input" v-model="val1">
					</view>
				</view>
			</view>
			<view class="zd_wrapper grid-wraper">
				<view class="slide_new">
					<table>
						<thead>
							<tr>
								<th>{{$t('filter.ckbm')}}</th>
								<th>{{$t('filter.kwbm')}}</th>
								<th>{{$t('filter.zjbm')}}</th>
								<th>{{$t('filter.wlbm')}}</th>
								<th>{{$t('filter.wlpc')}}</th>
								<th>{{$t('filter.ckkc')}}</th>
							</tr>
						</thead>
						<tbody>
							<tr v-for="(e, i) in dataList" :key="i" :class="{'checked': e.id === pkId}" @tap="toCheck(e)">
								<td>{{e.stor_code}}</td>
								<td>{{e.struct_code}}</td>
								<td>{{e.vehicle_code}}</td>
								<td>{{e.material_code}}</td>
								<td>{{e.pcsn}}</td>
								<td>{{e.qty}}</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 submit-bar">
			<button class="zd-col-5 button-default" @tap="toEmpty">{{$t('btn.cancle')}}</button>
			<button class="zd-col-8 button-primary" @tap="searchList">{{$t('btn.search')}}</button>
			<button class="zd-col-8 button-primary" :class="{'button-info': !pkId}" @tap="toSure">{{$t('btn.confirm')}}</button>
		</view>
	</view>
</template>

<script>
	import NavBar from '@/components/NavBar.vue'
	import SearchBox from '@/components/SearchBox.vue'
	import {structattrPage} from '@/utils/getData2.js'
	export default {
		components: {
			NavBar,
			SearchBox
		},
		data() {
			return {
				title: '',
				val1: '',
				options: [{value: 'FStockPallet', text: this.$t('text.tpk')}, {value: 'FStockId', text: this.$t('text.lxk')}],
				index: '',
				dataList: [],
				pkId: '',
				pkObj: {},
				reload: false,
				status: 'more',
				contentText: {
					contentdown: this.$t('more.ckgd'),
					contentrefresh: this.$t('more.jzz'),
					contentnomore: this.$t('more.mygd')
				},
				totalCount: 0,
				pageNum: 1,
				pageSize: 10
			};
		},
		onLoad (options) {
			this.title = options.title
		},
		methods: {
			searchList () {
				this.dataList = []
				this.pageNum = 1
				this._structattrPage()
			},
			async _structattrPage () {
				let res = await structattrPage(this.pageNum + '', this.pageSize + '', this.index, this.val1, true)
				if (res.code === '200') {
					this.totalCount = res.totalElements
					if (res.totalElements > 0) {
						const dataMap = res.content
						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._structattrPage()
					}, 1000)
				} else { //停止加载
					this.status = 'noMore'
				}
			},
			toCheck (e) {
				this.pkId = this.pkId === e.id ? '' : e.id
				this.pkObj = this.pkId === e.id ? e : {}
			},
			toEmpty () {
				this.index = ''
				this.val1 = ''
				this.dataList = []
				this.pageNum = 1
				this.pkId = ''
			},
			toSure () {
				if (this.pkId) {
					this.$store.dispatch('setPublicObj', this.pkObj)
					uni.navigateBack()
				}
			}
		}
	}
</script>

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