const core = getApp().globalData.requirejs("core")
import getMerchFn from './getMerchFn'
module.exports = {
	init: function(that) {
		getApp().globalData.util.loginByCode().then(loginByCode => {
			if (!that.merch) {
				uni.showLoading({
					title: '拼命加载中...'
				});
			}
			that.credit1 = loginByCode.credit1
			let optionsScen = that.option;
			//#ifdef MP-WEIXIN 
			let scene = ';'
			if (typeof optionsScen != 'undefined' && typeof optionsScen.q != 'undefined' && optionsScen
				.q) {
				let url = decodeURIComponent(optionsScen.q);
				scene = getApp().globalData.util.getQueryVariable('scene', url);
				scene = core.str2Obj(decodeURIComponent(scene));
			} else if (optionsScen && typeof(optionsScen.scene) != "undefined" && optionsScen.scene) {
				scene = core.str2Obj(decodeURIComponent(optionsScen.scene));
			} else {
				uni.showModal({
					title: '提示',
					content: '不小心崩溃了,重新扫码试试吧',
					success: function() {
						uni.navigateBack({
							delta: 2
						})
					}
				})
			}
			that.option = scene
			getMerchFn.getMerchID(that, scene)
			//#endif

			//#ifdef MP-ALIPAY
			// 这是之前的版本 无法使用 支付宝小程序
			function getAlipayQRCode() {
				let queryDataTmp = uni.getStorageSync('qr_scan_data')
				
				if (typeof(queryDataTmp) != 'undefined' && queryDataTmp) {
					getMerchFn.getMerchID(that, queryDataTmp)
					that.option = queryDataTmp
					uni.removeStorageSync('qr_scan_data')
				} else {
					uni.hideLoading()
					uni.showModal({
						title: '提示',
						content: '网络开小差啦,重新扫码试试吧!1623124889'
					});
					return;
				}
			}
			getAlipayQRCode() 
			/* let scene = ';'
			if (typeof optionsScen != 'undefined' && typeof optionsScen.q != 'undefined' && optionsScen
				.q) {
				let url = decodeURIComponent(optionsScen.q);
				scene = getApp().globalData.util.getQueryVariable('scene', url);
				scene = core.str2Obj(decodeURIComponent(scene));
			} else if (optionsScen && typeof(optionsScen.scene) != "undefined" && optionsScen.scene) {
				scene = core.str2Obj(decodeURIComponent(optionsScen.scene));
			} else {
				uni.showModal({
					title: '提示',
					content: '不小心崩溃了,重新扫码试试吧',
					success: function() {
						uni.navigateBack({
							delta: 2
						})
					}
				})
			}
			that.option = scene
			getMerchFn.getMerchID(that, scene) */
			//#endif
			//#ifdef H5
			getMerchFn.getMerchID(that, that.option)
			// #endif
			
		})
	}
}
