<template>
    <view class="page">
	<NavBar :title="$t('录入入库单')"></NavBar>
	<view class="infoedit">
		<u-form ref="form" :modelValue="form" class="login-form" :labelWidth="190">
			<u-form-item prop="tb001" :label="$t('入库单别：')">
				<input
					v-model="form.tb001"
					type="text"
					
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc013" :label="$t('类型：')">
				<uni-data-select
				v-model="form.tc013"
				:clear="false"
				:localdata="typeData"
				></uni-data-select>
			</u-form-item>
			<u-form-item prop="tc004" :label="$t('工单单别：')">
				<input
					v-model="form.tc004"
					type="text"
					@confirm="inputCC"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc005" :label="$t('工单单号：')">
				<input
					v-model="form.tc005"
					focus
					type="text"
					@confirm="inputCC"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc006" :label="$t('移出加工顺序:')">
				<input
					v-model="form.tc006"
					
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tb005" :label="$t('移出地：')">
				<input
					v-model="form.tb005"
					
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc056" :label="$t('库位：')">
				<input
					v-model.number="form.tc056"
					
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>

			<u-form-item prop="tb008" :label="$t('移入地：')">
				<input
					v-model.number="form.tb008"
					
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc032" :label="$t('批号：')">
				<input
					v-model.number="form.tc032"
					
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc036" :label="$t('转移数量：')">
				<input
					v-model="form.tc036"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc020" :label="$t('使用人时：')">
				<input
					v-model="form.tc020"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="tc021" :label="$t('使用机时：')">
				<input
					v-model="form.tc020"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item style="width:100%;">
			<button
				size="medium"
				type="primary"
				style="width:95%;margin-top: 50rpx"
				@click="submit()"
			>
				<span>{{$t('确定')}}</span>
			</button>
			</u-form-item>
		</u-form>
	</view>
    </view>
  </template>
  
  <script>
import i18n from '../../lang/index'

  import StickyNavBar from "@/components/StickyNavBar/index.vue";
  import ContentLoadingMore from "@/components/ContentLoadingMore/index.vue";
  export default {
    components: {
      StickyNavBar,
      ContentLoadingMore,
    },
	onLoad(option) {
		if (option.info) {
			let data = JSON.parse(decodeURIComponent(option.info));
			this.index = option.index
			this.info = data
			this.form = data.moctis[this.index]
			this.form['tc004'] = this.form['tc004'] ? this.form['tc004'].trim() : ''
			this.form['tc005'] = this.form['tc005'] ? this.form['tc005'].trim() : ''
			this.form['tc006'] = this.form['tc006'] ? this.form['tc006'].trim() : ''
			this.form['tc056'] = this.form['tc056'] ? this.form['tc056'].trim() : ''
		}
	},
    data() {
      return {
		info: null,
		index: 0,
		typeData: [{
				text: '1:正常完成',
				value: '1'
			},
			{
				text: '2:返工完成',
				value: '2'
			},
			{
				text: '3:退回返工',
				value: '3'
			},
			{
				text: '4:拨转',
				value: '4'
			},
			{
				text: '5:盘盈盘亏',
				value: '5'
			},
			{
				text: '6:投入',
				value: '6'
			}
		],
		form: {
			tc013: '1',
			tb001: 'D20',
			tc004: '5101',
			tc005: null,
			tc006: null,
			tb005: null,
			tc056: null,
			tb008: null,
			tc032: null,
			tc036: null,
			tc020: null,
			tc020: null,
		}
      };
    },
    created() {
    },
    methods: {
		inputCC(e){
			if(e && e.detail.value) {
				if(e.detail.value.includes("-")){
					const arr = e.detail.value.split("-")
					if (arr.length === 2) {
						this.form.tc004 = arr[0]
						this.form.tc005 = arr[1]
					}
				} else {
					this.submit()
				}
			}
		},
		submit(row) {
			if (!this.form['tb001']) {
				return this.$u.toast(i18n.t('请输入入库单别'))
			}
			if (!this.form['tc004']) {
				return this.$u.toast(i18n.t('请输入工单单别'))
			}
			if (!this.form['tc005']) {
				return this.$u.toast(i18n.t('请输入工单单号'))
			}
			if (!this.form['tc006']) {
				return this.$u.toast(i18n.t('请输入移出加工顺序'))
			}
			if (!this.form['tb005']) {
				return this.$u.toast(i18n.t('请输入移出地'))
			}
			if (!this.form['tc056']) {
				return this.$u.toast(i18n.t('请输入库位'))
			}
			if (!this.form['tb008']) {
				return this.$u.toast(i18n.t('请输入移入地'))
			}
			if (!this.form['tc036']) {
				return this.$u.toast(i18n.t('请输入入库数量'))
			}
			this.$u.api.createforstorage(this.form).then(res => {
				if(res.success) {
					this.$u.toast(i18n.t('入库成功'))
					this.form =  {
						tc013: '1',
						tb001: 'D20',
						tc004: '5101',
						tc005: null,
						tc006: null,
						tb005: null,
						tc056: null,
						tb008: null,
						tc032: null,
						tc036: null,
						tc020: null,
						tc020: null,
					}
				}
			})
		}
    },
  };
  </script>
  
  <style lang="scss" scoped>
  /deep/ .u-sticky {
    top: 0 !important;
    background: #fff;
  }
  .infoedit {
	padding: 20rpx 20rpx;
	.underline {
		border-bottom: 1px solid #d5d5d5;
		padding-bottom: 0px;
    	line-height: 40px;
		font-weight: 500;
		margin-left: 20rpx;
		font-size: 19px;
	}
	.u-border-bottom:after {
		display: none;
	}
	/deep/ .uni-select{
		border: none !important;
	}
	
  }
  
  </style>
  