var priceshow = false; var timeshow = false; function priceTime(){ $(".pricefat").mouseover(function(){ if(!$(".pricefat").hasClass("active")){ $("#minprice").css({"border-color":"#2cb7ca"}); $("#maxprice").css({"border-color":"#2cb7ca"}); $(".pricebut").show(); $(".pricefat").addClass("customtime-active"); } }).mouseout(function(){ if(!$(".pricefat").hasClass("active")){ if(!priceshow){ $("#minprice").css({"border-color":""}); $("#maxprice").css({"border-color":""}); $(".pricebut").hide(); $(".pricefat").removeClass("customtime-active"); } } }) $("#minprice,#maxprice").blur(function(){ if(!priceshow&&!$(".pricefat").hasClass("active")){ $("#minprice").css({"border-color":""}); $("#maxprice").css({"border-color":""}); $(".pricebut").hide(); $(".pricefat").removeClass("customtime-active"); } }) $("#minprice").click(function(){ priceshow=true; $(".pricebut").show(); $(".pricefat").addClass("customtime-active"); }) $("#maxprice").click(function(){ priceshow=true; $(".pricebut").show(); $(".pricefat").addClass("customtime-active"); }) // $(".timerInput").mouseover(function(){ if(!$(".timerInput").hasClass("active")){ $("#starttime").css({"border-color":"#2cb7ca"}); $("#endtime").css({"border-color":"#2cb7ca"}); $("#timebut").show(); $(".timerInput").addClass("customtime-active"); } }).mouseout(function(){ if(!$(".timerInput").hasClass("active")){ if(!timeshow){ $("#starttime").css({"border-color":""}); $("#endtime").css({"border-color":""}); $("#timebut").hide(); $(".timerInput").removeClass("customtime-active"); } } }) // $("#starttime").click(function(){ timeshow = true; $("#timebut").show(); $(".timerInput").addClass("customtime-active"); $('.custom-select').css("border-color", '#e0e0e0').children('.icon-arrow').removeClass('up') $('.custom-select').siblings().hide() }) $("#endtime").click(function(){ timeshow = true; $("#timebut").show(); $(".timerInput").addClass("customtime-active"); $('.custom-select').css("border-color", '#e0e0e0').children('.icon-arrow').removeClass('up') $('.custom-select').siblings().hide() }) } function showToast (text, duration) { if (!text) return duration = duration || 2000 var _html = "" _html+='
' _html+='' + text + '
' $('body').append(_html) setTimeout(function(){ $('#j-toast').fadeOut().remove(); }, duration) } var EasyAlert = { timeout: null, waitTime: 1000, show: function(text,css,waitTime){ if(this.timeout != null){ clearTimeout(this.timeout); this.hide(); this.timeout = null; } var thisClass = this; this.timeout = setTimeout(function(){ thisClass.hide(); thisClass.timeout = null; },waitTime?waitTime:this.waitTime); $("body").append('
'+text+'
'); if(typeof(css) != "undefined"&&css!=""){ $("#easyAlert").css(css); } $("#easyAlert").css({"left":"50%","margin-top":-($("#easyAlert").outerHeight()/2),"margin-left":-($("#easyAlert").outerWidth()/2)}).show(); }, hide: function(){ $("#easyAlert").remove(); } } var EasyPopup = function(id){ this.id = id; var thisClass = this; document.getElementById(id).ontap = function(e){ if(e.target.id == id){ thisClass.hide(); } } this.show = function(){ $("#"+this.id).fadeIn(); var mainObj = $("#"+id+">div:first"); mainObj.css({"margin-top":-(mainObj.outerHeight()/2 + 35)}); }, this.hide = function(){ $("#"+this.id).fadeOut(); } } // 部分页面没有全局工具函数 if (typeof utils !== 'object') { utils = {} } Date.prototype.pattern = function (fmt) { if (!fmt) return '' var o = { 'y+': this.getFullYear(), 'M+': this.getMonth() + 1, // 月份 'd+': this.getDate(), // 日 // 12小时制 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时 // 24小时制 'H+': this.getHours(), // 小时 'm+': this.getMinutes(), // 分 's+': this.getSeconds(), // 秒 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度 'S': this.getMilliseconds(), // 毫秒 'E+': this.getDay(), // 周 }; var week = { '0': '日', '1': '一', '2': '二', '3': '三', '4': '四', '5': '五', '6': '六' }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); } if (/(E+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '星期' : '周') : '') + week[ this.getDay() + '']); } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]) .length))); } } return fmt; } utils.dateFromNow = function (originTime, useOld) { if (!originTime) return // 原始时间 - 传入的时间戳 var originTimeStamp = +new Date(originTime) // 当前时间戳 var nowTimeStamp = +new Date() // 时间戳相差多少 var diffTimeStamp = nowTimeStamp - originTimeStamp var postfix = diffTimeStamp > 0 ? '前' : '后' // 求绝对值 ms(毫秒) var diffTimeStampAbsMs = Math.abs(diffTimeStamp) var diffTimeStampAbsS = Math.round(diffTimeStampAbsMs / 1000) // 10天的秒数 var days11 = 11 * 24 * 60 * 60 // var dataMap = { // zh: ['年', '个月', '星期', '天', '小时', '分钟', '秒'], // number: [365*24*60*60, 30*24*60*60, 7*24*60*60, 24*60*60, 60*60, 60, 1] // } var dataMap = { zh: ['天', '小时', '分钟', '秒'], number: [24 * 60 * 60, 60 * 60, 60, 1] } var timeString = '' // 10天前 var tenDaysAgo = diffTimeStampAbsS > days11 // 是否是当天 var isCurrentDay = new Date(originTimeStamp).pattern('yyyy.MM.dd') === new Date().pattern('yyyy.MM.dd') var condition = !isCurrentDay if (useOld) { condition = tenDaysAgo } if (condition) { // 不是当天,则使用正常日期显示 var originDate = new Date(originTimeStamp) var nowDate = new Date() // 是否同年 var sameYear = originDate.getFullYear() === nowDate.getFullYear() // 如果是当年,则不显示年 var patternString = sameYear ? 'MM-dd' : 'yyyy-MM-dd' timeString = originDate.pattern(patternString) } else { for (var i = 0; i < dataMap.number.length; i++) { var inm = Math.floor(diffTimeStampAbsS / dataMap.number[i]) if (inm != 0) { timeString = inm + dataMap.zh[i] + postfix break } } } return timeString } //计算时差 function timeDiff(date){ var date1 = date;//开始时间 var date2 = new Date();//结束时间 var date3 = date2.getTime()-date1.getTime();//时间差的毫秒数 //计算出相差天数 var days = Math.floor(date3/(24*3600*1000)); //计算出小时数 var leave1 = date3%(24*3600*1000);//计算天数后剩余的毫秒数 var hours = Math.floor(leave1/(3600*1000)); //计算相差分钟数 var leave2 = leave1%(3600*1000);//计算小时数后剩余的毫秒数 var minutes = Math.floor(leave2/(60*1000)); //计算相差秒数 var td = "30秒前"; if(days > 0){ if (days > 10) { var date1year = date1.getFullYear(); var date2year = date2.getFullYear(); var date1month = date1.getMonth()+1; var date1day = date1.getDate(); if(date1month < 10){ date1month ="0"+date1month; } if(date1day < 10){ date1day ="0"+date1day; } if (date1year 0){ td = hours+"小时前"; }else if(minutes > 0){ td = minutes+"分钟前"; } return td; } function redirect(zbadd,link,sid,sds){ if(link != null && typeof(link) != "undefined"){ link = link.replace(/\n/g,""); if(!/^http/.test(link)){ link="http://"+link } } if(sds){ window.location.href="/article/content/"+sid+".html?keywords="+encodeURIComponent(sds); }else{ window.location.href="/article/content/"+sid+".html"; } } function newredirect(zbadd,link,sid,sds,index){ if(link != null && typeof(link) != "undefined"){ link = link.replace(/\n/g,""); if(!/^http/.test(link)){ link="http://"+link } } var pt = "" if (index==1){ pt="projectMatch=项目匹配" } if(sds){ pt = "&"+pt window.location.href="/article/content/"+sid+".html?keywords="+encodeURIComponent(sds)+pt; }else{ window.location.href="/article/content/"+sid+".html"+pt; } } function pcredirect(link,sid){ window.open("/pcdetail/"+sid+".html"); } var isNumber = /^[0-9]+$/ var isLetter = /^[a-zA-Z]+$/ function isRegExp (value) { return Object.prototype.toString.call(value) === '[object RegExp]' } function keyWordHighlight (value, oldChars, newChar) { if(typeof(oldChars) == "undefined" || oldChars == null || typeof(newChar) == "undefined" || newChar == null || newChar == "" || oldChars == '略'){ return value; } var array = []; if(oldChars instanceof Array){ array = oldChars.concat(); }else{ array.push(oldChars); } // 非字符串替换集合 var notStrReplacer = [] for (var i = 0; i < array.length; i++) { if (!array[i]) { continue } else { if (isRegExp(array[i])) { // 正则直接替换 // 注意:该正则中必须包含至少一个分组匹配,分组中的内容用来替换 notStrReplacer.push(array[i]) array[i] = '' } else { // 字符串替换 array[i] = array[i].replace(/([\$\(\)\*\+\.\[\]\?\/\\\^\{\}\|])/g, '\\$1').replace(/\s+/g, '') } // array[i] = array[i].replace(/\$/g,"\\$"); // array[i] = array[i].replace(/\(/g,"\\("); // array[i] = array[i].replace(/\)/g,"\\)"); // array[i] = array[i].replace(/\*/g,"\\*"); // array[i] = array[i].replace(/\+/g,"\\+"); // array[i] = array[i].replace(/\./g,"\\."); // array[i] = array[i].replace(/\[/g,"\\["); // array[i] = array[i].replace(/\]/g,"\\]"); // array[i] = array[i].replace(/\?/g,"\\?"); // array[i] = array[i].replace(/\\/g,"\\"); // array[i] = array[i].replace(/\//g,"\\/"); // array[i] = array[i].replace(/\^/g,"\\^"); // array[i] = array[i].replace(/\{/g,"\\{"); // array[i] = array[i].replace(/\}/g,"\\}"); // array[i] = array[i].replace(/\|/g,"\\|"); } } // 数组去空 var lastArr = [] array.forEach(function (item) { if (item) { lastArr.push(item) } }) if (lastArr.length === 0 && notStrReplacer.length === 0) { return value } lastArr = lastArr.sort(function (a, b) { return b.length - a.length }) if (notStrReplacer.length) { for (var j = 0; j < notStrReplacer.length; j++) { // 正则替换 value = value.replace(notStrReplacer[j], newChar) } } if (lastArr.length) { value = value.replace(new RegExp('(' + lastArr.join('|') + ')', 'gmi'), newChar) } return value } function getWxVersion(){ var wechatInfo = navigator.userAgent.match(/MicroMessenger\/([\d\.]+)/i); if(!wechatInfo) { return null; } return wechatInfo[1]; } /** * 设置光标在短连接输入框中的位置 * @param inpObj 输入框 * @param pos */ function setCursorPos(inpObj, pos){ if(navigator.userAgent.indexOf("MSIE") > -1){ var range = document.selection.createRange(); var textRange = inpObj.createTextRange(); textRange.moveStart('character',pos); textRange.collapse(); textRange.select(); }else{ inpObj.setSelectionRange(pos,pos); } } /** * 获取光标在短连接输入框中的位置 * @param inpObj 输入框 */ function getCursorPos(inpObj){ if(navigator.userAgent.indexOf("MSIE") > -1) { // IE var range = document.selection.createRange(); range.text = ''; range.setEndPoint('StartToStart',inpObj.createTextRange()); return range.text.length; } else { return inpObj.selectionStart; } } //获取url中参数 function getUrlParam(name){ var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if(r != null) return unescape(r[2]); return null; } /******* 获取url参数(正则)********/ function getParam(name) { var search = document.location.search; // alert(search); var pattern = new RegExp("[?&]" + name + "\=([^&]+)", "g"); var matcher = pattern.exec(search); var items = null; if (null != matcher) { try { items = decodeURIComponent(decodeURIComponent(matcher[1])); } catch (e) { try { items = decodeURIComponent(matcher[1]); } catch (e) { items = matcher[1]; } } } return items; }; //获取滚动条宽度 function getScrollWidth() { var noScroll, scroll, oDiv = document.createElement("DIV"); oDiv.style.cssText = "position:absolute; top:-1000px; width:100px; height:100px; overflow:hidden;"; noScroll = document.body.appendChild(oDiv).clientWidth; oDiv.style.overflowY = "scroll"; scroll = oDiv.clientWidth; document.body.removeChild(oDiv); return noScroll-scroll; } //表头固定 var TableHeadFixed = function(className,isminus,flag,pageName, callback){ if (typeof callback !== 'function') { callback = function () {} } if(typeof(className) == "undefined"){ className = "tabContainer-2"; } if(typeof(isminus) == "undefined"){ isminus = true; } if(typeof(flag) == "undefined"){ flag = true; } var cHeight = document.body.clientHeight; if(cHeight <= 0){ cHeight = 500; } var thisFlag = false; var prevSelectType = null; $(window).scroll(function(event){ if(!$("#right-table").hasClass("active") && flag){ return; } //超级搜索页面增加处理逻辑 if(pageName == "supsearch"){ if(prevSelectType != selectType){ thisFlag = false; } prevSelectType = selectType; if(selectType == "all"){ className = "tabContainer" }else{ className = "tabContainer-2"; } } var tableHeight = $("."+className).outerHeight(); if(tableHeight <= cHeight){ $("."+className+" .lucene-table").removeClass("tabfixed tababsolute"); $("."+className+" .lucene-table>table:first").css("top",'64px'); callback(false) thisFlag = false; return; } var offsetTop = $("."+className).offset().top; var scrollTop = $(this).scrollTop(); var oTop = offsetTop; var ooTop = offsetTop; if(isminus){ oTop+=20; ooTop-=20; } if(scrollTop >= (oTop-64)){ if(ooTop + tableHeight - scrollTop -20 <= cHeight){ if(!thisFlag){ $("."+className+" .lucene-table").addClass("tababsolute"); $("."+className+" .lucene-table>table:first").css("top",scrollTop); } thisFlag = true; }else{ if(thisFlag){ $("."+className+" .lucene-table").removeClass("tababsolute"); $("."+className+" .lucene-table>table:first").css("top",'64px'); } callback(false) thisFlag = false; } $("."+className+" .lucene-table").addClass("tabfixed"); callback(true) }else{ $("."+className+" .lucene-table").removeClass("tabfixed tababsolute"); $("."+className+" .lucene-table>table:first").css("top",'64px'); callback(false) thisFlag = false; } }); } //页面跳转输入框光标位置 function moveEnd(obj) { obj.focus(); var len = obj.value.length; if (document.selection) { var sel = obj.createTextRange(); sel.moveStart('character', len); sel.collapse(); sel.select(); } else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') { obj.selectionStart = obj.selectionEnd = len; } } function mySysIsIos(){ return !!navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端 } // 金额转换 function moneyUnit(num, type, lv) { if (num === '' || num == null || num == undefined || isNaN(num)) return '' var levelArr = ['元', '万元', '亿元', '万亿元'] if (type === void 0) { type = 'string'; } if (lv === void 0) { lv = 0; } if (num === 0) { if (type === 'string') { return '0'; } if (type === 'lv') { return levelArr[lv]; } if (type === 'number') { return 0; } if (type === 'index') { return lv; } } var result = num / Math.pow(10000, lv); if (result > 10000 && lv < 2) { return this.moneyUnit(num, type, lv + 1) } else { if (type === 'string') { return String(Math.floor(result * 100) / 100).replace('.00', '') + levelArr[lv]; } if (type === 'lv') { return levelArr[lv]; } if (type === 'index') { return lv; } if (type === 'number') { return String(Math.floor(result * 100) / 100).replace('.00', ''); } } } /* * 时间格式化函数(将时间格式化为,2019年08月12日,2019-08-12,2019/08/12的形式) * * * pattern参数(想要什么格式的数据就传入什么格式的数据) * · 'yyyy-MM-dd' ---> 输出如2019-09-20 * · 'yyyy-MM-dd hh:mm' ---> 输出如2019-09-20 08:20 * · 'yyyy-MM-dd HH:mm:ss' ---> 输出如2019-09-20 18:20:23 * · 'yyyy/MM/dd' ---> 输出如2019/09/20 * · 'yyyy年MM月dd日' ---> 输出如2019年09月20日 * · 'yyyy年MM月dd日 hh时mm分' ---> 输出如2019年09月20日 08时20分 * · 'yyyy年MM月dd日 hh时mm分ss秒' ---> 输出如2019年09月20日 08时20分23秒 * · 'yyyy年MM月dd日 hh时mm分ss秒 EE' ---> 输出如2019年09月20日 08时20分23秒 周二 * · 'yyyy年MM月dd日 hh时mm分ss秒 EEE' ---> 输出如2019年09月20日 08时20分23秒 星期二 * * 参考: https://www.cnblogs.com/mr-wuxiansheng/p/6296646.html */ Date.prototype.pattern = function (fmt) { if (!fmt) return '' var o = { 'y+': this.getFullYear(), 'M+': this.getMonth() + 1, // 月份 'd+': this.getDate(), // 日 // 12小时制 'h+': this.getHours() % 12 == 0 ? 12 : this.getHours() % 12, // 小时 // 24小时制 'H+': this.getHours(), // 小时 'm+': this.getMinutes(), // 分 's+': this.getSeconds(), // 秒 'q+': Math.floor((this.getMonth() + 3) / 3), // 季度 'S': this.getMilliseconds(), // 毫秒 'E+': this.getDay(), // 周 }; var week = { '0': '日', '1': '一', '2': '二', '3': '三', '4': '四', '5': '五', '6': '六' }; if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length)); } if (/(E+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, ((RegExp.$1.length > 1) ? (RegExp.$1.length > 2 ? '星期' : '周') : '') + week[ this.getDay() + '']); } for (var k in o) { if (new RegExp('(' + k + ')').test(fmt)) { fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]) .length))); } } return fmt; } $(function(){ //自定义tap if("ontouchend" in document){ $(document).on("touchstart", function(e) { var $target = $(e.target); $target.data("isMoved", 0); $target.data("startTime", Date.now()); }); $(document).on("touchmove", function(e) { var $target = $(e.target); $target.data("isMoved", 1); }); $(document).on("touchend", function(e) { var $target = $(e.target); var startTime = $target.data("startTime"); if(Date.now()-startTime>200){ return; } if($target.data("isMoved") == 1){ return; } $target.trigger("tap"); }); }else{ $(document).on("click", function(e) { var $target = $(e.target); $target.trigger("tap"); }); } }); /** * 根据keys校验object必填项 * @param {Array} keys - 待校验字段keys * @param {Object} target - 待校验object * @returns {boolean} - 是否通过 */ function checkRequiredKeys (keys, target) { try { // 职位/部门特殊处理, 满足时移除部门校验 if (keys.indexOf('branch') !== -1 && keys.indexOf('position') !== -1) { if (target['position'] === '总裁' || target['position'] === '总经理') { keys.splice(keys.indexOf('branch'), 1) } } return !keys.some(function (k) { var tempValue = target[k] var result = false if (typeof tempValue === 'number') { tempValue = tempValue.toString() } if (typeof tempValue === 'string') { result = tempValue.trim() !== '' } if (typeof tempValue === 'boolean') { result = true } return !result }) } catch (e) { console.warn(e) return false } } /** * 根据keys覆盖object必填项 * @param {Object}target - 指定需替换的object * @param {Object}now - 数据来源object * @param {Array}[keys] - 指定需替换的keys * @returns {Object} - 替换后的object,需注意target已被替换 */ function echoRequiredValues (target, now, keys) { try { Object.keys(now).forEach(function (k) { if (keys && keys.indexOf(k) === -1) { return } if (target.hasOwnProperty(k)) { target[k] = JSON.parse(JSON.stringify(now[k])) } }) return target } catch (e) { console.warn(e) return {} } } /** * ----S 金额转换 --- * @desc 同步金额转换函数-与PC、MOBILE 端其他项目保持一致,经过 babel 转化,原始代码参照其他项目 * @date 2022-10-08 目前用于表格中预算、中标金额字段展示格式化 */ /** * 金额转换 * @param money 金额 * @param config * @param config.type 类型 full | number | unit * @param config.level 初始单位索引 * @param config.levelArr 单位数组 ['元', '万', '亿', '万亿'] * @param config.unit 计算单位 10000 * @param config.digit 精度,保留小数位数 2 * @param config.degrade 指定单位索引时,所需精度不够是否降级单位 false * @returns {*|string|string|number} */ function recursiveCalculationMoney(money, config, start) { if (config === void 0) { config = {}; } if (start === void 0) { start = false; } var _Object$assign = Object.assign({ type: 'full', level: 0, levelArr: ['元', '万元', '亿元', '万亿元'], digit: 2, degrade: false, unit: 10000 }, config), type = _Object$assign.type, level = _Object$assign.level, levelArr = _Object$assign.levelArr, unit = _Object$assign.unit, digit = _Object$assign.digit, degrade = _Object$assign.degrade; // 提取纯数字 var computMoney = String(money).match(/^\d+(\.\d+)?/g) || [0]; computMoney = Number(computMoney[0]); // 是否指定单位索引 var lockUnit = start && level > 0; // 判断是否需要递归单位 if (!lockUnit) { var canNext = computMoney / Math.pow(unit, level + 1) >= 1 && level + 1 < levelArr.length; if (canNext) { return recursiveCalculationMoney(computMoney, { type: type, level: level + 1, levelArr: levelArr, digit: digit, degrade: degrade, unit: unit }); } } // 浮点数精度 var digitNumber = Math.pow(10, digit); // 指定单位索引时,如不满足精度要求,是否需要降级单位处理 var computLevel = level; var needDegrade = degrade && computMoney * digitNumber < Math.pow(unit, level); if (lockUnit && needDegrade) { computLevel--; } // 计算金额 computMoney = Number(String(Math.floor(computMoney / Math.pow(unit, computLevel) * digitNumber) / digitNumber)); // 返回结果 switch (type) { case 'full': { if (computMoney === 0) { return ''; } else { return computMoney + levelArr[computLevel]; } } case 'unit': { return levelArr[computLevel]; } case 'number': { return computMoney; } } } function tableFormatMoney(money, config) { if (config === void 0) { config = {}; } return recursiveCalculationMoney(money, config, true); } /** * ----E 金额转换 --- */ // 元素是否在视口中 function isElementVisible (el) { var rect = el.getBoundingClientRect() var vWidth = window.innerWidth || document.documentElement.clientWidth var vHeight = window.innerHeight || document.documentElement.clientHeight if ( rect.right < 0 || rect.bottom < 0 || rect.left > vWidth || rect.top > vHeight ) { return false } return true }