|
|
@@ -1,9 +1,3 @@
|
|
|
-
|
|
|
-import {
|
|
|
- Base64
|
|
|
-} from '@/js_sdk/js-base64/base64';
|
|
|
-
|
|
|
-
|
|
|
let tools = {}
|
|
|
/**
|
|
|
* 大小判断
|
|
|
@@ -15,7 +9,15 @@ tools.sortNumber = function (a, b) {
|
|
|
return a - b;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+/**
|
|
|
+ * 隐藏手机号码
|
|
|
+ * @param phone
|
|
|
+ * @returns {*}
|
|
|
+ */
|
|
|
+tools.hidePhone = function (phone) {
|
|
|
+ let reg = /^(\d{3})\d{4}(\d{4})$/;
|
|
|
+ return phone.replace(reg, '$1****$2');
|
|
|
+}
|
|
|
/**
|
|
|
* 保留两位小数
|
|
|
* @param num
|
|
|
@@ -53,7 +55,7 @@ tools.error = function (msg) {
|
|
|
'title': msg,
|
|
|
'icon': 'error',
|
|
|
'mask': true,
|
|
|
- 'duration': 1500
|
|
|
+ 'duration': 1000
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -66,7 +68,7 @@ tools.success = function (msg) {
|
|
|
'title': msg,
|
|
|
'icon': 'success',
|
|
|
'mask': true,
|
|
|
- 'duration': 1500
|
|
|
+ 'duration': 1000
|
|
|
})
|
|
|
}
|
|
|
|
|
|
@@ -87,6 +89,23 @@ tools.hideLoading = function () {
|
|
|
uni.hideLoading();
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 32位随机字符串+时间 首位字母
|
|
|
+ */
|
|
|
+tools.SetString = function () {
|
|
|
+ let str = '';
|
|
|
+ let list=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','1','2','3','4','5','6','7','8','9','0'];
|
|
|
+ let numOne = Math.round(Math.random()*14);
|
|
|
+ let oneStr = list[numOne];
|
|
|
+ for (let i=1;i<=32;i++){
|
|
|
+ let num = Math.round(Math.random()*24);
|
|
|
+ str += list[num];
|
|
|
+ }
|
|
|
+ let time = new Date().getTime()
|
|
|
+ return oneStr+str+time;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取时间戳(毫秒)
|
|
|
* @returns {number}
|
|
|
@@ -96,6 +115,20 @@ tools.getTime = function () {
|
|
|
}
|
|
|
|
|
|
|
|
|
+// 返回上级
|
|
|
+tools.leftClick = function () {
|
|
|
+ let pages = getCurrentPages();
|
|
|
+ if (pages.length > 1) {
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/index/index'
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
tools.updateVersion = function (sysVersion, appUrl) {
|
|
|
let app_version = plus.runtime.version;
|
|
|
console.log('版本号信息对比------------------------------' + app_version + '---------' + sysVersion)
|
|
|
@@ -118,8 +151,8 @@ tools.updateVersion = function (sysVersion, appUrl) {
|
|
|
if (res.confirm === true) {
|
|
|
plus.runtime.install(//安装
|
|
|
downloadResult.tempFilePath, {
|
|
|
- force: true
|
|
|
- },
|
|
|
+ force: true
|
|
|
+ },
|
|
|
function (res) {
|
|
|
tools.success('更新成功,重启中')
|
|
|
plus.runtime.restart();
|
|
|
@@ -143,33 +176,141 @@ tools.updateVersion = function (sysVersion, appUrl) {
|
|
|
*/
|
|
|
tools.imgDeal = function (str) {
|
|
|
console.log(str)
|
|
|
- if(str===null || str===undefined){
|
|
|
+ if (str === null || str === undefined) {
|
|
|
return '';
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
return str.replace(/\<img/gi, '<img style="width:100%;height:auto;display:block;"');
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 获取用户类型
|
|
|
+ * @returns {number}
|
|
|
+ */
|
|
|
+tools.getReceivingType = function () {
|
|
|
+ let receivingType = uni.getStorageSync('receivingType')
|
|
|
+ if (!receivingType) {
|
|
|
+ receivingType = 0;
|
|
|
+ } else {
|
|
|
+ receivingType = receivingType * 1;
|
|
|
+ }
|
|
|
+ return receivingType;
|
|
|
+}
|
|
|
|
|
|
/**
|
|
|
- * 获取平台类型 1:微信,2:支付宝
|
|
|
- * @returns {boolean|number}
|
|
|
+ * 获取是否有录单权限
|
|
|
+ * @returns {number}
|
|
|
*/
|
|
|
-tools.platformType = function () {
|
|
|
- let ua = window.navigator.userAgent.toLowerCase();
|
|
|
- if (ua.indexOf('micromessenger') != -1) {
|
|
|
- return 1;
|
|
|
- } else if (ua.indexOf('alipay') != -1) {
|
|
|
- return 2;
|
|
|
+tools.getEnteringType = function () {
|
|
|
+ let enteringType = uni.getStorageSync('enteringType')
|
|
|
+ if (!enteringType) {
|
|
|
+ enteringType = 0;
|
|
|
} else {
|
|
|
- return 0;
|
|
|
+ enteringType = enteringType * 1;
|
|
|
}
|
|
|
+ return enteringType;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 记录用户登录信息
|
|
|
+ * @param data
|
|
|
+ * @param type
|
|
|
+ */
|
|
|
+tools.setLoginData = function (data, type) {
|
|
|
+ uni.setStorageSync('m_id', data.m_id)
|
|
|
+ uni.setStorageSync('token', data.token)
|
|
|
+ uni.setStorageSync('status', data.status)
|
|
|
+ uni.setStorageSync('ministerType', data.minister_type)
|
|
|
+ uni.setStorageSync('receivingType', data.receivingType)
|
|
|
+ uni.setStorageSync('enteringType', data.enteringType)
|
|
|
+ if (type) {
|
|
|
+ tools.success('登陆成功')
|
|
|
+ setTimeout(() => {
|
|
|
+ if (data.status * 1 === 0) {
|
|
|
+ //审核状态跳转至待审核页面
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/login/module/await-audit'
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ let excelPath=uni.getStorageSync('excelPath');
|
|
|
+ console.log('excelPath:'+excelPath)
|
|
|
+ if(excelPath){
|
|
|
+ uni.reLaunch({
|
|
|
+ url: excelPath
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ uni.reLaunch({
|
|
|
+ url: '/pages/index/index'
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }, 1500)
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
- * 获取开发平台
|
|
|
+ * 获取日期
|
|
|
+ * @returns {string}
|
|
|
+ */
|
|
|
+tools.getDate = function () {
|
|
|
+ let myDate = new Date();
|
|
|
+ // let myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
|
|
|
+ // let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
|
|
|
+ // let myToday = myDate.getDate(); //获取当前日(1-31)
|
|
|
+ // let myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
|
|
|
+ // let myHour = myDate.getHours(); //获取当前小时数(0-23)
|
|
|
+ // let myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
|
|
|
+ // let mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
|
|
|
+ return myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate()
|
|
|
+}
|
|
|
+
|
|
|
+tools.getRandFileName = function (filePath) {
|
|
|
+ let extIndex = filePath.lastIndexOf('.');
|
|
|
+ let extName = extIndex === -1 ? '' : filePath.substr(extIndex);
|
|
|
+ return parseInt('' + Date.now() + Math.floor(Math.random() * 900 + 100), 10).toString(36) + extName;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 拨打电话
|
|
|
+ * @param phone
|
|
|
+ */
|
|
|
+tools.makingCall = function (phone) {
|
|
|
+ uni.makePhoneCall({
|
|
|
+ phoneNumber: phone
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+tools.getOssVideo = function (url) {
|
|
|
+ let strFileName = url.substring(0, url.lastIndexOf("."));
|
|
|
+ return strFileName + '_vj_0.jpg';
|
|
|
+}
|
|
|
+
|
|
|
+tools.getFileType = function (url) {
|
|
|
+ let suffixArr = ['.pdf', '.doc', '.docx', '.xlsx', '.xls']
|
|
|
+ let suffix = url.substring(url.lastIndexOf("."));
|
|
|
+ console.log(suffix)
|
|
|
+ let suffixKey = suffixArr.indexOf(suffix)
|
|
|
+ let fileType = 1;
|
|
|
+ if (suffixKey < 1) {
|
|
|
+ fileType = 1
|
|
|
+ } else if (suffixKey < 3) {
|
|
|
+ fileType = 2
|
|
|
+ } else {
|
|
|
+ fileType = 3
|
|
|
+ }
|
|
|
+ return fileType
|
|
|
+}
|
|
|
+tools.getFileName = function (url) {
|
|
|
+ return url.substring(url.lastIndexOf("/") - 1, url.lastIndexOf("."));
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取平台类型
|
|
|
* @returns {string}
|
|
|
*/
|
|
|
tools.getPlatform = function () {
|
|
|
@@ -187,7 +328,7 @@ tools.getPlatform = function () {
|
|
|
platForm = 'APP';
|
|
|
//#endif
|
|
|
// #ifdef MP-WEIXIN
|
|
|
- platForm = 'MP-WEIXIN'; // 小程序
|
|
|
+ platForm = 'MP-WEIXIN';
|
|
|
//#endif
|
|
|
// #ifdef MP-ALIPAY
|
|
|
platForm = 'MP-ALIPAY';
|
|
|
@@ -215,24 +356,133 @@ tools.getPlatform = function () {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 记录用户登录信息
|
|
|
- * @param data
|
|
|
- * @param type
|
|
|
+ * 等额本息
|
|
|
+ * @param loansMoney
|
|
|
+ * @param refundNum
|
|
|
+ * @param interestRate
|
|
|
*/
|
|
|
-tools.setLoginData = function (data) {
|
|
|
- uni.setStorageSync('m_id', data.m_id)
|
|
|
- uni.setStorageSync('token', data.token)
|
|
|
- tools.success('登陆成功')
|
|
|
- setTimeout(() => {
|
|
|
- uni.reLaunch({
|
|
|
- url: '/pages/index/index'
|
|
|
- });
|
|
|
- }, 1500)
|
|
|
+tools.getAverageCapitalPlusInterest = function (loansMoney, refundNum, interestRate) {
|
|
|
+ console.log('getAverageCapitalPlusInterest:等额本息')
|
|
|
+ let repaymentMoney = 0;
|
|
|
+ if (!loansMoney || loansMoney <= 0 || !refundNum || refundNum <= 0 || !interestRate || interestRate <= 0) {
|
|
|
+ return repaymentMoney
|
|
|
+ }
|
|
|
+ let monthlyInterest = interestRate / 12 / 100;
|
|
|
+ // console.log( ((monthlyInterest * Math.pow((1 + monthlyInterest), refundNum)) / (Math.pow((1 + monthlyInterest), refundNum) - 1)))
|
|
|
+ repaymentMoney = (loansMoney * ((monthlyInterest * Math.pow((1 + monthlyInterest), refundNum)) / (Math.pow((1 + monthlyInterest), refundNum) - 1))).toFixed(2)
|
|
|
+ // console.log('repaymentMoney:'+repaymentMoney)
|
|
|
+ return repaymentMoney
|
|
|
+}
|
|
|
|
|
|
+/**
|
|
|
+ * 等额本金
|
|
|
+ * @param loansMoney
|
|
|
+ * @param refundNum
|
|
|
+ * @param interestRate
|
|
|
+ * @returns {number}
|
|
|
+ */
|
|
|
+tools.getAverageCapital = function (loansMoney, refundNum, interestRate) {
|
|
|
+ console.log('getAverageCapital:等额本金')
|
|
|
+ let repaymentMoney = 0;
|
|
|
+ if (!loansMoney || loansMoney <= 0 || !refundNum || refundNum <= 0 || !interestRate || interestRate <= 0) {
|
|
|
+ return repaymentMoney
|
|
|
+ }
|
|
|
+ let monthlyInterest = interestRate / 12 / 100;
|
|
|
+ repaymentMoney = (loansMoney / refundNum + loansMoney * monthlyInterest).toFixed(2)
|
|
|
+ return repaymentMoney
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 先息后本
|
|
|
+ * @param loansMoney
|
|
|
+ * @param interestRate
|
|
|
+ * @returns {string|number}
|
|
|
+ */
|
|
|
+tools.getInterestFirst = function (loansMoney, interestRate) {
|
|
|
+ console.log('getInterestFirst:先息后本')
|
|
|
+ let repaymentMoney = 0;
|
|
|
+ if (!loansMoney || loansMoney <= 0 || !interestRate || interestRate <= 0) {
|
|
|
+ return repaymentMoney
|
|
|
+ }
|
|
|
+ let monthlyInterest = interestRate / 12 / 100;
|
|
|
+ repaymentMoney = (loansMoney * monthlyInterest).toFixed(2)
|
|
|
+ return repaymentMoney
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取日期
|
|
|
+ * @returns {{d: number, y: number, m: number}}
|
|
|
+ */
|
|
|
+tools.getDateArr = function (time) {
|
|
|
+ console.log('time:' + time)
|
|
|
+ let myDate = new Date(time);
|
|
|
+ let myYear = myDate.getFullYear(); //获取完整的年份(4位,1970-????)
|
|
|
+ let myMonth = myDate.getMonth() + 1; //获取当前月份(0-11,0代表1月)
|
|
|
+ let myToday = myDate.getDate(); //获取当前日(1-31)
|
|
|
+ // let myDay = myDate.getDay(); //获取当前星期X(0-6,0代表星期天)
|
|
|
+ // let myHour = myDate.getHours(); //获取当前小时数(0-23)
|
|
|
+ // let myMinute = myDate.getMinutes(); //获取当前分钟数(0-59)
|
|
|
+ // let mySecond = myDate.getSeconds(); //获取当前秒数(0-59)
|
|
|
+ return {'y': myYear, 'm': myMonth>=10?myMonth:'0'+myMonth, 'd': myToday>=10?myToday:'0'+myToday};
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 获取统计时间
|
|
|
+ * @param d
|
|
|
+ * @param num
|
|
|
+ * @returns {[{d: number, y: number, m: number},{d: number, y: number, m: number}]}
|
|
|
+ */
|
|
|
+tools.getStatisticsDate = function (d, num) {
|
|
|
+ let date = new Date(d)
|
|
|
+ let dateTime = date.getTime();
|
|
|
+ dateTime += (num * 86400000);
|
|
|
+ return [tools.getDateArr(dateTime), tools.getDateArr(dateTime)];
|
|
|
+}
|
|
|
|
|
|
+/**
|
|
|
+ *
|
|
|
+ * @returns {[{d: number, y: number, m: number},{d: number, y: number, m: number}]}
|
|
|
+ */
|
|
|
+tools.getNextWeek = function (d, num) {
|
|
|
+ let date = new Date(d)
|
|
|
+ let dateTime = date.getTime();
|
|
|
+ console.log('start:' + dateTime)
|
|
|
+ dateTime += (num * 86400000);
|
|
|
+ let weekDate = new Date(dateTime)
|
|
|
+ let weekday = weekDate.getDay();
|
|
|
+ let weekStarTime;
|
|
|
+ let weekEndTime;
|
|
|
+ if (weekday === 0) {
|
|
|
+ weekStarTime = dateTime - 86400000 * 6;
|
|
|
+ weekEndTime = dateTime;
|
|
|
+ } else {
|
|
|
+ weekStarTime = dateTime - (86400000 * (weekday - 1));
|
|
|
+ weekEndTime = weekStarTime + (86400000 * 7);
|
|
|
+ }
|
|
|
+ return [tools.getDateArr(weekStarTime), tools.getDateArr(weekEndTime)];
|
|
|
+}
|
|
|
|
|
|
+tools.getNextMonth = function (d, num) {
|
|
|
+ let date = new Date(d)
|
|
|
+ let dateTime = date.getTime();
|
|
|
+ dateTime += (num * 86400000);
|
|
|
+ let newDate = new Date(dateTime)
|
|
|
+ let year = newDate.getFullYear(); //获取完整的年份(4位,1970-????)
|
|
|
+ let month = newDate.getMonth(); //获取当前月份(0-11,0代表1月)
|
|
|
+ let starTime = new Date(year, month , 1).valueOf() ;
|
|
|
+ let endTime = new Date(year, month+ 1 , 1).valueOf() - 86400000;
|
|
|
+ return [tools.getDateArr(starTime), tools.getDateArr(endTime)];
|
|
|
+}
|
|
|
|
|
|
+tools.getNextYear = function (d, num) {
|
|
|
+ let date = new Date(d)
|
|
|
+ let dateTime = date.getTime();
|
|
|
+ dateTime += (num * 86400000);
|
|
|
+ let newDate = new Date(dateTime)
|
|
|
+ let year = newDate.getFullYear(); //获取完整的年份(4位,1970-????)
|
|
|
+ let starTime = new Date(year, 0 , 1).valueOf() ;
|
|
|
+ let endTime = new Date(year+ 1, 0 , 1).valueOf() - 86400000;
|
|
|
+ return [tools.getDateArr(starTime), tools.getDateArr(endTime)];
|
|
|
+}
|
|
|
|
|
|
export default tools
|