<template>
    <view class="page">
	<NavBar :title="$t('修改委外检验信息')"></NavBar>
	<view class="infoedit">
		<u-form ref="form" :modelValue="form" class="login-form" :labelWidth="160">
			<u-form-item prop="ti003" :label="$t('序号：')" class="disabled">
				<input
					v-model="form.ti003"
					type="text"
					disabled
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti004" :label="$t('品号：')" class="disabled">
				<input
					v-model="form.ti004"
					disabled
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti005" :label="$t('品名：')" class="disabled">
				<input
					v-model="form.ti005"
					disabled
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti014" :label="$t('工单单号：')" class="disabled">
				<input
					v-model="form.ti014"
					disabled
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti010" :label="$t('批号：')" class="disabled">
				<input
					v-model="form.ti010"
					disabled
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti007" :label="$t('进货数量：')" class="disabled">
				<input
					v-model="form.ti007"
					disabled
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti019" :label="$t('验收数量：')">
				<input
					v-model.number="form.ti019"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti020" :label="$t('计价数量：')">
				<input
					v-model.number="form.ti020"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti022" :label="$t('验退数量：')">
				<input
					v-model.number="form.ti022"
					type="text"
					@confirm="submit"
				>
				</input>
			</u-form-item>
			<u-form-item prop="ti021" :label="$t('报废数量：')">
				<input
					v-model.number="form.ti021"
					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]
		}
	},
    data() {
      return {
		info: null,
		index: 0,
		form: {
			ti003: null,
			ti004: null,
			ti005: null,
			ti014: null,
			ti007: null,
			ti019: null,
			ti020: null,
			ti022: null,
			ti021: null,
		}
      };
    },
    created() {
    },
    methods: {
		submit(row) {
			if (this.form['ti020'] || this.form['ti019']) {
				const ti019 = this.form['ti019'] || 0
				const ti020 = this.form['ti020'] || 0
				if (ti020 > ti019) return this.$u.toast(i18n.t('计价数量不能大于验收数量'))
			}
			if (this.form['ti019'] || this.form['ti022'] || this.form['ti021']) {
				const ti019 = this.form['ti019'] || 0
				const ti022 = this.form['ti022'] || 0
				const ti021 = this.form['ti021'] || 0
				const ti007 = Number(this.form['ti007'])
				if (ti019 + ti022 + ti021 > ti007) return this.$u.toast(i18n.t('验收数量+报废数量+验退数量不能大于进货数量'))
			}
			this.info[this.index] = {...this.info[this.index], ...this.form}
			uni.redirectTo({
              url: '/pages/mocthforcheck/Info?info=' + encodeURIComponent(JSON.stringify(this.info))
            });
		}
    },
  };
  </script>
  
  <style lang="scss" scoped>
  ::v-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;
	}
	
  }
  </style>
  