<template>
	<view class="p-root-merchantManagement-dynamicNotice g_bg_f_5 g_p_10 g_pb_120" style="min-height: 100vh;padding-top: 0;">
		
		<view class="m-card">
			<view class="g_h_24"></view>
			<view class="" hover-class="none" hover-stop-propagation="false">
				<view class="g_p_10 g_flex_row_between flex_center g_bg_f g_radius_8 g_fs_16" hover-class="none"
					hover-stop-propagation="false" style="padding: 16px 10px;">
					<view class="g_flex_column_center g_fw_500 g_c_0 g_fs_17" hover-class="none" hover-stop-propagation="false"> 同步平台职位 </view>
					<view class="g_flex_column_center" hover-class="none" hover-stop-propagation="false">
						<u-switch @change="handleSwitch($event, 'platform')" 
											cusSize='24' 
											cusTop='2' 
											:cusLeft='jobSwitch ? 3.5 : 2.2' 
											v-model="jobSwitch" 
											activeColor="#027aff" 
											inactiveColor="#e5e5e5"
						></u-switch>
					</view>
				</view>
				<view class="g_mt_4 g_c_8 g_fs_14 g_pl_10" style="line-height: 1.5;" hover-class="none" hover-stop-propagation="false"> 打开开关后, 系统会实时同步一次，然后系统会每天在23:00自动同步平台上最近上新的职位。 </view>
			</view>
		</view>
		
		<view class="m-card">
			<view class="g_h_32"></view>
			<view class="" hover-class="none" hover-stop-propagation="false">
				<view class="g_p_10 g_flex_row_between flex_center g_bg_f g_radius_8 g_fs_16" hover-class="none"
					hover-stop-propagation="false" style="padding: 16px 10px;">
					<view class="g_flex_column_center g_fw_500 g_c_0 g_fs_17" hover-class="none" hover-stop-propagation="false"> 职位列表显示报名数 </view>
					<view class="g_flex_column_center" hover-class="none" hover-stop-propagation="false">
						<u-switch @change="handleSwitch($event, 'applyNumDisplay')" 
											cusSize='24' 
											cusTop='2' 
											:cusLeft='applySwitch ? 3.5 : 2.2' 
											v-model="applySwitch" 
											activeColor="#027aff" 
											inactiveColor="#e5e5e5"
						></u-switch>
					</view>
				</view>
				<view class="g_mt_4 g_c_8 g_fs_14 g_pl_10" style="line-height: 1.5;" hover-class="none" hover-stop-propagation="false"> 打开开关后, 职位列表会显示“报名100+”等字样，目前这个数据可能不太准确，仅供参考。  </view>
			</view>
		</view>
		
		
		
	</view>
</template>

<script>
export default {
	onShareAppMessage() {
		return this.G.shareFun();
	},
	onLoad(options) {
		this.applySwitch = this.appInfo.applyNumDisplay == 1 ? true : false;
		this.getShareInfo();
	},
	data() {
		return {
			applySwitch: false,
			jobSwitch: false,
			appInfo: uni.getStorageSync("miniApp-info"),
		};
	},
	methods: {
		getShareInfo() {
			this.G.Get(this.api.merchantManagement_getShareJobsBtn, {}, (res) => {
				console.log(res);
				this.jobSwitch = res;
			});
		},
		handleSwitch(e, type) {
			console.log(e, type);
			new Promise((resolve, reject) => {
				if (type == "platform") {
					if (e) {
						this.G.Get(this.api.merchantManagement_addAllShareJobs, {}, (res) => {
							console.log(res);
							resolve();
						});
					} else {
						this.G.Get(this.api.merchantManagement_removeAllShareJobs, {}, (res) => {
							console.log(res);
							resolve();
						});
					}
				} else {
					this.G.Put(this.api.merchantManagement_updateField, { fieldName: "applyNumDisplay", fieldValue: e ? 1 : 0 }, (res) => {
						console.log(res);
						resolve();
					});
				}
			}).then(() => {
				this.G.getAgencyInfo();
			});
		},
	},
};
</script>

<style lang="less">
.p-root-person-idform {
	.m-submit {
		.bocai_btn_type_infro {
			background: #ccc !important;
			color: #fff !important;
			font-weight: 600 !important;
			font-size: 18px !important;
		}
	}
	.cardText {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		text-align: center;
	}
}
</style>
