import * as config from '../config' const rolesList = [] const ossUploadUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/'; const chooseImage = { count: '1', sizeType: ['original', 'compressed'], sourceType: ['album'], } const imgType = '请选择图片来源' const imgTypeList = [{ name: '相册', }, { name: '拍照', } ] // 当前日期是否超过今天(校验有效期) 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 < year) { return false } if (year1 == year && month1 < month) { return false } if (year1 == year && month1 == month && day1 <= day) { return false } return true } const makeValidityPeriod = function(type, name) { //获取当前年 let nowDate = new Date(); let year = nowDate.getFullYear() let _list = [] let _list1 = [] // let _list2 = ["一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"] let _list2 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"] let _list3 = ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" ] let _ValidityPeriod = [] for (let i = 0; i < 30; i++) { _list1.push(year + i) } if (type == 0) { _list1.unshift(name) _list2.unshift('') _list3.unshift('') } _list.push(_list1, _list2, _list3) return _list } const getListByUserId = function() { let baseUrlNew = config.def().baseUrlNew var userInfo = uni.getStorageSync("userInfo") console.log("------", userInfo) if (userInfo) { uni.request({ url: baseUrlNew + '/roleMenu/query/getListByUserId', data: { userId: userInfo.id ? userInfo.id : userInfo.data.id }, method: 'GET', success: (res) => { 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 } // const getAddress = (item) => { // let regex = "(?[^省]+省|.+自治区)(?[^自治州]+自治州|[^市]+市|[^盟]+盟|[^地区]+地区|.+区划)(?[^市]+市|[^县]+县|[^旗]+旗|.+区)?(?[^区]+区|.+镇)?(?.*)"; // return item.match(regex).groups // } // 辽宁省沈阳市新民市公主屯镇委公主屯派出所 const formatLocation = (str) => { // console.log('``````') // console.log(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 "澳"; } const getDistance = (lat1, lng1, lat2, lng2) => { function Rad(d) { return d * Math.PI / 180.0; } if (!lat1 || !lng1) { return ''; } // lat1用户的纬度 // lng1用户的经度 // lat2商家的纬度 // lng2商家的经度 let radLat1 = Rad(lat1); let radLat2 = Rad(lat2); let a = radLat1 - radLat2; let b = Rad(lng1) - Rad(lng2); let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow( Math.sin(b / 2), 2))); s = s * 6378.137; s = Math.round(s * 10000) / 10000; s = s.toFixed(2) //保留两位小数 return s } const logout = () => { uni.removeStorage({ key: 'userInfo' }) } export default { getListByUserId, setAudit, ossUploadUrl, contactCustomerService, chooseImage, periodOfValidity, imgType, imgTypeList, makeValidityPeriod, getProvinceAbbreviation, // getAddress, formatLocation, getDistance, logout, filterUrban, filterArea }