<template>
	<view class="affirm-page">
		<view class="affirm-view overscroll">
			<!-- 门店信息 -->
			<form>
				<!-- 登录信息 -->
				<view class="module-com input-line-wrap">
					<appFormSend :form.sync="form" :customId="customId" :orderid="orderId"> </appFormSend>
				</view>
			</form>
			<view class="admin-button-com-box">
				<button class="admin-button-com blue big" @tap="formSubmit">确定</button>
			</view>

		</view>
		<!-- 选择客户 -->
		<!-- <AppCustomerSel :show.sync="showCustomer" @change="changeCustomerFn" /> -->
    <kd-entrance></kd-entrance>
	</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-send1";
const formUtil = require("@/utils/formValidation.js");
import { sendExpressage } from "@/api/order/index";
// import { getUserDet } from "@/api/member/index";
import { mapActions, mapGetters } from "vuex";

export default {
	name: "BillingAffirm", // 开单确认
	components: {
		TuiListCell,
		// AppAvatarModule,
		// SimpleAddress,
		// AppAreaSel,
		// AppCustomerSel,
		// appFormRadioBtn,
		// appAddressGroup,
		// appSendTime,
		appFormSend
	},
	// mixins: [productMins],
	data() {
		return {
			customId:'',
			orderId:'',
			autoLoad: false,
			form: {
				shopId: "",
				shopName: "",
				receiveProvince: "",
				receiveCity: "",
				receiveFloor: "",
				receiveAddress: "",
				receiveLong: "",
				receiveLat: "",
				sendType: "3",
				sendSide: "2",
				sendDate: "",
				sendTime: "",
				sendCost: "",
				customId: "",
				product: ""
			},

			// 详细地址
			// showRegion: false,
			showCustomer: false
		};
	},
	onLoad(e) {
		this.customId = e.id;
		this.orderId = e.orderId;
		if (!this.getMerchantInfo && this.customId != '0') {
			this.initMerchantInfo().then(data => {
				// uni.setNavigationBarTitle({title: data.name});
				uni.setNavigationBarTitle({title: '确认客户地址'});
			});
		} else {
			// uni.setNavigationBarTitle({title: this.getMerchantInfo.name});
			uni.setNavigationBarTitle({title: '确认客户地址'});
		}
	},
	computed: {
		...mapGetters(["getMerchantInfo", "getLoginInfo"])
	},
	methods: {
		...mapActions(["initMerchantInfo"]),
		init() {
			this._getDet();
		},
		// api
		_getDet() {
			let data = uni.getStorageSync("modifyShopB");
			if (this.$util.isEmpty(data)) return;
			Object.keys(this.form).forEach((i, index) => {
				// if (i != 'password') {
				this.form[i] = data[i];
				// }
			});
		},

		changeCustomerFn(info) {
			console.log("changeCustomerFn", info);
			this.form.customId = info.id;
			this.form.customName = info.name;
		},
		confirmFn(options) {
			console.log(options)
			sendExpressage({ id: this.orderId,sendCost:options.sendCost,expressId:options.sendSide,sendTime:options.sendTime }).then(res => {
				// this.form.province = res.data.province;
				// this.form.city = res.data.city;
				// this.$emit("selectAdress", this.form);
				// uni.navigateTo({url:'/pagesOrder/ship'});
				uni.navigateBack({delta: 1});
			})
		},
		// 表单验证
		async formSubmit(e) {
			try {
				// 表单规则
				let rules = [];

				// {
				// 	name: "sendTime",
				// 		rule: ["required"],
				// 	msg: ["请输入具体时间"]
				// }
				// 进行表单检查
				let formData = this.form;
				if (formData.sendType == "1") {
				} else {
					let temp = [
						{
							name: "receiveProvince",
							rule: ["required"],
							msg: ["请选择地址"]
						},
						{
							name: "receiveAddress",
							rule: ["required"],
							msg: ["请填写详细地址"]
						}
					];
					rules = rules.concat(temp);
				}

				const product = this.selectList.map(ele => {
					return { productId: ele.id, bigNum: ele.bigCount, smallNum: ele.smallCount };
				});
				formData.product = JSON.stringify(product);
				if (!this.getMerchantInfo) {
					await this.initMerchantInfo();
				}
				formData.shopId = this.getMerchantInfo.id;
				if (this.waySele == 1) {
					formData.sendCost = "免运费";
				}
				console.log(9999, formData);
				let checkRes = formUtil.validation(formData, rules);
				// 验证通过!
				if (!checkRes) {
					this.confirmFn(formData);
				} else {
					this.$msg(checkRes);
				}
			} catch (error) {
				console.log(999999, error);
			}
		},
		gobackEvent() {
			uni.navigateBack({
				delta: 1
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.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 {
					display: flex;
					margin-bottom: 20px;
					.item-icon {
						flex-shrink: 0;
						width: 140px;
						height: 140px;
					}
					.item-info {
						display: flex;
						flex-direction: column;
						justify-content: center;
						flex: 1;
						margin-left: 20px;
						.info-line {
							margin-bottom: 20px;
							display: flex;
							justify-content: space-between;
							align-items: flex-end;
							.item-name {
								color: #666;
								font-size: 28px;
							}
							.item-price {
								color: #333;
								font-size: 22px;
								.price {
									font-size: 32px;
									font-weight: bold;
								}
							}
							.item-type {
								color: #999;
								font-size: 24px;
							}
							.item-count {
								color: #666;
								font-size: 24px;
							}
						}
					}
				}
			}
			.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;
			// }
		}

		.admin-button-com-box{
			display: flex;
			justify-content: space-between;
			.admin-button-com{
				width: 100%;
				display: block;
				margin: 0 auto;
				&.active{
					background: #c4c4c5;
					border: 1px solid #c4c4c5;
				}
			}
		}

	}
	.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;
			display: block;
			margin: 0 auto;
		}
	}
}
</style>
