<template>
	<view class="lists">
		<view class="search">
			<view class="search-v">
				<scanlistener
				v-if="showScanlistener"
				class="input"
				suffixIcon="scan"
				@iconClick="scanQrcode"
				v-model="selfNo"
				:placeholder="$t('请扫描条形码')"
				placeholder-class="phclass"
				@confirm="getData"
				@submit="selfNo=$event;getData()"
				/>
				<!-- <image src="../../static/images/scan.png" mode="" @click="scanQrcode"></image> -->
			</view>
		</view>
		<view class="listView">
			<view class="list-title">
				<image class="message" src="../../static/images/message.png" mode=""></image>
				<text class="status-name">{{$t('状态')}}</text>
				<view class="list-status">
					<picker :value="statusIndex" :range="statusData" @change="statusChange" v-if="statusData.length > 0">
						<view class="uni-input">{{statusData[statusIndex]}}</view>
					</picker>
					<image src="../../static/images/down.png" mode=""></image>
				</view>
			</view>

			<view class="listItems">
				<view class="listItemsView" v-for="(i, v) in data" @click="goDetail(i.id, i)">
					<view class="listItemsView-title">
						<image src="../../static/images/no.png" mode=""></image>
						<text class="noTitle">{{i.selfNo}}</text>
					</view>
					<view class="listItemsView-item">
						<view class="listItemsView-item-v">
							<view class="">
								<text>{{$t('方数')}}({{$t('计划/实装')}})：</text>
								<text>{{i.boxStatistics.volume}}/{{i.boxStatistics.unloadVolume}}</text>
							</view>
							<view class="">
								<text>{{$t('重量')}}({{$t('计划/实装')}})：</text>
								<text>{{i.boxStatistics.weight}}/{{i.boxStatistics.loadWeight}}</text>
							</view>
							<view class="">
								<text>{{$t('数量')}}({{$t('实装/已卸')}})：</text>
								<text>{{i.boxStatistics.num}}/{{i.boxStatistics.loadNum}}</text>
							</view>
							<view class="">
								<text>{{$t('状态')}}：</text>
								<text>{{i.shipmentStatusText}}</text>
							</view>
						</view>
						<view class="listItemsView-item-v">
							<view class="">
								<text>{{$t('到仓时间')}}：</text>
								<text>{{$util.formatDate(i.tyTime)}}</text>
							</view>
							<view class="">
								<text>{{$t('目的地')}}：</text>
								<text>{{i.destWarehouseResp.titleZh}}</text>
							</view>
							<view class="">
								<text>{{$t('运输方式')}}：</text>
								 <dict-tag :type="DICT_TYPE.ECW_TRANSPORT_TYPE" :value="i.transportType" />
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-load-more :status="status" :icon-size="16" :content-text="contentText" />
	</view>
</template>
<script>
	import * as types from '../../store/mutations-types.js';
	import { uniLoadMore } from '@dcloudio/uni-ui';
	import { unloadPage } from './api';
	export default {
		name: 'unloadCabinet',
		components: { uniLoadMore },
		data() {
			return {
				data: [],
				page: 1,
				totalPage: 1,
				selfNo: '',
				status: 'more',
				contentText: {
					contentdown: this.$t('上拉加载更多'),
					contentrefresh: this.$t('加载中'),
					contentnomore: this.$t('没有更多')
				},
				statusData: [this.$t('全部'), this.$t('待卸柜'), this.$t('卸柜中'), this.$t('卸柜审批中'), this.$t('已卸柜')],
				statusValue: ['', '1', '3', '5', '7'],
				statusIndex: 0,
			}
		},
		onLoad () {
			this.getData()
			uni.setNavigationBarTitle({
				title:this.$t('待卸柜列表')
			})
		},
		onShow () {
		},
		onPullDownRefresh() {
			this.page = 1;
			this.getData()
		},
		onReachBottom() {
			this.page++
			if(this.page <= this.totalPage){
				this.getData()
			} else {
				this.status = 'noMore'
			}
		},
		methods: {
			scanQrcode () {
				let t = this
				uni.scanCode({
					onlyFromCamera: true,
					success: function (res) {
						t.selfNo = res.result
						t.page = 1
						t.getData()
						t.ScanSuccess()
					},
					fail() {
						t.ScanError()
					}
				});
			},
			getData() {
				unloadPage(this.selfNo, this.statusValue[this.statusIndex], this.page).then(res => {
					if(this.page == 1){
						this.data = res.list
					} else {
						this.data = this.data.concat(res.list)
					}
					this.totalPage = res.pages
					if(res.list.length == 0){
						this.status = 'noMore'
					}
					console.log(this.status)
				})
			},
			goDetail (e, i) {
				uni.navigateTo({
					url: './detail?shipmentId=' + e
				})
			},
			statusChange (e) {
				this.statusIndex = e.detail.value
				this.page = 1
				this.getData()
			}
		}
	}
</script>
<style lang="scss">
	@import './list.scss';
</style>
