<template>
	<view class="page">
		 <view class="bg-white mt-1 py-1 font-md">
		 	<item-row title="生产订单号" :span="6">{{detail.CJDD}}</item-row>
		 	<item-row title="物品号" :span="6">{{detail.WPH}}</item-row>
		 	<item-row title="生产订单数量" :span="6">{{detail.DDSL1}}</item-row>
		 </view>
		<btn-save @save='onSubmit' :disabledOk="disabledSubmit"></btn-save>
	</view>
</template>

<script>
	import btnSave from "@/components/common/btn-save.vue"
	import itemRow from "@/components/common/item-row.vue"
	import {formateScanData} from "@/common/utils/common.js"
	import {mapGetters} from "vuex"
	import {updateProduceBegin,queryByCjdd} from "@/api/api.js"
	
	export default {
		components:{
			btnSave,
			itemRow
		},
		data () {
			return {
				barcode:null, //条形码
				orderno:null,  // 生产订单号
				detail:{} ,  // 订单详情
			}
		},
		computed:{
			...mapGetters(['disabledSubmit'])
		},
		onLoad (e) {
			this.barcode=e.barcode
			const {orderno}=formateScanData(e.barcode)
			this.orderno=orderno
			this._queryByCjdd()
		},
		methods:{
			// 获取数据
			async _queryByCjdd () {
				const reqdata={
					CJDD:this.orderno
				}
				const resdata=await queryByCjdd(reqdata)
				this.detail=resdata[0]
				return resdata
			},
			// 保存
			async _updateProduceBegin () {
				const reqdata={
					CJDD:this.detail.CJDD
				}
				const resdata=await updateProduceBegin(reqdata)
				return resdata
			},
			// 提交接口
			onSubmit () {
				uni.showModal({
					title:"确定提交吗?",
					success:async res=>{
						if (res.confirm) {
							await this._updateProduceBegin()
							uni.showToast({
								title:"保存成功"
							})
							uni.reLaunch({
								url:"/pages/index/index"
							})
						}
					}
				})
				
			}
		},
	}
	
	
</script>

<style>
</style>
