diff --git a/packages/packageBuy/pages/shopDetail/shopDetail.vue b/packages/packageBuy/pages/shopDetail/shopDetail.vue index 3ee836e..b035a34 100644 --- a/packages/packageBuy/pages/shopDetail/shopDetail.vue +++ b/packages/packageBuy/pages/shopDetail/shopDetail.vue @@ -650,21 +650,31 @@ } }, utilFail: res => { + console.log(res) uni.showToast({ title: res, duration: 5000 }) - console.log(res); } }) } }, utilFail: r => { - uni.showToast({ - title: r, - duration: 5000 - }) - console.log(r); + uni.showModal({ + title: '', + content: r, + showCancel: false, + success() { + if (r == "重复购买") { + + uni.redirectTo({ + url: "../../../packageOrder/pages/myOrder/myOrder" + }) + + } + } + }); + } }) diff --git a/utils/util.js b/utils/util.js index 3a0c798..d15236c 100755 --- a/utils/util.js +++ b/utils/util.js @@ -13,40 +13,41 @@ const formatTime = date => { const month = date.getMonth() + 1; const day = date.getDate(); return [year, month, day].map(formatNumber).join('-'); -}; - - +}; + + // 其他更多是格式化有如下: // yyyy:mm:dd|yyyy:mm|yyyy年mm月dd日|yyyy年mm月dd日 hh时MM分等,可自定义组合 -function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') {try { - - // 如果为null,则格式化当前时间 - if (!dateTime) dateTime = Number(new Date()); - // 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式 - if (dateTime.toString().length == 10) dateTime *= 1000; - if (dateTime.toString().indexOf("-")>-1) dateTime= dateTime.replace(/-/g,'/') - let date = new Date(dateTime); - - let ret; - let opt = { - "y+": date.getFullYear().toString(), // 年 - "m+": (date.getMonth() + 1).toString(), // 月 - "d+": date.getDate().toString(), // 日 - "h+": date.getHours().toString(), // 时 - "M+": date.getMinutes().toString(), // 分 - "s+": date.getSeconds().toString() // 秒 - // 有其他格式化字符需求可以继续添加,必须转化成字符串 - }; - for (let k in opt) { - ret = new RegExp("(" + k + ")").exec(fmt); - if (ret) { - fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) - }; - }; - return fmt; - }catch(e){ - console.log(e) +function timeFormat(dateTime = null, fmt = 'yyyy-mm-dd') { + try { + + // 如果为null,则格式化当前时间 + if (!dateTime) dateTime = Number(new Date()); + // 如果dateTime长度为10或者13,则为秒和毫秒的时间戳,如果超过13位,则为其他的时间格式 + if (dateTime.toString().length == 10) dateTime *= 1000; + if (dateTime.toString().indexOf("-") > -1) dateTime = dateTime.replace(/-/g, '/') + let date = new Date(dateTime); + + let ret; + let opt = { + "y+": date.getFullYear().toString(), // 年 + "m+": (date.getMonth() + 1).toString(), // 月 + "d+": date.getDate().toString(), // 日 + "h+": date.getHours().toString(), // 时 + "M+": date.getMinutes().toString(), // 分 + "s+": date.getSeconds().toString() // 秒 + // 有其他格式化字符需求可以继续添加,必须转化成字符串 + }; + for (let k in opt) { + ret = new RegExp("(" + k + ")").exec(fmt); + if (ret) { + fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, "0"))) + }; + }; + return fmt; + } catch (e) { + console.log(e) } } @@ -97,8 +98,8 @@ const auditStatusDic = { }; // 请求封装 const request = options => { - if (!options.customLoading) { - //if(false){ + if (!options.customLoading) { + //if(false){ uni.showLoading({ title: '正在加载' }); @@ -135,6 +136,7 @@ const request = options => { uni.request({ ...options, success: function(res) { + uni.hideLoading(); if (res.statusCode != 200) { if (options.utilFail != undefined) { if (res.statusCode == 401) { @@ -160,16 +162,19 @@ const request = options => { } } }, - fail: options.utilFail, + fail: function(res) { + uni.hideLoading(); + options.utilFail(res); + }, complete: function(res) { if (!options.customLoading) { uni.hideNavigationBarLoading(); - uni.hideLoading(); + } else { // 当前页面请求数量-1 if (options.bindThis) { //options.bindThis.setData({ - //loadingCount: options.bindThis.data.loadingCount - 1 + //loadingCount: options.bindThis.data.loadingCount - 1 //}); } } @@ -264,14 +269,14 @@ const payOrder = (orderID, orderType, success, fail) => { const getRegions = () => { request({ - api: 'api/get-regions', - customLoading:true, + api: 'api/get-regions', + customLoading: true, utilSuccess: function(res) { var r = res[0]; r.latitude = 31.53908730560652; //res.latitude;31.536744,120.40841 r.longitude = 120.41435442003421; // res.longitude; - uni.setStorageSync("region", r); - + uni.setStorageSync("region", r); + }, utilFail: function(res) { console.log(res) @@ -354,65 +359,65 @@ const getfile = (id, success, fail) => { // } // }); }; - + const openid_info_key = "openid_info" -const user_info_key = 'user_info_key' -const solgn="无锡新吴欢迎您"; - -const shareInfo=(type)=>{ - - return { - title:solgn - } -} - -const getOpenidInfo= (cb, refresh) => { - cb = cb || function() {} - refresh = refresh || false - if (!refresh) { - let user_info = uni.getStorageSync(user_info_key) - if (user_info && user_info.openid && user_info.session_key) { - cb(user_info) - return - } +const user_info_key = 'user_info_key' +const solgn = "无锡新吴欢迎您"; + +const shareInfo = (type) => { + + return { + title: solgn + } +} + +const getOpenidInfo = (cb, refresh) => { + cb = cb || function() {} + refresh = refresh || false + if (!refresh) { + let user_info = uni.getStorageSync(user_info_key) + if (user_info && user_info.openid && user_info.session_key) { + cb(user_info) + return } + } + + uni.login({ + provider: 'weixin', + success: (res) => { + uni.request({ + url: HOST + 'api/member/login-by-code', + method: 'POST', + data: { + code: res.code + }, + success: result => { + const user_info1 = result.data.data.user_info + user_info1.openid = user_info1.wechat_openid + uni.setStorageSync(user_info_key, user_info1) + cb(user_info1) + } + }); + } + }); +} + +const getUserProfile = (cb) => { + cb = cb || function() {} + + wx.getUserProfile({ + desc: '用于完善会员资料', + success: (res) => { + uni.setStorageSync('user_profile', res.userInfo) + cb(res.userInfo) + } + }) +} + +const getUserInfoCache = () => { + return uni.getStorageSync(user_info_key) +} - uni.login({ - provider: 'weixin', - success: (res) => { - uni.request({ - url: HOST + 'api/member/login-by-code', - method: 'POST', - data: { - code: res.code - }, - success: result => { - const user_info1 = result.data.data.user_info - user_info1.openid = user_info1.wechat_openid - uni.setStorageSync(user_info_key, user_info1) - cb(user_info1) - } - }); - } - }); - } - - const getUserProfile=(cb) => { - cb = cb || function() {} - - wx.getUserProfile({ - desc: '用于完善会员资料', - success: (res) => { - uni.setStorageSync('user_profile', res.userInfo) - cb(res.userInfo) - } - }) - } - - const getUserInfoCache= () => { - return uni.getStorageSync(user_info_key) - } - //获取订单详情 const getOrderInfo = (id, success, fail) => { @@ -752,11 +757,11 @@ var Base64 = { } return this.UTF8ToUTF16(res.join('')); - }, - - - - + }, + + + + }; @@ -791,10 +796,10 @@ module.exports = { getOrderInfo: getOrderInfo, getOrderItemInfo: getOrderItemInfo, stateArr: stateArr, - getRegions: getRegions, - getOpenidInfo:getOpenidInfo, - getUserProfile:getUserProfile, - getUserInfoCache:getUserInfoCache, - timeFormat:timeFormat, - shareInfo:shareInfo + getRegions: getRegions, + getOpenidInfo: getOpenidInfo, + getUserProfile: getUserProfile, + getUserInfoCache: getUserInfoCache, + timeFormat: timeFormat, + shareInfo: shareInfo };