<template>
	<view class="checkSubmit">
		<view class="dtl">
			<view class="">
				物料编码：{{option.materialCode}}
			</view>
			<view class="">
				二维码编码：{{option.supplierName}}
			</view>
			<view class="">
				物料名称：{{option.materialName}}
			</view>
		</view>
		<view class="form-box" style="margin:0 30rpx">
			<uni-forms ref="baseForm" :modelValue="formData" label-position="top">
				<view class="commons-title">
					质检结果
				</view>
				<uni-forms-item label="称重结果" required>
					<input 
						style="border-bottom:1px solid #dcdcdc;width:90%;display: inline-block;" 
						:type="'number'"  
						v-model="formData.weighingResults" 
						:min="0" placeholder="请输入称重结果" />
					<span style="margin-left:30rpx">kg</span>	
				</uni-forms-item>
				<uni-forms-item label="实际克重" required>
					<input 
						style="border-bottom:1px solid #dcdcdc;width:90%;display: inline-block;" 
						:type="'number'"  
						v-model="formData.unitWeight" 
						:min="0" placeholder="请输入实际克重" />
					<span style="margin-left:30rpx">g</span>	
				</uni-forms-item>
				
			</uni-forms>
		</view>
		<view class="submit-box">
			<button @click="checkSubmit(1)" style="background:#0066CC; color:#fff;margin-bottom: 30rpx;">确定</button>
		</view>
	</view>
</template>

<script>
	import {
		getInfo
	} from "@/util/api.js";
	import Vue from 'vue'
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	import {
		dateFormat,
		getTime
	} from '../../util/uitl.js'
	export default {
		components: {
			htzImageUpload,
		},
		data() {
			return {

				formData: {
					quantitycheckId: null,
					materialId: null,
					quantity: null,
					qrCode: null,
					checkJudgment: null,
					checkQty: null,
					imageUrl: null,
					id: null,
					imageUrlAry: [],
					weighingResults:0,
					unitWeight:0,
				},
				imgs:[],
				option: null,
				imgUrl: null,
				checkListData: [],
				optionCopy:null,
			}
		},
		onLoad(option) {
			
			
			const v = this
			
			v.userData = Vue.prototype.$userInfo
			v.option = JSON.parse(decodeURIComponent(option.data))
			v.optionCopy = JSON.parse(JSON.stringify(v.option))
			v.formData.stockQuantitycheckId = v.option.id
			v.formData.materialId = v.option.materialCode
			v.formData.quantity = v.option.quantity
			v.formData.checkQty = v.option.quantity
			v.formData.qrCode = v.option.qrCode
			v.formData.unitWeight = v.option.unitWeight
			v.formData.weighingResults = v.option.weighingResults
			if(v.option.id2){
				v.formData = v.option
				v.formData.id = v.option.id2
			}
			console.log(v.formData,123123123)
			// uni.getStorage({
			// 	key: "checkListData",
			// 	success(_data) {
			// 		console.log(_data)
			// 		v.checkListData = []
			// 	},
			// 	fail() {

			// 	}
			// })
			console.log(v.formData)
		},
		methods: {
			imgDelete(_index){
				const v = this
				v.imgs.splice(_index,1)
			},
			bindUpload() {
				const v = this
				wx.chooseImage({
					count: 1,
					sizeType: ["original", "compressed"], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ["album", "camera"], // 可以指定来源是相册还是相机，默认二者都有
					success: function(res) {
						// 返回选定照片的本地文件路径列表，tempFilePath可以作为img标签的src属性显示图片
						var tempFilePaths = res.tempFilePaths
						for (var i = 0; i < tempFilePaths.length; i++) {
							v.imgs.push({loadingType:true})
							wx.uploadFile({
								url: 'https://wmswx.adprintingplus.com/api/wx/common/uploadFile',
								filePath: tempFilePaths[i],
								name: "file",
								header: {
									"content-type": "multipart/form-data",
									'Authorization': Vue.prototype.$token,
								},
								success: function(res) {
									console.log(res.data)
									res.data = JSON.parse(res.data)
									if (res.data.code == 200) {
										wx.showToast({
											title: "上传成功",
											icon: "none",
											duration: 1500
										})
										v.imgs.splice(-1)
										v.imgs.push(res.data.data)
									}

								},
								fail: function(err) {
									wx.showToast({
										title: "上传失败",
										icon: "none",
										duration: 2000
									})
								},
								complete: function(result) {
									console.log(result.errMsg)
								}
							})
						}
					}
				})

			},
			zidingyiSuccess() {

			},
			checkSubmit(_type) {
				const v = this
				v.formData.checkJudgment = _type
				v.$post('/wx/check/weighTemp',v.formData).then(res=>{
					if(res.code == 200){
						uni.showToast({
							title: '提交成功，跳转中！'
						})
						setTimeout(() => {
							
							wx.reLaunch({
								url: '/pages/weigh/checkDtl?data=' + encodeURIComponent(JSON.stringify(v.optionCopy))
							})
						}, 2000)
					}
				})
				

			},
			select(e) {
				console.log(e)
				const v = this
				v.$post('/wx/common/uploadFile', {
					file: e.tempFilePaths[0]
				}).then(res => {

				})
			},
		},
	}
</script>

<style lang="less">
	.checkSubmit {
		.submit-box {

			padding: 0 30rpx;
		}

		.dtl {
			padding: 30rpx;
			border-bottom: 1rpx solid #dcdcdc;
			font-size: 26rpx;
			line-height: 40rpx;
		}

		.addQrcode-list {
			height: 80rpx;
			display: flex;
			justify-content: space-between;
			padding: 15rpx;
			border-bottom: 1rpx solid #dcdcdc;
			font-size: 24rpx;

			.fl {
				display: flex;

				.code {
					margin-right: 20rpx;
				}
			}

			.fr {
				line-height: 80rpx;
			}
		}
	}

	.popup-input-warp {
		padding: 30rpx 40rpx;
	}


	.txt {
		margin-bottom: 20rpx;
	}

	.imglist {
		display: flex;
		flex-wrap: wrap;
	}

	.imglist .item {
		width: 150rpx;
		height: 150rpx;
		margin-right: 22rpx;
		margin-bottom: 10rpx;
		position: relative;
	}

	.imglist .last-item {
		width: 150rpx;
		height: 150rpx;
		text-align: center;
		line-height: 146rpx;
		border: 2rpx dashed #8B97A9;
		box-sizing: border-box;
	}

	.imglist .item image {
		width: 100%;
		height: 100%;
	}

	.imglist .item .delete {
		width: 30rpx;
		height: 30rpx;
		position: absolute;
		top: -25rpx;
		right: -12rpx;
		font-size: 40rpx;
		font-weight: bold;
	}
</style>
