<template>
	<!-- 订单调仓弹窗 -->
	<view class="cu-modal" :class="transferModal ? 'show' : ''" style="z-index: 900;">
		<view class="cu-dialog">
			<view class="transferModal_title">
				{{title}}
			</view>
			<view class="cu-form-group">
				<view class="title">{{$t('到仓时间')}}:</view>
				<picker mode="date" :value="arrival_date" @change="selectArrivalDate">
					<view class="picker">{{ arrival_date ? arrival_date : $t('选择时间') }}</view>
				</picker>
			</view>
			<view class="cu-bar bg-white justify-end top-line">
				<view class="action">
					<button class="cu-btn bg-green" @tap="submitTransfer">{{$t('确认')}}</button>
					<button class="cu-btn bg-grey margin-left" @tap="cancelTransfer">{{$t('取消')}}</button>
				</view>
			</view>
		</view>
	</view>

</template>

<script>
	import * as types from '../../../store/mutations-types.js';
	import {
		transferWarehouses
	} from '../../../api/api.js';
	import mixins from '../../../mixins/mixin.js';
	import {
		uniIcons
	} from '@dcloudio/uni-ui';

	export default {
		mixins: [mixins],
		props: ['loadId'],
		components: {
			uniIcons
		},
		data() {
			return {
				transfer_order:'',
				arrival_date:'',
				transferModal:false,
				title:'',
				callbackData:false
			}
		},
		filters: {
			
		},
		computed: {
		},
		methods: {
			show(show, transfer_order,title,callbackData) {
				if(!!show){
					this.transfer_order = transfer_order;
					this.title = title||'';
					this.arrival_date = '';
					this.transferModal = !!show;
					this.callbackData = callbackData;
				}else{
					this.transferModal = !!show;
				}	
			},
			submitTransfer() {
				if(!this.arrival_date){
					this.$store.dispatch(types.SHOW_ALERT, {
						msg: this.$t('请选择到仓时间')
					});
					return false
				}
				transferWarehouses(this.arrival_date,this.transfer_order).then(data=>{
					this.$store.dispatch(types.SHOW_TOAST, {
						msg: data
					});
					setTimeout(() => {
						this.show(false);
						this.$emit('submit',this.callbackData);
					}, 1000);
				})
			},
			// 取消
			cancelTransfer(){
				this.show(false);
				// this.$emit('cancel');
			},
			selectArrivalDate(e){
				this.arrival_date = e.detail.value;
			},
		}
	}
</script>

<style>
	.transferModal_title{
		background-color: #ffffff;
		padding: 30upx;
		color: #e54d42;
		border-bottom: #ddd solid 1px;
		font-size: 28upx;
	}
</style>
