货无忧
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

157 lines
4.0 KiB

"use strict";
const common_vendor = require("../common/vendor.js");
const utils_IDCardVerification = require("./IDCardVerification.js");
const utils_base64 = require("./base64.js");
const config_host = require("../config/host.js");
const api = {
loginModalState: true,
getloctiontime() {
common_vendor.index.request({
url: "https://restapi.amap.com/v5/direction/driving",
method: "POST",
data: {
key: "高德地图KEY",
origin: "",
//起点经纬度
destination: "",
//终点经纬度
waypoints: "",
//途经点
show_fields: "cost"
},
success(res) {
console.log(res);
}
});
},
urlToObj: (url) => {
let obj = {};
let str = url.slice(url.indexOf("?") + 1);
let arr = str.split("&");
for (let j = arr.length, i = 0; i < j; i++) {
let arr_temp = arr[i].split("=");
obj[arr_temp[0]] = arr_temp[1];
}
return obj;
},
upfile: (file) => {
console.log(file);
return new Promise((relove, reject) => {
common_vendor.index.showLoading({
title: "上传中"
});
let header = {};
let token = common_vendor.index.getStorageSync("access_token");
header["Blade-Auth"] = `bearer ${token}`;
header.Authorization = `Basic ${utils_base64.base64.encode(config_host.APPKEY)}`;
common_vendor.index.uploadFile({
url: `${config_host.host}blade-resource/oss/endpoint/put-file`,
filePath: file,
name: "file",
header,
success: (uploadFileRes) => {
common_vendor.index.hideLoading();
relove(JSON.parse(uploadFileRes.data).data);
}
});
});
},
imgurl: (url) => {
if (url) {
if (url.indexOf("http") == -1) {
return config_host.imghost + url;
} else {
return url;
}
} else {
return "";
}
},
/**
* 失败
*/
error: (msg) => {
return new Promise((relove, reject) => {
common_vendor.index.showToast({
title: msg,
icon: "none",
duration: 2e3
});
setTimeout(() => {
relove();
}, 2e3);
});
},
/**
* 成功提示
*/
success: (msg) => {
return new Promise((relove, reject) => {
common_vendor.index.showToast({
title: msg,
icon: "success",
duration: 2e3
});
setTimeout(() => {
relove();
}, 2e3);
});
},
/**
* 确认对话框
* @param {Object} contents
* @param {Object} callback
*/
confirm: (contents) => {
return new Promise((relove, reject) => {
common_vendor.index.showModal({
title: "提示",
content: contents,
success: function(res) {
if (res.confirm) {
relove();
}
}
});
});
},
payment: (param) => {
return new Promise((relove, reject) => {
common_vendor.index.requestPayment({
provider: "wxpay",
timeStamp: param.timeStamp,
nonceStr: param.nonceStr,
package: param.package,
signType: param.signType,
paySign: param.paySign,
success: function(res) {
relove(res);
},
fail: function(err) {
console.log(err);
api.error("支付失败");
}
});
});
},
checkFormat_IDCardNumber: (idCardNumber) => {
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if (idCardNumber == "") {
return false;
} else if (reg.test(idCardNumber) === false) {
console.log("错误1");
return false;
} else if (utils_IDCardVerification.checkIDCard_province(idCardNumber) === false) {
console.log("错误2");
return false;
} else if (utils_IDCardVerification.checkIDCard_birthday(idCardNumber) === false) {
console.log("错误3");
return false;
} else if (utils_IDCardVerification.checkParity(idCardNumber) === false) {
console.log("错误4");
return false;
}
return true;
}
};
exports.api = api;