| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295 |
- const app = getApp();
- let WebIM = (wx.WebIM = require("../hxChatSDK/utils/WebIM")["default"]);
- const env = {
- NODE_ENV: 'pota',
- dev: {
- apiUrl: 'https://rsapi.zhiqiyun.net'
- },
- prd: {
- apiUrl: 'https://apimall.zhiqiyun.com'
- },
- pota: {
- // apiUrl: 'http://192.168.110.98:8098'
- // apiUrl: 'http://192.168.110.180:8098' ,//f
- // apiUrl: 'http://192.168.110.182:8094' ,//z
- // apiUrl: 'http://192.168.110.176:8098' //y
- // apiUrl: 'http://192.168.110.117:8098'//l
- // apiUrl: 'http://192.168.110.216:8098'
- apiUrl: 'http://192.168.110.180:8098' ,//wjg
- }
- }
- var header = {
- 'content-type': 'application/x-www-form-urlencoded',
- 'appId': 'ZQhe229Ax49Pdpy', //中国人寿测试环境
- }
- /**小程序配置 */
- const publics = {
- picUrls: 'https://zhiqiyun.oss-cn-hangzhou.aliyuncs.com/static/', //图片地址
- 'copyrighttitle': '智企云', //底部版权公司名称
- 'copyrighttel': '400-698-5980', //底部版权服务电话
- 'copyrightlogo': 'zhiqiyun', //底部版权 logo 文件名
- 'yaomeng': 'https://cfwz.yaomengwang.cn/hunan?enterpriseCode=hnty&orderId=', //药盟接口地址
- 'storemanagers': 'https://websmall.zhiqiyun.com?appId=', //saas门店管理地址(智企云所有)
- 'channel': '', //处方中间渠道号 SAAS系统为空
- 'is_customer_pick_up': false,
- 'mapLBSKEY': 'CBRBZ-5SHKL-3NCPX-EP5MQ-B57M6-CWFUU',
- 'iconSrc': 'red/',
- 'titleTopBgColor': '#FFF',
- // 小程序ID wxe7bec198ecfe1162
- // 文章栏目code
- 'fxCode': 'faxian', //发现
- 'xbrmCode': 'xiaobairumen', //小白入门
- 'tbalCode': 'toubaoanli', //投保案例
- 'lpalCode': 'lipeianli', //理赔案例
- 'gfdtCode':'gfdt',//官方动态
- }
- /*
- * 获取token
- */
- const getToken = (success) => {
- let token = getStorage('AUTH_TOKEN');
- if (token) {
- success.call(this, token);
- return false;
- } else {
- loadToken(data => {
- success.call(this, data);
- });
- }
- }
- const loadToken = (success) => {
- let that = this
- uni.request({
- url: env[env.NODE_ENV].apiUrl + '/api/access_token',
- data: {},
- method: 'get',
- header: header,
- success(json) {
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code !== 0) return msg(json.data.msg)
- setStorage('AUTH_TOKEN', json.data.data);
- success.call(that, json.data.data);
- },
- fail() {
- msg('access_token 获取失败');
- }
- })
- }
- /**
- * 微信小程序静默授权登录
- * @param {*} parentId
- * @param {*} merchantId
- */
- const silenceLogin = (parentId, merchantId) => {
- // #ifdef MP-WEIXIN
- return new Promise((resolve, reject) => {
- if (!isLogins(false)) { //未登录
- uni.login({
- success(res) {
- console.log('静默授权登录>>>', res);
- let params = {
- code: res.code,
- parentId: parentId ? parentId : '',
- merchantId: merchantId ? merchantId : ''
- }
- postRequest('/api/v3/silence/login', params, data => {
- if (data.token) setStorage('AUTH_TOKEN', data.token);
- getRequest('/api/user/info', {}, suc => {
- data.isDistriUser = suc.isDistriUser;
- setStorage('userInfo', data);
- getIMToken(false);
- });
- resolve();
- });
- }
- });
- } else {
- initIMChat();
- resolve();
- }
- });
- // #endif
- }
- const getsysConfig = (upData)=>{
- // upData true刷新缓存系统参数
- return new Promise((r,j)=>{
- if(upData){
- getRequest('/api/other/config', {}, res => {
- setStorage('configRes', JSON.stringify(res));
- r(res)
- });
- }else{
- if(getStorage('configRes')) r(JSON.parse(getStorage('configRes')))
- else{
- getRequest('/api/other/config', {}, res => {
- setStorage('configRes', JSON.stringify(res));
- r(res)
- });
- }
- }
- })
- }
- /**
- * 初始化 IMsdk
- */
- const initIMChat = () => {
- var user = getStorage('userInfo');
- if (user) {
- var imToken = getStorage('imToken');
- if (imToken) {
- //初始化IM
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + user.id
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: 'RS_' + user.id,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- } else {
- getRequest('/api/im/msg/userToken', {}, suc => {
- setStorage('imToken', suc);
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + user.id
- });
- getApp().globalData.conn.open({
- apiUrl: WebIM.config.apiURL,
- user: 'RS_' + user.id,
- pwd: getStorage('imToken'),
- accessToken: getStorage('imToken'),
- appKey: WebIM.config.appkey
- });
- });
- }
- }
- }
- const getIMToken = (isUpdatToken) => {
- var user = getStorage('userInfo');
- getRequest('/api/im/msg/userToken', {}, suc => {
- setStorage('imToken', suc);
- if (isUpdatToken) {
- //更新token
- uni.setStorage({
- key: "myUsername",
- data: 'RS_' + user.id
- });
- getApp().globalData.conn.open({
- user: 'RS_' + user.id,
- accessToken: getStorage('imToken'),
- });
- getApp().globalData.onLoginSuccess(uni.getStorageSync("myUsername"));
- } else {
- initIMChat();
- }
- }, true);
- }
- /**
- * 跳转进入消息列表
- */
- const jumpConversation = () => {
- if (!isLogins(true)) { //未登录
- return;
- }
- getIMToken(true);
- }
- const getWXUserProfile = (suc) => {
- let that = this;
- var sessionKey = '';
- var openid = '';
- getApp().globalData.getCheckSessoin(json => {
- sessionKey = json.session_key;
- openid = json.openid;
- });
- try {
- uni.getUserProfile({
- desc: '完善信息',
- success: res => {
- updataWxInfos(res.iv, res.encryptedData, sessionKey, openid, suc);
- },
- fail: res => {
- console.log('授权失败数据>>>', res);
- msg(res);
- }
- });
- } catch (e) {
- // 老版
- wx.getUserInfo({
- success: function(ress) {
- updataWxInfos(res.iv, res.encryptedData, sessionKey, openid, suc);
- }
- });
- }
- }
- /**
- * 保存微信头像
- */
- const updataWxInfos = (iv, encryptedData, sessionKey, openid, suc) => {
- if (!encryptedData || !iv) return false;
- let _params = {
- sessionKey: sessionKey,
- openId: openid,
- iv: iv,
- encryptedData: encryptedData
- };
- postRequest('/api/user/weixin/update', _params, json => {
- setStorage('userInfo', json);
- suc.call();
- });
- }
- const clearValueEmpty = (data) => {
- let keyValue = {};
- for (let key in data) {
- let value = typeof data[key];
- if (value == 'string' && value) {
- if (data[key] != 'undefined' && data[key] != " " && data[key] != undefined && data[key] != null) {
- keyValue[key] = data[key];
- }
- // keyValue[key] = data[key];
- } else if (value == 'number' && value != null) {
- keyValue[key] = data[key];
- } else if (value == 'boolean') {
- keyValue[key] = data[key];
- } else {
- if (data[key]) keyValue[key] = data[key];
- }
- }
- return keyValue;
- }
- /**
- * 公共请求
- *
- * @param {*} url 请求url
- * @param {*} data 请求参数
- * @param {*} method 请求方法
- * @param {*} success 成功函数
- * @param {*} isLoad 是否显示加载提示
- */
- const baseRequest = (url, data, method, success, isLoad) => {
- getToken(token => {
- if (!isLoad) uni.showNavigationBarLoading();
- header.authorityToken = token;
- // if (url.indexOf('/v3') != -1 || url.indexOf('/paper/create') != -1) {
- // header['content-type'] = 'application/json;charset=UTF-8'
- // } else {
- header['content-type'] = 'application/json;charset=UTF-8'
- // }
- uni.request({
- url: env[env.NODE_ENV].apiUrl + url,
- data: clearValueEmpty(data),
- method: method,
- header: header,
- success(json) {
- if (!isLoad) uni.hideNavigationBarLoading();
- if (json.statusCode !== 200) return msg(json.data.message);
- if (json.data.code === 10021 || json.data.code === 10020) {
- // console.log("第二次执行")
- removeStorage('AUTH_TOKEN');
- removeStorage('userInfo');
- return redirectIndex();
- }
- if (json.data.code !== 0) {
- return msg(json.data.msg)
- }
- // console.log("第二次执行")
- let data = json.data.data;
- if (typeof data === 'string' && data.indexOf("{") === 0) {
- data = JSON.parse(data);
- }
- success.call(this, data);
- },
- fail() {
- if (!isLoad) uni.hideNavigationBarLoading();
- },
- // complete(){
- // success.call(this, data);
- // },
- })
- })
- }
- const loadIng = (msg) => {
- uni.showLoading({
- title: msg,
- mask: true
- })
- }
- /**POST请求 */
- const postRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'post', success, isLoad);
- }
- const postRequestLoding = (url, data, success, isLoding) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'post', success, false, isLoding);
- }
- /**GET请求 */
- const getRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'get', success, isLoad);
- }
- /**Put请求 */
- const putRequest = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'put', success, isLoad)
- }
- const putRequestJson = (url, data, success, isLoad) => {
- header['content-type'] = 'application/json;charset=UTF-8'
- baseRequest(url, data, 'put', success, isLoad)
- }
- /**
- * 上传文件
- * @param {*} url 请求url
- * @param {*} data 携带数据
- * @param {*} success 请求成功函数
- */
- const uploadFile = (url, data, success) => {
- // console.log(env[env.NODE_ENV].apiUrl + url, data)
- getToken(token => {
- uni.uploadFile({
- url: env[env.NODE_ENV].apiUrl + url,
- filePath: data,
- name: 'file',
- header: {
- 'appId': header['appId'],
- 'authorityToken': token
- },
- success(res) {
- if (res.statusCode !== 200) return msg('文件上传失败');
- let data = JSON.parse(res.data);
- if (data.code !== 0) return msg(data.msg);
- success.call(this, data.data);
- },
- })
- })
- }
- /**弹窗 */
- const msg = (title, success) => {
- if (title) {
- uni.showToast({
- title: title,
- icon: 'none',
- success() {
- if (success) success.call(this);
- }
- });
- }
- return false;
- }
- const msgConfirm = (msg, success, cancel) => {
- uni.showModal({
- title: '提示',
- content: msg,
- success(res) {
- if (res.confirm) {
- success.call(this);
- } else {
- if (cancel) cancel.call(this);
- }
- }
- })
- }
- const msgConfirmText = (msg, confirmText, success, cancel) => {
- uni.showModal({
- title: '提示',
- content: msg,
- confirmText: confirmText,
- success(res) {
- if (res.confirm) {
- success.call(this);
- } else {
- if (cancel) cancel.call(this);
- }
- }
- })
- }
- const alertMsg = (msg, success) => {
- uni.showModal({
- title: '提示',
- content: msg,
- showCancel: false,
- success(res) {
- if (success) success.call(this);
- }
- })
- return false;
- }
- const load = msg => {
- uni.showLoading({
- title: msg,
- mask: true
- })
- }
- const g = (url, success, isLoad) => {
- getRequest(url, {}, success, isLoad)
- }
- const p = (url, success, isLoad) => {
- postRequest(url, {}, success, isLoad)
- }
- const send = (url, mobile, success, error) => {
- if (!mobile) {
- return msg('手机号码不能为空', error);
- }
- postRequest(url, {
- phone: mobile
- }, json => {
- if (json.code !== 0) {
- return msg(json.msg, error);
- }
- let time = 60;
- const initTime = setInterval(() => {
- time--;
- if (time > 0) {
- success.call(this, time + '秒后获取');
- } else {
- clearInterval(initTime);
- success.call(this, '获取验证码');
- }
- }, 1000)
- })
- }
- // 登陆拦截
- const redirectIndex = (params) => {
- // uni.clearStorageSync();
- // console.log(params)
- var pages = getCurrentPages();
- // console.log("pages》》》》》登陆拦截", pages);
- let currentUrl;
- if (pages) {
- var currentPage = pages[pages.length - 1];
- if (currentPage) {
- currentUrl = currentPage.route;
- let query = currentPage.data.query;
- if (query) {
- for (let key in query) {
- const fo = key + '=' + query[key];
- currentUrl += currentUrl.indexOf('?') > -1 ? '&' + fo : '?' + fo;
- }
- }
- if (currentUrl) {
- console.log('currentUrl》》》》》', currentUrl);
- setStorage("REDIRECT_URL", '/' + currentUrl)
- if (currentUrl == 'pages/authorize/authorize') {
- console.log('当前已经处于登录页面,不在向下执行跳转');
- return
- }
- }
- }
- }
- let redirectUrl = '/pages/authorize/authorize' + (params ? params : '');
- // console.log("登陆拦截")
- uni.navigateTo({
- url: redirectUrl
- })
- return false;
- }
- const saveImage = (url) => {
- uni.saveImageToPhotosAlbum({
- filePath: url,
- success() {
- msg('图片保存成功');
- }
- })
- }
- const saveImageToPhotosAlbum = (url) => {
- if (!url) return msg('小程序码不存在');
- uni.getImageInfo({
- src: url,
- success(json) {
- // uni.getSetting({
- // success(res) {
- // if (!res.authSetting['scope.writePhotosAlbum']) {
- // uni.authorize({
- // scope: 'scope.writePhotosAlbum',
- // success() {
- // saveImage(json.path);
- // }
- // })
- // } else {
- // saveImage(json.path);
- // }
- // }
- // })
- }
- })
- }
- const getConfig = (config, id) => {
- let con = {};
- config.info.forEach(inf => {
- // console.log(inf.version, inf.version ? inf.version.indexOf(id) : '-')
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- config.card.forEach(inf => {
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- config.realTime.forEach(inf => {
- if (inf.isSet && (!inf.version || inf.version.indexOf(id) > -1))
- con[inf.setName] = inf.setDefault;
- });
- return con;
- }
- const isLogin = async (error) => {
- let userInfo = getStorage('userInfo');
- if (!userInfo || !userInfo.id) {
- if (error) return false;
- // console.log("第一次执行")
- return redirectIndex();
- }
- return true;
- }
- //检测是否登录
- const isLogins = (isGoLogin) => {
- let userInfo = getStorage('userInfo');
- if (!userInfo) {
- if (isGoLogin) {
- redirectIndex();
- }
- return false;
- }
- return true;
- }
- const setStorage = (key, value) => {
- uni.setStorageSync(env.NODE_ENV + "_" + key, value)
- }
- const getStorage = (key) => {
- return uni.getStorageSync(env.NODE_ENV + "_" + key)
- }
- const removeStorage = (key) => {
- return uni.removeStorageSync(env.NODE_ENV + "_" + key);
- }
- /**
- * 缓存模板id
- */
- // const gettmplIds = () => {
- // getRequest('/api/wxmes/querylist', {}, res => {
- // setStorage('tmplIds', res)
- // console.log(res)
- // })
- // }
- //微信支付订单公共方法
- const payOrder = (id, success) => {
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id
- };
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- if (getStorage('isVideoScene')) {
- uni.checkBeforeAddOrder({
- success(res) {
- console.log('下单前置检查', res)
- let data = res.data;
- data.requiredFundType = 0;
- datas.sceneCheckStr = JSON.stringify(data);
- wexinPay(datas, success)
- },
- })
- } else {
- wexinPay(datas, success)
- }
- }
- //支付中或已支付
- const payStatus = (json, id, success) => {
- if (json && json.code === 115) {
- setTimeout(res => {
- uni.hideLoading();
- isShowLoading = false;
- uni.showModal({
- title: '提示',
- content: '当前订单正在支付或30秒后重试',
- confirmText: '我知道了',
- showCancel: false,
- success(res) {}
- })
- }, 3000)
- return false;
- }
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- }
- // 支付成功回调
- const paySuccess = (id, success) => {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- }
- // 支付失败回调
- const payFail = (id) => {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- }
- const wexinPay = (datas, success) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- // #ifdef MP-WEIXIN
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log('json',json)
- payStatus(json, datas.id, success)
- const sceneCheckStr = datas.sceneCheckStr;
- if (sceneCheckStr && JSON.parse(sceneCheckStr).requiredFundType === 1) {
- console.log('拉起收银台')
- wx.requestOrderPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- orderInfo: json.orderInfo,
- paySign: json.sign,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- console.log(res);
- payFail(datas.id)
- }
- })
- } else {
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- console.log(res);
- payFail(datas.id)
- }
- })
- }
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- // #ifdef MP-ALIPAY
- datas.payChannel = 'alipay_lite ';
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: json.packages,
- success: function() {
- paySuccess(datas.id, success)
- },
- fail: function(res) {
- payFail(datas.id)
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- }
- //微信支付订单公共方法
- const payOrdersss = (id, success) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- var loctionAddressMap = getStorage('loctionAddressMap');
- var datas = {
- id: id
- };
- if (loctionAddressMap) {
- datas.province = loctionAddressMap.province;
- datas.city = loctionAddressMap.city;
- };
- // #ifdef MP-WEIXIN
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- // #ifdef MP-ALIPAY
- datas.payChannel = 'alipay_lite ';
- postRequest('/api/order/weixin/pay', datas, json => {
- // console.log(json)
- if (json.type === 2 || json.type === 3) {
- //调用后台判断订单是否支付成功
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- if (res.isSuccess || i === 4) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 200);
- // success.call(this);
- return false;
- }
- uni.requestPayment({
- provider: 'alipay',
- orderInfo: json.packages,
- success: function() {
- console.log('支付成功')
- let i = 0;
- let timer = setInterval(() => {
- postRequest('/api/order/check', {
- id: id
- }, res => {
- console.log(i)
- if (res.isSuccess || i === 5) {
- clearInterval(timer);
- success.call(this, res.isSuccess);
- } else {
- i++;
- }
- }, true)
- }, 500);
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/orderDet/orderDet?id=' + id,
- })
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- // #endif
- }
- //微信支付订单公共方法 ==活动
- const payOrders = (id, success, type) => {
- let isShowLoading = false;
- if (!isShowLoading) {
- loadIng('加载中');
- // console.log('加载中')
- isShowLoading = true;
- }
- postRequest('/api/order/weixin/pay', {
- id: id
- }, json => {
- // console.log(json)
- payStatus(json, id, success)
- uni.requestPayment({
- timeStamp: json.timeStamp,
- nonceStr: json.nonceStr,
- package: json.packages,
- signType: json.signType,
- paySign: json.sign,
- success: function() {
- paySuccess(id, success)
- },
- fail: function(res) {
- console.log('支付失败')
- postRequest('/api/order/cancelPay', {
- id: id
- }, data => {
- uni.redirectTo({
- url: '/mine/activity/activity',
- })
- })
- console.log(res);
- }
- })
- if (isShowLoading) {
- uni.hideLoading();
- isShowLoading = false;
- }
- })
- }
- const authSetting = (authority, success, error) => {
- // console.log(authority,success)
- // #ifndef H5
- uni.getSetting({
- success(res) {
- if (res.authSetting[authority]) {
- success.call(this);
- return false;
- }
- uni.authorize({
- scope: authority,
- success() {
- success.call(this);
- },
- fail: function(res) {
- error.call(this);
- }
- })
- }
- })
- // #endif
- }
- const getLocation = (suss) => {
- // #ifdef MP-WEIXIN
- authSetting('scope.userLocation', () => {
- // load('定位中…');
- uni.getLocation({
- type: 'gcj02',
- // isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res, "789")
- suss.call(this, res);
- },
- fail: function(res) {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- }, () => {
- // uni.hideLoading();
- console.log("取消")
- suss.call(this, 1)
- });
- // #endif
- // #ifdef MP-ALIPAY
- uni.getLocation({
- type: 'gcj02',
- // isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res, "789")
- suss.call(this, res);
- },
- fail: function(res) {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- // #endif
- // #ifdef H5
- uni.getLocation({
- type: 'gcj02',
- isHighAccuracy: true,
- success: function(res) {
- // uni.hideLoading();
- console.log(res)
- suss.call(this, res, "789");
- },
- fail: function() {
- console.log("调用失败", res)
- suss.call(this, 2)
- // uni.hideLoading();
- }
- })
- // #endif
- }
- const scopeAddress = (success) => {
- // #ifdef MP-WEIXIN
- authSetting('scope.address', () => {
- uni.chooseAddress({
- success: function(res) {
- success.call(this, res);
- },
- })
- }, () => {
- msg('未设置开放权限')
- });
- // #endif
- // #ifdef MP-ALIPAY
- uni.chooseAddress({
- success: function(res) {
- success.call(this, res);
- },
- })
- // #endif
- }
- const isAuth = () => {
- const user = getStorage('userInfo');
- return user && user.id;
- }
- // 去掉字符串中的特殊字符和转义字符
- const excludeSpecial = (s) => {
- // 去掉转义字符
- // s = s.replace(/[\'\"\\\/\b\f\n\r\t]/g, '');
- const pattern = /[`~!@#$^&*()=|{}':;',\\\[\]\.<>\/?~!@#¥……&*()——|{}【】';:""' + - - _ % 。,、?\s]/g;
- if (s != undefined || s != null) {
- s = s.replace(pattern, "")
- }
- return s;
- }
- // 数字单位格式化
- function unitConverter(num) {
- // text 数字+单位 number格式化后的数字 unit单位
- console.log(num)
- if (!num || isNaN(num)) {
- return {
- text: 0,
- number: 0,
- unit: ''
- }
- }
- num = Number(num)
- if (Math.abs(num) > 100000000) {
- return {
- text: (num / 100000000).toFixed(2) + '亿',
- number: (num / 100000000).toFixed(2),
- unit: '亿'
- }
- } else if (Math.abs(num) > 10000) {
- return {
- text: (num / 10000).toFixed(2) + '万',
- number: (num / 10000).toFixed(2),
- unit: '万'
- }
- } else {
- return {
- text: num,
- number: num,
- unit: ''
- }
- }
- }
- // 行为操作
- const saveBehavior = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、海报
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知 13、素材 15、科室 16、海报 20、医生 21日历、探索 47评价
- postRequest('/api/v3/behavior/save', params, data => {
- success.call(this, data)
- })
- }
- const getBehavior = (params, success) => {
- //用户行为:behavior 1、关注 2、收藏 3、点赞 4、浏览 5、确认 6、海报
- //用户行为操作对象:type 1、产品 2、赛事 3、未知 4、内容 5、课程 6、老师 7、素材 8、题目 9、资料领取 10、招聘职位 11、用户 12、用户须知 13、素材 15、科室 16、海报 20、医生 21日历、探索 47评价
- console.log('行为')
- getRequest('/api/v3/behavior/get', params, data => {
- success.call(this, data)
- })
- }
- /**
- * 跳入聊天
- * @param {Object} userId 对方用户ID
- * @param {Object} avatar 对方用户头像
- * @param {Object} realName 对方用户名称
- */
- const jumpSingleChatRoom = function(userId, avatar, realName) {
- var my = uni.getStorageSync("myUsername");
- var nameList = {
- myName: my,
- your: 'rs_' + userId
- };
- uni.setStorage({
- key: 'imUserInfo_' + nameList.your,
- data: {
- avatar: avatar,
- id: userId,
- nickName: realName
- }
- });
- uni.navigateTo({
- url: "/chat/chatroom/chatroom?username=" + JSON.stringify(nameList)
- });
- }
- /**
- * text:展示导航名
- * iconPath:未点击显示图标
- * selectedIconPath:选中图标
- * pagePath:页面路径
- * channel:匹配名
- * click:点击事件
- * index:排序
- * show:是否显示
- */
- var selectedIconPath
- if (header.appId == 'ZQ1VK5oc17I387E') {
- selectedIconPath = '/static/pages/images/' + publics.iconSrc + 'yunyao_h.png'
- } else {
- selectedIconPath = '/static/pages/images/' + publics.iconSrc + 'home_h.png'
- }
- var tab = [{
- text: "首页",
- iconPath: "/static/pages/images/home.png",
- selectedIconPath: '/static/pages/images/home_h.png',
- pagePath: 'pages/index/index',
- channel: 'home',
- click: 'goHome',
- index: 1,
- show: true
- },
- {
- text: "活动",
- iconPath: "/static/pages/images/activity.png",
- selectedIconPath: '/static/pages/images/activity_h.png',
- pagePath: 'pages/matchList/index',
- click: 'goMatch',
- channel: 'match',
- index: 2,
- show: true
- },
- {
- text: "社区",
- iconPath: "/static/pages/images/interactive.png",
- selectedIconPath: '/static/pages/images/interactive_h.png',
- pagePath: 'pages/interactive/index',
- click: 'goInteractive',
- channel: 'interactive',
- index: 3,
- show: true
- },
- {
- text: "发现",
- iconPath: "/static/pages/images/found.png",
- selectedIconPath: '/static/pages/images/found_h.png',
- pagePath: 'pages/found/found',
- click: 'goFound',
- channel: 'found',
- index: 3,
- show: true
- },
- {
- text: "我的",
- iconPath: '/static/pages/images/user.png',
- selectedIconPath: '/static/pages/images/user_h.png',
- pagePath: 'pages/user/user',
- click: 'goUser',
- channel: 'user',
- index: 6,
- show: true
- }
- ]
- module.exports = {
- setStorage: setStorage,
- getStorage: getStorage,
- postRequest: postRequest,
- postRequestLoding: postRequestLoding,
- getRequest: getRequest,
- putRequest: putRequest,
- putRequestJson: putRequestJson,
- msg: msg,
- g: g,
- p: p,
- env: env,
- send: send,
- redirectIndex: redirectIndex,
- saveImage: saveImage,
- saveImageToPhotosAlbum: saveImageToPhotosAlbum,
- uploadFile: uploadFile,
- msgConfirm: msgConfirm,
- getConfig: getConfig,
- load: load,
- isLogin: isLogin,
- isLogins: isLogins,
- payOrder: payOrder,
- payOrders: payOrders,
- getLocation: getLocation,
- scopeAddress: scopeAddress,
- isAuth: isAuth,
- alertMsg: alertMsg,
- getToken: getToken,
- loadIng: loadIng,
- removeStorage: removeStorage,
- public: publics,
- header: header,
- // gettmplIds: gettmplIds,
- excludeSpecial: excludeSpecial,
- tab: tab,
- msgConfirmText: msgConfirmText,
- silenceLogin: silenceLogin,
- getWXUserProfile: getWXUserProfile,
- updataWxInfos: updataWxInfos,
- saveBehavior: saveBehavior,
- getBehavior: getBehavior,
- unitConverter: unitConverter,
- initIMChat: initIMChat,
- getIMToken: getIMToken,
- jumpConversation: jumpConversation,
- jumpSingleChatRoom: jumpSingleChatRoom,
- getsysConfig:getsysConfig
- }
|