import * as config from '../config' var sdkwx = uni.requireNativePlugin('Hdgq-LocSdkWX'); const rolesList = [] const gjList=[] const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/'; const chooseImage = { count: '1', sizeType: ['original', 'compressed'], sourceType: ['album'], } const imgType = '请选择图片来源' const imgTypeList = [{ name: '相册', }, { name: '拍照', } ] //定位sdk授权 const sdkAuth = function(){ var enterpriseSenderCode = config.def().enterpriseSenderCode var environment = config.def().environment var appId = '' var appSecurity = '' let phoneType = uni.getSystemInfoSync().platform //判断手机类型 if (phoneType == "android") { appId = config.def().androidAppId appSecurity = config.def().androidAppSecurity } else if (phoneType == "ios") { appId = config.def().iosAppId appSecurity = config.def().iosAppSecurity } console.log("appid:" + appId + "安全码:" + appSecurity + "发送代码:" + enterpriseSenderCode) sdkwx.auth(appId, appSecurity, enterpriseSenderCode, environment, function(res) { if (res.type == "onSuccess") { //成功 console.log("授权成功") console.log(res) } else if (res.type == "onFailure") { //失败 var errorCode = res.data.errorCode; //错误码 var errorMsg = res.data.errorMsg; //错误描述 console.log("授权失败") console.log(res) } }); } //定位sdk开启 const sdkStart = function(carNo,driverName,remark,shippingNoteInfos){ sdkwx.start(carNo, driverName, remark, shippingNoteInfos, function(res) { if (res.type == "onSuccess") { //成功 console.log("开启定位成功!!!") console.log(res) var shippingNoteInfos = res.data[0]; //运单信息列表 console.log(shippingNoteInfos, "sdassss") if (shippingNoteInfos) { let dateTtime = Number(shippingNoteInfos.interval + 1000) console.log("开始定时", dateTtime) // that.send() } } else if (res.type == "onFailure") { //失败 console.log("开启定位失败!!!") console.log(res) var errorCode = res.data.errorCode; //错误码 var errorMsg = res.data.errorMsg; //错误描述 setTimeout(() => { console.log("定时") // that.send() }, 915204); } }); } // 当前日期是否超过今天(校验有效期) const periodOfValidity=function(year1,month1,day1){ let nowDate = new Date(); let year = nowDate.getFullYear() let month = nowDate.getMonth() + 1 let day = nowDate.getDate() if(year1 { if (res.statusCode === 200) { uni.setStorageSync("jurisdiction", res.data.data) let list = getUserAllRoles(res.data.data); uni.setStorageSync("rolesList", list) } } }) } } const getUserAllRoles = (item) => { console.log(item) for (let i = 0; i < item.length; i++) { rolesList.push(item[i].name) // console.log('用户权限',rolesList) if (item[i].children && item[i].children.length > 0) { getUserAllRoles(item[i].children) } } return rolesList; } const setAudit = (item) => { let _list = uni.getStorageSync("copyTaskInfo") let _isShowbtn = true if (_list.length == 0) { _isShowbtn = false } for (let i = 0; i < _list.length; i++) { if (_list[i].businessId == item.id) { _list.splice(i, 1) uni.setStorageSync("copyTaskInfo", _list) } } if (_list.length > 0) { uni.navigateTo({ url: _list[0].itemUrl + '&isShowbtn=' + _isShowbtn, }) } console.log(item) } const contactCustomerService = (phone) => { console.log(phone) //客服 if (!phone) { phone = '4006688647' } const res = uni.getSystemInfoSync(); // ios系统默认有个模态框 if(res.platform=='ios'){ uni.makePhoneCall({ phoneNumber:phone, success(){ console.log('拨打成功了'); }, fail() { console.log('拨打失败了'); } }) }else{ //安卓手机手动设置一个showActionSheet uni.showActionSheet({ itemList: [phone,'呼叫'], success:function(res){ console.log(res); if(res.tapIndex==1){ uni.makePhoneCall({ phoneNumber: phone, success: (res) => { console.log('调用成功!') }, // 失败回调 fail: (res) => { console.log('调用失败!') // contactCustomerService(item) } }) } } }) } // console.log("联系客服") // uni.makePhoneCall({ // phoneNumber: item, // success: (res) => { // console.log('调用成功!') // }, // // 失败回调 // fail: (res) => { // console.log('调用失败!') // contactCustomerService(item) // } // }); } // 获取市、区简称 const filterUrban = (s) => { if (s.lastIndexOf('市') != -1) { return s.substring(0, s.length - 1) } return s } const filterArea = (q) => { if (q.lastIndexOf('区') != -1) { return q.substring(0, q.length - 1) } return q } // 根据当前时间获取本周一到本周日日期 function getDates() { // var new_Date = new Date(t2) var new_Date = new Date() var timesStamp = new_Date.getTime() var currenDay = new_Date.getDay() var dates = [] for (var i = 0; i < 7; i++) { dates.push(new Date(timesStamp + 24 * 60 * 60 * 1000 * (i - (currenDay + 6) % 7)).toLocaleDateString().replace( /[年月]/g, '-').replace(/[日上下午]/g, '')); } var weekStar = new Date(dates[0] + ' 00:00:00').getTime() var weekEnd = new Date(dates[dates.length - 1] + ' 23:59:59').getTime() var week = [weekStar, weekEnd] return week } //判断是否是今天,昨天,明天 function isToday(str,type) { //type == 0 判断是否是今天,type == 1 判断是否是昨天,type == 2 判断是否是明天 if (type == 0){ if (new Date(str).toDateString() === new Date().toDateString()) { // console.log('今天'); return true } else{ // console.log('不是今天'); return false } }if (type == 1) { if (new Date(str).toDateString() === new Date(new Date().getTime() -1000 * 60 * 60 * 24).toDateString()) { // console.log('昨天'); return true } else{ // console.log('不是昨天'); return false } } if (type == 2) { if (new Date(str).toDateString() === new Date(new Date().getTime() +1000 * 60 * 60 * 24).toDateString()) { // console.log('明天'); return true } else{ // console.log('不是明天'); return false } } } const changeTime = (t1) => { // console.log(t1) // t1截止时间 t2当前时间 // 调用getDtes函数把当前时间传过去,获取本周一和本周日时间戳 // var weeks = getDates(t2) var weeks = getDates() // console.log(weeks) var dateBegin = new Date(t1.replace(/-/g,'/'))//解决ios时new Date(2021-04-17 09:50:20)报错 // var dateEnd = new Date(t2) var dateEnd = new Date() // 时间戳 var end = dateBegin.getTime() // console.log(end) var nows = dateEnd.getTime() // console.log(nows) // 获取当天0点时间戳todayStar const start = new Date(new Date(dateEnd).toLocaleDateString()) start.setTime(start.getTime()) var todayStar = new Date(start).getTime() // console.log(todayStar) // 获取当天23点59分59秒时间戳todayEnd var ends = new Date(new Date(new Date(dateEnd).toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1) var todayEnd = new Date(ends).getTime() // console.log(todayEnd) // 时间差的毫秒数 var dateDiff = Math.abs(dateBegin.getTime() - dateEnd.getTime()) // 计算出相差天数 var dayDiff = Math.floor(dateDiff / (24 * 3600 * 1000)) // console.log(dayDiff); // 计算天数后剩余的毫秒数 var leave1 = dateDiff % (24 * 3600 * 1000) // 计算出小时数 var hours = Math.floor(leave1 / (3600 * 1000)) // console.log(hours); // 计算相差分钟数 var leave2 = leave1 % (3600 * 1000) // 计算小时数后剩余的毫秒数 // 计算相差分钟数 var minutes = Math.floor(leave2 / (60 * 1000)) // console.log(minutes); // t1截止时间 t2当前时间 if (dateEnd < dateBegin) { if ((dayDiff === 0)) { if (hours === 0) { if (minutes < 30 || minutes == 30) { return minutes + '分钟后' }else{ return '今天' + t1.substring(10, 16) } } else { if (isToday(end,0)) { return '今天' + t1.substring(10, 16) }else{ return '明天' + t1.substring(10, 16) } } } else if (dayDiff === 1) { if (isToday(end,2)){ return '明天' + t1.substring(10, 16) }else{ if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) { var weekArray = new Array('日', '一', '二', '三', '四', '五', '六') var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date return '周' + week + t1.substring(10, 16) } else { return t1.substring(0, 16).replace(/-/g, '/') } } } else { if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) { var weekArray = new Array('日', '一', '二', '三', '四', '五', '六') var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date return '周' + week + t1.substring(10, 16) } else { return t1.substring(0, 16).replace(/-/g, '/') } } } if (dateEnd === dateBegin) { return '刚刚' } if (dateEnd > dateBegin) { if (dayDiff === 0) { if (hours === 0) { if (minutes < 60 || minutes == 60) { if (minutes < 5 || minutes == 5) { return '刚刚' } else { return minutes + '分钟前' } } else { return '今天' + t1.substring(10, 16) } } else { if (isToday(end,0)) { return hours+'小时前' }else{ return '昨天' + t1.substring(10, 16) } } } else if (dayDiff === 1) { if (isToday(end,1)){ // return '昨天' + t1.substring(10, 16) return dayDiff + '天前' }else{ if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) { var weekArray = new Array('日', '一', '二', '三', '四', '五', '六') var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date return '周' + week + t1.substring(10, 16) } else { return t1.substring(0, 16).replace(/-/g, '/') } } }else if (dayDiff < 30){ // return dayDiff +'天前'+ t1.substring(10, 16) return dayDiff +'天前' }else if (dayDiff > 30 && dayDiff < 365){ return t1.substring(5, 10) }else if (dayDiff > 365){ return t1.substring(0, 4) }else { if ((weeks[0] < end || weeks[0] == end) && (weeks[1] > end || weeks[1] == end)) { var weekArray = new Array('日', '一', '二', '三', '四', '五', '六') var week = weekArray[new Date(t1.replace(/-/g,'/')).getDay()] // 注意此处必须是先new一个Date return '周' + week + t1.substring(10, 16) } else { return t1.substring(0, 16).replace(/-/g, '/') } } } } const formatLocation = (str) => { let area = {} let index11 = 0 let index1 = str.indexOf("省") if (index1 == -1) { index11 = str.indexOf("自治区") if (index11 != -1) { area.Province = str.substring(0, index11 + 3) } else { area.Province = str.substring(0, 0) } } else { area.Province = str.substring(0, index1 + 1) } let index2 = str.indexOf("市") if (index11 == -1) { area.City = str.substring(index11 + 1, index2 + 1) } else { if (index11 == 0) { area.City = str.substring(index1 + 1, index2 + 1) } else { area.City = str.substring(index11 + 3, index2 + 1) } } let index3 = str.indexOf("区") if (index3 == -1) { index3 = str.indexOf("县") if (index3 == -1) { index3 = str.lastIndexOf("市") if (index3 == -1) { index3 = str.indexOf("镇") if (index3 == -1) { } else { area.Country = str.substring(index2 + 1, index3 + 1) } } else { area.Country = str.substring(index2 + 1, index3 + 1) } } else { area.Country = str.substring(index2 + 1, index3 + 1) } } else { area.Country = str.substring(index2 + 1, index3 + 1) } area.Village = str.substring(index3 + 1, str.length) return area; } //获取省份简称 const getProvinceAbbreviation = (province) => { if (province == "北京市" || province == "北京") return "京"; else if (province == "天津市" || province == "天津") return "津"; else if (province == "重庆市" || province == "重庆") return "渝"; else if (province == "上海市" || province == "上海") return "沪"; else if (province == "河北省" || province == "河北") return "冀"; else if (province == "山西省" || province == "山西") return "晋"; else if (province == "辽宁省" || province == "辽宁") return "辽"; else if (province == "吉林省" || province == "吉林") return "吉"; else if (province == "黑龙江省" || province == "黑龙江") return "黑"; else if (province == "江苏省" || province == "江苏") return "苏"; else if (province == "浙江省" || province == "浙江") return "浙"; else if (province == "安徽省" || province == "安徽") return "皖"; else if (province == "福建省" || province == "福建") return "闽"; else if (province == "江西省" || province == "江西") return "赣"; else if (province == "山东省" || province == "山东") return "鲁"; else if (province == "河南省" || province == "河南") return "豫"; else if (province == "湖北省" || province == "湖北") return "鄂"; else if (province == "湖南省" || province == "湖南") return "湘"; else if (province == "广东省" || province == "广东") return "粤"; else if (province == "海南省" || province == "海南") return "琼"; else if (province == "四川省" || province == "四川") return "川"; else if (province == "贵州省" || province == "贵州") return "贵"; else if (province == "云南省" || province == "云南") return "云"; else if (province == "陕西省" || province == "陕西") return "陕"; else if (province == "甘肃省" || province == "甘肃") return "甘"; else if (province == "青海省" || province == "青海") return "青"; else if (province == "台湾省" || province == "台湾") return "台"; else if (province == "内蒙古自治区" || province == "内蒙古") return "蒙"; else if (province == "广西壮族自治区" || province == "广西") return "桂"; else if (province == "宁夏回族自治区" || province == "宁夏") return "宁"; else if (province == "新疆维吾尔自治区" || province == "新疆") return "新"; else if (province == "西藏自治区" || province == "西藏") return "藏"; else if (province == "香港特别行政区" || province == "香港") return "港"; else if (province == "澳门特别行政区" || province == "澳门") return "澳"; } export default { getListByUserId, setAudit, ossUploadUrl, contactCustomerService, chooseImage, imgType, imgTypeList, makeValidityPeriod, periodOfValidity, sdkAuth, getProvinceAbbreviation, formatLocation, filterUrban, filterArea, sdkStart, fUN_AmapLocation, changeTime, gjList }