/* eslint-disable */ import mRouter from '@/utils/router'; import mStore from '@/store'; import appShare from '@/utils/share'; import { http } from '@/utils/request'; import pageData from "@/pages/myTask/repairList/addRepair/pageData.js" export default { /** * toast提示 */ toast(title, duration = 3000, mask = false, icon = 'none') { if (Boolean(title) === false) { return; } uni.showToast({ title, duration, mask, icon }); }, // 工单状态 stateComm(type) { const state = { 1: 1000, 2: 2000, 3: 3000, 4: 4000 } return state[type] }, // 通过工单标识获取到工单id getOrderId(id,fn) { const params = { pid:0, flag:1 } http.get("GongDanType/GetList",params).then((res)=>{ if(res.state.toLowerCase() ==="success"){ res.data.forEach(v => { if(v.identification == id) { fn(v.id) } }) } }) }, httpPost(url, params, delta,fn) { uni.showLoading({title: '加载中'}) http.post(url, params).then((res) => { uni.hideLoading() if (res.state.toLowerCase() === "success") { uni.showToast({ title: '操作成功', duration: 500 }); setTimeout(() => { uni.$emit("updateList", {}); //列表刷新数据 uni.navigateBack({delta}) fn(false) }, 500) }else{ this.toast(res.message) fn(false) } }) }, httpGetDetail(url, type, workorderid, fn) { const params = { type, workorderid, token: uni.getStorageSync("token"), } http.get(url, params).then((response) => { if (response.state.toLowerCase() === "success") { fn(response.data) } }).catch((e) => { console.log(e); }) }, // 通过名称获取id getValueByText(text, data) { let value; data.forEach(v =>{ if(v.text == text){ value = v.value } }) return value }, // 通过id获取工单标识 getIdentification(treeData, id){ for (let i = 0; i < treeData.length; i++) { if (treeData[i].id == id) { return treeData[i].identification } else { if (treeData[i].children) { var res = this.getIdentification(treeData[i].children, id) if (res !== undefined) { return res } } } } }, // 详情返回页面 参数表示页面回退几级 returnPage(index) { uni.navigateBack({ delta: index, }) }, getImgString(string) { const imgIdListToString= string.toString() const imgid = (imgIdListToString.substring(imgIdListToString.length - 1) == ',') ? imgIdListToString.substring(0, imgIdListToString.length - 1) : imgIdListToString; return imgid }, // 防抖 // 例子 debounceList = debounce(getList, 5000)先声明 // 后debounceList()调用,每个页面声明一次即可,调用可多次 debounce(fn, delay=3000, immediate = false, resultCallback) { // 1.定义一个定时器, 保存上一次的定时器 let timer = null let isInvoke = false // 2.真正执行的函数 const _debounce = function(...args) { return new Promise((resolve, reject) => { // 取消上一次的定时器 if (timer) clearTimeout(timer) // 判断是否需要立即执行 if (immediate && !isInvoke) { const result = fn.apply(this, args) if (resultCallback) resultCallback(result) resolve(result) isInvoke = true } else { // 延迟执行 timer = setTimeout(() => { // 外部传入的真正要执行的函数 const result = fn.apply(this, args) if (resultCallback) resultCallback(result) resolve(result) isInvoke = false timer = null }, delay) } }) } // 封装取消功能 _debounce.cancel = function() { if (timer) clearTimeout(timer) timer = null isInvoke = false } return _debounce }, // 通过子级部门id获取父级 callback(treeData, id){ for (let i = 0; i < treeData.length; i++) { if (Number(treeData[i].id) == Number(id)) { return [treeData[i].text] } else { if (treeData[i].children) { var res = this.callback(treeData[i].children, id) if (res !== undefined) { return res.concat(treeData[i].text) } } } } }, findParents(treeData, id) { let string = '' if (treeData.length == 0) return if (id == undefined) return if(this.callback(treeData, id) !== undefined) { this.callback(treeData, id).reverse().forEach((v,n) => { string += v + '/' }) } const text = (string.substring(string.length - 1) == '/') ? string.substring(0, string.length - 1) : string; return text }, // 通过工单类别获取对应部门id getDepartidByOrderid(treeData, id){ for (let i = 0; i < treeData.length; i++) { if (Number(treeData[i].id) == Number(id)) { return [treeData[i].autoDept]+ ','+ [treeData[i].identification] } else { if (treeData[i].children) { var res = this.callback(treeData[i].children, id) if (res !== undefined) { return res.concat(treeData[i].autoDept) + ','+ [treeData[i].identification] } } } } }, // 通过科室编码获取对应部门id getDepartidByDepartCode(treeData, code){ for (let i = 0; i < treeData.length; i++) { if (treeData[i].identification == code) { return treeData[i].id } else { if (treeData[i].children) { var res = this.getDepartidByDepartCode(treeData[i].children, code) if (res !== undefined) { console.log(treeData[i].id) return res } } } } }, findUserName(data, id) { let string = '' if (!id) { return '' } else { data.forEach((v, n) => { if (v.value == id) { string = v.text } }) } return string }, //获取当前时间 CurentTime() { const now = new Date(); const year = now.getFullYear(); //年 const month = now.getMonth() + 1; //月 .toString().padstart(2,0) const day = now.getDate().toString().padStart(2, 0); //日 const hh = now.getHours().toString().padStart(2, 0); //时 const mm = now.getMinutes().toString().padStart(2, 0); //分 const ss = now.getSeconds().toString().padStart(2, 0); //秒 return year + "-" + month.toString().padStart(2, 0) + "-" + day + " " + hh + ":" + mm + ":" + ss; }, /** *获取当前日期: YYYY-MM-DD */ getNowDate() { var myDate = new Date(); myDate.getYear(); // 获取当前年份(2位) var YY = myDate.getFullYear(); // 获取完整的年份(4位,1970-????) var MM = myDate.getMonth() + 1; // 获取当前月份(0-11,0代表1月) MM = MM > 9 ? MM : "0" + MM; var DD = myDate.getDate(); // 获取当前日(1-31) DD = DD > 9 ? DD : "0" + DD; return YY + "-" + MM + "-" + DD; }, getPreDate(pdate = 3600 * 1000 * 24 * 30) { const start = new Date(); start.setTime(start.getTime() - pdate); start.getYear(); // 获取当前年份(2位) const YY = start.getFullYear(); // 获取完整的年份(4位,1970-????) let MM = start.getMonth() + 1; // 获取当前月份(0-11,0代表1月) MM = MM > 9 ? MM : "0" + MM; let DD = start.getDate(); // 获取当前日(1-31) DD = DD > 9 ? DD : "0" + DD; return YY + "-" + MM + "-" + DD; }, //获取当前时间年月份 CurentTimeType() { const now = new Date(); const year = now.getFullYear(); //年 const month = now.getMonth() + 1; //月 .toString().padstart(2,0) const day = now.getDate().toString().padStart(2, 0); //日 const hh = now.getHours().toString().padStart(2, 0); //时 const mm = now.getMinutes().toString().padStart(2, 0); //分 const ss = now.getSeconds().toString().padStart(2, 0); //秒 return year + "年" + month.toString().padStart(2, 0) + "月" + day + "日" + hh + "时" + mm + "分" + ss + "秒"; }, /** * 返回上一页携带参数 */ prePage(index) { let pages = getCurrentPages(); let prePage = pages[pages.length - (index || 2)]; // #ifdef H5 return prePage; // #endif return prePage.$vm; }, /** * 开发环境全局打印日志 * @param {Object} title */ log(title) { if (process.env.NODE_ENV === 'development' && Boolean(title) === true) { console.log(JSON.stringify(title)); } }, /** * 异步获取设备信息 */ getInfoAsync() { return new Promise((resolve, reject) => { plus.device.getInfo({ success(e) { resolve(e); }, fail(e) { reject(e.message); } }); }); }, /** * 安卓10不支持IMEI,则获取OAID */ getOaidAsync() { return new Promise((resolve, reject) => { plus.device.getOAID({ success(e) { resolve(e); }, fail(e) { reject(e.message); } }); }); }, /** * 获取一个随机数 * @param {Object} min * @param {Object} max */ random(min, max) { switch (arguments.length) { case 1: return parseInt(Math.random() * min + 1, 10); break; case 2: return parseInt(Math.random() * (max - min + 1) + min, 10); break; default: return 0; break; } }, /** * 获取ios的IDFA */ getIdfa() { let idfa = ''; try { if ('iOS' == plus.os.name) { let manager = plus.ios.invoke('ASIdentifierManager', 'sharedManager'); if (plus.ios.invoke(manager, 'isAdvertisingTrackingEnabled')) { let identifier = plus.ios.invoke(manager, 'advertisingIdentifier'); idfa = plus.ios.invoke(identifier, 'UUIDString'); plus.ios.deleteObject(identifier); } plus.ios.deleteObject(manager); } } catch (e) { console.error('获取idfa失败'); } return idfa; }, /* * obj 转 params字符串参数 * 例子:{a:1,b:2} => a=1&b=2 */ objParseParam(obj) { let paramsStr = ''; if (obj instanceof Array) return paramsStr; if (!(obj instanceof Object)) return paramsStr; for (let key in obj) { paramsStr += `${key}=${obj[key]}&`; } return paramsStr.substring(0, paramsStr.length - 1); }, /* * obj 转 路由地址带参数 * 例子:{a:1,b:2} => /pages/index/index?a=1&b=2 */ objParseUrlAndParam(path, obj) { let url = path || '/'; let paramsStr = ''; if (obj instanceof Array) return url; if (!(obj instanceof Object)) return url; paramsStr = this.objParseParam(obj); paramsStr && (url += '?'); url += paramsStr; return url; }, /* * 获取url字符串参数 */ getRequestParameters(locationhref) { let href = locationhref || ''; let theRequest = new Object(); let str = href.split('?')[1]; if (str != undefined) { let strs = str.split('&'); for (let i = 0; i < strs.length; i++) { theRequest[strs[i].split('=')[0]] = strs[i].split('=')[1]; } } return theRequest; }, /** * 加密字符串 */ strEncode(str) { const key = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let l = key.length; let a = key.split(''); let s = '', b, b1, b2, b3; for (let i = 0; i < str.length; i++) { b = str.charCodeAt(i); b1 = b % l; b = (b - b1) / l; b2 = b % l; b = (b - b2) / l; b3 = b % l; s += a[b3] + a[b2] + a[b1]; } return s; }, /** * 解密字符串 */ strDecode(str) { const key = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let l = key.length; let b, b1, b2, b3, d = 0, s; s = new Array(Math.floor(str.length / 3)); b = s.length; for (let i = 0; i < b; i++) { b1 = key.indexOf(str.charAt(d)); d++; b2 = key.indexOf(str.charAt(d)); d++; b3 = key.indexOf(str.charAt(d)); d++; s[i] = b1 * l * l + b2 * l + b3; } b = eval('String.fromCharCode(' + s.join(',') + ')'); return b; }, /** * 比较版本号 */ compareVersion(reqV, curV) { if (curV && reqV) { let arr1 = curV.split('.'), arr2 = reqV.split('.'); let minLength = Math.min(arr1.length, arr2.length), position = 0, diff = 0; while ( position < minLength && (diff = parseInt(arr1[position]) - parseInt(arr2[position])) == 0 ) { position++; } diff = diff != 0 ? diff : arr1.length - arr2.length; if (diff > 0) { if (position == minLength - 1) { return 1; } else { return 2; } } else { return 0; } } else { return 0; } }, /** * H5复制 */ h5Copy(content) { let textarea = document.createElement('textarea'); textarea.value = content; textarea.readOnly = 'readOnly'; document.body.appendChild(textarea); textarea.select(); // 选择对象 textarea.setSelectionRange(0, content.length); //核心 let result = document.execCommand('Copy'); // 执行浏览器复制命令 textarea.remove(); const msg = result ? '复制成功' : '复制失败'; this.toast(msg); }, /** * app分享 */ handleAppShare(shareUrl, shareTitle, shareContent, shareImg) { let shareData = { shareUrl, shareTitle, shareContent, shareImg }; appShare(shareData, res => {}); }, // 去掉字符串中的空格 trim(str) { if (!str) { return ''; } return str.replace(/\s*/g, ''); }, // 判断两个对象是否相同 isObjectValueEqual(x, y) { // 指向同一内存时 if (x === y) { return true; } else if ( typeof x == 'object' && x != null && typeof y == 'object' && y != null ) { if (Object.keys(x).length != Object.keys(y).length) return false; for (var prop in x) { if (y.hasOwnProperty(prop)) { if (!this.isObjectValueEqual(x[prop], y[prop])) return false; } else return false; } return true; } else return false; }, platformGroupFilter() { let platformGroup = 'wechat'; // #ifdef H5 platformGroup = 'h5'; // #endif // #ifdef MP-QQ platformGroup = 'qqMp'; // #endif // #ifdef MP-WEIXIN platformGroup = 'wechatMp'; // #endif // #ifdef MP-ALIPAY platformGroup = 'aliMp'; // #endif // #ifdef MP-QQ platformGroup = 'qqMp'; // #endif // #ifdef MP-BAIDU platformGroup = 'baiduMp'; // #endif // #ifdef APP-PLUS switch (uni.getSystemInfoSync().platform) { case 'android': platformGroup = 'android'; break; case 'ios': platformGroup = 'ios'; break; } // #endif return platformGroup; } };