712 lines
17 KiB
JavaScript
712 lines
17 KiB
JavaScript
import globalData from '@/common/js/globalData.js';
|
|
|
|
export default {
|
|
address: 'https://www.opsoul.com:8881',
|
|
// 异步接口拦截
|
|
addInterceptor() {
|
|
uni.addInterceptor('request', {
|
|
invoke(args) {
|
|
uni.showLoading({
|
|
mask: true,
|
|
title: '加载中'
|
|
})
|
|
// request 触发前拼接 url
|
|
args.url = 'https://www.opsoul.com:8881' + args.url;
|
|
// args.url = 'http://192.168.2.54:80' + args.url;
|
|
// args.url = 'http://127.0.0.1:80' + args.url;
|
|
if (args.data && Object.prototype && Object.prototype.toString.call(args.data) === '[object Object]') {
|
|
args.data.deptId = globalData.deptId;
|
|
args.data.from = globalData.from;
|
|
}
|
|
if (args.header) {
|
|
args.header.deptId = globalData.deptId;
|
|
args.header.from = globalData.from;
|
|
}
|
|
// console.log("停止触发");
|
|
// return false;
|
|
},
|
|
success(res) {
|
|
uni.hideLoading();
|
|
if (!res || !res.data || res.data.code !== 0) {
|
|
uni.showToast({
|
|
title: '系统错误',
|
|
icon: 'error'
|
|
})
|
|
}
|
|
},
|
|
fail(err) {
|
|
uni.hideLoading();
|
|
uni.showToast({
|
|
title: '请求失败',
|
|
icon: 'error'
|
|
})
|
|
},
|
|
complete(res) {
|
|
uni.hideLoading();
|
|
}
|
|
})
|
|
},
|
|
async authAndGetLocation() {
|
|
let _this = this;
|
|
// 通过 wx.getSetting 先查询一下用户是否授权了 "scope.userLocation" 这个 scope
|
|
let wxGetSettinsRes = await wx.getSetting();
|
|
if (!wxGetSettinsRes.authSetting['scope.userLocation']) {
|
|
// 用户授权
|
|
let authRes = await wx.authorize({
|
|
scope: 'scope.userLocation'
|
|
})
|
|
if (authRes && authRes.errMsg.indexOf('ok') != -1) {
|
|
// 用户已经同意, 后续调用此接口不会弹窗询问
|
|
await _this.wxGetLocation();
|
|
} else {
|
|
// 用户已经拒绝过授权
|
|
let wxOpenSettingRes = await wx.openSetting()
|
|
if (wxOpenSettingRes && wxOpenSettingRes.authSetting && wxOpenSettingRes.authSetting['scope.userLocation']) {
|
|
await _this.wxGetLocation();
|
|
}
|
|
}
|
|
} else {
|
|
await _this.wxGetLocation();
|
|
}
|
|
},
|
|
async wxGetLocation() {
|
|
let res = await wx.getLocation({
|
|
type: 'gcj02'
|
|
})
|
|
if (!res || !res.latitude) {
|
|
return;
|
|
}
|
|
let areaRes = await this.baiduGetLoacation(res.latitude, res.longitude);
|
|
areaRes = areaRes.data;
|
|
if (areaRes) {
|
|
let areaArr = [areaRes.provinceArea, areaRes.cityArea, areaRes.countryArea];
|
|
// let areaArr = [areaRes.cityArea, areaRes.countryArea];
|
|
let curLocation = {
|
|
area: areaArr,
|
|
updateTimes: new Date().getTime()
|
|
}
|
|
uni.setStorageSync('curLocation', curLocation);
|
|
}
|
|
},
|
|
async storageLocation(res) {
|
|
let areaRes = await this.baiduGetLoacation(res.latitude, res.longitude);
|
|
areaRes = areaRes.data;
|
|
if (areaRes) {
|
|
let areaArr = [areaRes.provinceArea, areaRes.cityArea, areaRes.countryArea];
|
|
// let areaArr = [areaRes.cityArea, areaRes.countryArea];
|
|
let curLocation = {
|
|
area: areaArr,
|
|
updateTimes: new Date().getTime()
|
|
}
|
|
uni.setStorageSync('curLocation', curLocation);
|
|
}
|
|
},
|
|
async getCurArea() {
|
|
try{
|
|
let curLocation = uni.getStorageSync('curLocation');
|
|
if (curLocation && curLocation.updateTimes) {
|
|
let curTimes = new Date().getTime();
|
|
let deltaSeconds = curTimes - curLocation.updateTimes;
|
|
if (deltaSeconds >= 15 * 60 * 1000) {
|
|
// 设定重新获取定位的时间间隔为15分钟
|
|
await this.wxGetLocation();
|
|
curLocation = uni.getStorageSync('curLocation');
|
|
}
|
|
} else {
|
|
await this.wxGetLocation();
|
|
curLocation = uni.getStorageSync('curLocation');
|
|
}
|
|
if (curLocation && curLocation.area) {
|
|
return curLocation.area;
|
|
}
|
|
}catch(e){
|
|
console.error(e)
|
|
}
|
|
return null;
|
|
},
|
|
async baiduGetLoacation(latitude, longitude) {
|
|
let res = await uni.request({
|
|
url: '/tool/baidu/getLocation',
|
|
method: 'POST',
|
|
data: {
|
|
location: latitude + ',' + longitude
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async login() {
|
|
let userInfo = await wx.getUserProfile({
|
|
desc: '用于小程序登录'
|
|
});
|
|
console.log(userInfo)
|
|
// 获取微信登录凭证
|
|
const wxLoginRes = await wx.login();
|
|
// 获取openid
|
|
const wxAuthRes = await uni.request({
|
|
url: '/wx/auth',
|
|
header: {
|
|
code: wxLoginRes.code
|
|
}
|
|
})
|
|
const openId = wxAuthRes[1].data.data.openid;
|
|
// 第一次从服务端获取用户信息
|
|
let wxGetUserRes = await this.qryUserInfo(openId);
|
|
// 获取失败则获取微信信息再调用注册接口
|
|
if (!wxGetUserRes.data && wxGetUserRes.code === 0) {
|
|
// 注册完成后再次从服务端获取用户信息
|
|
let registerRes = await this.registerUser({
|
|
openId: openId,
|
|
name: userInfo.userInfo.nickName,
|
|
customerLogoUrl: userInfo.userInfo.avatarUrl,
|
|
status: 0
|
|
});
|
|
if (registerRes.code === 0) {
|
|
wxGetUserRes = await this.qryUserInfo(openId);
|
|
}
|
|
}
|
|
if (!wxGetUserRes.data) {
|
|
userInfo = null;
|
|
} else {
|
|
userInfo = {
|
|
...wxGetUserRes.data,
|
|
wxLoginCode: wxLoginRes.code
|
|
}
|
|
}
|
|
if (!userInfo || userInfo.customerId == null || userInfo.customerId == undefined) {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '微信用户信息获取失败,请退出小程序重试'
|
|
})
|
|
return false;
|
|
}
|
|
// 页面存储用户登录有效信息,以便其他页面调用
|
|
uni.setStorageSync('userProfile', userInfo);
|
|
return true;
|
|
},
|
|
async storageExistUser() {
|
|
uni.clearStorageSync('userProfile');
|
|
// 获取微信登录凭证
|
|
const wxLoginRes = await wx.login();
|
|
// 获取openid
|
|
const wxAuthRes = await uni.request({
|
|
url: '/wx/auth',
|
|
header: {
|
|
code: wxLoginRes.code
|
|
}
|
|
})
|
|
const openId = wxAuthRes[1].data.data.openid;
|
|
// 从服务端获取用户信息
|
|
let wxGetUserRes = await this.qryUserInfo(openId);
|
|
let userInfo = null;
|
|
if (wxGetUserRes.data) {
|
|
userInfo = {
|
|
...wxGetUserRes.data,
|
|
wxLoginCode: wxLoginRes.code
|
|
}
|
|
}
|
|
uni.setStorageSync('userProfile', userInfo);
|
|
},
|
|
async registerUser(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/wx/addUser',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async qryUserInfo(openId) {
|
|
let res = await uni.request({
|
|
url: '/wx/getUserInfo',
|
|
method: 'POST',
|
|
data: {
|
|
openId: openId
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async qryUserPhone(code) {
|
|
let res = await uni.request({
|
|
url: '/wx/auth/phone',
|
|
method: 'GET',
|
|
header: {
|
|
code: code
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async updateUser(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/update',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
// 更新用户信息的方法顺便更新本地缓存
|
|
if (res[1].data.code === 0) {
|
|
let userInfo = this.getCurUserInfo();
|
|
let wxGetUserRes = await this.qryUserInfo(userInfo.openId);
|
|
let newUserInfo;
|
|
if (wxGetUserRes.data) {
|
|
newUserInfo = {
|
|
...wxGetUserRes.data,
|
|
wxLoginCode: userInfo.wxLoginCode
|
|
}
|
|
}
|
|
uni.setStorageSync('userProfile', newUserInfo);
|
|
}
|
|
return res[1].data;
|
|
},
|
|
async storagePhoneIntoUserInfo(code) {
|
|
let phoneRes = await this.qryUserPhone(code);
|
|
if (phoneRes && phoneRes.msg === '获取手机号码异常') {
|
|
uni.showToast({
|
|
icon: 'none',
|
|
title: '请先确认登录微信号是否已绑定手机号'
|
|
})
|
|
return false;
|
|
}
|
|
if (phoneRes && phoneRes.data) {
|
|
let userInfo = this.getCurUserInfo();
|
|
await this.updateUser({
|
|
customerId: userInfo.customerId,
|
|
account: phoneRes.data,
|
|
phone: phoneRes.data
|
|
})
|
|
return true;
|
|
}
|
|
},
|
|
wxLogin() {
|
|
return wx.login();
|
|
},
|
|
getCurUserInfo() {
|
|
let userProfile = uni.getStorageSync('userProfile');
|
|
return userProfile;
|
|
},
|
|
async refreshCurUserCache() {
|
|
let newUserInfo = await this.getCurUserNoCache();
|
|
uni.setStorageSync('userProfile', newUserInfo);
|
|
},
|
|
async getCurUserNoCache() {
|
|
let userInfo = this.getCurUserInfo();
|
|
let wxGetUserRes = await this.qryUserInfo(userInfo.openId);
|
|
if (!wxGetUserRes.data) {
|
|
userInfo = null;
|
|
} else {
|
|
userInfo = {
|
|
...wxGetUserRes.data,
|
|
wxLoginCode: userInfo.wxLoginCode
|
|
}
|
|
}
|
|
return userInfo;
|
|
},
|
|
getProductCategories(params = {}) {
|
|
return uni.request({
|
|
url: '/goods/deptcategory/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
},
|
|
qryProductPage(params = {}) {
|
|
return uni.request({
|
|
url: '/goods/goods/app/list',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
},
|
|
async placeOrder(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/server/app',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getWxPayParams(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/pay/wx/lite',
|
|
method: 'POST',
|
|
header: {
|
|
code: params.code,
|
|
orderMasterCode: params.orderMasterCode
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getAddressList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/address/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async addAddressList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/address/insert',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async editAddressList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/address/update',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async delAddressList(customerAddressId) {
|
|
let res = await uni.request({
|
|
url: '/customer/address/delete',
|
|
method: 'POST',
|
|
data: {
|
|
customerAddressId: customerAddressId
|
|
},
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async areaListByStep(params = {
|
|
parentCode: null
|
|
}) {
|
|
let res = await uni.request({
|
|
url: '/system/area/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async listByStepWithAllNode(params = {
|
|
goodsCategoryId: null
|
|
}) {
|
|
let res = await uni.request({
|
|
url: '/goods/deptcategory/app/listByStep',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async listByStep(params = {
|
|
goodsCategoryId: null
|
|
}) {
|
|
let res = await uni.request({
|
|
url: '/goods/deptcategory/listByStep',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async uploadFile(filePath) {
|
|
let res = await uni.uploadFile({
|
|
url: this.address + '/tool/qiniu/upload',
|
|
filePath: filePath,
|
|
name: 'uploadFile'
|
|
})
|
|
let resStr = res[1].data;
|
|
let resObj = null;
|
|
if (resStr != null && resStr.length > 0) {
|
|
try {
|
|
resObj = JSON.parse(resStr);
|
|
} catch(e) {
|
|
console.log(e)
|
|
}
|
|
}
|
|
if (!resObj || resObj.code !== 0) {
|
|
uni.showToast({
|
|
icon: 'error',
|
|
title: '上传失败'
|
|
})
|
|
return '';
|
|
}
|
|
return resObj.url;
|
|
},
|
|
// async qryOrderGoodsPage(params = {}) {
|
|
// let res = await uni.request({
|
|
// url: '/order/goods/list',
|
|
// method: 'POST',
|
|
// data: params,
|
|
// header: {
|
|
// pageNum: params.pageNum,
|
|
// pageSize: params.pageSize
|
|
// }
|
|
// })
|
|
// return res[1].data;
|
|
// },
|
|
async bindBankCard(params) {
|
|
let res = await uni.request({
|
|
url: '/customer/bankcard/bind',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getBindBankCardByCustomerId(params) {
|
|
let res = await uni.request({
|
|
url: '/customer/bankcard/getByCustomerId',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getGoodsDetail(params) {
|
|
let res = await uni.request({
|
|
url: '/goods/goods/getDetail',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data.data;
|
|
},
|
|
async qryFinancialCount(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/financial/detail/count',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async qryFinancialDetail(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/financial/detail/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async qryOrderPage(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/app/list',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async countOrderList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/app/count',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async updateOrder(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/editOrderMaster',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async cancelMasterOrder(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/cancel',
|
|
method: 'POST',
|
|
data: {
|
|
orderMasterId: params.orderMasterId
|
|
},
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getHotGoods(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/goods/goods/hot/list',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getHotCategory(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/goods/deptcategory/app/hot/category',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getOrderMasterDetail(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/app/detail',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getWorkerList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/worker/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getWorkerAllDetailById(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/worker/getDetailById',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getUnlimitedWxacode(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/wx/unlimited/wxacode',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async sendVertifyCode(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/tool/sms/send',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async addCustomerPlace(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/place/app/add',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getCustomerPlaceList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/place/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async qryCustomerList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/app/list',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getDetailListByMasterId(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/app/getDetailListByMasterId',
|
|
method: 'POST',
|
|
data: params.orderMasterId
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getAfterList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/after/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async countAfterList(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/master/after/count',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async addAfterServiceRecord(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/worker/record/add',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async delAfterServiceRecord(ids) {
|
|
let res = await uni.request({
|
|
url: '/worker/record/remove',
|
|
method: 'POST',
|
|
data: {
|
|
ids: ids
|
|
},
|
|
header: {
|
|
'content-type': 'application/x-www-form-urlencoded'
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getOrderAfterServiceRecords(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/worker/record/app/list',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async editAfterServiceRecord(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/worker/record/edit',
|
|
method: 'POST',
|
|
data: params,
|
|
header: {
|
|
pageNum: params.pageNum,
|
|
pageSize: params.pageSize
|
|
}
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getChangeOrderPrice(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/order/detail/app/getChangePrice',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async addCustomerSelection(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/selection/app/add',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async getMembersWaitingApproval(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/place/app/myCustomerPlace',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
},
|
|
async editCustomerPlace(params = {}) {
|
|
let res = await uni.request({
|
|
url: '/customer/place/app/edit',
|
|
method: 'POST',
|
|
data: params
|
|
})
|
|
return res[1].data;
|
|
}
|
|
}
|