<template>
	<view class="ordersubmit">
		<!-- @click="chosenAddress(ds.address.id)" -->
		<view class="add-box">
			<!-- <view v-if="address.province && address.province != ''" class="add-info"> -->
			<view v-if="namelist&&namelist.length>0" class="add-info">
				<view class="area">
					<view class="name-top">
						<view class="mask-lit22" :style="{ 'background-color': mc }">{{Thename.substr(0,1)}}
						</view>
						<view class="switch-box1" @click="mask()">
							<view class="switch-box2">{{Thename}}</view>
							<view class="switch-box3">点击切换学员</view>
						</view>
					</view>
				</view>
				<view class="address">
				</view>
			</view>
			<view v-if="namelist.length<=0" class="add-info2">
				<view @click="chosenAddress()">请添加学员</view>
			</view>
			<view class="arrow" @click="chosenAddress()">
				<u-icon name="arrow" size="32" color="#444"></u-icon>
			</view>
		</view>

		<view class="pay">
			<view>支付方式</view>
			<view style="text-align: right;">在线支付</view>
			<!-- <u-radio-group v-model="IsQZJC" :size="36" :active-color='mc'>
				<u-radio shape="circle" :name="0">微信支付</u-radio>
				<u-radio shape="circle" :name="1">支付宝支付</u-radio>
			</u-radio-group> -->
		</view>
		<!-- <view class="discountbox" style="padding: 15px 0;margin-bottom: 12px;" v-if="ds.total_price >0">
			<view class="filed" style="justify-content: space-between;">
				<view class="left" style="display: flex;flex-direction: row;align-items: center;">
					<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/lvqian.png" style="width: 15px;height: 15px;margin-right: 3px;"></image>
					找人代付
				</view>
				<u-checkbox-group>
					<u-checkbox @change="checkboxChange" shape="circle" :active-color='mc' v-model="checked"></u-checkbox>
				</u-checkbox-group>
			</view>
		</view> -->
		<view class="goods" v-for="(x, i) in mchs" :key="i">
			<view class="store">
				<u-icon name="shop-o" size="30" color="#232323"></u-icon>
				<text style="margin-left: 10px;">{{ x.mch.name }}</text>
			</view>
			<view class="store-list">
				<template v-if="x.goods_list.length == 1">
					<view class="goodbox" v-for="(y, yi) in x.goods_list" :key="yi">
						<image :src="y.cover_pic" mode="scaleToFill" class="image" />
						<view class="goodinfo">
							<view class="name">
								<view
									v-if="y.marketingLogo.iswords && y.marketingLogo.iswords==1&& y.marketingLogo.words!=''"
									class="Logo" :style="{color: y.marketingLogo.wordsColor,
											background:y.marketingLogo.wordsBack ,}">
									{{y.marketingLogo.words}}
								</view>
								<image
									v-if="y.marketingLogo.iswords&&y.marketingLogo.iswords==2&& y.marketingLogo.ico!=''"
									mode="heightFix" :src="y.marketingLogo.ico"
									style=" height: 12px;margin-right: 5px" />
								{{ y.name }}
							</view>
							<view class="attr">已选择：
								<span v-for="(item,index3) in y.specificationNameList" :ket="index3">
									{{item}}
								</span>
							</view>
							<view
								v-if="y.freeShipping_Use==true && y.freeShippingDescription!=null && y.freeShippingDescription !=''"
								style="height: 22px;line-height: 22px;font-size: 11px;color: #FF4048;background: #fdf6ec;padding: 0 5px;margin-bottom: 5px;display: inline-block;">
								<text>{{y.freeShippingDescription}}</text>
							</view>
							<view
								v-if="y.freeShipping_Use==false  && y.freeShippingDescription!=null && y.freeShippingDescription !=''"
								style="height: 22px;line-height: 22px;font-size: 11px;color: #909399;background: #f4f4f5;padding: 0 5px;margin-bottom: 5px;display: inline-block;">
								<text>{{y.freeShippingDescription}}</text>
							</view>
							<view class="price">
								<view class="left" :style="{ color: mc }">
									<text class="small">￥</text>
									<text>{{ y.goods_attr.price }}</text>
								</view>
								<view class="right">x{{ y.num }}</view>
							</view>
							<view v-if="y.address_disabled">
								<u-tag size="mini" text="不在配送范围内" type="warning" />
							</view>
						</view>
					</view>
				</template>
				<template v-else>
					<view class="goodboxmore">
						<view class="good-list">
							<view style="white-space: nowrap;display: flex;flex-direction: row;">
								<view v-for="(y, yi) in x.goods_list" :key="yi" class="item"
									style="position: relative;">
									<image :src="y.cover_pic" mode="aspectFill" class="item" />
									<view v-if='y.address_disabled'
										style="width: 100%;height: 20px;position: absolute;left: 0;bottom: 0;line-height: 20px;font-size: 10px;color: #ff9900;background: #fdf6ec;">
										<text style="margin-left: 3px;">不在配送范围</text>
									</view>
								</view>
							</view>
						</view>
						<view class="infos">
							<view class="text">共{{ x.goods_list.length }}件</view>
							<u-icon name="ellipsis" size="36" @click="showGoodListHandler(i)"></u-icon>
						</view>
					</view>
				</template>
				<template>
					<view class="goodboxmore"
						style="font-size: 12px;color: #000000;display: flex;flex-direction: row;flex-wrap: wrap;"
						v-if="x.pinkageList.length>0 && x.goods_list.length>1 ">
						已满足:
						<view
							style="height: 22px;line-height: 22px;font-size: 12px;color: #FF4048;background: #fdf6ec;padding: 0 5px;margin-left: 10px;margin-bottom: 5px;"
							v-for="(y, yi) in x.pinkageList" :key="yi">
							<text>{{y.Name}}</text>
						</view>
					</view>
				</template>
				<view class="peisong">
					<view>配送</view>
					<view style="text-align: right; padding-right: 5px;">{{ x.delivery.send_type_name }}</view>
					<u-icon name="ellipsis" size="36" @click="showPeisongHandler(i)"></u-icon>
					<peisong :list="x.delivery.send_type_list" :index="i" @close="changeSendTypeHandler"
						:send-type="x.delivery.send_type" v-if="x.delivery.showDelivery"></peisong>
				</view>
				<view class="liuyan">
					<u-field padding="0px" label-width="80" v-model="BuyerMessage" label="留言"
						placeholder="建议留言前先与客服沟通确认"></u-field>
				</view>
			</view>
		</view>
		<view class="discountbox">
			<view class="filed">
				<view class="left">优惠券</view>
				<view class="right">
					<text class="content" v-if="mchs[0].coupon.user_coupon_id == 0 && couponList.length>0"
						@click="showCouponHandler">选择优惠券</text>
					<text class="content" v-else-if="couponList.length==0">暂无优惠券</text>
					<text class="content" v-else :style="{ color: mc }"
						@click="showCouponHandler">已优惠{{ mchs[0].coupon.coupon_discount }}元</text>
					<u-icon name="ellipsis" size="36" v-if="couponList.length > 0" @click="showCouponHandler"></u-icon>
				</view>
			</view>
			<view class="filed" v-if="IsDeposit==1 && mchs[0].deposit.can_use == true">
				<view class="left">储蓄卡</view>
				<view class="right">
					<text class="content" v-if="mchs[0].deposit.use_deposit_id == 0 && cashCardList.length>0"
						@click="showcashcardbtn">选择储蓄卡</text>
					<text class="content" v-else-if="cashCardList.length==0">暂无储蓄卡</text>
					<text class="content" v-else :style="{ color: mc }"
						@click="showcashcardbtn">已抵扣{{ mchs[0].deposit.deposit_price }}元</text>
					<u-icon name="ellipsis" size="36" v-if="cashCardList.length > 0" @click="showcashcardbtn"></u-icon>
				</view>
			</view>
			<view class="filed" v-if="integral.can_use">
				<view class="left">积分抵扣</view>
				<view class="right">
					<text class="content"
						:style="{ color: secondary }">{{ `使用${integral.use_num}积分抵扣${integral.deduction_price}元` }}</text>
					<u-checkbox-group>
						<u-checkbox v-model="userInt" :active-color="mc" @change="changeUseInt" :icon-size="28"
							shape="circle"></u-checkbox>
					</u-checkbox-group>
				</view>
			</view>
		</view>
		<view class="discountbox">
			<view class="filed">
				<view class="left">商品金额</view>
				<view class="right">
					<text class="price">￥{{ goodPrice.toFixed(2) }}</text>
				</view>
			</view>
			<view class="filed">
				<view class="left">运费</view>
				<view class="right">
					<text class="price" :style="{ color: mc }">+￥{{ expressPrice.toFixed(2) }}</text>
				</view>
			</view>
			<view class="filed">
				<view class="left">优惠</view>
				<view class="right">
					<text class="price" :style="{ color: mc }">-￥{{ couponPrice.toFixed(2) }}</text>
				</view>
			</view>

			<view class="filed" v-if="mchs.length>0&&mchs[0].is_deduction_commission">
				<view class="left">佣金抵扣</view>
				<view class="right">
					<text class="price" :style="{ color: mc }">-￥{{ mchs[0].deduction_commission }}</text>
				</view>
			</view>
			<view class="filed" v-if="integral.can_use">
				<view class="left">积分抵扣</view>
				<view class="right">
					<text class="price"
						:style="{ color: mc }">-￥{{ userInt ? integral.deduction_price.toFixed(2) : '0.00' }}</text>
				</view>
			</view>
			<view class="filed" v-if="IsDeposit==1 && mchs[0].deposit.can_use == true">
				<view class="left">储蓄卡抵扣</view>
				<view class="right">
					<text class="price" :style="{ color: mc }">-￥{{ cashPrice.toFixed(2) }}</text>
				</view>
			</view>
		</view>

		<view class="btton-box">
			<view class="left" :style="{ color: mc }">
				<text>￥</text>
				<text class="bold">{{ ds.total_price }}</text>
			</view>
			<view class="right">
				<u-button :disabled="!address_enable" size="80" :ripple="true" shape="circle"
					@click="ds.promptNoSuperiorFY== true ? submitModel():submitOrderHandler()" :custom-style="{
						backgroundColor: mc,
						height: '80rpx',
						color: '#FFF',
						fontSize: '14px'
					}">
					<u-loading mode="circle" style="margin-right: 5px;" v-if="submitOrder"></u-loading>
					{{btntext}}
				</u-button>
			</view>
		</view>
		<coupon v-if="couponList.length > 0 && showCoupon" :list="couponList" :current="formdata.User_Coupon_Id"
			@close="closeCouponHandler"></coupon>
		<cashCard v-if="cashCardList.length > 0 && showcashcard" :list="cashCardList" :current="formdata.Use_Deposit_Id"
			@close="closecashcard"></cashCard>

		<view class="notOption" v-if="submitOrder"></view>
		<good-list :list="goodData" v-if="showGoodList" @close="closeGoodListHandler"></good-list>
		<payCom v-if="payBtn" :payInfo="payInfo" :isAlipay="isAlipay" :StuId='JJSWStuId' :TeacherIds='EduTeacherId'
			@closePay="closePay"></payCom>

		<u-toast ref="uToast" />
		<u-popup v-model="payExit" mode="center" :mask-close-able="false">
			<view style="background:#fff;width:500rpx">
				<view style="padding:10px 0 0 10px">提交失败</view>
				<view style="text-align:center;padding-bottom:40rpx">
					<view style="margin:80rpx 0">支付取消</view>
					<span @click="exitPay"
						style="padding:10rpx 50rpx;color:#fff;background:#19be6b;border-radius: 12px;">确定</span>
				</view>
			</view>
		</u-popup>
		<u-popup v-model="zhaoren" mode="center" :mask-close-able="false">
			<view style="background:#fff;width:500rpx;font-family: aa;border-radius: 10px;">
				<view
					style="width: 88%;height: 35px;display: flex;flex-direction: row;align-items: flex-end;justify-content: flex-end;margin-left: 6%;"
					@click="exitPay">
					<u-icon name="close" size="40"></u-icon>
				</view>
				<view style="padding:10px 0 0 10px;text-align:center;">代付金额</view>
				<view style="text-align:center;padding-bottom:40rpx;">
					<view class="daif" :style="{'color': mc}">
						<text style="margin-bottom: 2px;">
							￥
						</text>
						<span :style="{'font-size': '30px','color': mc}">{{ds.total_price}}</span>
					</view>
					<u-button :disabled="!address_enable" size="30" :ripple="true" shape="circle" open-type="share"
						:custom-style="{
							backgroundColor: mc,
							width:'350rpx',
							height: '80rpx',
							color: '#FFF',
							fontSize: '14px'
						}">
						发送给微信好友
					</u-button>
				</view>
			</view>
		</u-popup>
		<u-modal v-model="showReviceModal" content="您的上级不存在，当前订单不会返佣，是否继续？" :show-cancel-button="true"
			:show-title="false" @confirm="submitOrderHandler" :border-radius="20"></u-modal>
		<!-- 切换学员弹窗 -->
		<u-popup v-model="show" mode="center" length="90%">
			<view style="background: #fff; border-radius: 10rpx;" class="mask-box">
				<view class="mask-down">
					<view class="mask-down2">切换学员</view>
					<view @click="cloGood()"></view>
					<u-icon name="cross" color="#9F9F9F" @click="cloGood()" size="40"> </u-icon>
				</view>
				<scroll-view scroll-y="true" style="height: 500rpx;">
					<view>
						<view class="mask-lit" v-for="(item, i) in namelist" :key="i" @click="masklist(item,i)">
							<view>
								<text class="mask-lit2"
									:style="{ 'background-color': mc }">{{item.StuName.substr(0,1)}}</text>

								<text :class="[actuve==i?'mask-lit3':'mask-lit33']">{{item.StuName}}</text>
							</view>
							<view v-if="actuve==i">
								<u-icon name="success" size="40"></u-icon>
							</view>
						</view>
					</view>
				</scroll-view>
				<view class="determine-box">
					<view :style="{ 'background-color': mc }" class="determine-box2" @click="determine()">确定</view>
				</view>
			</view>
		</u-popup>
		<!-- 支付宝弹窗 -->
		<!-- <Alipay v-if="AlipayMask"  :AlipayMask='AlipayMask' :payInfo="payInfo" :isAlipay="isAlipay" :StuId='JJSWStuId' :TeacherIds='mrk' @closePay="closePay">
			</Alipay> -->
		<u-popup mode="center" v-model="showExame">
			<view style="width: 577rpx;padding-top:129rpx;text-align:center;height: 509rpx;background: #FFFFFF;border-radius: 50rpx; position: relative;">
				<image src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/exambg.png" mode="widthFix" style="width:220rpx;height:118px;position: absolute; top:-52rpx;right:27rpx;"></image>
				<view style="font-size: 34rpx;font-weight: bold;color: #10100F;">
					测验提醒
				</view>
				<view style="margin-top:32rpx; font-size: 28rpx;font-weight: 500;color: #959595;">
					此课程需要学员完成测验<br/>通过后才能报名
				</view>
				<view style="margin-top:50rpx">
					<view style="width:50%;margin:0 auto;">
						<u-button type="error" shape="circle" @click="goExameHandler">立即测验</u-button>
					</view>
				</view>
				<view style="margin-top:30rpx;color:#FA5B23;font-size:30rpx" @click="showExame=false">
					取消报名
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import payCom from '@/components/pay/submit2Pay';
	// import Alipay from '@/components/pay/Alipay';//支付宝弹窗
	import peisong from '@/components/peisong/index';
	import coupon from '@/components/coupon/index';
	import cashCard from '@/components/coupon/cashCard'; //储蓄卡
	import goodList from '@/components/goods/order-good-list';

	export default {
		components: {
			payCom,
			peisong,
			coupon,
			goodList,
			cashCard,
			// Alipay
		},
		data() {
			return {
				limits: false,
				AlipayMask: false,
				IsQZJC: 0,
				EduTeacherId: '',
				ClassId: '',
				PaperId:'',
				PublishId:'',
				// mrk3: '',
				isAlipay: 2, //1微信 2微信支付宝
				JJSWStuId: "",
				Thename2: '',
				u: {},
				Thename: '姓名',
				actuve: 0,
				namelist: [],
				show: false,
				address_enable: '',
				payExit: false,
				payBtn: false,
				checked: false,
				btntext: '提交订单',
				zhaoren: false,
				zrName: '是好友就帮忙代付',
				zrimg: 'https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/zhaoren.png',
				formData: {
					list: [{
						mch_id: 0,
						goods_list: [],
						distance: 0,
						remark: '',
						order_form: [],
						use_integral: 0,
						user_coupon_id: 0,
						use_deposit_id: 0,
					}],
					address_id: 0
				},
				formdata: {},
				DeliveryMethod: '',
				pageTitle: '填写订单',
				address: {},
				mchs: [],
				mc: '',
				ds: {
					total_price: '0.00'
				},
				expressPrice: 0.0,
				goodPrice: 0.0,
				couponPrice: 0.0,
				cashPrice: 0.0,
				integral: {
					can_use: false,
					use: false,
					use_num: 0,
					deduction_price: 0
				},
				path: '',
				secondary: '',
				userInt: false,
				loading: true,
				couponList: [],
				showCoupon: false,
				submitOrder: false,
				isLeave: false,
				goodData: [],
				showGoodList: false,
				DetailList: [],
				IsFormShoppingCart: 2,
				adressInfo: {},
				payInfo: {
					OpenId: '', //ow_7I5XC1-RGwwk8QANBmWKYKmOc
					OrderId: '',
					OrderPayType: 1,
					GoodsName: ''
				},
				ShoppingCartIdList: [],
				BuyerMessage: '',
				showReviceModal: false,
				//抵扣金额
				deduction_commission: 0,
				cashCardList: [],
				showcashcard: false,
				onecoupon: true, //第一次进页面的时候选最优的优惠券
				IsDeposit: 0, //是否开启储蓄卡功能
				showExame:false,
				examInfo:''
			};
		},
		onLoad(option) {
			this.u = uni.getStorageSync('mall_UserInfo')
			if (option.goods) {
				this.formData.list[0].goods_list = JSON.parse(decodeURIComponent(option.goods));
			}
			if (option.formData) {
				this.formData = JSON.parse(decodeURIComponent(option.formData));
				this.formdata = JSON.parse(decodeURIComponent(option.formData));
				this.formdata.Use_Deposit_Id = 0; //储蓄卡ID 2021-4-8加的
			}
			if (option.IsFormShoppingCart) {
				this.IsFormShoppingCart = option.IsFormShoppingCart;
			}
			if (option.ShoppingCartIdList) {
				this.ShoppingCartIdList = JSON.parse(option.ShoppingCartIdList);
			}
			this.payInfo.OpenId = uni.getStorageSync('mall_UserInfo').OpenId;
			this.IsDeposit = uni.getStorageSync('basedata') ? uni.getStorageSync('basedata').mall.setting.IsDeposit : 0
			this.initPage();
			this.mc = this.$uiConfig.mainColor;
			this.secondary = this.$uiConfig.secondary;
		},

		onShow() {
			this.init();
			if (this.isLeave) {
				uni.navigateBack({
					delta: 1
				});
			}
			this.studentslist()
		},
		methods: {
			// 学员列表
			studentslist() {
				let testCmd = '/api/WeChatPublic/GetStuList'
				let postMsg = {
					UnionId: this.u.Unoinid
				}
				this.requestJJSWAdmin(testCmd, postMsg,
					(res) => {
						// console.log("111",res);
						if (res.data.Data.length > 0) {
							this.namelist = res.data.Data
							this.Thename = res.data.Data[0].StuName
							this.Thename2 = res.data.Data[0].StuName
							this.JJSWStuId = res.data.Data[0].StuId
						}
					}
				);
			},
			// 弹窗开关
			mask() {
				this.show = true
			},
			cloGood() {
				this.show = false
			},
			masklist(item, i) {
				this.actuve = i
				this.Thename2 = item.StuName
				this.JJSWStuId = item.StuId
			},
			determine() {
				this.Thename = this.Thename2
				this.show = false
			},
			onShareAppMessage() {
				return {
					title: this.zrName,
					path: this.path,
					imageUrl: 'https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/zhaoren.png'
				};
			},
			exitPay() {
				this.payExit = false;
				uni.redirectTo({
					url: "/pages/order/index/index?status=0",
				});
			},
			closePay() {
				this.payBtn = false;
				this.payExit = true;
				this.AlipayMask = false
			},
			closeGoodListHandler() {
				this.goodData = [];
				this.showGoodList = false;
			},
			showGoodListHandler(i) {
				this.goodData = this.mchs[i].goods_list;
				this.showGoodList = true;
			},
			submitModel() {
				this.showReviceModal = true;
			},
			// 报名限制
		 Registration() {
				let postMsg = {
					StuId: this.JJSWStuId,
					ClassIds: this.ClassId
				}
				let that = this
				let obj={
					// PaperId:this.PaperId,
					// PublishId:this.PublishId,
					// GuestId:this.JJSWStuId
				}
			 this.requestJJSWAdmin("/api/WeChatPublic/CheckStuSubmitOrder", postMsg,
					(res) => {
						if (res.data.Code != 1) {
							that.limits = true
							if(res.data.Message&&res.data.Message!='')
							{
								uni.showToast({
									title: res.data.Message,
									icon: "none",
								});
							}
							if(res.data.Data.PaperId>0&&res.data.Data.PublishId>0&&res.data.Data.StuId){
								obj.PaperId=res.data.Data.PaperId
								obj.PublishId=res.data.Data.PublishId
								obj.StuId=res.data.Data.StuId
								this.showExame=true
								this.examInfo = JSON.stringify(obj)
								// 跳转入学考试
							}
						} else {
							that.limits = false
							this.OrderInterface()
						}
						// console.log('llll',that.limits)
					}
					
				);
			},
			goExameHandler(){
				uni.redirectTo({
					url: `/pages/webbox/webbox?limit=${this.examInfo}`
				});
			},
			// 提交订单接口
			OrderInterface() {
				// that.adressInfo.Consignee = '测试'
				// that.adressInfo.ShoppingAddress = '四川成都龙泉驿1'
				// that.JJSWStuId = '10724';
				// that.Thename="HK";
				// if (that.adressInfo.Consignee == '') {
				// 	this.$refs.uToast.show({
				// 		title: '请选择收货信息！',
				// 		type: 'warning'
				// 	});
				// 	return;
				// }
				let that =this
				if (!this.submitOrder && !that.limits) {
					this.submitOrder = true;
					uni.requestSubscribeMessage({
						tmplIds: this.ds.template_message_list,
						complete(res) {
							// console.log('44444444444444444')
							that.submitOrder = false;
							let form = {};
							// form.Consignee = that.adressInfo.Consignee;
							form.Consignee = that.Thename;
							form.Mobile = that.adressInfo.Mobile;
							form.Province = that.adressInfo.Province;
							form.City = that.adressInfo.City;
							form.District = that.adressInfo.District;
							form.ShoppingAddress = that.adressInfo.ShoppingAddress;
							form.BuyerMessage = that.BuyerMessage;
							form.DeliveryMethod = that.formdata.DeliveryMethod;
							form.DetailList = that.DetailList;
							form.User_Coupon_Id = that.formdata.User_Coupon_Id;
							form.Use_Deposit_Id = that.formdata.Use_Deposit_Id;
							form.DepositMoney = that.cashPrice; //储蓄卡抵扣金额
							form.DepositFreightMoney = that.expressPrice; //储蓄卡抵扣运费
							form.CouponMoney = that.couponPrice;
							form.FreightMoney = that.expressPrice;
							form.Income = that.ds.total_price;
				
							form.IsFormShoppingCart = that.IsFormShoppingCart;
							form.Use_Integral = that.formdata.Use_Integral;
							form.ShoppingCartIdList = that.ShoppingCartIdList;
							form.JJSWStuId = that.JJSWStuId;
							form.AnchorName = uni.getStorageSync("AnchorName") ? uni.getStorageSync(
									"AnchorName")
								.AnchorName : ''; //直播名称
							if (that.mchs && that.mchs.length > 0) {
								that.deduction_commission = that.mchs[0].deduction_commission;
							}
							form.DeductionCommission = that.deduction_commission;
							that.request2({
									url: '/api/AppletOrder/SetAppletGoodsOrderInfo',
									data: form
								},
								res => {
									// console.log('7777777777')
									if (res.resultCode == 1) {
										that.payInfo.OrderId = res.data.OrderId;
										that.payInfo.total_price = that.ds.total_price;
										if (res.data.OrderStatus == 5) {
											let info = {
												OrderId: that.payInfo.OrderId,
												total_price: that.ds.total_price,
												StuId: that.JJSWStuId,
												TeacherIds: that.EduTeacherId,
											}
											uni.reLaunch({
												url: '/pages/order-submit/pay-success2?payInfo=' +
													JSON.stringify(info)
											})
										} else {
											if (that.checked == true) {
												that.zhaoren = true;
												let u = uni.getStorageSync("mall_UserInfo");
												let uid = u.UserId ? u.UserId : 0;
												let Up = u.UserPageType ? u.UserPageType : 0;
												let SmallShopId = u.SmallShopId ? u.SmallShopId : 0;
												if (SmallShopId == 0) {
													//如果微店id为0 去找所属微店id
													SmallShopId = u.UserSmallShopId ? u.UserSmallShopId :
													0;
												}
												that.path = '/pages/index/index?OrderId=' + res.data
													.OrderId +
													"&user_id=" + uid + "&Up=" + Up +
													"&SmallShopId=" + SmallShopId + '&JumpType=4';
											} else {
				
												if (that.formdata.Use_Deposit_Id != 0 && that.ds
													.total_price ==
													0) { //如果使用了储蓄卡 就直接支付成功 跳入支付结果
													uni.reLaunch({
														url: '/pages/order-submit/pay-success?payInfo=' +
															JSON.stringify(that.payInfo)
													})
												} else { //没使用的话 就弹出支付页面
													if (that.IsQZJC == 1) {
														that.AlipayMask = true
													} else {
														that.payBtn = true;
													}
				
												}
											}
										}
				
									} else {
										that.$refs.uToast.show({
											title: res.data.message,
											type: 'warning'
										});
									}
									uni.hideNavigationBarLoading();
								}
							);
						}
					});
				}
			},
			// 提交订单按钮
			 submitOrderHandler() {
				 let that = this;
				 if (that.JJSWStuId == '' || that.Thename == '') {
				 	this.$refs.uToast.show({
				 		title: '请添加学员！',
				 		type: 'warning'
				 	});
				 	return;
				 }
				that.Registration()
			},
			closeCouponHandler(e) {
				if (e != -1) {
					this.formdata.User_Coupon_Id = e;
					this.init();
				}
				this.showCoupon = false;
			},
			closecashcard(e) {
				if (e != -1) {
					this.formdata.Use_Deposit_Id = e;
					this.init();
				}
				this.showcashcard = false;
			},
			showCouponHandler() {
				this.showCoupon = true;
			},
			showcashcardbtn() {
				this.showcashcard = true;
			},
			initCoupon() {
				let ProductList = [];
				this.DetailList = [];
				this.mchs.forEach(item => {
					item.goods_list.forEach(list => {
						let obj = {
							GoodsClassId: list.categoryIdList,
							GoodsPrice: list.total_price,
							ProductId: list.id
						};
						let obj1 = {
							SpecificationSort: list.goods_attr.sign_id,
							Number: list.num,
							GoodsId: list.id,
							SpecificationList: list.specificationNameList
						};
						ProductList.push(obj);
						this.DetailList.push(obj1);
					});
				});
				this.request2({
						url: '/api/AppletCoupon/GetNoUseCouponList',
						data: {
							ProductList: ProductList
						}
					},
					res => {
						if (res.resultCode == 1) {
							this.couponList = res.data;
							if (this.onecoupon == true) {
								this.onecoupon = false
								this.couponList.map(x => {
									if (x.isBest == 1) { //进去页面优先选择优惠券
										this.formdata.User_Coupon_Id = x.id
										this.init()
										return
									}
								})
							}
						}
					}
				);
				//获取用户储蓄卡
				this.request2({
						url: '/api/AppletCoupon/GetNoUseDeposit',
						data: {}
					},
					res => {
						if (res.resultCode == 1) {
							this.cashCardList = res.data;
						}
					}
				);
			},
			changeSendTypeHandler(e) {
				let i = e.index;
				let obj = this.mchs[i];
				obj.delivery.showDelivery = false;
				this.$set(this.mchs, i, obj);
				this.$forceUpdate();
				if (e && e.val) {
					if (this.mchs[i].delivery.send_type != e.val) {
						this.formdata.DeliveryMethod = e.val;
						this.init();
					}
				}
			},
			showPeisongHandler(x) {
				let obj = this.mchs[x];
				obj.delivery.showDelivery = true;
				this.$set(this.mchs, x, obj);
				this.$forceUpdate();
			},
			chosenAddress(id) {
				// uni.navigateTo({
				// 	url: '/pages/address/address?form=ordersubmit&id=' + id
				// });
				uni.navigateTo({
					url: '/pages/address/address2'
				});
			},
			changeUseInt(e) {
				this.userInt = e.value;
				this.formdata.Use_Integral = this.userInt ? 1 : 0;
				this.init();
			},
			initPage() {
				let currentPages = getCurrentPages();
				let u = '/' + currentPages[currentPages.length - 1].route;
				let pages = uni.getStorageSync('basedata') ? uni.getStorageSync('basedata').bar_title : [];
				pages.forEach(x => {
					if (x.value == u) {
						this.pageTitle = x.new_name ? x.new_name : x.name;
					}
				});
				uni.setNavigationBarTitle({
					title: this.pageTitle
				});
			},
			init() {
				// 获取跳转接口
				let EduTeacherIdlist = []
				let ClassIdlist = []
				// let list3 = []
				this.loading = true;
				this.request2({
						url: '/api/AppletOrder/GetAppletGoodsSettlementInfoForZY',
						data: this.formdata
					},
					res => {
						this.loading = false;
						if (res.resultCode == 1) {
							this.address = res.data.address;
							this.address_enable = res.data.address_enable;
							this.mchs = res.data.mch_list;
							this.mchs.forEach(x => {
								x.goods_list.forEach(j => {
									j.marketingLogo = JSON.parse(j.marketingLogo)
									EduTeacherIdlist.push(j.EduTeacherId)
									ClassIdlist.push(j.EduData.ClassId)
									// list3.push(j.EduData.ClassPersion)
								})
							})
							
							this.EduTeacherId = EduTeacherIdlist.toString()
							this.ClassId = ClassIdlist.toString()
							// this.mrk3 = list3.toString()
							this.payInfo.GoodsName = this.mchs[0].goods_list[0].name.slice(0, 10);
							this.formdata.DeliveryMethod = this.mchs[0].delivery.send_type;
							this.ds = res.data;
							this.expressPrice = 0.0;
							this.goodPrice = 0.0;
							this.couponPrice = 0.0;
							this.cashPrice = 0.0;
							if (res.data.total_price < 0) {
								this.ds.total_price = 0
							}
							this.integral = {
								can_use: false,
								use: false,
								use_num: 0,
								deduction_price: 0
							};
							this.formatPrice();
							this.initCoupon();
							this.adressInfo = {
								Consignee: this.address.name,
								Mobile: this.address.mobile,
								Province: this.address.province_id,
								City: this.address.city_id,
								District: this.address.district_id,
								ShoppingAddress: this.address.detail
							};
						}
						uni.hideNavigationBarLoading();
					}
				);
			},
			formatPrice() {
				if (this.mchs) {
					this.mchs.forEach(x => {
						x.delivery.showDelivery = false;
						if (x.delivery.send_type_list && x.delivery.send_type_list.length > 0) {
							x.delivery.send_type_list.forEach(y => {
								if (y.value == x.delivery.send_type) {
									x.delivery.send_type_name = y.name;
								}
							});
						}
						//绑定商品价格 HK 2022-10-11新增 判断是否有绑定商品
						let tempRelevancePrice = 0;
						if (x.goods_list && x.goods_list.length > 0) {
							x.goods_list.forEach(rootItem => {
								if (rootItem.GoodsRelevanceList && rootItem.GoodsRelevanceList.length >
									0) {
									rootItem.GoodsRelevanceList.forEach(qitem => {
										tempRelevancePrice += parseFloat(qitem.RelevancePrice);
									})
								}
							})
						}
						//HK 2022-10-11 新增结束
						this.goodPrice += parseFloat(x.total_goods_price) + parseFloat(tempRelevancePrice);
						this.expressPrice += parseFloat(x.express_price);
						this.couponPrice += parseFloat(x.coupon.coupon_discount || 0.0);
						this.cashPrice += parseFloat(x.deposit.deposit_price || 0.0);
						if (x.integral.can_use) {
							this.integral.can_use = true;
							this.integral.use = false;
							this.integral.use_num += x.integral.use_num;
							this.integral.deduction_price += parseFloat(x.integral.deduction_price);
						}
					});
				}
			},
			formatAttr() {
				this.mchs.forEach(x => {
					this.userInt = x.integral.use;
					x.goods_list.forEach(y => {
						let attrStr = '';
						y.attr_list.forEach((z, i) => {
							if (i > 0) {
								attrStr += ' ';
							}
							attrStr += z.attr_group_name + ' ' + z.attr_name;
						});
						y.attrStr = attrStr;
					});
				});
			},
			checkboxChange(val) {
				if (val.value == true) {
					this.btntext = '找人代付'
				} else {
					this.btntext = '提交订单'
				}
			},
		}
	};
</script>

<style>
	.u-toast{
		height: auto !important;
	}
	.add-info2 {
		width: 1px;
		flex: 1;
		min-height: 60px;
		display: block;
		padding: 10px 0;
		display: flex;
		align-items: center;
	}

	.determine-box {
		margin: auto;
		height: 80rpx;
		font-size: 28rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		margin-top: 50rpx;
	}

	.determine-box2 {
		display: flex;
		justify-content: center;
		align-items: center;
		width: 60%;
		border-radius: 50rpx;
		color: #fff;
		height: 80rpx;
	}

	.mask-lit22 {
		width: 50rpx;
		height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		border-radius: 50%;
		text-align: center;
		line-height: 40rpx;
		color: #FFF;
		margin-right: 20rpx;
	}

	.switch-box2 {
		font-size: 28rpx;
	}

	.switch-box3 {
		font-size: 24rpx;
		color: #999;
	}

	.name-top {
		display: flex;
		align-items: center;
	}

	.mask-lit {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 20rpx;
	}

	.mask-lit33 {
		font-size: 28rpx;
		color: black;
	}

	.mask-lit3 {
		font-size: 28rpx;
		color: black;
		font-weight: bold;
	}

	.mask-lit2 {
		font-size: 28rpx;
		display: inline-block;
		margin-right: 20rpx;
		border-radius: 50%;
		/* background-color: red; */
		width: 50rpx;
		height: 50rpx;
		/* display: flex; */
		text-align: center;
		line-height: 50rpx;
		color: #FFF;
	}

	.mask-box {
		padding: 40rpx;
	}

	.mask-down {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 30rpx;
	}

	.mask-down2 {
		font-weight: bold;
		font-size: 32rpx;
	}

	button[disabled] {
		color: rgba(0, 0, 0, .3) !important;
		background-color: #f7f7f7 !important;
	}

	.ordersubmit {
		min-height: 100vh;
		padding: 0 5px;
		background: #f6f6f6;
		padding-bottom: 40px;
		font-family: 'oswald';
	}

	.ordersubmit .add-box {
		padding: 10px;
		background: #fff;
		display: flex;
		align-items: center;
		position: relative;
		border-radius: 10px;
		overflow: hidden;
		margin-bottom: 12px;
	}

	.ordersubmit .add-box .arrow {
		width: 16px;
		height: 16px;
	}

	.ordersubmit .add-box .add-info {
		width: 1px;
		flex: 1;
		min-height: 60px;
		display: flex;
		align-items: center;
		padding: 10px 0;
	}

	.ordersubmit .add-box .add-info .address {
		font-size: 13px;
		color: #333;
		margin-bottom: 5px;
	}

	.ordersubmit .add-box .add-info .area {
		font-size: 18px;
		color: #000;
		margin-bottom: 5px;
		font-weight: 600;
	}

	.ordersubmit .daif {
		margin: 40rpx 0;
		font-size: 20px;
		display: flex;
		flex-direction: row;
		align-items: flex-end;
		width: 100%;
		justify-content: center;
	}

	.ordersubmit .add-box::before {
		position: absolute;
		right: 0;
		bottom: 0;
		left: 0;
		height: 2px;
		background: repeating-linear-gradient(-45deg, #ff6c6c 0, #ff6c6c 20%, transparent 0, transparent 25%, #1989fa 0, #1989fa 45%, transparent 0, transparent 50%);
		background-size: 80px;
		content: '';
	}

	.ordersubmit .pay {
		margin-bottom: 12px;
		background: #fff;
		border-radius: 10px;
		padding: 10px;
		align-items: center;
		height: 50px;
		color: #232323;
		display: flex;
		justify-content: space-between;
	}

	/* .ordersubmit .pay view {
		flex: 1;
	}
 */
	.ordersubmit .goods {
		padding: 20px 10px;
		margin-bottom: 12px;
		background: #fff;
		border-radius: 10px;
	}

	.ordersubmit .goods .store {
		color: #000;
		margin-bottom: 20px;
		display: flex;
	}

	.ordersubmit .goodbox {
		margin-bottom: 20px;
		display: flex;
	}

	.ordersubmit .goodbox .image {
		width: 200rpx;
		height: 200rpx;
		border-radius: 5px;
		margin-right: 10px;
	}

	.ordersubmit .goodbox .goodinfo {
		width: 1px;
		flex: 1;
	}

	.ordersubmit .goodbox .goodinfo .name {
		height: 18px;
		font-size: 14px;
		color: #232323;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 15px;
	}

	.ordersubmit .goodbox .goodinfo .attr {
		height: 16px;
		font-size: 12px;
		color: #999;
		overflow: hidden;
		text-overflow: ellipsis;
		margin-bottom: 10px;
	}

	.ordersubmit .goodbox .goodinfo .price {
		display: flex;
		align-items: center;
	}

	.ordersubmit .goodbox .goodinfo .price .left {
		font-size: 20px;
		font-family: 'oswald';
		width: 1px;
		flex: 1;
	}

	.ordersubmit .goodbox .goodinfo .price .left .small {
		font-size: 13px;
	}

	.ordersubmit .goodbox .goodinfo .price .right {
		color: #444;
		font-size: 13px;
	}

	.ordersubmit .goodboxmore {
		margin-bottom: 20px;
		display: flex;
	}

	.ordersubmit .goodboxmore .good-list {
		display: flex;
		flex: 1;
		overflow-x: auto;
	}

	.ordersubmit .goodboxmore .good-list .item {
		width: 70px;
		height: 70px;
		border-radius: 5px;
		margin-right: 10px;
	}

	.ordersubmit .goodboxmore .infos {
		display: flex;
		width: 80px;
	}

	.ordersubmit .goodboxmore .infos .text {
		text-align: center;
		font-size: 13px;
		width: 57px;
		margin-right: 5px;
		line-height: 70px;
	}

	.ordersubmit .store-list .peisong {
		margin-bottom: 20px;
		display: flex;
		align-items: center;
		color: #333;
	}

	.ordersubmit .store-list .peisong view {
		flex: 1;
	}

	.ordersubmit .store-list .peisong view:last-child {
		text-align: right;
	}

	.ordersubmit .discountbox {
		padding: 20px 0;
		margin-bottom: 20px;
		background: #fff;
		border-radius: 10px;
		display: block;
	}

	.ordersubmit .filed {
		display: flex;
		align-items: flex-start;
		margin-bottom: 20px;
		padding: 0 10px;
	}

	.ordersubmit .filed:last-child {
		margin-bottom: 0;
	}

	.ordersubmit .filed .left,
	.ordersubmit .filed .right {
		flex: 1;
		color: #232323;
	}

	.ordersubmit .filed .left {
		width: 120px;
	}

	.ordersubmit .filed .right {
		text-align: right;
		display: flex;
	}

	.ordersubmit .filed .right .icon {
		width: 18px;
		height: 18px;
	}

	.ordersubmit .filed .right .content {
		flex: 1;
		text-align: right;
		margin-right: 5px;
	}

	.ordersubmit .filed .right .price {
		font-size: 16px;
		flex: 1;
		text-align: right;
		font-family: 'oswald';
	}

	.ordersubmit .btton-box {
		height: 50px;
		display: flex;
		padding: 5px 10px;
		border-top: 1px solid #f5f5f5;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		align-items: center;
		background: #fff;
		z-index: 3;
	}

	.ordersubmit .notOption {
		position: fixed;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		background: transparent;
		z-index: 2;
	}

	.ordersubmit .btton-box .left {
		font-size: 16px;
		flex: 1;
		font-family: 'oswald';
	}

	.ordersubmit .btton-box .left .bold {
		font-size: 24px;
	}

	.ordersubmit .btton-box .right {
		width: 120px;
	}

	.ordersubmit .Logo {
		padding: 1px 5px;
		display: inline-block;
		font-size: 22rpx;
		margin-right: 5rpx;
		border-radius: 4px;
	}
</style>
