<template>
	<view class="affirm-page">
		<view class="affirm-view overscroll">
			<!-- 门店信息 -->
			<form>
				<view class="module-com">
					<view class="commodity-view">
						<view class="commodity-list">
							<view class="commodity-item">
									<view class="flex-space commodity-title">
										<view class="ov-1x">{{ selectPxInfo.name }}</view>
										<text>￥{{ selectPxInfo.tuition }}</text>
									</view>
								<view class="flex-space commodity-center">
									<view class="ov-1x">{{ selectPxInfo.target }}</view>
									<text>x1</text>
								</view>
							</view>
						</view>
					</view>
				</view>
				<!-- 登录信息 -->
				<view class="module-com input-line-wrap">
					<tui-list-cell class="line-cell" :hover="false" :arrow="true">
						<view class="tui-title ">客户</view>
						<view class="tui-input" v-if="clientInfo.id" @click="showCustomer = true">{{ clientInfo.name }}</view>
						<view class="tui-placeholder" style="width: 100%" v-else @click="showCustomer = true">请选择客户</view>
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false" :arrow="false" >
						<view class="tui-title ">姓名</view>
						<input type="number" placeholder="请输入真实姓名" v-model="name" placeholder-class="tui-placeholder">
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false" :arrow="false" >
						<view class="tui-title ">手机号</view>
						<input type="number" placeholder="请填写" v-model="phone" placeholder-class="tui-placeholder">
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false" :arrow="false">
						<view class="tui-title ">结算方式</view>
						<button class="admin-button-com mini-btn" :class="payType==res.id?'blue':'default'" style="margin-right: 10rpx"
														@tap="payType=res.id"  v-for="(res,i) in getDictionariesInfo.htPayWayOption">
							{{ res.name }}
						</button>
					</tui-list-cell>


<!--					<appFormSend :form.sync="form"> </appFormSend>-->
				</view>
			</form>
		</view>
		<view class="under-bar">
			<view class="price-view">
				<text class="price-title">收款</text>
				<text class="price-number">
					¥ <text class="large">{{ selectPxInfo.tuition  }}</text>
				</text>
			</view>
			<button class="admin-button-com blue middle" @click="affirmFormSubmit">确定</button>
		</view>
		<!-- 选择客户 -->
		<AppCustomerSel :show.sync="showCustomer" @change="changeCustomerFn" />
	</view>
</template>

<script>
import TuiListCell from "@/components/plugin/list-cell";
import AppAvatarModule from "@/components/module/app-avatar";
import SimpleAddress from "@/components/plugin/simple-address";
import AppAreaSel from "@/components/app-area-sel";
import AppCustomerSel from "@/components/app-customer-sel";
import productMins from "@/mixins/product";
import appFormRadioBtn from "@/components/app-formRadio-btn";
import appAddressGroup from "@/components/app-address-group";
import appSendTime from "@/components/app-send-time";
import appFormSend from "@/components/app-form-send";
const formUtil = require("@/utils/formValidation.js");
import { createOrder,freight,createPxClassOrder } from "@/api/order/index";
// import { freight } from "@/api/order";
import { mapActions, mapGetters } from "vuex";

export default {
	name: "BillingAffirm", // 开单确认
	components: {
		TuiListCell,
		AppAvatarModule,
		SimpleAddress,
		AppAreaSel,
		AppCustomerSel,
		appFormRadioBtn,
		appAddressGroup,
		appSendTime,
		appFormSend
	},
	mixins: [productMins],
	data() {
		return {
			selectPxInfo:'',//选中的-培训班
			autoLoad: false,
			name:'',
			phone:'',
			payType:null,//选中的-支付类型
			clientInfo: '',//客户信息
			showCustomer: false
		};
	},
	onLoad() {
		setTimeout(()=>{
			this.payType = this.getDictionariesInfo.htPayWayOption[0].id;
		},100)
		this.selectPxInfo = uni.getStorageSync('affirmPxClass');
	},
	computed: {
		...mapGetters(["getMerchantInfo", "getLoginInfo","getDictionariesInfo"])
	},
	methods: {
		...mapActions(["initMerchantInfo"]),
		affirmFormSubmit() {
			let pattern = /^1\d{10}$/;  //验证以1开头11位数
			if (this.name == '') {
				uni.showToast({title: '请输入姓名', icon: 'none'});
				return;
			}
			if (!pattern.test(this.phone)) {
				uni.showToast({title: '请输入正确的手机号', icon: 'none'});
				return;
			}
			if (this.payType == null) {
				uni.showToast({title: '请选择付款方式', icon: 'none'});
				return;
			}
			let options = {
				classId: this.selectPxInfo.id,
				customId: this.clientInfo.id,
				name: this.name,
				mobile: this.phone,
				payWay: this.payType,
			}
			let self = this;
			uni.showModal({
				title: '提示',
				content: '确认开单？',
				success: function (res) {
					if (res.confirm) {
						createPxClassOrder(options).then(res => {
							// this.$msg("下单成功");
							uni.removeStorageSync('affirmPxClass')
							uni.redirectTo({url:'/common/pageSuccess?title=开单成功'})
						});
						// self.formSubmit();
					}
				}
			});
		},
		//选择客户
		changeCustomerFn(info) {
			this.clientInfo = info;
		},
	}
};
</script>

<style lang="scss" scoped>
.admin-button-com {
	margin-right: 20upx;
}
.affirm-page {
	position: relative;
	height: 100%;
	display: flex;
	flex-direction: column;

	.affirm-view {
		flex: 1;
		padding: 20px;
		background-color: #f0f2f6;

		.commodity-view {
			display: flex;
			flex-direction: column;
			.commodity-list {
				padding: 20px;
				.commodity-item {
					.commodity-title{
							view{
								width: 70%;
								font-size: 28rpx;
							}
							text{
								color: #ff1f1f;
							}
					}
					.commodity-center{
						margin-top: 20rpx;
						color: #949494;
						view{width: 70%;}
					}
				}
			}
			.summary-bar {
				padding: 0 20px;
				height: 90px;
				display: flex;

				align-items: center;
				justify-content: space-between;
				border-top: 1px solid #eeeeee;
				.operate-view {
					display: flex;

					align-items: center;
					color: #3385ff;
					font-size: 26px;
					.iconfont {
						margin-right: 20px;
						font-size: 40px;
					}
				}
				.describe-view {
					display: flex;

					align-items: center;
					color: #333;
					font-size: 24px;
					.price {
						font-weight: bold;
						font-size: 36px;
					}
				}
			}
		}

		.module-com {
			background-color: #fff;
			margin-bottom: 20px;

			border-radius: 10px;
			overflow: hidden;
			.member-wrap {
				.member-det {
					font-size: 24px;
					margin-left: 20px;
				}
			}
			.remark-wrap {
				align-items: flex-start;
				.remark {
					height: 240px;
				}
			}
			// .tui-placeholder,
			// .tui-input {
			// 	padding-right: 30px;
			// 	width: 100%;
			// 	text-align: right;
			// }
		}
	}
	.under-bar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 20px;
		width: 100%;
		height: 100px;
		background-color: #fff;

		box-shadow: 0px -1px 6px 0px rgba(4, 0, 0, 0.06);
		.price-view {
			display: flex;
			align-items: center;
			font-size: 24px;
			.price-title {
				color: #333;
			}
			.price-number {
				margin: 0 20px;
				color: #ff2842;
				.large {
					font-size: 40px;
				}
			}
		}
		.admin-button-com {
			width: 200px;
		}
	}
}
</style>
