<template>
	<view class="pb100" :class="isAgree ? 'all-list' : ''">
		<!-- <view v-if="specialType == 1" class="form-top-nav d-b-c">
			<view class="form-top-nav-item" :class="{ active: registType == 0 }" @click="changeRegistType(0)">{{ $t('w_0261') }}</view>
			<view class="form-top-nav-item" :class="{ active: registType == 1 }" @click="changeRegistType(1)">{{ $t('w_0262') }}</view>
		</view> -->
		<!-- 复购专区 -->
		<repurchase :cid="specialArea" :storehouse="storehouse" :storeList="storeList" :userCountry="userCountry" v-if="specialType == 3"
			:deliveryList="deliveryList" :storeLists="storeLists" :transportType="transportType"
			@changeInput="changeInput" @queryOrderPostage="queryOrderPostage"></repurchase>
		<!-- 注册专区 -->
		<register :storehouse="storehouse" :storeList="storeList" :userCountry="userCountry" v-if="specialType == 1"
			:isFirst="isFirst" :accountList="accountList" :transportType="transportType" :countryList="countryList"
			:deliveryList="deliveryList" :storeLists="storeLists" @changeInput="changeInput"
			@queryOrderPostage="queryOrderPostage" :registType="registType" :placeDeptList="placeDeptList"
			:registerBank="registerBank"></register>
		<!-- 分享专区 -->
		<fans :storehouse="storehouse" :storeList="storeList" :userCountry="userCountry" v-if="specialType == 4"
			:accountList="accountList" :transportType="transportType" :countryList="countryList"
			:deliveryList="deliveryList" @changeInput="changeInput" @queryOrderPostage="queryOrderPostage"></fans>
		<!-- 升级专区 -->
		<upgrade :storehouse="storehouse" :storeList="storeList" :userCountry="userCountry" v-if="specialType == 2"
			:deliveryList="deliveryList" :storeLists="storeLists" :transportType="transportType"
			@changeInput="changeInput" :countryList="countryList" @queryOrderPostage="queryOrderPostage"></upgrade>
		<!-- 福利专区 || 积分专区 -->
		<welfare :storehouse="storehouse" :storeList="storeList" :userCountry="userCountry" v-if="specialType == 5"
			:deliveryList="deliveryList" :transportType="transportType" @changeInput="changeInput"
			@queryOrderPostage="queryOrderPostage"></welfare>

		<Product :cid="specialArea" :storehouse="storehouse" :userCountry="userCountry" :storeList="storeList"
			:memberAddress="memberAddress" :shareType="shareType" :deliveryList="deliveryList" :storeLists="storeLists"
			:borderunits="borderunits" :transportType="transportType" @showAddPicker="showMulLinkageThreePicker"
			@delAddress="delAddress" @queryOrderPostage="queryOrderPostage"></Product>
		<view class="f26 gray9 d-c-c radiogroup" v-if="buyAgreementFlag != 1">
			<radio color="#FB3024" style="transform: scale(0.7)" @click="isRead = !isRead" :checked="isRead" value="" />
			{{ $t("w_0207") }}
			<text class="" style="color: #fb3024" @click="isxieyi = true">《{{ $t("w_0208") }}》</text>
		</view>
		<!-- <button class="normal-sub-btn" style="margin-top: 37rpx;" @click="gotoPage('/pages/order/cashier')">购买</button> -->
		<button class="normal-sub-btn" style="margin-top: 37rpx" @click="subFunc">
			{{ $t("w_0085") }}
		</button>
		<view v-if="isAgree && waresExtList.length > 0">
			<view class="pop-bg" @click="closeAgreement"></view>
			<view class="agreement-pop">
				<view class="d-e-c mb20">
					<!-- <view v-if="alertTime > 0" class="f24 gray9">{{ alertTime + 's' }}</view> -->
					<!-- <view v-else @click="closeAgreement"><u-icon name="close" size="28rpx" color="#999"></u-icon></view> -->
				</view>
				<view v-for="(item, index) in waresExtList" :key="index">
					<view class="fb mb20 f30 gray3 tc">{{ item.title }}</view>
					<view class="agreement-content"><u-parse :content="item.content"></u-parse></view>
				</view>
				<view class="d-c-c mt20">
					<button class="mr20 pop-btn" v-if="alertTime > 0" disabled>
						{{ $t("w_0210") }}({{ alertTime }}s)
					</button>
					<button class="mr20 pop-btn" v-else @click="closeAgreement">
						{{ $t("w_0210") }}
					</button>
				</view>
			</view>
		</view>
		<view v-if="isxieyi && waresExtList2.length > 0">
			<view class="pop-bg" @click="isxieyi = false"></view>
			<view class="agreement-pop">
				<view class="d-e-c mb20">
					<view @click="isxieyi = false"><u-icon name="close" size="28rpx" color="#999"></u-icon></view>
				</view>
				<view v-for="(item, index) in waresExtList2" :key="index">
					<view class="fb mb20 f30 gray3 tc">{{ item.title }}</view>
					<view class="agreement-content"><u-parse :content="item.content"></u-parse></view>
				</view>
				<view class="d-c-c mt20">
					<button class="mr20 pop-btn" @click="isxieyi = false">
						{{ $t("w_0210") }}
					</button>
				</view>
			</view>
		</view>
		<mpvue-city-picker v-if="is_load" ref="mpvueCityPicker" :province="province"
			:pickerValueDefault="cityPickerValueDefault" @onConfirm="onConfirm"></mpvue-city-picker>
	</view>
</template>

<script>
	import Product from "./part/product.vue";
	import repurchase from "./part/repurchase.vue";
	import fans from "./part/fans.vue";
	import register from "./part/register.vue";
	import upgrade from "./part/upgrade.vue";
	import welfare from "./part/welfare.vue";
	import mpvueCityPicker from "@/components/mpvue-citypicker/mpvueCityPicker.vue";
	import xieyi from "./part/xieyi.js";
	export default {
		components: {
			Product,
			repurchase,
			fans,
			register,
			upgrade,
			welfare,
			mpvueCityPicker,
		},
		data() {
			return {
				/* 1注册订单 2升级订单 3其他订单 7嗨粉订单 1确认分享注册订单*/
				specialArea: 0,
				registType: 0,
				is_load: false,
				shoppingIds: [],
				isRead: false,
				shareType: 0,
				alertTime: 10,
				waresExtList: [],
				waresExtList2: [xieyi],
				isxieyi: false,
				form: {
					upgradeMemberCode: "",
					upgradeMemberName: "",
					deliveryWay: 0,
					transType: "",
					/* 安置部门 */
					placeDept: "",
					placeDeptVal: "",
					postage: "",
					pkCountry: 1, //自然国家
					pkSettleCountry: 1, //结算国家
					parent: "", //推荐编号
					parentName: "", //推荐名称
					placeParent: "", //安置编号
					placeParentName: "", //安置名称
					recName: "", //收货人
					recPhone: "", //联系方式
					recAddress: "", //详细地址
					recProvince: "", //联系地址-省
					recCity: "", //联系地址-市
					recCounty: "",
					dizhi: ["", "", ""],
					dzName: ["", "", ""],
					nameList: "",
					memberName: "", //会员名称
					phone: "", //联系方式
					idCard: "", //身份证号
					pkBank: "", //银行名称
					cardNumber: "", //银行卡号
					subBankName: "", //开会支行
					email: "", //电子邮箱，比如 example@qq.com
					orderItemsParams: [],
					postage: "", //邮费
					priceAmount: "",
					borderPriceAmount: "",
					assAchieveAmount: "",
					achieveAmount: "",
					fwzx: "",
					deleteList: [],
					specialArea: "",
					pkGrade: 0,
					pkGradeVal: "",
					pkMemberStore: "",
					pkStorehouse: "",
					accountName: "",
				},
				isAgree: false,
				time1: null,

				registerPage: {},
				token: "",

				/* 地址 */
				cityPickerValueDefault: [0, 0, 0],
				province: [],
				city: [],
				area: [],
				addressName: "",
				accountList: [],
				countryList: [],
				storeList: [],
				storeLists: [],
				storehouse: [],
				transportType: [],
				deliveryList: [],
				waresCodeList: [],
				countryloading: false,
				bankloading: false,
				transportloading: false,
				deliveryloading: false,
				memberAddress: [],
				isEnough: false,
				clock: false,
				specialType: 0,
				isFirst: false,
				userCountry: 0,
				transnational: false,
				isAddPath: false,
				borderunits: "",
				placeDeptList: [],
				buyAgreementFlag: 0,
				registerBank: 0,
			};
		},
		onShow() {
			if (this.isAddPath) {
				this.getMemberAddress();
			}
		},
		destroyed() {
			clearInterval(this.time1);
			this.time1 = null;
		},
		async onLoad(e) {
			//生成token
			this.getGenerate();

			/* 注册专区手动选择的结算国 */
			this.userCountry = e.userCountry || 0;
			this.specialArea = e.specialArea * 1;

			//获取用户信息
			await this.getInfo();
			/* 获取地区 */

			/* 获取历史记录 */
			// this.getMemberAddress();
			// this.form.memberName = this.getUserId() || '';

			// this.form.fwzx = this.getUserId() || '';
			this.shoppingIds = uni.getStorageSync("cartinfo");
			this.borderunits = uni.getStorageSync("borderUnit");
			let title = this.$t("ENU_TRADE_T_121");
			switch (e.specialArea * 1) {
				case 0:
					//  '商品专区';
					title = this.$t("ENU_TRADE_T_121");
					break;
				case 1:
					// title = '自营专区';ENU_MENU_311
					title = this.$t("ENU_MENU_311");
					break;
				case 2:
					// title = '升级专区-升级专区';
					title = this.$t("ENU_MENU_321");
					break;
				case 3:
					// title = '自营专区';
					title = this.$t("ENU_TRADE_T_121");
					break;
				case 7:
					// title = '嗨粉注册';
					title = this.$t("N_I_2");
					break;
				case 10:
					// title = '重消专区';
					title = this.$t("ENU_MENU_360");
					break;
				case 11:
					// title = '积分专区';
					title = this.$t("ENU_MENU_350");
					break;
				case 12:
					// title = '工具流';
					title = this.$t("ENU_MENU_333");
					break;
				case 13:
					// title = '福利专区';
					title = this.$t("ENU_MENU_340");
					break;
				case 14:
					// title = '直播专区';
					title = this.$t("ENU_MENU_334");
					break;
				case 18:
					// title = '创客礼包';
					title = this.$t("ENU_SPECIAL_A_18");
					break;
				case 19:
					// title = '赋能礼包';
					title = this.$t("ENU_SPECIAL_A_19");
					break;
				case 21:
					// title = '海粉专区';
					title = this.$t("N_I_4");
					break;
				case 22:
					// title = '合作专区';
					title = this.$t("ENU_SPECIAL_A_22");
					break;
				case 23:
					// title = '提货专区';
					title = this.$t("ENU_SPECIAL_A_8");
					break;
				case 24:
					// title = '乐学易考';
					title = this.$t("ENU_MENU_312");
					break;
				case 25:
					// title = '乐学易考';
					title = this.$t("ENU_MENU_322");
					break;
				case 26:
					// title = '乐学易考';
					title = this.$t("ENU_MENU_335");
					break;
				case 27:
					// title = '海粉升级';
					title = this.$t("ENU_ORDER_T_27");
					break;
				case 101:
					title = this.$t("fn_004");
					break;
				case 102:
					title = this.$t("ENU_MENU_316");
					break;
				case 201:
					title = this.$t("fn_007");
					break;
				case 202:
					title = this.$t("fn_008");
					break;
				case 30:
					title = this.$t("fn_009");
					break;
				case 33:
					title = this.$t("APP_ADD_27");
					break;
			}
			uni.setNavigationBarTitle({
				title: title,
			});

			this.form.specialArea = e.specialArea * 1;
			this.shareType = e.shareType || 0;

			if (this.specialArea != 21) {
				this.getShoppingDetail();
			} else {
				this.queryConfirmWaresinfo();
			}
			/* 未使用 */
			/* 获取银行信息 */

			this.getBankData();

			/* 获取运输方式 */
			this.getTransportType();
			/* 获取发货方式 */
			this.getDeliveryList();
			/*  */
			// if (this.specialArea == 18 || this.specialArea == 19 || this.specialArea == 23) {
			// 	this.specialArea = 13;
			// }
			/* 注册权限 */
			if (
				this.specialArea == 1 ||
				this.specialArea == 24 ||
				this.specialArea == 101 ||
				this.specialArea == 102
			) {
				this.specialType = 1;
				// this.form.parent = this.getUserId() || '';
				/* 一键注册 */
				// this.getQuickReg();
				this.registType = 1;
				this.getRegisterPage();
			}
			/* 升级专区 */
			if (
				this.specialArea == 2 ||
				this.specialArea == 25 ||
				this.specialArea == 27 ||
				this.specialArea == 201 ||
				this.specialArea == 202
			) {
				this.specialType = 2;
				// this.form.upgradeMemberCode = this.getUserId() || '';
				/* 校验等级 */
				if (this.form.upgradeMemberCode) {
					this.validateUpgRel();
				}
			}
			/* 复购专区 */
			if (
				this.specialArea == 3 ||
				this.specialArea == 12 ||
				this.specialArea == 14 ||
				this.specialArea == 22 ||
				this.specialArea == 26 ||
				this.specialArea == 30 ||
				this.specialArea == 33
			) {
				this.specialType = 3;
				// this.form.upgradeMemberCode = this.getUserId() || '';
				/* 校验等级 */
				this.validateUpgRel();
			}
			/* 嗨粉分享专区 */
			if (this.specialArea == 7 || this.specialArea == 21) {
				this.specialType = 4;
				this.form.parent = this.getUserId() || "";
				/* 一键注册 */
				this.getQuickReg();
			}
			/* 嗨粉分享专区 */
			if (this.specialArea == 21) {
				this.specialType = 6;
				this.form.parent = this.getUserId() || "";
				// this.queryConfirmWaresinfo()
			}
			/* 福利专区 */
			if (
				this.specialArea == 13 ||
				this.specialArea == 11 ||
				this.specialArea == 10 ||
				this.specialArea == 18 ||
				this.specialArea == 19 ||
				this.specialArea == 23
			) {
				this.specialType = 5;
				this.form.upgradeMemberCode = this.getUserId() || "";
				this.validateUpgRel();
			}
			console.log("specialType:" + this.specialType);
		},
		provide: function() {
			return {
				form: this.form,
			};
		},
		methods: {
			/* 店铺 */
			getStore() {
				let self = this;
				self._get("member/api/store/list", {}, (res) => {
					self.storeList = res.rows || [];
					console.log(self.storeList);
				});
			},
			getStoreList() {
				let self = this;
				self._get("member/api/store/store-list", {}, (res) => {
					self.storeLists = res.rows || [];
					console.log(self.storeLists, "storeLists");
				});
			},
			/* 仓库 */
			getStorehouse() {
				let self = this;
				self._get("system/api/storehouse/list", {}, (res) => {
					self.storehouse = res.rows || [];
				});
			},
			getInfo() {
				let self = this;
				return new Promise((resolve, reject) => {
					self._get("member/api/member/get-info", {}, (res) => {
						self.buyAgreementFlag = res.data.buyAgreementFlag;
						if (self.buyAgreementFlag == 1) {
							self.isRead = true;
						}
						self.form.fwzx = res.data.memberCode;
						self.form.pkCountry = res.data.pkCountry;
						self.form.upgradeMemberCode = res.data.memberCode;
						console.log("当前用户");
						/* 选择的国家不是自己国籍 */
						if (
							self.userCountry != 0 &&
							self.userCountry != res.data.pkSettleCountry
						) {
							self.transnational = true;
							/* 如果是跨国升级 */
							if (self.specialArea == 201 || self.specialArea == 202) {
								self.form.upgradeMemberCode = "";
							}
						}
						console.log(self.transnational);
						/* 非注册专区获取结算国家 */
						if (!self.userCountry) {
							/* 当前用户结算国家 */
							self.userCountry = res.data.pkSettleCountry;
						}
						console.log(self.userCountry);
						self.getCountry();
						self.getAreaData();
						if (self.userCountry != 1) {
							self.getStore();
							self.getStoreList();
							self.getStorehouse();
						}
						resolve(true);
					});
				});
			},
			/*三级联动选择*/
			showMulLinkageThreePicker() {
				this.$refs.mpvueCityPicker.show();
			},

			/*确定选择的省市区*/
			onConfirm(e) {
				let self = this;
				self.form["rec" + "Province"] = e.cityCode[0];
				self.form["rec" + "City"] = e.cityCode[1];
				self.form["rec" + "County"] = e.cityCode[2];
				self.form.nameList = self.getAddName();
				self.queryOrderPostage();
			},
			getAddName: function() {
				let self = this;
				let pid = 0;
				let cid = 0;
				let aid = 0;
				let defaultValue = [0, 0, 0];
				pid = self.form["rec" + "Province"];
				cid = self.form["rec" + "City"];
				aid = self.form["rec" + "County"];
				defaultValue = self.cityPickerValueDefault;
				let address = self.getAddressName(pid, cid, aid, defaultValue);
				return address;
			},

			/* 省市区回显 */
			getAddressName(pid, cid, aid, piker) {
				let self = this;
				/* 省市区列表 */
				if (!self.province) {
					return;
				}
				let add = "";
				let citydata = [];
				let areadata = [];
				self.province.forEach((item, index) => {
					if (item["id"] == pid) {
						add += item["name"];
						citydata = item["children"];
						piker[0] = index;
						if (citydata && citydata.length > 0) {
							citydata.forEach((citem, cindex) => {
								if (citem["id"] == cid) {
									add += citem["name"];
									areadata = citem["children"] ? citem["children"] : [];
									piker[1] = cindex;
									if (areadata && areadata.length > 0) {
										areadata.forEach((aitem, aindex) => {
											if (aitem["id"] == aid) {
												add += aitem["name"];
												piker[2] = aindex;
												return;
											}
										});
									}
								}
							});
						}
					}
				});
				return add;
			},
			async changeInput(e) {
				let self = this;
				console.log(e);
				if (e == "parent") {
					if (self.registType == 0) {
						self.getQuickReg();
					} else {
						self.validPCode();
					}
				}
				if (e == "clearPlaceParent") {
					console.log("清楚部门");
					self.placeDeptList = [];
					self.form.placeDept = "";
				}
				if (e == "placeParent") {
					self.valiDPPCode();
				}
				if (e == "placeDept") {
					self.valiDPPCode2();
				}
				if (e == "upgradeMemberCode") {
					const flag = await self.validateUpgRel();
					if (flag) {
						if (
							self.specialArea == 3 ||
							self.specialType == 5 ||
							self.specialArea == 30 ||
							self.specialArea == 33
						) {} else {
							console.log("---------");
							self.valiMemLevel();
						}
					}
				}
			},
			changeRegistType(n) {
				this.registType = n;
				if (n == 0) {
					this.form.parent = this.getUserId() || "";
					this.getQuickReg();
				} else {
					this.form.parent = "";
					this.form.parentName = "";
					this.form.placeParent = "";
					this.form.placeParentName = "";
					this.form.placeDept = "";
				}
			},

			// 验证获取会员等级
			async getValidMemLevel() {
				let self = this;
				let menber = await self.getMemberAddress();
				let params = {
					achieveAmount: self.form.achieveAmount,
					assAchieveAmount: self.form.assAchieveAmount,
					orderItemsParams: self.form.orderItemsParams,
					priceAmount: self.form.priceAmount,
					specialArea: self.specialArea,
					deleteList: self.form.deleteList,
					pkCountry: self.form.userCountry,
					pkSettleCountry: self.userCountry,
				};
				if (self.specialType == 2) {
					params.recCity = self.form.recCity;
					params.recCounty = self.form.recCounty;
					params.recProvince = self.form.recProvince;
					params.transType = self.form.transType;
					params.deliveryWay = self.form.deliveryWay;
					params.upgradeMemberCode = self.form.upgradeMemberCode;
				}
				let callback = function() {
					self.queryOrderPostage();
					console.log("-----------");
					console.log(params);
					self._post("sale/api/order/valid-mem-level", params, (res) => {
						self.form.pkGradeVal = res.data.pkGradeVal || "";
						self.form.pkGrade = res.data.pkGrade || "";
						self.isEnough = res.data.isEnough;
					});
				};
				if (menber) {
					callback();
				}
			},

			/* 生成token */
			getGenerate() {
				let self = this;
				self._get("system/api/idempotent/generate", {}, (res) => {
					uni.setStorageSync("token", res.msg);
				});
			},
			async queryConfirmWaresinfo() {
				let self = this;
				self._post(
					"sale/api/wares/query-confirm-waresinfo", {
						confirmOrderWaresInfoParamsList: self.shoppingIds,
					},
					(res) => {
						self.form.orderItemsParams = res.data;
						let arr = [];
						let arr2 = [];
						self.form.orderItemsParams.forEach((item) => {
							arr.push(item.waresCode);
						});
						self.shoppingIds.forEach((item) => {
							arr2.push({
								shoppingId: item.shoppingId,
							});
						});
						self.waresCodeList = arr;
						self.form.deleteList = arr2;
						self.form.priceAmount = res.data[0].priceAmount;
						self.form.achieveAmount = res.data[0].pvAmount;
						self.getMemberAddress();
					}
				);
			},
			/* 获取商品信息 */
			getShoppingDetail() {
				let self = this;

				self._post(
					"sale/api/shopping/get-shopping-wares-detail", {
						shoppingIds: self.shoppingIds,
						specialArea: self.form.specialArea,
					},
					(res) => {
						self.form.priceAmount = res.data.priceAmount;
						self.form.borderPriceAmount = res.data.borderPriceAmount;
						self.form.assAchieveAmount = res.data.assAchieveAmount;
						self.form.achieveAmount = res.data.achieveAmount;
						self.form.orderItemsParams = res.data.orderItemsParams;
						let arr = [];
						let arr2 = [];
						self.form.orderItemsParams.forEach((item) => {
							arr.push(item.waresCode);
						});
						self.shoppingIds.forEach((item) => {
							arr2.push({
								shoppingId: item,
							});
						});
						self.waresCodeList = arr;
						self.form.deleteList = arr2;
						if (self.specialType != 3 && self.specialType != 5) {
							if (self.form.upgradeMemberCode) {
								self.getValidMemLevel();
							}
						} else {
							self.getMemberAddress();
						}
						// return;
						/* 测试先关闭 */
						self.getWaresAgreement();
					}
				);
			},
			/* 注册页面显示权限 */
			getRegisterPage() {
				let self = this;
				self._get("system/api/register-page/config", {}, (res) => {
					self.registerBank = res.data;
				});
				// self._get("system/api/register-page/list", {}, (res) => {
				//   self.registerPage = res.data;
				// });
			},

			getWaresAgreement() {
				let self = this;
				self._post(
					"sale/api/wares/get-wares-agreement", {
						waresCodeList: self.waresCodeList,
					},
					(res) => {
						self.alertTime = res.data.alertTime;
						self.waresExtList = res.data.waresExtList;
						if (self.waresExtList && self.waresExtList.length > 0) {
							self.openAgreement();
						}
					}
				);
			},
			/* 查询邮费 */
			queryOrderPostage() {
				let self = this;
				if (self.specialType == 4) {
					self.selfOrderPostage();
					return;
				}
				let params = {};
				if (self.specialArea != 21) {
					params = {
						achieveAmount: self.form.achieveAmount,
						assAchieveAmount: self.form.assAchieveAmount,
						orderItemsParams: self.form.orderItemsParams,
						priceAmount: self.form.priceAmount,
						recCity: self.form.recCity,
						recCounty: self.form.recCounty,
						recProvince: self.form.recProvince,
						specialArea: self.specialArea,
						deliveryWay: self.form.deliveryWay,
						transType: self.form.transType,
						deleteList: self.form.deleteList,
					};
				} else {
					params = {
						deleteList: self.form.deleteList,
						deliveryWay: self.form.deliveryWay,
						recCity: self.form.recCity,
						recCounty: self.form.recCounty,
						recProvince: self.form.recProvince,
						specialArea: self.specialArea,
						transType: self.form.transType,
					};
				}
				self._post("sale/api/order/query-order-postage", params, (res) => {
					self.form.postage = res.data.postage;
				});
			},
			/* 查询邮费 */
			selfOrderPostage() {
				let self = this;
				self._post(
					"sale/api/order/self-order-postage", {
						specialArea: self.specialArea,
						deliveryWay: self.form.deliveryWay,
						transType: self.form.transType,
						recProvince: self.form.recProvince,
						recCity: self.form.recCity,
						recCounty: self.form.recCounty,
						orderItemsParams: self.form.orderItemsParams,
					},
					(res) => {
						self.form.postage = res.data.postage;
					}
				);
			},
			closeAgreement(e) {
				if (e == true) {
					if (this.alertTime > 0) {
						return;
					}
					this.isRead = true;
				}
				clearInterval(this.time1);
				this.time1 = null;
				this.isAgree = false;
			},
			openAgreement() {
				let self = this;
				self.isAgree = true;
				self.time1 = setInterval(function() {
					if (self.alertTime > 0) {
						self.alertTime--;
					} else {
						clearInterval(self.time1);
						self.time1 = null;
					}
				}, 1000);
			},
			moveHandle() {
				return false;
			},
			// 获取省市区
			getAreaData() {
				let self = this;
				self._get(
					"system/api/area/tree", {
						pkCountry: self.userCountry,
					},
					function(res) {
						self.province = res.data;
						self.is_load = true;
					}
				);
			},
			/*获取银行数据*/
			getBankData() {
				let self = this;
				self.bankloading = true;
				self._get(
					"system/api/bank/list", {
						pkCountry: self.userCountry
					},
					function(res) {
						self.accountList = res.data;
						self.bankloading = false;
					}
				);
				// self._get("system/api/bank/list", {}, function (res) {
				//   self.accountList = res.data;
				//   self.bankloading = false;
				// });
			},
			bindPickerChange: function(e) {
				if (this.type == "detail") {
					return;
				}
				this.bank_index = e.detail.value;
				// console.log(this.bank_index);
				this.account_info = this.accountList[this.bank_index];
				this.form.pkBank = this.account_info.pkId;
			},
			getCountry() {
				let self = this;
				self.countryloading = true;
				self._get("system/api/country/list", {}, function(res) {
					self.countryList = res.data;
					self.countryloading = false;
					console.log("获取国家");
				});
			},
			getTransportType() {
				let self = this;
				self.transportloading = true;
				self._get("system/pub/enums/transport-type", {}, function(res) {
					self.transportType = res.data;
					if (self.form.transType === "") {
						self.form.transType = self.transportType[0].value;
					}
					self.transportloading = false;
				});
			},
			getDeliveryList() {
				let self = this;
				self.transportloading = true;
				self._get("system/pub/enums/api-delivery-list", {}, function(res) {
					self.deliveryList = res.data;
					self.form.deliveryWay = self.deliveryList[0].value;
					self.deliveryloading = false;
				});
			},
			getMemberAddress() {
				let self = this;
				return new Promise((resolve, reject) => {
					self._get(
						"member/api/member-address/list", {
							upgradeMemberCode: self.form.upgradeMemberCode,
						},
						function(res) {
							console.log(self.transnational);
							/* 判断是否是非本国 */
							if (!self.transnational) {
								self.memberAddress = res.data;
							}
							if (self.memberAddress && self.memberAddress.length > 0) {
								let e = self.memberAddress[0];
								self.form.recName = e.recName;
								self.form.recPhone = e.recPhone;
								self.form.recProvince = e.recProvince;
								self.form.recCity = e.recCity;
								self.form.recCounty = e.recCounty;
								self.form.nameList = e.recArea;
								self.form.recAddress = e.recAddress;
								self.form.dizhi = [e.recProvince, e.recCity, e.recCounty];
								self.queryOrderPostage();
							}
							if (self.specialArea == 21) {
								self.queryOrderPostage();
							}
							self.isAddPath = true;
							resolve(true);
						},
						(err) => {
							uni.showToast({
								title: res.msg,
								icon: "none",
							});
							resolve(false);
						}
					);
				});
			},
			/*删除地址*/
			delAddress(e) {
				let self = this;
				uni.showModal({
					title: "提示",
					content: self.$t("w_0088") + "?",
					success: function(o) {
						o.confirm &&
							self._delete(
								"member/api/member-address/" + e, {},
								function(result) {
									uni.showToast({
										title: self.$t("w_0089"),
										duration: 2000,
									});
									self.getMemberAddress();
								}
							);
					},
				});
			},
			// 验证升级编号在登陆人伞下
			valiMemLevel() {
				let self = this;
				return new Promise((resolve, reject) => {
					let params = {
						achieveAmount: self.form.achieveAmount,
						assAchieveAmount: self.form.assAchieveAmount,
						orderItemsParams: self.form.orderItemsParams,
						priceAmount: self.form.priceAmount,
						specialArea: self.specialArea,
						deleteList: self.form.deleteList,
					};
					if (self.specialType == 2) {
						params.recCity = self.form.recCity;
						params.recCounty = self.form.recCounty;
						params.recProvince = self.form.recProvince;
						params.deliveryWay = self.form.deliveryWay;
						params.upgradeMemberCode = self.form.upgradeMemberCode;
					}
					console.log(params);
					console.log("---------");
					self._post("sale/api/order/valid-mem-level", params, function(res) {
						if (res.code == 200) {
							self.form.pkGradeVal = res.data.pkGradeVal;
							self.form.isEnough = res.data.isEnough;
							self.form.pkGrade = res.data.pkGrade;
							resolve(true);
						} else {
							uni.showToast({
								title: res.msg,
								icon: "none",
							});
							self.clock = false;
							resolve(false);
						}
					});
				});
			},
			// 验证升级编号在登陆人伞下
			validateUpgRel() {
				let self = this;
				return new Promise((resolve, reject) => {
					console.log("验证");
					if (!self.form.upgradeMemberCode) {
						uni.showToast({
							title: this.$t("w_0097"),
							icon: "none",
							duration: 2000,
						});
						return;
					}
					self._post(
						"sale/api/order/validate-upg-rel", {
							upgradeMemberCode: self.form.upgradeMemberCode,
							pkSettleCountry: self.userCountry,
						},
						function(res) {
							if (res.code == 200) {
								self.form.upgradeMemberCode = res.data.upgradeMemberCode;
								self.form.upgradeMemberName = res.data.upgradeMemberName;
								// self.form.postage = res.data.postage;
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			// 一键注册
			getQuickReg() {
				let self = this;
				return new Promise((resolve, reject) => {
					self._post(
						"sale/api/order/quick-reg", {
							parent: self.form.parent,
							specialArea: self.specialArea,
							pkSettleCountry: self.userCountry,
						},
						function(res) {
							if (res.code == 200) {
								self.form.parentName = res.data.parentName;
								self.form.placeDept = res.data.placeDept;
								self.form.placeDeptVal = res.data.placeDeptVal;
								self.form.placeParent = res.data.placeParent;
								self.form.placeParentName = res.data.placeParentName;
								self.isFirst = res.data.isFirst;
								console.log();
								if (self.specialType == 1) {
									self.valiDPPCode();
								}
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			// 注册订单验证手机号
			validPhone() {
				let self = this;
				return new Promise((resolve, reject) => {
					self._post(
						"sale/api/order/valid-phone", {
							memberName: self.form.memberName,
							phone: self.form.phone,
							placeParent: self.form.placeParent,
						},
						function(res) {
							if (res.code == 200) {
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			/* 安置部门切换校验 不改变安置部门列表 */
			valiDPPCode2() {
				let self = this;
				if (self.form.placeParent == "") {
					return false;
				}
				return new Promise((resolve, reject) => {
					self._post(
						"sale/api/order/valid-p-p-code", {
							parent: self.form.parent,
							placeParent: self.form.placeParent,
							placeDept: self.form.placeDept,
							pkSettleCountry: self.form.pkSettleCountry,
						},
						function(res) {
							if (res.code == 200) {
								// self.isFirst = res.data.isFirst;
								console.log(self.isFirst);
								if (res.data.placeDept) {
									self.form.placeDept = res.data.placeDept;
								}
								if (res.data.placeParent) {
									self.form.placeParent = res.data.placeParent;
								}
								if (res.data.placeParentName) {
									self.form.placeParentName = res.data.placeParentName;
								}
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			// 注册订单验证安置人编号
			valiDPPCode(e) {
				let self = this;
				if (self.form.placeParent == "") {
					return false;
				}
				return new Promise((resolve, reject) => {
					console.log("校验2");
					self._post(
						"sale/api/order/valid-p-p-code", {
							parent: self.form.parent,
							placeParent: self.form.placeParent,
							placeDept: self.form.placeDept,
							pkSettleCountry: self.form.pkSettleCountry,
						},
						function(res) {
							if (res.code == 200) {
								// self.isFirst = res.data.isFirst;
								console.log(self.isFirst);
								if (!e) {
									if (res.data.placeDept) {
										self.form.placeDept = res.data.placeDept;
									}
									if (res.data.placeParent) {
										self.form.placeParent = res.data.placeParent;
									}
									if (res.data.placeParentName) {
										self.form.placeParentName = res.data.placeParentName;
									}
									if (res.data.placeDeptList) {
										let list = [];
										res.data.placeDeptList.forEach((item) => {
											list.push({
												name: self.$t("fn_010") + item + self.$t(
													"fn_011"),
												value: item,
											});
										});
										self.placeDeptList = list;
									}
								}
								console.log("校验2结束");
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			/* 注册订单验证推荐人编号 */
			validPCode(e) {
				let self = this;
				return new Promise((resolve, reject) => {
					console.log("校验1");
					self._post(
						"sale/api/order/valid-p-code", {
							parent: self.form.parent,
						},
						function(res) {
							if (res.code == 200) {
								self.isFirst = res.data.isFirst;
								if (!e) {
									self.form.parent = res.data.parent;
									self.form.parentName = res.data.parentName;
									// self.form.postage = res.data.postage;
									if (res.data.placeDept) {
										self.form.placeDept = res.data.placeDept;
									}
									if (res.data.placeParent) {
										self.form.placeParent = res.data.placeParent;
									}
									if (res.data.placeParentName) {
										self.form.placeParentName = res.data.placeParentName;
									}
									self.changeInput("placeParent");
								}
								console.log("校验1结束");
								resolve(true);
							} else {
								uni.showToast({
									title: res.msg,
									icon: "none",
								});
								self.clock = false;
								resolve(false);
							}
						}
					);
				});
			},
			async subFunc() {
				let self = this;
				console.log("clock:" + self.clock);
				if (self.clock) {
					return;
				}

				console.log(this.form);
				let callBack = function(params) {
					let url = "";
					if (self.specialType == 1) {
						url = "sale/api/order/confirm-reg-order";
					}
					if (
						self.specialType == 2 ||
						self.specialType == 3 ||
						self.specialType == 5
					) {
						url = "sale/api/order/confirm-oth-order";
					}
					if (self.specialType == 4) {
						url = "sale/api/order/confirm-fun-order";
					}
					if (self.specialType == 6) {
						url = "sale/api/order/confirm-share-order";
					}
					uni.showLoading({
						title: "Loading...",
					});
					self.clock = true;
					self._post(
						url,
						params,
						(res) => {
							console.log("下单");
							if (res.code == 200) {
								self.gotoPage(
									"/pages/order/cashier?orderCode=" +
									res.data.orderCode +
									"&specialArea=" +
									res.data.specialArea +
									"&pkSettleCountry=" +
									self.userCountry,
									"redirect"
								);
							}
						},
						false,
						(com) => {
							uni.hideLoading();
							self.clock = false;
						}
					);
				};
				let params = self.form;
				let flag = false;
				let values = [];
				if (!self.isRead) {
					uni.showToast({
						title: this.$t("w_0091"),
						duration: 1000,
						icon: "none",
					});
					return false;
				}

				if (self.specialType == 2) {
					values.push({
						name: this.$t("w_0097"),
						value: "upgradeMemberCode",
						callback: function(e) {
							return e != "";
						},
					}, {
						name: this.$t("w_0101"),
						value: "pkMemberStore",
						callback: function(e) {
							if (self.form.deliveryWay != 2) {
								return e != "";
							} else {
								return true;
							}
						},
					});
				}
				if (self.specialType == 3) {
					values.push({
						name: this.$t("w_0280"),
						value: "upgradeMemberCode",
						callback: function(e) {
							return e != "";
						},
					}, {
						name: this.$t("w_0101"),
						value: "pkMemberStore",
						callback: function(e) {
							if (self.form.deliveryWay != 2) {
								return e != "";
							} else {
								return true;
							}
						},
					});
				}
				if (self.specialType == 5) {
					values.push({
						name: this.$t("w_0046"),
						value: "upgradeMemberCode",
						callback: function(e) {
							return e != "";
						},
					});
				}
				if (self.specialType == 1 || self.specialType == 4) {
					values.push({
						name: this.$t("w_0264") /* 请输入推荐编号 */ ,
						value: "parent",
						callback: function(e) {
							return e != "";
						},
					});
					if (this.form.email) {
						values.push({
							name: this.$t("w_0277") /* 请输入邮箱 */ ,
							value: "email",
							callback: function(e) {
								const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
								return emailRegex.test(e);
							},
						});
					}
					if (self.registerBank == 0) {
						values.push({
							name: this.$t("w_0302") /* 请选择银行卡 */ ,
							value: "pkBank",
							callback: function(e) {
								return e != "";
							},
						}, {
							name: this.$t("w_0271") /* 请输入银行卡号 */ ,
							value: "cardNumber",
							callback: function(e) {
								return e != "";
							},
						}, {
							name: this.$t("w_0272") /* 请输入开户支行 */ ,
							value: "subBankName",
							callback: function(e) {
								return e != "";
							},
						}, {
							name: this.$t("MN_F_T_539") /* 请输入开户姓名 */ ,
							value: "accountName",
							callback: function(e) {
								return e != "";
							},
						}, {
							name: this.$t("w_0269") /* 请输入证件号码 */ ,
							value: "idCard",
							callback: function(e) {
								return e != "";
							},
						});
					}

					values.push({
						name: this.$t("w_0060") /* 请输入会员姓名 */ ,
						value: "memberName",
						callback: function(e) {
							return e != "";
						},
					}, {
						name: this.$t("w_0053") /* 请输入联系方式 */ ,
						value: "phone",
						callback: function(e) {
							return e.length != "";
						},
					}, {
						name: this.$t("w_0204") /* 请输入正确联系方式 */ ,
						value: "phone",
						callback: function(e) {
							let patrn = /^\d+$/;
							return e.length >= 6 && e.length <= 20 && patrn.test(e);
						},
					});
				}
				if (self.specialType == 1) {
					values.push({
						name: this.$t("w_0266"),
						value: "placeParent",
						callback: function(e) {
							return e != "";
						},
					}, {
						name: this.$t("w_0268"),
						value: "placeDept",
						callback: function(e) {
							return e != "";
						},
					}, {
						name: this.$t("w_0101"),
						value: "pkMemberStore",
						callback: function(e) {
							if (self.form.deliveryWay != 2) {
								return e != "";
							} else {
								return true;
							}
						},
					});
				}
				if (self.form.deliveryWay == 4) {
					values.push({
						name: this.$t("w_0067"),
						/* 收货人 */
						value: "recName",
						callback: function(e) {
							return e != "";
						},
					});
					values.push({
						name: this.$t("w_0053"),
						/* 请输入联系方式 */
						value: "recPhone",
						callback: function(e) {
							let patrn = /^\d+$/;
							return e.length >= 6 && e.length <= 20 && patrn.test(e);
						},
					});
					values.push({
						name: this.$t("w_0069"),
						/* 请选择收货地址 */
						value: "nameList",
						callback: function(e) {
							return e != "";
						},
					});
					values.push({
						name: this.$t("w_0070"),
						/* 请输入详细地址 */
						value: "recAddress",
						callback: function(e) {
							return e != "";
						},
					});
				} else {
					delete params.recName;
					delete params.recPhone;
					delete params.recAddress;
					delete params.recProvince;
					delete params.recCity;
				}

				console.log(values);
				values.forEach((item, index) => {
					if (typeof params[item.value] === "string") {
						params[item.value] = params[item.value].trim();
					}
					// params[item.value] = params[item.value].trim();
					if (!flag && !item.callback(params[item.value])) {
						flag = item.name;
						return;
					}
				});
				if (flag) {
					uni.showToast({
						title: flag,
						duration: 1000,
						icon: "none",
					});
					return false;
				}
				// let newObj = Object.keys(params).filter(key => params[key] !== '').reduce((acc, key) => {
				//   acc[key] = params[key];
				//   return acc;
				// }, {});
				// params = newObj;
				// params.transType = '';
				// delete params.dzName;
				// delete params.fwzx;
				// delete params.pkCountry;
				// delete params.pkGrade;
				if (
					self.specialType != 1 &&
					self.specialType != 2 &&
					self.specialType != 4
				) {
					delete params.pkSettleCountry;
				}

				console.log("values:true");
				if (self.specialType == 1) {
					console.log("开始校验");
					/* 注册推荐人 */
					const res1 = await this.validPCode(true);
					/* 注册安置人 */
					const res2 = await this.valiDPPCode(true);
					console.log("结束校验");
					/* 注册手机号 */
					// let res3 = await this.validPhone();
					// if (res1 && res2 && res3) {
					if (res1 && res2) {
						console.log("校验成功");
						callBack(params);
					}
				} else if (self.specialType == 2) {
					let res1 = await this.validateUpgRel();
					let res2 = await this.valiMemLevel();
					if (res1 && res2) {
						callBack(params);
					}
				} else if (self.specialType == 3 || self.specialType == 5) {
					let res1 = await this.validateUpgRel();
					if (res1) {
						callBack(params);
					}
				} else if (self.specialType == 4) {
					let res1 = await this.validPhone();
					let res2 = await this.getQuickReg();
					if (res1 && res2) {
						callBack(params);
					}
				} else if (self.specialType == 6) {
					let orderItemsParams = [];
					self.shoppingIds.forEach((item) => {
						orderItemsParams.push({
							channel: 2,
							pkId: item.pkTWares,
							quantity: item.quantity,
							waresItemsParamList: [{
								pkWaresSpecsSku: item.pkTWaresSku,
							}, ],
						});
					});
					let param = {
						deleteList: params.deleteList,
						deliveryWay: params.deliveryWay,
						dizhi: params.dizhi,
						fwzx: "",
						nameList: params.nameList,
						orderItemsParams: orderItemsParams,
						postage: params.postage,
						recAddress: params.recAddress,
						recCity: params.recCity,
						recCounty: params.recCounty,
						recName: params.recName,
						recPhone: params.recPhone,
						recProvince: params.recProvince,
						specialArea: params.specialArea,
						transType: params.transType,
					};
					callBack(param);
				} else {
					return;
					callBack(params);
				}
			},
		},
	};
</script>

<style lang="scss">
	.all-list {
		overflow: hidden;
		position: fixed;
		height: 100%;
		width: 100%;
	}

	.pop-bg {
		position: fixed;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 99;
		background-color: rgba(0, 0, 0, 0.65);
	}

	.pop-btn {
		min-width: 264rpx;
		box-sizing: border-box;
		height: 76rpx;
		background: #fb3024;
		border-radius: 38rpx;
		font-size: 30rpx;
		font-family: SourceHanSansCN;
		font-weight: 400;
		color: #f9f9f9;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 0 40rpx;
		line-height: 1.5;
	}

	.pop-btn.close {
		background: #cccccc;
	}

	.agreement-pop {
		position: fixed;
		top: 20vh;
		left: 0;
		right: 0;
		margin: auto;
		z-index: 100;
		background-color: #fff;
		width: 665rpx;
		box-sizing: border-box;
		border-radius: 20rpx;
		padding: 39rpx 39rpx 73rpx 35rpx;
	}

	.agreement-content {
		font-size: 24rpx;
		font-family: SourceHanSansCN;
		font-weight: 400;
		color: #333333;
		line-height: 52rpx;
		word-break: break-all;
		max-height: 40vh;
		overflow: auto;
		padding: 0 20rpx;
		box-sizing: border-box;
	}

	.agreement-content::-webkit-scrollbar {
		/*滚动条整体样式*/
		/*高宽分别对应横竖滚动条的尺寸*/
		display: block;
		width: 5rpx !important;
		height: 1rpx !important;
		-webkit-appearance: default-button;
	}

	.agreement-content::-webkit-scrollbar-thumb {
		/*滚动条里面小方块*/
		border-radius: 10px;
		background-color: #909399;
		// background-image: -webkit-linear-gradient(45deg,
		//     rgba(255, 255, 255, 0.2) 25%,
		//     transparent 25%,
		//     transparent 50%,
		//     rgba(255, 255, 255, 0.2) 50%,
		//     rgba(255, 255, 255, 0.2) 75%,
		//     transparent 75%,
		//     transparent);
	}

	.agreement-content::-webkit-scrollbar-track {
		/*滚动条里面轨道*/
		box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
		background: #ededed;
		border-radius: 10px;
	}

	.form-title {
		width: 750rpx;
		height: 106rpx;
		background: #fb3024;
		padding-left: 44rpx;
		padding-right: 25rpx;
		position: relative;
		box-sizing: border-box;
		font-size: 28rpx;
		color: #ffffff;
		line-height: 106rpx;
		font-weight: bold;
		z-index: 1;
	}

	.form-title.redtitle {
		width: 750rpx;
		height: 106rpx;
		background: #fb3024;
		padding-left: 44rpx;
		position: relative;
		box-sizing: border-box;
		font-size: 28rpx;
		color: #fff;
		line-height: 106rpx;
		font-weight: bold;
		z-index: 1;
	}

	.form-title::before {
		content: "";
		position: absolute;
		top: 0;
		bottom: 0;
		margin: auto;
		left: 25rpx;
		width: 6rpx;
		height: 24rpx;
		background-color: #fb3024;
		z-index: 1;
	}

	.redtitle.form-title::before {
		content: "";
		position: absolute;
		top: 0;
		bottom: 0;
		margin: auto;
		left: 25rpx;
		width: 6rpx;
		height: 24rpx;
		background-color: #fff;
		z-index: 1;
	}

	.form-upload {
		padding: 30rpx 23rpx;
	}

	.form-upload-name {
		font-size: 28rpx;
		color: #333;
		margin-bottom: 20rpx;
	}

	.form-upload-tips {
		font-size: 24rpx;
		color: #999;
		margin-bottom: 20rpx;
	}

	.form-upload-tips2 {
		font-size: 24rpx;
		color: #fb3024;
		line-height: 1.5;
	}

	.upload-add {
		width: 142rpx;
		height: 142rpx;
		margin-right: 18rpx;
		margin-bottom: 18rpx;
	}

	.radiogroup::v-deep uni-radio:not([disabled]) .uni-radio-input:hover {
		border-color: #eee;
	}

	.form-top-nav {
		height: 94rpx;
		background: #fb3024;
	}

	.form-top-nav-item {
		text-align: center;
		font-size: 28rpx;
		color: #fff;
		line-height: 1.5;
		word-break: break-all;
		flex: 1;
		padding: 0 20rpx;
		flex-shrink: 0;
		height: 94rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		position: relative;
	}

	.form-top-nav-item.active::before {
		content: "";
		width: 52rpx;
		position: absolute;
		left: 0;
		right: 0;
		bottom: 12rpx;
		margin: auto;
		height: 6rpx;
		background: #ffffff;
		border-radius: 4rpx;
	}
</style>