123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536 |
- import * as config from '../config'
- const selectContractNo = {}
- const detailData = {}
- const erpWarehouse = {}
- let rolesList = []
- const gjList = []
- const dtList = []
- const now = Date.now || function() {
- return new Date().getTime();
- };
- const isArray = Array.isArray || function(obj) {
- return obj instanceof Array;
- };
- const getListByUserId = function() {
- let baseUrlNew = config.def().baseUrlNew
- var userInfo = uni.getStorageSync("userInfo")
- var pcUserInfo = uni.getStorageSync("pcUserInfo")
- console.log("------", userInfo)
- if (pcUserInfo) {
- uni.request({
- url: baseUrlNew + '/commonUser/getListByUserId',
- data: {
- staffMobilePhone: pcUserInfo.userMobilePhone,
- compId: pcUserInfo.compId
- },
- method: 'POST',
- success: (res) => {
- if (res.statusCode === 200) {
- // debugger
- rolesList = []
- uni.setStorageSync("jurisdiction", res.data.data)
- let list = getUserAllRoles(res.data.data);
- uni.setStorageSync("rolesList", list)
- }
- }
- })
- }
- }
- const getUserAllRoles = (item) => {
- console.log(item)
- // debugger
- 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 contactCustomerService = (phone) => {
- console.log(phone)
- //客服
- if (!phone) {
- phone = '18241771147'
- }
- 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 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 getNowFormatDate = () => {
- var date = new Date();
- var seperator1 = "-";
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var strDate = date.getDate();
- if (month >= 1 && month <= 9) {
- month = "0" + month;
- }
- if (strDate >= 0 && strDate <= 9) {
- strDate = "0" + strDate;
- }
- var currentdate = year + seperator1 + month + seperator1 + strDate;
- return currentdate;
- }
- //获取当天+N日期
- const getNowNumFormatDate = (num) => {
- var date = new Date();
- var seperator1 = "-";
- var year = date.getFullYear();
- var month = date.getMonth() + 1;
- var strDate = date.getDate() + num;
- if (month >= 1 && month <= 9) {
- month = "0" + month;
- }
- if (strDate >= 0 && strDate <= 9) {
- strDate = "0" + strDate;
- }
- var currentdate = year + seperator1 + month + seperator1 + strDate;
- return currentdate;
- }
- const convertCurrency = (money) => {
- //汉字的数字
- var cnNums = new Array('零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖');
- //基本单位
- var cnIntRadice = new Array('', '拾', '佰', '仟');
- //对应整数部分扩展单位
- var cnIntUnits = new Array('', '万', '亿', '兆');
- //对应小数部分单位
- var cnDecUnits = new Array('角', '分', '毫', '厘');
- //整数金额时后面跟的字符
- var cnInteger = '整';
- //整型完以后的单位
- var cnIntLast = '元';
- //最大处理的数字
- var maxNum = 999999999999999.9999;
- //金额整数部分
- var integerNum;
- //金额小数部分
- var decimalNum;
- //输出的中文金额字符串
- var chineseStr = '';
- //分离金额后用的数组,预定义
- var parts;
- if (money == '') {
- return '';
- }
- money = parseFloat(money);
- if (money >= maxNum) {
- //超出最大处理数字
- return '';
- }
- if (money == 0) {
- chineseStr = cnNums[0] + cnIntLast + cnInteger;
- return chineseStr;
- }
- //转换为字符串
- money = money.toString();
- if (money.indexOf('.') == -1) {
- integerNum = money;
- decimalNum = '';
- } else {
- parts = money.split('.');
- integerNum = parts[0];
- decimalNum = parts[1].substr(0, 4);
- }
- //获取整型部分转换
- if (parseInt(integerNum, 10) > 0) {
- var zeroCount = 0;
- var IntLen = integerNum.length;
- for (var i = 0; i < IntLen; i++) {
- var n = integerNum.substr(i, 1);
- var p = IntLen - i - 1;
- var q = p / 4;
- var m = p % 4;
- if (n == '0') {
- zeroCount++;
- } else {
- if (zeroCount > 0) {
- chineseStr += cnNums[0];
- }
- //归零
- zeroCount = 0;
- chineseStr += cnNums[parseInt(n)] + cnIntRadice[m];
- }
- if (m == 0 && zeroCount < 4) {
- chineseStr += cnIntUnits[q];
- }
- }
- chineseStr += cnIntLast;
- }
- //小数部分
- if (decimalNum != '') {
- var decLen = decimalNum.length;
- for (var i = 0; i < decLen; i++) {
- var n = decimalNum.substr(i, 1);
- if (n != '0') {
- chineseStr += cnNums[Number(n)] + cnDecUnits[i];
- }
- }
- }
- if (chineseStr == '') {
- chineseStr += cnNums[0] + cnIntLast + cnInteger;
- } else if (decimalNum == '') {
- chineseStr += cnInteger;
- }
- return chineseStr;
- }
- //获取省份简称
- 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 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 fUN_AmapLocation = uni.requireNativePlugin('FUN-AmapLocation');
- 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, '/')
- }
- }
- }
- }
- export default {
- changeTime,
- detailData,
- selectContractNo,
- contactCustomerService,
- now,
- isArray,
- erpWarehouse,
- getListByUserId,
- setAudit,
- getNowFormatDate,
- getNowNumFormatDate,
- getProvinceAbbreviation,
- convertCurrency,
- filterUrban,
- filterArea,
- gjList,
- dtList,
- fUN_AmapLocation
- }
|