|
|
|
|
@ -4,7 +4,8 @@ const HOSTARR = {
|
|
|
|
|
'production': 'http://118.31.104.155:9003'
|
|
|
|
|
}; // 审核状态
|
|
|
|
|
|
|
|
|
|
const HOST = HOSTARR[process.env.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
|
|
|
|
|
const HOST = HOSTARR[process.env
|
|
|
|
|
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formatTime = date => {
|
|
|
|
|
@ -14,13 +15,77 @@ const formatTime = date => {
|
|
|
|
|
return [year, month, day].map(formatNumber).join('-');
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const user_info_key = "userInfo_token";
|
|
|
|
|
const user_key = "userInfo";
|
|
|
|
|
|
|
|
|
|
const getUserInfo = (cb, refresh) => {
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
|
refresh = refresh || false
|
|
|
|
|
if (!refresh) {
|
|
|
|
|
let user_info = uni.getStorageSync(user_key)
|
|
|
|
|
if (!isNull(user_info)) {
|
|
|
|
|
cb(user_info)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
request({
|
|
|
|
|
api: '/api/mobile/user/show',
|
|
|
|
|
utilSuccess: function(res) {
|
|
|
|
|
uni.setStorageSync(user_key, res)
|
|
|
|
|
cb(res)
|
|
|
|
|
},
|
|
|
|
|
utilFail: function(res) {}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const getOpenidInfo = (cb, refresh) => {
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
|
refresh = refresh || false
|
|
|
|
|
if (!refresh) {
|
|
|
|
|
let user_info = uni.getStorageSync(user_info_key)
|
|
|
|
|
if (!isNull(user_info)) {
|
|
|
|
|
cb(user_info)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uni.login({
|
|
|
|
|
provider: 'weixin',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
console.log(res.code);
|
|
|
|
|
let url = HOST + '/api/mobile/user/login?code=' + res.code;
|
|
|
|
|
uni.request({
|
|
|
|
|
url: url,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
success: result => {
|
|
|
|
|
let user_info = result.data
|
|
|
|
|
uni.setStorageSync(user_info_key, user_info)
|
|
|
|
|
cb(user_info)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const stateArr = {
|
|
|
|
|
"save": "待处理",
|
|
|
|
|
"ongoing": "处理中",
|
|
|
|
|
"finished": "已处理"
|
|
|
|
|
|
|
|
|
|
const getUserProfile = (cb) => {
|
|
|
|
|
cb = cb || function() {}
|
|
|
|
|
|
|
|
|
|
wx.getUserProfile({
|
|
|
|
|
desc: '用于完善会员资料',
|
|
|
|
|
success: (res) => {
|
|
|
|
|
uni.setStorageSync('user_profile', res.userInfo)
|
|
|
|
|
cb(res.userInfo)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const formatTimeAll = date => {
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = date.getMonth() + 1;
|
|
|
|
|
@ -46,6 +111,23 @@ const alert = msg => {
|
|
|
|
|
});
|
|
|
|
|
}; // 订单状态
|
|
|
|
|
|
|
|
|
|
const toast = msg => {
|
|
|
|
|
// setTimeout(function() {
|
|
|
|
|
// uni.showToast({
|
|
|
|
|
// icon: "none",
|
|
|
|
|
// title: msg,
|
|
|
|
|
// duration: 2000
|
|
|
|
|
// })
|
|
|
|
|
// }, 2000)
|
|
|
|
|
|
|
|
|
|
uni.showModal({
|
|
|
|
|
title: '',
|
|
|
|
|
content: msg,
|
|
|
|
|
showCancel: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}; // 订单状态
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const orderStatusDic = {
|
|
|
|
|
'0': '待确认',
|
|
|
|
|
@ -82,7 +164,7 @@ const request = options => {
|
|
|
|
|
//'content-type': 'application/json'
|
|
|
|
|
}; // 如果已登录,请求中拼openId
|
|
|
|
|
|
|
|
|
|
var access_token = uni.getStorageSync('userInfo').access_token;
|
|
|
|
|
var access_token = uni.getStorageSync(user_info_key).access_token;
|
|
|
|
|
|
|
|
|
|
if (isLogin()) {
|
|
|
|
|
options.data = {
|
|
|
|
|
@ -100,6 +182,7 @@ const request = options => {
|
|
|
|
|
uni.request({
|
|
|
|
|
...options,
|
|
|
|
|
success: function(res) {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
if (res.statusCode != 200) {
|
|
|
|
|
if (options.utilFail != undefined) {
|
|
|
|
|
if (res.statusCode == 401) {
|
|
|
|
|
@ -112,11 +195,12 @@ const request = options => {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!isNull(res.data.errorcode) || res.data.errorcode == 0) {
|
|
|
|
|
|
|
|
|
|
if (res.data.hasOwnProperty("errcode")) {
|
|
|
|
|
if (options.utilFail != undefined) {
|
|
|
|
|
options.utilFail(res.data.errormsg || '接口发生未知错误');
|
|
|
|
|
options.utilFail(res.data.errmsg || '接口发生未知错误');
|
|
|
|
|
} else {
|
|
|
|
|
options.utilFail(res.data.errormsg);
|
|
|
|
|
options.utilFail(res.data.errmsg);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (options.utilSuccess != undefined) {
|
|
|
|
|
@ -129,7 +213,7 @@ const request = options => {
|
|
|
|
|
complete: function(res) {
|
|
|
|
|
if (!options.customLoading) {
|
|
|
|
|
uni.hideNavigationBarLoading();
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
// 当前页面请求数量-1
|
|
|
|
|
if (options.bindThis) {
|
|
|
|
|
@ -143,27 +227,11 @@ const request = options => {
|
|
|
|
|
}; // 提交formID封装
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uploadFormID = formID => {
|
|
|
|
|
var timestamp = Math.floor(new Date().getTime() / 1000);
|
|
|
|
|
request({
|
|
|
|
|
api: 'WeChat/SaveFormID',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
FormIDs: formID
|
|
|
|
|
},
|
|
|
|
|
utilSuccess: function(res) {
|
|
|
|
|
console.log('上传formID成功');
|
|
|
|
|
},
|
|
|
|
|
utilFail: function(err) {
|
|
|
|
|
console.log('上传formID失败');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}; // 支付
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const payOrder = (orderID, orderType, success, fail) => {
|
|
|
|
|
uni.request({
|
|
|
|
|
url: HOST + 'WxPay/ToPay?openId=' + uni.getStorageSync('userInfo').WeChatOpenID + '&orderId=' +
|
|
|
|
|
url: HOST + 'WxPay/ToPay?openId=' + uni.getStorageSync(user_info_key).WeChatOpenID +
|
|
|
|
|
'&orderId=' +
|
|
|
|
|
orderID + '&OrderType=' + orderType,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
header: {
|
|
|
|
|
@ -226,128 +294,16 @@ const payOrder = (orderID, orderType, success, fail) => {
|
|
|
|
|
});
|
|
|
|
|
}; // 判断是否已登录(同时有open-id和PhoneNum, 则认为已登录)
|
|
|
|
|
|
|
|
|
|
const scanPay = (orderID, amt, scan, type, success, fail) => {
|
|
|
|
|
var access_token = uni.getStorageSync('userInfo').access_token;
|
|
|
|
|
console.log("1.支付进入")
|
|
|
|
|
var data = {
|
|
|
|
|
token: access_token,
|
|
|
|
|
order_id: orderID,
|
|
|
|
|
money: amt,
|
|
|
|
|
auth_code: scan,
|
|
|
|
|
type: type
|
|
|
|
|
};
|
|
|
|
|
console.log("2.参数")
|
|
|
|
|
console.log(data)
|
|
|
|
|
uni.showLoading({
|
|
|
|
|
title: '正在加载',
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
uni.request({
|
|
|
|
|
url: HOST + 'manager/scan-pay/' + orderID,
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
token: access_token,
|
|
|
|
|
order_id: orderID,
|
|
|
|
|
money: amt,
|
|
|
|
|
auth_code: scan,
|
|
|
|
|
type: type
|
|
|
|
|
},
|
|
|
|
|
header: {
|
|
|
|
|
'content-type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
uni.hideLoading();
|
|
|
|
|
if (isNull(res.data.errorcode)) {
|
|
|
|
|
success(res);
|
|
|
|
|
console.log("3.支付成功")
|
|
|
|
|
console.log(res)
|
|
|
|
|
} else {
|
|
|
|
|
alert("支付失败:" + res.data.errormsg);
|
|
|
|
|
console.log("4.支付失败")
|
|
|
|
|
console.log(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
fail: function(err) {
|
|
|
|
|
fail('当前网络状况不好');
|
|
|
|
|
console.log("4.支付失败")
|
|
|
|
|
console.log(res)
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}; // 判断是否已登录(同时有open-id和PhoneNum, 则认为已登录)
|
|
|
|
|
|
|
|
|
|
const isLogin = () => {
|
|
|
|
|
var userInfo = uni.getStorageSync('userInfo');
|
|
|
|
|
var userInfo = uni.getStorageSync(user_info_key);
|
|
|
|
|
return !isNull(userInfo.access_token);
|
|
|
|
|
}; // 判断是否为空
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getfile = (id, success, fail) => {
|
|
|
|
|
var access_token = uni.getStorageSync('userInfo').access_token;
|
|
|
|
|
var url = HOST + 'manager/get-attachment/' + id + '?token=' + access_token;
|
|
|
|
|
success(url);
|
|
|
|
|
// uni.request({
|
|
|
|
|
// url: HOST + 'manager/get-attachment/' + id + '?token=' + access_token,
|
|
|
|
|
// method: 'GET',
|
|
|
|
|
// header: {
|
|
|
|
|
// 'content-type': 'application/json'
|
|
|
|
|
// },
|
|
|
|
|
// success: function(res) {
|
|
|
|
|
// success(res); // 发送成功通知
|
|
|
|
|
// },
|
|
|
|
|
// fail: function(res) {
|
|
|
|
|
// fail(res);
|
|
|
|
|
// }
|
|
|
|
|
// });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取订单详情
|
|
|
|
|
const getOrderInfo = (id, success, fail) => {
|
|
|
|
|
var access_token = uni.getStorageSync('userInfo').access_token;
|
|
|
|
|
var url = HOST + 'manager/get-order/' + id + '?token=' + access_token;
|
|
|
|
|
uni.request({
|
|
|
|
|
url: url,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
header: {
|
|
|
|
|
'content-type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
res.data.factorjson = JSON.parse(res.data.factors);
|
|
|
|
|
success(res); // 发送成功通知
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
fail(res);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取订单详情
|
|
|
|
|
const getOrderItemInfo = (id, success, fail) => {
|
|
|
|
|
var access_token = uni.getStorageSync('userInfo').access_token;
|
|
|
|
|
var url = HOST + 'manager/get-order-item/' + id + '?token=' + access_token;
|
|
|
|
|
uni.request({
|
|
|
|
|
url: url,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
header: {
|
|
|
|
|
'content-type': 'application/json'
|
|
|
|
|
},
|
|
|
|
|
success: function(res) {
|
|
|
|
|
res.data.factorjson = JSON.parse(res.data.factors);
|
|
|
|
|
success(res.data); // 发送成功通知
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
fail(res);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const isNull = p => {
|
|
|
|
|
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
|
|
|
|
|
}; // 正则
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const phoneRegex = /^1\d{10}$/;
|
|
|
|
|
const idCardRegex = /^\d{17}([0-9]|X)$/; // 去掉特殊字符
|
|
|
|
|
|
|
|
|
|
@ -374,74 +330,6 @@ const randomStr = length => {
|
|
|
|
|
return ret;
|
|
|
|
|
}; // proType对应的中文描述
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const proTypeDic = {}; // 排序字段
|
|
|
|
|
|
|
|
|
|
const orderByArr = [{
|
|
|
|
|
id: '1',
|
|
|
|
|
name: '近期销量最高'
|
|
|
|
|
}, // { id: '2', name: '产品评价最高' },
|
|
|
|
|
{
|
|
|
|
|
id: '3',
|
|
|
|
|
name: '价格由高到低'
|
|
|
|
|
}, {
|
|
|
|
|
id: '4',
|
|
|
|
|
name: '价格由低到高'
|
|
|
|
|
}
|
|
|
|
|
]; // 日期天数
|
|
|
|
|
|
|
|
|
|
const travelDaysArr = [{
|
|
|
|
|
id: '1',
|
|
|
|
|
name: '2日',
|
|
|
|
|
minDay: 2,
|
|
|
|
|
maxDay: 2
|
|
|
|
|
}, {
|
|
|
|
|
id: '2',
|
|
|
|
|
name: '3日',
|
|
|
|
|
minDay: 3,
|
|
|
|
|
maxDay: 3
|
|
|
|
|
}, {
|
|
|
|
|
id: '3',
|
|
|
|
|
name: '4日',
|
|
|
|
|
minDay: 4,
|
|
|
|
|
maxDay: 4
|
|
|
|
|
}, {
|
|
|
|
|
id: '4',
|
|
|
|
|
name: '5日',
|
|
|
|
|
minDay: 5,
|
|
|
|
|
maxDay: 5
|
|
|
|
|
}, {
|
|
|
|
|
id: '5',
|
|
|
|
|
name: '6日',
|
|
|
|
|
minDay: 6,
|
|
|
|
|
maxDay: 6
|
|
|
|
|
}, {
|
|
|
|
|
id: '6',
|
|
|
|
|
name: '7日',
|
|
|
|
|
minDay: 7,
|
|
|
|
|
maxDay: 7
|
|
|
|
|
}, {
|
|
|
|
|
id: '7',
|
|
|
|
|
name: '8日',
|
|
|
|
|
minDay: 8,
|
|
|
|
|
maxDay: 8
|
|
|
|
|
}, {
|
|
|
|
|
id: '8',
|
|
|
|
|
name: '9日',
|
|
|
|
|
minDay: 9,
|
|
|
|
|
maxDay: 9
|
|
|
|
|
}, {
|
|
|
|
|
id: '9',
|
|
|
|
|
name: '10日',
|
|
|
|
|
minDay: 10,
|
|
|
|
|
maxDay: 10
|
|
|
|
|
}, {
|
|
|
|
|
id: '10',
|
|
|
|
|
name: '10日以上',
|
|
|
|
|
minDay: 11,
|
|
|
|
|
maxDay: 0
|
|
|
|
|
}]; // 中文星期
|
|
|
|
|
|
|
|
|
|
const weekdayArr = ['周日', '周一', '周二', '周三', '周四', '周五', '周六']; // 是否合法的身份证
|
|
|
|
|
|
|
|
|
|
const isValidCardID = cardID => {
|
|
|
|
|
@ -648,25 +536,22 @@ module.exports = {
|
|
|
|
|
formatTimeAll: formatTimeAll,
|
|
|
|
|
formatNumber: formatNumber,
|
|
|
|
|
alert: alert,
|
|
|
|
|
getfile: getfile,
|
|
|
|
|
getOpenidInfo: getOpenidInfo,
|
|
|
|
|
request: request,
|
|
|
|
|
uploadFormID: uploadFormID,
|
|
|
|
|
payOrder: payOrder,
|
|
|
|
|
scanPay: scanPay,
|
|
|
|
|
isLogin: isLogin,
|
|
|
|
|
isNull: isNull,
|
|
|
|
|
phoneRegex: phoneRegex,
|
|
|
|
|
idCardRegex: idCardRegex,
|
|
|
|
|
filterSpecialChars: filterSpecialChars,
|
|
|
|
|
randomStr: randomStr,
|
|
|
|
|
proTypeDic: proTypeDic,
|
|
|
|
|
orderByArr: orderByArr,
|
|
|
|
|
travelDaysArr: travelDaysArr,
|
|
|
|
|
weekdayArr: weekdayArr,
|
|
|
|
|
Base64: Base64,
|
|
|
|
|
orderStatusDic: orderStatusDic,
|
|
|
|
|
auditStatusDic: auditStatusDic,
|
|
|
|
|
getOrderInfo: getOrderInfo,
|
|
|
|
|
getOrderItemInfo: getOrderItemInfo,
|
|
|
|
|
stateArr: stateArr
|
|
|
|
|
getUserProfile: getUserProfile,
|
|
|
|
|
getUserInfo: getUserInfo,
|
|
|
|
|
toast: toast,
|
|
|
|
|
isValidCardID:isValidCardID
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|