<template>
	<div class="team-manage-container g_bg_page">
		<div class="g_h_10"></div>
		<g-panel-form-slot
			:list="[
				{
					icon: '',
					label: '姓名',
					result: '',
					value: memberInfo.aliasName,
					path: '',
					placeholder: '请输入成员姓名',
					tip: 'slot-name',
					type: 'slot',
					pColumn: 8,
					require: true,
				},
				{
					icon: '',
					label: '手机号',
					result: '',
					value: memberInfo.tel,
					path: '',
					tip: 'slot-mobile',
					placeholder: '请输入成员手机号',
					type: 'slot',
					pColumn: 8,
					require: true,
				},
			]"
			@changeName="changeName"
			@changeMobile="changeMobile"
		></g-panel-form-slot>
		<div class="g_text_c g_mt_90">
			<g-button btnText="确定" type="primary" class="" @clickBtn="subMemberInfo"></g-button>
			<div class="g_c_sub g_mt_16" v-if="memberInfo.id" @click="delMember">删除成员</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			memberInfo: {},
		};
	},
	onShow() {},
	onLoad(options) {
		if (options.info) {
			console.log("options.info", options.info);
			this.memberInfo = JSON.parse(options.info);
			uni.setNavigationBarTitle({
				title: "修改成员信息",
			});
		} else {
			uni.setNavigationBarTitle({
				title: "添加成员",
			});
		}
	},
	created() {
		console.log(123123);
	},

	methods: {
		getMemberList() {
			let that = this;
			this.G.Get(this.api.order_peopleList, {}, (res) => {
				console.log("报名人列表：", res);
				that.memberList = res.recordList;
			});
		},
		addMember() {
			this.addMemberShow = true;
		},
		subMemberInfo() {
			let that = this;
			if (this.memberInfo.aliasName == "") {
				uni.showToast({
					title: "请输入成员姓名",
					icon: "none",
				});
				return false;
			}
			if (this.memberInfo.tel == "") {
				uni.showToast({
					title: "请输入成员手机号",
					icon: "none",
				});
				return false;
			}
			let exp = /^1[3-9]\d{9}$/; 
			console.log("that.memberInfo. tel", that.memberInfo.tel);
			console.log("exp.test(that.memberInfo.tel)", exp.test(that.memberInfo.tel));
			if (!exp.test(that.memberInfo.tel)) {
				uni.showToast({
					title: "请输入正确的手机号",
					icon: "none",
				});
				return false;
			}
			let url = "order_addMember";
			if (this.memberInfo.id) {
				// 判断是否是编辑成员
				url = "order_updateMember";
			}
			this.G.Post(this.api[url], this.memberInfo, (res) => {
				console.log("resresresres", res);
				uni.showToast({
					title: "提交成功",
				});
				setTimeout(() => {
					uni.navigateBack({
						detail: 1,
					});
				}, 1500);
			});
		},
		delMember() {
			let that = this;
			this.G.handleConfirm({
				title: "删除",
				content: "确定要删除该成员吗？",
				success: (res) => {
					if (res.confirm) {
						that.G.Post(that.api.order_checkMemberDel, { id: that.memberInfo.id }, (checkRes) => {
							if (checkRes) {
								that.G.handleConfirm({
									title: "删除",
									content: res,
									success: (res) => {
										if (res.confirm) {
											that.subDel();
										}
									},
								});
							} else {
								that.subDel();
							}
						});
					}
				},
			});
		},
		subDel() {
			let that = this;
			that.G.Post(that.api.order_delMember, { id: that.memberInfo.id }, (res) => {
				console.log(res);
				uni.showToast({
					title: "删除成功",
				});
				setTimeout(() => {
					uni.navigateBack({
						detail: 1,
					});
				}, 1500);
			});
		},
		changeName(e) {
			console.log("e", e);
			this.memberInfo.aliasName = e;
		},
		changeMobile(e) {
			console.log("e", e);
			this.memberInfo.tel = e;
		},
	},
};
</script>

<style lang="scss">
.creator {
	color: #46c7bb;
	border: 1px solid #46c7bb;
	background-color: #46c7ba3d;
}
.member {
	color: #f9676e;
	border: 1px solid #f9676e;
	background-color: #f9676e3d;
}
.manager {
	color: #0066d6;
	border: 1px solid #0066d6;
	background-color: #0066d63d;
}
.sticky {
	position: sticky;
	bottom: 0;
	left: 0;
	z-index: 999;
}
</style>
