import {
	ApiHttp
} from '@/utils/request.js'

const login = (params) => {
	return ApiHttp('/system/xcxLogin', params, 'POST')
}

const loginPhone = (params) => {
	return ApiHttp('/system/getPhone', params, 'POST')
}

const loginOut = (params) => {

}

const loginUserInfo = (params) => {
	return ApiHttp('/system/by-wx-user/getUserInfo', 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
}
