<template>
	<view class="p-root-other-more g_w_all g_h_all g_bg_f_5 g_pl_10 g_pr_10 g_kuaishou">
		<view class="g_h_10 g_w_pull"></view>
		<view class="g_bg_f g_pl_16 g_pr_16 g_radius_8 g_mb_24">
			<view class="g_flex_row_between g_h_56" v-if="type == 1 || type == 3" :class="type == 3 ? 'g_border_e_b' : ''">
				<view class="g_flex_column_center g_fs_16 g_c_3">不看他的职位</view>
				<view class="g_flex_column_center">
					<u-switch v-model="pLook" activeColor="#00B666" @change="handlePeople"></u-switch>
				</view>
			</view>
			<view class="g_flex_row_between g_h_56" v-if="type == 2 || type == 3">
				<view class="g_flex_column_center g_fs_16 g_c_3">不让他看我的职位</view>
				<view class="g_flex_column_center">
					<u-switch v-model="mLook" activeColor="#00B666" @change="handleSee"></u-switch>
				</view>
			</view>
		</view>
		<g-button mode="square" class="" type="delete" size="medium" :btnText="type == 1 || (type == 3 && from == 1) ? '取消关注' : '删除粉丝'" @clickBtn="goReturn"></g-button>
	</view>
</template>

<script>
export default {
	onReady() {
		this.G.setNavStyle();
	},
	onShareAppMessage() {
		return this.G.shareFun();
	},
	data() {
		return {
			id: 0,
			mLook: true,
			pLook: false,
			type: 0,
			delta: 2,
			lid: 0,
			hid: 0,
			from: 0,
		};
	},
	onLoad(options) {
		console.log("options", options);
		this.delta = options.delta;
		this.id = options.id;
		this.mLook = options.himSee == 1 ? false : true;
		this.pLook = options.lookHim == 1 ? false : true;
		this.type = options.type;
		this.lid = options.lid;
		this.hid = options.hid;
		this.from = options.from;
	},
	methods: {
		handleSee(e) {
			let that = this;
			that.G.Get(
				that.api.bind_isSee + "/" + that.hid,
				{
					id: that.hid,
					himSee: e ? 0 : 1,
				},
				() => {
					uni.showToast({
						icon: "success",
						title: "更新成功",
					});
				}
			);
		},
		handlePeople(e) {
			let that = this;
			that.G.Get(
				that.api.bind_setPeolple + "/" + that.lid,
				{
					id: that.lid,
					lookHim: e ? 0 : 1,
				},
				() => {
					uni.showToast({
						icon: "success",
						title: "更新成功",
					});
				}
			);
		},
		goReturn() {
			let that = this;
			if (that.type == 1 || (that.type == 3 && that.from == 1)) {
				that.G.handleConfirm({
					content: "确认取消关注吗？",
					success: (res) => {
						if (res.confirm) {
							that.G.Get(
								that.api.bind_cancelApply + "/" + that.id,
								{
									agencyId: that.id,
								},
								() => {
									uni.showToast({
										icon: "success",
										title: "取消关注成功",
									});
									setTimeout(() => {
										uni.navigateBack({
											delta: that.delta,
										});
									}, 1500);
								}
							);
						}
					},
				});
			} else {
				that.G.handleConfirm({
					content: "确认删除粉丝吗？",
					success: (res) => {
						if (res.confirm) {
							that.G.Get(
								that.api.bind_delApply + "/" + that.id,
								{
									agencyId: that.id,
								},
								() => {
									uni.showToast({
										icon: "success",
										title: "删除粉丝成功",
									});
									setTimeout(() => {
										uni.navigateBack({
											delta: that.delta,
										});
									}, 1500);
								}
							);
						}
					},
				});
			}
		},
	},
};
</script>

<style></style>
