<template>
	<view class="center">
		<view class="transaction">
			<u-form :model="purchaseOrder" ref="uForm" class="uForm">
				<u-form-item label="业务编号" prop="businessNumber" label-width="140" required>
					<u-input v-model="purchaseOrder.businessNumber" input-align="right" placeholder="请输入业务编号" />
				</u-form-item>
				<u-form-item label="收货方" prop="consignee" label-width="140" required>
					<u-input v-model="purchaseOrder.consignee" input-align="right" placeholder="请输入收货方名称" />
				</u-form-item>
				<u-form-item label="发货方" prop="shipper" label-width="140" required>
					<u-input v-model="purchaseOrder.shipper" input-align="right" placeholder="请输入发货方名称" />
				</u-form-item>
				<u-form-item label="货名" prop="goodsName" label-width="140" required>
					<u-input v-model="purchaseOrder.goodsName" input-align="right" placeholder="请输入货名，如玉米" />
				</u-form-item>
				<u-form-item label="货物单价（元/吨）" prop="goodsPrice" label-width="250" required>
					<u-input v-model="purchaseOrder.goodsPrice" input-align="right" placeholder="请输入货物单价" />
				</u-form-item>
				<u-form-item label="运费单价（元/吨）" prop="freightUnitPrice" label-width="250" required>
					<u-input v-model="purchaseOrder.freightUnitPrice" input-align="right" placeholder="请输入运费单价" />
				</u-form-item>
				<u-form-item label="运费承担方" prop="freightUnitPrice" label-width="250" required>
					<view class="con-list">
						<picker @change="packingChange" :value="packingIndex" :range="packingType">
							<view class="picker">
								{{packingIndex>-1?packingType[packingIndex]:'请选择'}}
							</view>
						</picker>
					</view>
				</u-form-item>
				<u-form-item label="收货地址" prop="receivingAddress" label-width="140" required>
					<u-input v-model="purchaseOrder.receivingAddress" input-align="right" placeholder="请输入收货地址" />
				</u-form-item>
				<u-form-item class='last' label="收货人账号" prop="accountNumber" label-width="160" required>
					<u-input v-model="purchaseOrder.accountNumber" input-align="right" placeholder="请输入收货人账号" />
				</u-form-item>
			</u-form>
		</view>
		<view class="account-tip">
			注：收货人账号为收货人注册易粮易运的手机号码
		</view>
		<view class='footer'>
			<button class="btn" @click="commit()">提交</button>
		</view>


	</view>
</template>

<script>
	// import fullPopup from '@/components/common/fullPopup'
	export default {
		name: "business",
		  components: {
		    // fullPopup
		  },
		data() {
			return {
				purchaseOrder: {
					freightPayer: "发货方承担"
				},
				packingType: ["发货方承担", "收货方承担"],
				isFreightUnitPrice: true,
				packingIndex: 0,
				phone: "",
				rules: {
					businessNumber: [{
						validator: (rule, value, callback) => {
							return !this.$u.test.isEmpty(value)
						},
						message: '业务编号不能为空',
						trigger: ['change', 'blur']
					}, ],
					consignee: [{
						validator: (rule, value, callback) => {
							return !this.$u.test.isEmpty(value)
						},
						message: '收货方不能为空',
						trigger: ['change', 'blur']
					}],
					shipper: [{
						validator: (rule, value, callback) => {
							return !this.$u.test.isEmpty(value)
						},
						message: '发货方不能为空',
						trigger: ['change', 'blur']
					}],

					goodsName: [{
						validator: (rule, value, callback) => {
							return !this.$u.test.isEmpty(value)
						},
						message: '货名不能为空',
						trigger: ['change', 'blur']
					}],
					goodsPrice: [{
							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'],
						}
					],
					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'],
						}
					],
					receivingAddress: [{
						validator: (rule, value, callback) => {
							return !this.$u.test.isEmpty(value)
						},
						message: '收获地址不能为空',
						trigger: ['change', 'blur']
					}],
					accountNumber: [{
							validator: (rule, value, callback) => {
								return !this.$u.test.isEmpty(value)
							},
							message: '手机号码不能为空',
							trigger: ['change', 'blur']
						},
						{
							validator: (rule, value, callback) => {
								return this.$u.test.mobile(value);
							},
							message: '手机号格式不正确',
							trigger: ['change', 'blur']
						}
					]
				}
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		onLoad(options) {
			this.phone = options.phone
		},
		methods: {
			packingChange(event) {
				console.log(event)
				this.packingIndex = event.detail.value;
			},
			commit() {
				this.purchaseOrder.shipperPhone = this.phone
				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 lang='scss'>
	page,
	.content {
		background: #F5F6FA;
	}

	.center {
		overflow-y: hidden;
		padding-bottom: 200rpx;
	}

	.c-row {
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-align: center;
		-webkit-align-items: center;
		align-items: center;
		padding: 20rpx 30rpx;
		position: relative;
	}

	.con-list {
		-webkit-box-flex: 1;
		-webkit-flex: 1;
		flex: 1;
		display: -webkit-box;
		display: -webkit-flex;
		display: flex;
		-webkit-box-orient: vertical;
		-webkit-box-direction: normal;
		-webkit-flex-direction: column;
		flex-direction: column;
		color: #303133;
		line-height: 40rpx;
		text-align: right;
		/* padding-right: 20rpx; */
		/* color: red; */
	}

	.transaction {
		background-color: #FFFFFF;
		margin: 10px;
		padding-bottom: 10px;
		border-radius: 10px;
	}

	.line {
		display: inline-block;
		padding: 5px;
		position: relative;
		font-size: 17px;
	}

	.line.active {
		font-size: 19px;
		font-weight: 900;
	}

	.line.active:after {
		content: '';
		display: block;
		position: absolute;
		width: 38px;
		left: 50%;
		transform: translateX(-50%);
		bottom: 0;
		border-bottom: 1px solid #22C572;
	}

	.cu-tag.badge {
		right: 26rpx;
	}

	.cu-item {
		height: 80rpx;
		display: inline-block;
		line-height: 80rpx;
	}

	.search-form {
		background: #F5F6F9;
		padding-left: 20rpx;
	}

	.title-tip {
		color: #E63113;
		text-align: right;
	}

	.tag1 {
		background: #F5F6F9;
		padding: 5px;
		color: #333333;
		display: inline-flex;
		font-size: 22rpx;
		border-radius: 3px;
		margin: 3px;
	}

	.tag {
		background: #F5F6F9;
		padding: 7px 12px;
		color: #333333;
		display: inline-flex;
		font-size: 22rpx;
		border-radius: 15px;
		margin: 3px;
	}

	.tag-bule {
		background: #EBEEFA;
		color: #5C76DF;
	}

	.tag-green {
		background: #C6F7BC;
		color: #065112;
	}

	.tag-yellow {
		background: #F9F2EA;
		color: #BE9C69;
	}

	.tag-red {
		background: #FEECE6;
		color: #FE6430;
	}

	.text-white {
		color: #fff;
	}

	.text-white text {
		position: relative;
		z-index: 2;
		background: linear-gradient(45deg, #3DC146, #B2D612);
		padding: 5px 10px;
		border-radius: 38rpx;
	}

	.guess-section {
		padding-bottom: 100upx;
		display: flex;
		flex-wrap: wrap;
		padding: 30upx;
		background: #fff;
		margin: 10px;
		border-radius: 6px;

		.type {
			border-radius: 10px;
			padding: 5px;
			wdith: 22px;
			height: 22px;
			line-height: 14px;
			font-size: 12px;
		}

		.type.send {
			background: #22C572;
			color: #fff;
		}

		.type.put {
			background: #FD714F;
			color: #fff;
		}

		.businessnumber {
			font-size: 16px;
			font-weight: 600;
		}

		.consigner {
			font-size: 12px;
		}

		.time {
			color: #878C9C;
		}

		.goods {
			font-size: 12px;
		}

		.goodsstatus {
			background: #F9F9FA;
			color: #9698A2;
			padding: 10px 0;
			padding-left: 47px;
			margin: 10px 0;
		}

		.del {
			width: 60px;
			height: 33px;
			line-height: 33px;
			font-size: 14px;
			background: #fff;
			border: 1px solid #CDCDCD;
			border-radius: 30px;
			text-align: center;
		}
	}

	.navbar {
		position: fixed;
		left: 0;
		top: var(--window-top);
		display: flex;
		width: 100%;
		height: 80upx;
		background: #fff;
		box-shadow: 0 2upx 10upx rgba(0, 0, 0, .06);
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 30upx;
			color: $font-color-dark;
			position: relative;

			&.current {
				color: $base-color;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 120upx;
					height: 0;
					border-bottom: 4upx solid $base-color;
				}
			}
		}

		.p-box {
			display: flex;
			flex-direction: column;

			.yticon {
				display: flex;
				align-items: center;
				justify-content: center;
				width: 30upx;
				height: 14upx;
				line-height: 1;
				margin-left: 4upx;
				font-size: 26upx;
				color: #888;

				&.active {
					color: $base-color;
				}
			}

			.xia {
				transform: scaleY(-1);
			}
		}

		.cate-item {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			width: 80upx;
			position: relative;
			font-size: 44upx;

			&:after {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				border-left: 1px solid #ddd;
				width: 0;
				height: 36upx;
			}
		}
	}

	/* 分类 */
	.cate-mask {
		position: fixed;
		left: 0;
		top: var(--window-top);
		bottom: 0;
		width: 100%;
		background: rgba(0, 0, 0, 0);
		z-index: 95;
		transition: .3s;

		.cate-content {
			width: 630upx;
			height: 100%;
			background: #fff;
			float: right;
			transform: translateX(100%);
			transition: .3s;
		}

		&.none {
			display: none;
		}

		&.show {
			background: rgba(0, 0, 0, .4);

			.cate-content {
				transform: translateX(0);
			}
		}
	}

	.cate-list {
		display: flex;
		flex-direction: column;
		height: 100%;

		.cate-item {
			display: flex;
			align-items: center;
			height: 90upx;
			padding-left: 30upx;
			font-size: 28upx;
			color: #555;
			position: relative;
		}

		.two {
			height: 64upx;
			color: #303133;
			font-size: 30upx;
			background: #f8f8f8;
		}

		.active {
			color: $base-color;
		}
	}

	.introduce-section .title {
		font-size: 17px;
		font-weight: bold;
		height: 40px;
		line-height: 40px;
		flex: 2.5;
		border-bottom: 1px solid #EEEEEE;
	}

	.introduce-section .address {
		color: #878C9C;
		font-size: 12px;
		padding: 10px 0 10px;
	}

	.introduce-section .price {
		padding: 10px 0 10px;
		color: #FD714F;
		font-size: 19px;
		font-weight: 700;
	}

	.introduce-section .guess-item {
		border-radius: 10px;
		background: #fff;
		padding: 0upx 30upx 20upx;
		margin: 8px;
		border-bottom: 1px solid #ccc;
	}

	/* 销售信息 */
	.introduce-section {
		.title-tip {
			flex: 1;
		}

		.price-box {
			display: flex;
			align-items: baseline;
			font-size: 26upx;
		}

		.price {
			font-size: $font-lg + 2upx;
		}

		.m-price {
			margin: 0 12upx;
			color: $font-color-light;
			text-decoration: line-through;
		}

		.coupon-tip {
			align-items: center;
			padding: 4upx 10upx;
			background: $uni-color-primary;
			font-size: $font-sm;
			color: #fff;
			border-radius: 6upx;
			line-height: 1;
			transform: translateY(-4upx);
		}

		.bot-row {
			display: flex;
			align-items: center;
			height: 50upx;
			font-size: $font-sm;
			color: $font-color-light;

			view {
				flex: 1;
			}
		}
	}

	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		padding: 20px 0;
		z-index: 999;
	}

	.btn {
		width: 90%;
		background: #22C572;
		color: #fff;
		border-radius: 30px;
	}

	.btn:after {
		border: none;
	}

	.account-tip {
		font-size: 24rpx;
		font-weight: 400;
		color: #AFB3BF;
		padding-left: 60rpx;
	}

	.uForm {
		padding: 0 40rpx;
	}
	.last::after{
		border: 0 solid transparent;
	}
</style>
