<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"
								v-for="(item, index) in selectList"
								:key="index"
							>
								<image class="item-icon" :src="item.cover" alt="商品图" />

								<view class="item-info">
									<view class="info-line">
										<text class="item-name">{{ item.itemName }}</text>
										<text class="item-price">
											<text class="unit">¥</text>

											<text class="price">
												{{ getSelectItemPrice(item) }}
											</text>
										</text>
									</view>
									<view class="info-line">
										<text class="item-type">{{ item.rank }}级</text>
										<text class="item-count">
											<text v-if="item.bigCount > 0 || item.smallCount > 0">{{
												`${item.bigCount}`
											}}</text>
											<text v-if="item.smallCount > 0">/</text>
											<text v-if="item.smallCount > 0">{{ item.smallCount }}</text>
										</text>
									</view>
								</view>
							</view>
						</view>
						<view class="summary-bar">
							<view class="operate-view" @click="gobackEvent">
								<text class="iconfont icongouwuche"></text>
								重选花材
							</view>
							<view class="describe-view">
								共{{ allCount.bigLength }}/{{ allCount.smallLength }}种,
								<!-- 共16扎9支， -->
								合计 ¥<text class="price">{{ allPrice }}</text>
							</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="packingMoney" placeholder-class="tui-placeholder">
					</tui-list-cell>
					<tui-list-cell class="line-cell" :hover="false" :arrow="false">
						<view class="tui-title ">送货</view>
						<button @tap="sendType=1" class="admin-button-com mini-btn" :class="sendType==1?'blue':'default'">自取</button>
						<button @tap="sendType=0" class="admin-button-com mini-btn" :class="sendType==0?'blue':'default'">配送</button>
					</tui-list-cell>
					<tui-list-cell v-if="sendType == 0" class="line-cell" :hover="false" :arrow="false" >
						<view class="tui-title ">运费</view>
						<input type="number" placeholder="选填" v-model="freight" 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" :key="i">
							{{ 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">{{ allPrice+Number(packingMoney)+Number(freight)  }}</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 } 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 {
			autoLoad: false,
			packingMoney:'',//包装费
			freight:'',//运费
			payType:1,//选中的-支付类型
			clientInfo: '',//客户信息
			showCustomer: false,
			sendType:1
		};
	},
	onLoad() {
		if (!this.getMerchantInfo) {
			this.initMerchantInfo().then(data => {
				uni.setNavigationBarTitle({
					title: data.name
				});
			});
		} else {
			uni.setNavigationBarTitle({
				title: this.getMerchantInfo.name
			});
		}
	},
	computed: {
		...mapGetters(["getMerchantInfo", "getLoginInfo","getDictionariesInfo"])
	},
	methods: {
		...mapActions(["initMerchantInfo"]),
		// 选取客户
		changeCustomerFn(info) {
			console.log("changeCustomerFn", info);
			this.clientInfo = info;
		},
		//确定开单
		affirmFormSubmit(){
			// if(this.clientInfo==''){uni.showToast({title:'请选择客户！',icon:'none'});return;}
			if(this.packingMoney==''){uni.showToast({title:'请输入包装费！',icon:'none'});return;}
			if(this.payType==null){uni.showToast({title:'请选择结算方式！',icon:'none'});return;}
			const product = this.selectList.map(ele => {
				return { productId: ele.id, bigNum: ele.bigCount, smallNum: ele.smallCount,classId:ele.classId,itemId:ele.itemId };
			});
			let options = {
				orderType:2,// 开单类型，1成品开单 2花材开单
				packingFee:this.packingMoney,// 包装费
				sendCost:this.freight,// 运费
				customId:this.clientInfo.id,// 客户
				payWay:this.payType,//付款方式
				sendType:this.sendType,
				product:JSON.stringify(product),//下单商品
			};
			let self = this;
			uni.showModal({
				title: '提示',
				content: '确认开单？',
				success: function (res) {
					if (res.confirm) {
						createOrder(options).then(res => {
							// this.$msg("下单成功");
							self.resetSelectInfoByType(self.pageType);
							const {
								data: { orderId, orderSn }
							} = res;
							let url = `/admin/billing/result?orderId=${orderId}&orderSn=${orderSn}&type=zuhe`;
							uni.redirectTo({url: url});
						});
					}
				}
			});
		},



		gobackEvent() {
			uni.navigateBack({
				delta: 1
			});
		}
	}
};
</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 {
					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;
			// }
		}
	}
	.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>
