<template>
	<view>
		<uni-forms ref="form" :modelValue="formData" :rules="rules">
			<uni-row>
				<uni-col :span="24">
					<uni-forms-item label="物料件号" :labelWidth='90' name="pieceNo">
						<uni-easyinput suffixIcon="scan" @iconClick="scanBar" v-model="formData.pieceNo" type="text" />
					</uni-forms-item>
				</uni-col>
			</uni-row>
		</uni-forms>
		<u-button type="primary" @click="submit">提交</u-button>
	</view>
</template>

<script>
	import {
		pieceReport
	} from "@/api/mes/jobReport.js";

	export default {
		mounted() {

		},
		data() {
			return {
				formData: {
					pieceNo: null,
				},

				rules: {
					pieceNo: {
						rules: [{
							required: true,
							errorMessage: '请输入件号！'
						}]
					},
				}
			}
		},
		methods: {
			scanBar() {
				const _this = this;
				uni.scanCode({
					scanType: ['qrCode', 'barCode'],
					success: function(res) {
						_this.formData.pieceNo = res.result;
					}
				});
			},
			submit() {
				const _this = this;
				this.$refs.form.validate().then(res => {
					uni.showModal({
						title: '提示',
						content: '您确定报工吗？',
						success: function(res) {
							if (res.confirm) {
								_this.$modal.loading('提交中')
								pieceReport(_this.formData.pieceNo, {}).then(res => {
									_this.$modal.closeLoading();
									_this.$modal.msgSuccess("件号报工成功！");
									setTimeout(() => {
										_this.$tab.switchTab("/pages/work/index");
									}, 500);
								});

							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				});
			},

		}
	}
</script>

<style>


</style>