// pages/interview-registration/index.js
import { getCompanyStatus } from '../../services/index'
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		show: false,
		options: {}
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		this.setData({
			options
		})
	},
	onShow: function (data) {
		let user_token = wx.getStorageSync('user_token');
		let user_id = wx.getStorageSync('user_id');
		let member_id = wx.getStorageSync('member_id');
		if (user_id && user_token && member_id) {
			const options = this.data.options;
			getCompanyStatus({ registerCompanyId: options.registerCompanyId }).then(data => {
				if (data.data.isOn) {
					let url = options.url;
					url = url + `?registerCompanyId=${options.registerCompanyId}`
					url = url + `&&user_token=${user_token}`
					url = url + `&&user_id=${user_id}`
					url = url + `&&member_id=${member_id}`
					url = url + `&&hpInterviewRegisterStatus=${Boolean(data.data.hpInterviewRegister)}`
					this.setData({
						url,
						show: true
					})
				} else {
					wx.showModal({
						title: '提示',
						confirmText: '确定',
						content: '二维码已停用',
						showCancel: false,
						success: (result) => {
							if (result.confirm) {
								wx.switchTab({
									url: '/pages/index/index',
								})
							}
						},
					})
				}
			})
		} else {
			wx.showModal({
				title: '提示',
				confirmText: '确定',
				content: '你还未登录，请立即登录',
				showCancel: false,
				success: res => {
					if (res.confirm) {
						wx.navigateTo({
							url: '/pages/login/login',
						})
					}
				}
			})
		}
	}
})