<template>
	<view class="warp">
		<view class="transaction">
			<u-form :model="purchaseOrder" ref="uForm" class="uForm">
				<u-form-item label="合同编号" prop="receivingAddress" label-width="140">
					<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
				</u-form-item>
				<u-form-item label="任务编号" prop="receivingAddress" label-width="140">
					<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
				</u-form-item>
				<u-form-item label="货名" prop="receivingAddress" label-width="140">
					<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="" disabled/>
				</u-form-item>
				<u-form-item label="发货地址" prop="receivingAddress" label-width="140" label-position='top'>
					<u-input v-model="purchaseOrder.receivingAddress" input-align="left" placeholder="" disabled/>
				</u-form-item>
				<u-form-item label="收货地址" prop="receivingAddress" label-width="140" label-position='top'>
					<u-input v-model="purchaseOrder.receivingAddress" input-align="left" placeholder="请输入收货地址" disabled/>
				</u-form-item>
				<u-form-item label="运费（元/吨）" prop="freightUnitPrice" label-width="250">
					<u-input v-model="purchaseOrder.freightUnitPrice" input-align="right" placeholder="请输入运费单价" />
				</u-form-item>
			</u-form>
		</view>
		<u-toast ref="uToast" />
		<view class="bottom-btn">
			<u-button type="primary" class="submit" hover-class="none">已通过</u-button>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				purchaseOrder: {
					freightUnitPrice: "123",
					receivingAddress:'444'
				},
				rules: {
					freightUnitPrice: [{
							validator: (rule, value, callback) => {
								return !this.$u.test.isEmpty(value)
							},
							message: '运费不能为空',
							trigger: ['change', 'blur']
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.amount(value)
							},
							message: '数值类型，最多保留两位小数',
							trigger: ['change', 'blur'],
						}
					]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			passSubmit(){
				this.$refs.uForm.validate(valid => {
					if (valid) {
						uni.showLoading({
							title: '正在加载',
							mask: true
						})
						console.log('验证通过');
						this.$api.doRequest('post',
							'/freightReceivingDispatching/api/insertFreightReceivingDispatching',
							this
							.purchaseOrder).then(res => {
							if (res.data.code == 200) {
								uni.showToast({
									title: '提交成功',
									icon: 'none',
									duration: 2000,
									success: function() {
										uni.navigateTo({
											url: `/pageA/freightTransport/index`
										})
									}
								})
				
							}
				
						}).catch(res => {
							// uni.showToast({
							// 	title: res.data.message,
							// 	icon: 'none',
							// 	duration: 2000
							// })
						})
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style scoped lang="scss">
	.transaction {
		background-color: #FFFFFF;
		margin: 10rpx;
		padding-bottom: 10rpx;
		border-radius: 20rpx;
	}
	.uForm {
		padding: 0 40rpx;
	}
	.u-form-item{
		padding: 0;
	}
	.bottom-btn {
		width: 100%;
		position: fixed;
		bottom: 40rpx;
		display: flex;
		z-index: 2;
	}
	.submit {
		width: 40%;
		background: #22C572;
		border-radius: 10rpx;
	}
</style>
