import {
	ApiHttp
} from '@/utils/request.js'
// 程序静默登录
const login = (params) => {
	return ApiHttp('/xcxLogin', params, 'GET')
}
// 获取手机号
const loginPhone = (params) => {
	return ApiHttp('/xcxPhoneLogin', params, 'GET')
}

const loginOut = (params) => {

}

const loginUserInfo = (params) => {
	return ApiHttp('/getInfo', params, 'GET')
}
const getDealerPhone = (params) => {
	return ApiHttp('/system/getDealerPhone', params, 'POST')
}

const getUserProfile = () => {
	return new Promise((resolve, reject) => {
		uni.getUserProfile({
			//获取微信信息
			desc: '用于获取您的个人信息', // 声明获取用户个人信息后的用途，不超过30个字符
			success: obj => {
				console.log('getUserInfo', obj);
				//接口调用成功的回调
				resolve(obj);
			},
			fail: (err) => {
				uni.showToast({
					title: '授权已取消',
					icon: 'error',
					mask: true
				});
				console.log(err, '授权已取消==============')
			}
		});
	});
}

const getLoginCode = () => {
	return new Promise((resolve, reject) => {
		uni.login({
			provider: 'weixin',
			success: res => {
				console.log('res-login', res);
				console.log('code', res.code);
				resolve(res);
			}
		});
	});
}

export {
	login,
	loginOut,
	getUserProfile,
	getLoginCode,
	loginPhone,
	loginUserInfo,
	getDealerPhone
}
