/**
 *@des 用户模块接口
 *@author zhengjinyi
 *@date 2020/03/19 14:56:57
 *@param registerByPass
 */
import request from '@/common/config/caimeiApi.js'
import $reg from '@/common/config/common.js'
/**
 *机构普通注册
 */
export function organizationVerifyRegisterFirst(params) {
	return new Promise(function(resolve,reject) {
		if( params.userName == ''){
			uni.showToast({title: '请输入联系人名称',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.bindMobile == ''){
			uni.showToast({title: '请输入手机号',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobile(params.bindMobile)){
			uni.showToast({title: '手机格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.activationCode == ''){
			uni.showToast({title: '请输入手机验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobileCode(params.activationCode)){
			uni.showToast({title: '验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.password == ''){
			uni.showToast({title: '请输入密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.checkPwd(params.password)){
			uni.showToast({title: '密码必须为8-16位字母数字的组合',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.passWordConfirm == ''){
			uni.showToast({title: '请再次确认密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.passWordConfirm !== params.password){
			uni.showToast({title: '两次输入的密码不一致',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(params.isAgreed == 0){
			uni.showToast({title: '请勾选同意协议',duration: 2000,mask:true,icon:'none'})
			return
		}
		request.post('/club/common',params,true,res => {
			if(res.code == 0){
				resolve(res);
			}else{
				reject(res)
			}
		})
	});
}
/**
 *机构升级会员机构
 */
export function organizationRegister(params) {
	return new Promise(function(resolve,reject) {
		request.post('/club/upgrade',params,true, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *机构修改资料
 */
export function organizationUpdateModifyInfo(params) {
	return new Promise(function(resolve,reject) {
		request.lodingGet('/user/club/applicationData',params, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *机构提交修改申请信息
 */
export function organizationModifyUpdate(params) {
	return new Promise(function(resolve,reject) {
		request.post('/user/club/updateCompanyInfo',params,true,res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *保存机构修改信息
 */
export function organizationUpdate(params) {
	return new Promise(function(resolve,reject) {
		request.post('/operation/modifiedData',params,true,res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *绑定邮箱
 */
export function bindingEmail(params) {
	return new Promise(function(resolve,reject) {
		if( params.email == ''){
			uni.showToast({title: '请输入邮箱地址',duration: 2000,mask:true, icon:'none'})
			return
		}
		if(!$reg.isEmail(params.email)){
			uni.showToast({title: '请输入正确的邮箱地址',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.code == ''){
			uni.showToast({title: '请输入邮箱验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isEmailCode(params.code)){
			uni.showToast({title: '验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		request.post('/user/binding',params,true, res => {
			if(res.code == 0){
				resolve(res);
			}else{
				reject(res)
			}
		})
	})
}
/**
 *绑定微信
 */
export function bindingWechat(params) {
	return new Promise(function(resolve,reject) {
		request.post('/club/bindingWx',params,true,res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *邀请码授权登录
 */
export function invitationCodeLogin(params) {
	return new Promise(function(resolve,reject) {
		request.post('/club/invitationCode',params,true, res => {
			if(res.code == 0 || res.code == 4){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *获取个人中心信息
 */
export function personalInfo(params) {
	return new Promise(function(resolve,reject) {
		request.lodingGet('/personalCenter/myCentre',params, res => {
			resolve(res)
		})
	})
}
/**
 *取消提示
 * userId
 */
export function cancelPrompt(params) {
	return new Promise(function(resolve,reject) {
		request.post('/personalCenter/cancelPrompt',params,false, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}

/**
 *获取账户余额明细
 */
export function accountInfo(params) {
	return new Promise(function(resolve,reject) {
		request.lodingGet('/personalCenter/touchBalance',params, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}

/**
 *用户状态初始化
 */
export function userInfoLogin(params) {
	return new Promise(function(resolve,reject) {
		request.post('/club/authorization',params,false, res => {
			if(res.code == 0 || res.code == 4){
				resolve(res)
			}else if(res.code == -6){
				reject(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *手机修改密码
 */
export function mobilePassword(params) {
	return new Promise(function(resolve,reject) {
		if( params.mobileOrEmail == ''){
			uni.showToast({title: '请输入手机号',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobile(params.mobileOrEmail)){
			uni.showToast({title: '手机格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.activateCode == ''){
			uni.showToast({title: '请输入手机验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobileCode(params.activateCode)){
			uni.showToast({title: '验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.passWord == ''){
			uni.showToast({title: '请输入密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.checkPwd(params.passWord)){
			uni.showToast({title: '密码必须为8-16位字母数字的组合',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.confirmPwd == ''){
			uni.showToast({title: '请再次确认密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.confirmPwd !== params.passWord){
			uni.showToast({title: '两次输入的密码不一致',duration: 2000,mask:true,icon:'none'})
			return
		}
		request.post('/user/findCompanyPwd',params, true,res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *邮箱修改密码
 */
export function emailPassword(params) {
	return new Promise(function(resolve,reject) {
		if( params.mobileOrEmail == ''){
			uni.showToast({title: '请输入邮箱',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isEmail(params.mobileOrEmail)){
			uni.showToast({title: '请输入正确的邮箱地址',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.activateCode == ''){
			uni.showToast({title: '请输入邮箱验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isEmailCode(params.activateCode)){
			uni.showToast({title: '验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.passWord == ''){
			uni.showToast({title: '请输入密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.checkPwd(params.passWord)){
			uni.showToast({title: '密码必须为8-16位字母数字的组合',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.confirmPwd == ''){
			uni.showToast({title: '请再次确认密码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.confirmPwd !== params.passWord){
			uni.showToast({title: '两次输入的密码不一致',duration: 2000,mask:true,icon:'none'})
			return
		}
		request.post('/user/findCompanyPwd',params,true, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
/**
 *修改手机号
 */
export function changeMobile(params) {
	return new Promise(function(resolve,reject) {
		if( params.contractMobile == ''){
			uni.showToast({title: '请输入新的手机号码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobile(params.contractMobile)){
			uni.showToast({title: '请输入正确的手机号码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.mobileCode == ''){
			uni.showToast({title: '请输入旧手机验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobileCode(params.mobileCode)){
			uni.showToast({title: '旧手机验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		if( params.newMobileCode == ''){
			uni.showToast({title: '请输入新手机验证码',duration: 2000,mask:true,icon:'none'})
			return
		}
		if(!$reg.isMobileCode(params.newMobileCode)){
			uni.showToast({title: '新手机验证码格式不正确',duration: 2000,mask:true,icon:'none'})
			return
		}
		request.post('/club/changeMobile',params,true, res => {
			if(res.code == 0){
				resolve(res)
			}else{
				reject(res)
			}
		})
	})
}
