You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
apply-assistant-v3/uni_modules/rh-ui/libs/utils/base.js

140 lines
3.8 KiB
JavaScript

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

let data = {
setReg($str, $type = 'default') {
if ($type == 'tel') {
return /^1[3-9]\d{9}$/.test($str);
}
if ($type == 'idcard') {
return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test($str);
}
},
/**
* 获取服务费类型
* @params returnFeeType 类型
* @params $type 1共享 0 普通
*/
setReturnFee(returnFee, returnFeeType, $type) {
// // console.log('here');
let servetype = '-',
$num = 1;
if ($type == 1) {
$num = 1;
} else {
$num = 100;
}
if (returnFeeType === 0) {
servetype = `${returnFee / $num || "--"}元/小时`;
} else if (returnFeeType === 1) {
servetype = `${returnFee / $num || "--"}元/日`;
} else if (returnFeeType === 2) {
servetype = `${returnFee / $num || "--"}元/月`;
} else if (returnFeeType === 3) {
servetype = `${returnFee / $num || "--"}元/次`;
} else if (returnFeeType === 4) {
servetype = `${returnFee / $num || "--"}元/件`;
} else if (returnFeeType === 5) {
servetype = `工人收入${returnFee / $num || "--"}%`;
} else if (returnFeeType === 6) {
servetype = `${returnFee / $num || "--"}`;
} else if (returnFeeType === 7) {
servetype = `费用待定`;
}
return servetype
},
/* 对象重组成字符串 */
objToStr(obj = {}, type = 'url') {
let str = '';
if (type == 'url') {
str = Object.keys(obj)
.map(key => `${key}=${obj[key]}`)
.join('&');
} else if (type == 'copy') {
str = Object.keys(obj)
.map(key => `${key}${obj[key]}`)
.join('');
}
return str;
},
isLogin() {
let that = this;
if (!uni.getStorageSync("apply-token")) {
uni.reLaunch({
url: '/root/person/loginIndex?path=/' + that.getPath().path + '&level=' + that.getPath().level
});
return false;
} else {
return true;
}
},
setNavStyle($form = 'default') {
if ($form == 'home') {
uni.setNavigationBarColor({
backgroundColor: "#fff",
frontColor: "#000000"
})
}
},
getInfoByIDcard(idCard) {
let info = {}
let birthday
if (idCard.length !== 15 && idCard.length !== 18) {
return {
sex: '',
age: '',
}
}
// 获取性别
if (idCard.length === 15) {
info.sex = ['女', '男'][idCard.substr(14, 1) % 2]
birthday = [idCard.substr(6, 2), idCard.substr(8, 2), idCard.substr(10, 2)].join('-')
} else if (idCard.length === 18) {
info.sex = ['女', '男'][idCard.substr(16, 1) % 2]
birthday = [idCard.substr(6, 4), idCard.substr(10, 2), idCard.substr(12, 2)].join('-')
}
// 获取年龄
let currentYear = new Date().getFullYear() //当前的年份
let calculationYear = new Date(birthday).getFullYear() //计算的年份
const wholeTime = currentYear + birthday.substring(4) //周岁时间
const calculationAge = currentYear - calculationYear //按照年份计算的年龄
//判断是否过了生日
if (new Date().getTime() > new Date(wholeTime).getTime()) {
info.age = calculationAge
} else {
info.age = calculationAge - 1
}
// console.log('info', info);
return info
},
shareFun(
path = "/pages/home/index",
image = "",
title = "报名助手"
) {
let params = {
path: path,
// imageUrl: this.store().localBaseImg + 'share.png', // image ? image :
imageUrl: image,
title: title
};
// console.log('分享数据:', params)
return params;
},
isValidIdCard(idCard) {
const idCardRegex = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])\d{3}[\dXx]$/;
if (!idCardRegex.test(idCard)) {
return false;
}
const factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
const checkCodeList = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
let sum = 0;
for (let i = 0; i < 17; i++) {
sum += parseInt(idCard[i]) * factors[i];
}
const checkCode = checkCodeList[sum % 11];
return checkCode === idCard[17].toUpperCase();
},
}
export default data;