<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_24"></view>
			<view class="" hover-class="none" hover-stop-propagation="false" @click="toSetOption('homeCity',fdbHomeCity)">
				<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">
						<div class="g_flex_row_end">
							<div class="g_flex_1 g_flex_column_center" style="font-size: 17px;color: #666;">
								{{ fdbHomeCity == 1 ? "全国" : "当前城市" }}
							</div>
							<div class="g_flex_none g_flex_column_center">
								<i class="iconfont iconfont icon-gengduo11 g_c_c"></i>
							</div>
						</div>
					</view>
				</view>
			</view>
		</view>
		
		<view class="m-card">
			<view class="g_h_24"></view>
			<view class="" hover-class="none" hover-stop-propagation="false" @click="toSetOption('homeTab',fdbHomeTab)">
				<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"> 职位默认tab </view>
					<view class="g_flex_column_center" hover-class="none" hover-stop-propagation="false">
						<div class="g_flex_row_end">
							<div class="g_flex_1 g_flex_column_center" style="font-size: 17px;color: #666;">
								{{ fdbHomeTab == 1 ? "全部" : "推荐" }}
							</div>
							<div class="g_flex_none g_flex_column_center">
								<i class="iconfont iconfont icon-gengduo11 g_c_c"></i>
							</div>
						</div>
					</view>
				</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) {
		let that = this;
		this.applySwitch = this.appInfo.applyNumDisplay == 1 ? true : false;
		// this.getShareInfo();
	},
	onShow() { 
		let that = this;
		that.G.Get(that.api.login_agencyInfo, {}, (aRes) => {
			uni.setStorageSync("agencyInfo", aRes.agency);
			let _data = aRes.agency;
			that.fdbHomeCity = _data.fdbHomeCity;// 0当前城市 1全国
			that.fdbHomeTab = _data.fdbHomeTab;//0推荐 1全部
			console.log("获取团队信息:", aRes, that.fdbHomeCity, that.fdbHomeTab);
		});
	},
	data() {
			return {
				applySwitch: false,
				jobSwitch: false,
				fdbHomeCity: false,
				fdbHomeTab: false,
				appInfo: uni.getStorageSync("miniApp-info"),
			};
		},
	methods: {
		toSetOption(type, value) {
			uni.navigateTo({
				url: "/root/merchantManagement/setOption?type=" + type + "&value=" + value,	
			});
		},
		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();
						});
					}
				} if (type == "defaultCity") {
					this.G.Put(this.api.merchantManagement_updateField, { fieldName: "fdbHomeCity", fieldValue: e ? 1 : 0 }, (res) => {
						console.log(res);
						resolve();
					});
				}if (type == "recommend") {
					this.G.Put(this.api.merchantManagement_updateField, { fieldName: "fdbHomeTab", fieldValue: e ? 1 : 0 }, (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>