global.js 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037
  1. /*全局自适应高度*/
  2. /*全局自适应高度*/
  3. function autoFlashHeight(){
  4. function getObjHeight(select) {
  5. return select.length > 0 ? select.height() : 0;
  6. }
  7. /*侧栏高度*/
  8. var sBar1 = getObjHeight($(".sjs-bar-1"));
  9. var sBar2 = getObjHeight($(".sjs-bar-2"));
  10. var sBar3 = getObjHeight($(".sjs-bar-3"));
  11. var sBar4 = getObjHeight($(".sjs-bar-4"));
  12. var sBar5 = getObjHeight($(".sjs-bar-5"));
  13. /*侧栏高度*/
  14. var cHeader = getObjHeight($(".c-header"));
  15. var sBar = getObjHeight($(".sjs-bar"));
  16. var sBart = getObjHeight($(".sjs-bart"));
  17. var sBarz = getObjHeight($(".side-bar"));
  18. var pBarz = getObjHeight($(".toolsbar-f"));
  19. var bdtopc = getObjHeight($(".body-height-top"));
  20. var bcontent = getObjHeight($(".bcontent-wrap"));
  21. $(".sjs-height-0").height($(window).height()-cHeader-90+53);
  22. $(".sjs-height-1").height($(window).height()-cHeader-bcontent-90+53);
  23. $(".sjs-height-2").height($(window).height()-cHeader-sBarz-120);
  24. $(".sjs-height-3").height($(window).height()-cHeader-sBar-492+25+150);/*492*/
  25. $(".sjs-height-4").height($(window).height()-cHeader-pBarz-110+75);
  26. $(".sjs-height-5").height($(window).height()-cHeader-sBar-492+55);/*492*/
  27. $(".sjs-height-6").height($(window).height()-cHeader-34-sBar1);
  28. $(".sp-wrap").height(bcontent-30);
  29. /*侧栏高度*/
  30. $(".sjs-sh-1").height($(window).height()-cHeader-sBar1-92+55);
  31. $(".sjs-sh-2").height($(window).height()-cHeader-sBar2-92+55);
  32. $(".sjs-sh-3").height($(window).height()-cHeader-sBar3-92+55);
  33. $(".sjs-sh-4").height($(window).height()-cHeader-sBar4-92+55);
  34. $(".sjs-sh-5").height($(window).height()-cHeader-sBar5-92+55);
  35. for (const sh of $('.sjs-sh')) {
  36. $(sh).height($(window).height()-cHeader-getObjHeight($('.sjs-bar', sh.parentNode))-getObjHeight($('.sjs-bottom', sh.parentNode))-92+55);
  37. }
  38. /*工程变更添加清单高度*/
  39. $(".sjs-biangeng-height").height($(window).height()/3.3);
  40. };
  41. $(window).resize(autoFlashHeight);
  42. /*全局自适应高度结束*/
  43. $(function(){
  44. /*侧滑*/
  45. $(".open-sidebar").click(function(){
  46. $(".slide-sidebar").animate({width:"800"}).addClass("open");
  47. });
  48. $("body").click(function(event){
  49. var e = event || window.event; //浏览器兼容性
  50. if(!$(event.target).is('a')) {
  51. var elem = event.target || e.srcElement;
  52. while (elem) { //循环判断至跟节点,防止点击的是div子元素
  53. if (elem.className == "open-sidebar" || elem.className == 'slide-sidebar open') {
  54. return false;
  55. }
  56. elem = elem.parentNode;
  57. }
  58. $(".slide-sidebar").animate({width:"0"}).removeClass("open")// 关闭处理
  59. }
  60. });
  61. /*侧滑*/
  62. /*工具提示*/
  63. $(function () {
  64. $('[data-toggle="tooltip"]').tooltip()
  65. });
  66. /*侧栏菜单*/
  67. $(".bg-nav > li > a").click(function() {
  68. var self = $(this);
  69. var subMenu = $(this).siblings('ul.sub-menu');
  70. if(subMenu.length > 0) {
  71. if(subMenu.is(":visible")) {
  72. self.find('.menu-arrow').removeClass('fa-angle-up').addClass('fa-angle-down');
  73. subMenu.slideUp('fast');
  74. self.parent().removeClass('active');
  75. }else{
  76. self.parent().addClass('active');
  77. self.find('.menu-arrow').removeClass('fa-angle-down').addClass('fa-angle-up');
  78. subMenu.slideDown('fast');
  79. }
  80. }
  81. });
  82. // 数据提交
  83. $("#submit-form").click(function() {
  84. $("#save-form").submit();
  85. });
  86. // modal弹窗拖动
  87. // $(document).on("show.bs.modal", ".modal", function() {
  88. // $(this).draggable({
  89. // handle: ".modal-header" // 只能点击头部拖动
  90. // });
  91. // $(this).css("overflow", "hidden");
  92. // });
  93. // 动态生成datepicker
  94. $('body').on('focus', ".datepicker-here", function (e) {
  95. if ($(this).data("datepicker") != "1") {
  96. $(this).datepicker();
  97. }
  98. $(this).data("datepicker", "1");
  99. });
  100. $('a[href="/setting/user"]').each(function () {
  101. if (getLocalCache('account-pageSize')) {
  102. $(this).attr('href', $(this).attr('href') + '?pageSize=' + getLocalCache('account-pageSize'));
  103. }
  104. });
  105. $('.change_sort_link').each(function () {
  106. const tender_id = $(this).attr('href').split('/')[2];
  107. let orderSetting = getLocalCache('change-'+ tender_id +'-list-order');
  108. if(orderSetting) {
  109. const orders = orderSetting.split('|');
  110. $(this).attr('href', $(this).attr('href') + '?sort=' + orders[0] + '&order=' + orders[1]);
  111. }
  112. });
  113. });
  114. function checkShowLast (count) {
  115. if (count > 12500) {
  116. $('a[name=showLevel][tag=last]').hide();
  117. } else {
  118. $('a[name=showLevel][tag=last]').show();
  119. }
  120. }
  121. /**
  122. * 提示框
  123. *
  124. * @param string message
  125. * @param string type
  126. * @param string icon
  127. * @return void
  128. */
  129. function toast(message, type, icon) {
  130. var toast = $(".toast");
  131. toast.addClass(type);
  132. toast.children('.message').html(message);
  133. var iconClass = 'fa-' + icon;
  134. toast.children('.icon').addClass(iconClass);
  135. toast.fadeIn(500);
  136. setTimeout(function() {
  137. toast.fadeOut('fast');
  138. toast.children('.message').text('');
  139. toast.children('.icon').removeClass(iconClass);
  140. }, 3000);
  141. }
  142. /**
  143. * 动态请求数据
  144. * @param {String} url - 请求链接
  145. * @param data - 提交数据
  146. * @param {function} successCallback - 返回成功回调
  147. * @param {function} errorCallBack - 返回失败回调
  148. */
  149. const postData = function (url, data, successCallback, errorCallBack, showWaiting = true) {
  150. if (showWaiting) showWaitingView();
  151. $.ajax({
  152. type:"POST",
  153. url: url,
  154. data: {'data': JSON.stringify(data)},
  155. dataType: 'json',
  156. cache: false,
  157. timeout: 60000,
  158. beforeSend: function(xhr) {
  159. let csrfToken = Cookies.get('csrfToken_j');
  160. xhr.setRequestHeader('x-csrf-token', csrfToken);
  161. },
  162. success: function(result){
  163. if (result.err === 0) {
  164. if (successCallback) {
  165. successCallback(result.data);
  166. }
  167. } else if (result.err === 2) {
  168. toastr.error('error: ' + result.msg);
  169. setTimeout(function () {
  170. window.location.href = '/login';
  171. },1000);
  172. } else {
  173. toastr.error('error: ' + result.msg);
  174. if (errorCallBack) {
  175. errorCallBack(result.msg);
  176. }
  177. }
  178. if (showWaiting) closeWaitingView();
  179. },
  180. error: function(jqXHR, textStatus, errorThrown){
  181. toastr.error('error: ' + textStatus + " " + errorThrown);
  182. if (errorCallBack) {
  183. errorCallBack();
  184. }
  185. if (showWaiting) closeWaitingView();
  186. }
  187. });
  188. };
  189. /**
  190. * 动态请求数据(压缩数据)
  191. * @param {String} url - 请求链接
  192. * @param data - 提交数据
  193. * @param {function} successCallback - 返回成功回调
  194. * @param {function} errorCallBack - 返回失败回调
  195. */
  196. const postDataCompress = function (url, data, successCallback, errorCallBack, htype = 'progress') {
  197. if (htype === 'wait') showWaitingView();
  198. if (htype === 'progress') showProgress();
  199. $.ajax({
  200. type:"POST",
  201. url: url,
  202. data: {'data': LZString.compressToUTF16(JSON.stringify(data))},
  203. dataType: 'json',
  204. cache: false,
  205. timeout: 80000, // 导入清单Excel(10w行)预计需要时间
  206. beforeSend: function(xhr) {
  207. let csrfToken = Cookies.get('csrfToken_j');
  208. xhr.setRequestHeader('x-csrf-token', csrfToken);
  209. },
  210. success: function(result){
  211. if (htype === 'progress') doneProgress();
  212. if (result.err === 0) {
  213. if (successCallback) {
  214. successCallback(result.data);
  215. }
  216. } else if (result.err === 2) {
  217. toastr.error('error: ' + result.msg);
  218. setTimeout(function () {
  219. window.location.href = '/login';
  220. },1000);
  221. } else {
  222. toastr.error('error: ' + result.msg);
  223. if (errorCallBack) {
  224. errorCallBack(result.msg);
  225. }
  226. }
  227. if (htype === 'wait') closeWaitingView();
  228. if (htype === 'progress') closeProgress();
  229. },
  230. error: function(jqXHR, textStatus, errorThrown){
  231. toastr.error('error: ' + textStatus + " " + errorThrown);
  232. if (errorCallBack) {
  233. errorCallBack();
  234. }
  235. if (htype === 'wait') closeWaitingView();
  236. if (htype === 'progress') closeProgress();
  237. }
  238. });
  239. };
  240. /**
  241. * 动态请求数据
  242. * @param {String} url - 请求链接
  243. * @param data - 提交数据
  244. * @param {function} successCallback - 返回成功回调
  245. * @param {function} errorCallBack - 返回失败回调
  246. */
  247. const postDataWithFile = function (url, formData, successCallback, errorCallBack, showWaiting = true) {
  248. if (showWaiting) showWaitingView();
  249. if (formData.getAll('file[]').length > 10) {
  250. toastr.error('文件数量不能多于10个');
  251. if (showWaiting) closeWaitingView();
  252. return
  253. }
  254. $.ajax({
  255. type:"POST",
  256. url: url,
  257. data: formData,
  258. dataType: 'json',
  259. cache: false,
  260. // 告诉jQuery不要去设置Content-Type请求头
  261. contentType: false,
  262. // 告诉jQuery不要去处理发送的数据
  263. processData: false,
  264. timeout: 60000,
  265. beforeSend: function(xhr) {
  266. let csrfToken = Cookies.get('csrfToken_j');
  267. xhr.setRequestHeader('x-csrf-token', csrfToken);
  268. },
  269. success: function(result){
  270. if (result.err === 0) {
  271. if (successCallback) {
  272. successCallback(result.data);
  273. }
  274. } else if (result.err === 2) {
  275. toastr.error('error: ' + result.msg);
  276. setTimeout(function () {
  277. window.location.href = '/login';
  278. },1000);
  279. } else {
  280. toastr.error('error: ' + result.msg);
  281. if (errorCallBack) {
  282. errorCallBack();
  283. }
  284. }
  285. if (showWaiting) closeWaitingView();
  286. },
  287. error: function(jqXHR, textStatus, errorThrown){
  288. toastr.error('error: ' + textStatus + " " + errorThrown);
  289. if (errorCallBack) {
  290. errorCallBack();
  291. }
  292. if (showWaiting) closeWaitingView();
  293. }
  294. });
  295. };
  296. const postDataWithFileProgress = function (url, formData, successCallback, errorCallBack) {
  297. showUploadFileProgress();
  298. $.ajax({
  299. type:"POST",
  300. url: url,
  301. data: formData,
  302. dataType: 'json',
  303. cache: false,
  304. // 告诉jQuery不要去设置Content-Type请求头
  305. contentType: false,
  306. // 告诉jQuery不要去处理发送的数据
  307. processData: false,
  308. beforeSend: function(xhr) {
  309. let csrfToken = Cookies.get('csrfToken_j');
  310. xhr.setRequestHeader('x-csrf-token', csrfToken);
  311. },
  312. success: function(result){
  313. doneProgress();
  314. if (result.err === 0) {
  315. if (successCallback) {
  316. successCallback(result.data);
  317. }
  318. } else if (result.err === 2) {
  319. toastr.error('error: ' + result.msg);
  320. setTimeout(function () {
  321. window.location.href = '/login';
  322. },1000);
  323. } else {
  324. toastr.error('error: ' + result.msg);
  325. if (errorCallBack) {
  326. errorCallBack();
  327. }
  328. }
  329. closeProgress();
  330. },
  331. error: function(jqXHR, textStatus, errorThrown){
  332. toastr.error('error: ' + textStatus + " " + errorThrown);
  333. if (errorCallBack) {
  334. errorCallBack();
  335. }
  336. closeProgress();
  337. },
  338. xhr: function() {
  339. var xhr = new XMLHttpRequest();
  340. //使用XMLHttpRequest.upload监听上传过程,注册progress事件,打印回调函数中的event事件
  341. xhr.upload.addEventListener('progress', function (e) {
  342. console.log(e);
  343. //loaded代表上传了多少
  344. //total代表总数为多少
  345. var progressRate = (e.loaded / e.total) * 95;
  346. //通过设置进度条的宽度达到效果
  347. setUploadFileProgress(progressRate);
  348. })
  349. return xhr;
  350. }
  351. });
  352. }
  353. const postCompressFile = function (url, data, successCallback, errorCallBack) {
  354. $.ajax({
  355. type:"POST",
  356. url: url,
  357. data: {'data': JSON.stringify(data)},
  358. // dataType: 'blob',
  359. cache: false,
  360. timeout: 60000,
  361. xhrFields: {
  362. responseType: 'blob'
  363. },
  364. beforeSend: function(xhr) {
  365. let csrfToken = Cookies.get('csrfToken_j');
  366. xhr.setRequestHeader('x-csrf-token', csrfToken);
  367. },
  368. success: function(result){
  369. // if (result.err === 0) {
  370. // if (successCallback) {
  371. // successCallback(result.data);
  372. // }
  373. // } else if (result.err === 2) {
  374. // toastr.error('error: ' + result.msg);
  375. // setTimeout(function () {
  376. // window.location.href = '/login';
  377. // },1000);
  378. // } else {
  379. // toastr.error('error: ' + result.msg);
  380. // if (errorCallBack) {
  381. // errorCallBack(result.msg);
  382. // }
  383. // }
  384. if (successCallback) {
  385. successCallback(result)
  386. }
  387. },
  388. error: function(jqXHR, textStatus, errorThrown){
  389. toastr.error('error: ' + textStatus + " " + errorThrown);
  390. if (errorCallBack) {
  391. errorCallBack();
  392. }
  393. }
  394. });
  395. }
  396. /**
  397. * 获取url中参数
  398. * @param variable
  399. * @returns {*}
  400. */
  401. function getQueryVariable(variable) {
  402. var query = window.location.search.substring(1);
  403. var vars = query.split("&");
  404. for (var i=0;i<vars.length;i++) {
  405. var pair = vars[i].split("=");
  406. if(pair[0] == variable){return pair[1];}
  407. }
  408. return(false);
  409. }
  410. const zeroRange = 0.00000001;
  411. function checkZero(value) {
  412. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  413. }
  414. function checkFieldChange(o, n) {
  415. return o == n || ((!o || o === '') && (n === ''));
  416. }
  417. var bShowWaiting = false, beginWaitingTime;
  418. //关闭等待窗口
  419. function closeWaitingView() {
  420. bShowWaiting = false;
  421. const time = parseInt(new Date());
  422. setTimeout(function () {
  423. var bgDiv = document.getElementById("bgDiv");
  424. var msgDiv = document.getElementById("msgDiv");
  425. //移除背景遮罩层div
  426. if(bgDiv != null){
  427. document.body.removeChild(bgDiv);
  428. }
  429. //移除中间信息提示层div
  430. if(msgDiv != null){
  431. document.body.removeChild(msgDiv);
  432. }
  433. }, Math.max(beginWaitingTime - time + 500, 0));
  434. }
  435. //显示等待窗口
  436. function showWaitingView() {
  437. // bShowWaiting = true;
  438. // setTimeout(function () {
  439. // if (!bShowWaiting) return;
  440. // beginWaitingTime = parseInt(new Date());
  441. // var msgw = 300; //提示窗口的宽度
  442. // var msgh = 100; //提示窗口的高度
  443. //
  444. // var sWidth, sHeight;
  445. // sWidth = document.body.clientWidth;
  446. // sHeight = document.body.clientHeight;
  447. //
  448. // //背景遮罩层div
  449. // var bgObj = document.createElement("div");
  450. // bgObj.setAttribute('id', 'bgDiv');
  451. // bgObj.style.zIndex = '9998';
  452. // bgObj.style.position = "absolute";
  453. // bgObj.style.top = "0px";
  454. // bgObj.style.background = "#888";
  455. // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  456. // bgObj.style.opacity = "0.6";
  457. // bgObj.style.left = "0px";
  458. // bgObj.style.width = sWidth + "px";
  459. // bgObj.style.height = sHeight + "px";
  460. // document.body.appendChild(bgObj);
  461. //
  462. // //信息提示层div
  463. // var msgObj = document.createElement("div");
  464. // msgObj.style.zIndex = '9999';
  465. // msgObj.setAttribute("id", "msgDiv");
  466. // msgObj.setAttribute("align", "center");
  467. // msgObj.style.position = "absolute";
  468. // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  469. // msgObj.style.width = msgw + "px";
  470. // msgObj.style.height = msgh + "px";
  471. // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  472. // msgObj.style.left = (sWidth - msgw) / 2 + "px";
  473. // document.body.appendChild(msgObj);
  474. //
  475. // //中间等待图标
  476. // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  477. // }, 1000);
  478. beginWaitingTime = parseInt(new Date());
  479. var msgw = 300; //提示窗口的宽度
  480. var msgh = 100; //提示窗口的高度
  481. var sWidth, sHeight;
  482. sWidth = document.body.clientWidth;
  483. sHeight = document.body.clientHeight;
  484. //背景遮罩层div
  485. var bgObj = document.createElement("div");
  486. bgObj.setAttribute('id', 'bgDiv');
  487. bgObj.style.zIndex = '9998';
  488. bgObj.style.position = "absolute";
  489. bgObj.style.top = "0px";
  490. // bgObj.style.background = "#888";
  491. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  492. bgObj.style.opacity = "0.6";
  493. bgObj.style.left = "0px";
  494. bgObj.style.width = sWidth + "px";
  495. bgObj.style.height = sHeight + "px";
  496. document.body.appendChild(bgObj);
  497. //信息提示层div
  498. var msgObj = document.createElement("div");
  499. msgObj.style.zIndex = '9999';
  500. msgObj.setAttribute("id", "msgDiv");
  501. msgObj.setAttribute("align", "center");
  502. msgObj.style.position = "absolute";
  503. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  504. msgObj.style.width = msgw + "px";
  505. msgObj.style.height = msgh + "px";
  506. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  507. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  508. document.body.appendChild(msgObj);
  509. //中间等待图标
  510. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  511. }
  512. let progressInterval;
  513. function showProgress() {
  514. var sWidth, sHeight;
  515. sWidth = document.body.clientWidth;
  516. sHeight = document.body.clientHeight;
  517. //背景遮罩层div
  518. var bgObj = document.createElement("div");
  519. bgObj.setAttribute('id', 'bgDiv');
  520. bgObj.style.zIndex = '9998';
  521. bgObj.style.position = "absolute";
  522. bgObj.style.top = "0px";
  523. bgObj.style.background = "#888";
  524. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  525. bgObj.style.opacity = "0.6";
  526. bgObj.style.left = "0px";
  527. bgObj.style.width = sWidth + "px";
  528. bgObj.style.height = sHeight + "px";
  529. document.body.appendChild(bgObj);
  530. //信息提示层div
  531. var msgObj = document.createElement("div");
  532. msgObj.classList.add('progress');
  533. msgObj.style.zIndex = '9999';
  534. msgObj.style.position = "absolute";
  535. msgObj.setAttribute("id", "progressDiv");
  536. msgObj.style.height = "2px";
  537. msgObj.style.width = "600px";
  538. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  539. msgObj.style.left = (sWidth - 600) / 2 + "px";
  540. document.body.appendChild(msgObj);
  541. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  542. const processObj = $('.progress-bar');
  543. let count = 0;
  544. progressInterval = setInterval(function () {
  545. const pos = parseInt(processObj.attr('aria-valuenow'));
  546. if (pos < 20) { // 1
  547. processObj.attr('aria-valuenow', pos + 2);
  548. processObj.width((pos + 2) + '%');
  549. } else if (pos < 40) { // 2
  550. processObj.attr('aria-valuenow', pos + 1);
  551. processObj.width((pos + 1) + '%');
  552. } else if (pos < 60) { // 4
  553. count += 1;
  554. if (count % 2 === 0) {
  555. processObj.attr('aria-valuenow', pos + 1);
  556. processObj.width((pos + 1) + '%');
  557. }
  558. } else if (pos < 80) { // 10
  559. count += 1;
  560. if (count % 5 === 0) {
  561. processObj.attr('aria-valuenow', pos + 1);
  562. processObj.width((pos + 1) + '%');
  563. }
  564. } else if (pos < 90) { // 15
  565. count += 1;
  566. if (count % 15 === 0) {
  567. processObj.attr('aria-valuenow', pos + 1);
  568. processObj.width((pos + 1) + '%');
  569. }
  570. } else if (pos < 95) { // 20
  571. count += 1;
  572. if (count % 40 === 0) {
  573. processObj.attr('aria-valuenow', pos + 1);
  574. processObj.width((pos + 1) + '%');
  575. }
  576. } else if (pos < 100) { // 30
  577. count += 1;
  578. if (count % 60 === 0) {
  579. processObj.attr('aria-valuenow', pos + 1);
  580. }
  581. }
  582. }, 100);
  583. }
  584. function doneProgress() {
  585. clearInterval(progressInterval);
  586. $('.progress-bar').attr('aria-valuenow', 100).width('100%');
  587. }
  588. function closeProgress() {
  589. setTimeout(function () {
  590. var bgDiv = document.getElementById("bgDiv");
  591. var msgDiv = document.getElementById("progressDiv");
  592. //移除背景遮罩层div
  593. if(bgDiv != null){
  594. document.body.removeChild(bgDiv);
  595. }
  596. //移除中间信息提示层div
  597. if(msgDiv != null){
  598. document.body.removeChild(msgDiv);
  599. }
  600. }, 500);
  601. }
  602. function showUploadFileProgress() {
  603. var sWidth, sHeight;
  604. sWidth = document.body.clientWidth;
  605. sHeight = document.body.clientHeight;
  606. //背景遮罩层div
  607. var bgObj = document.createElement("div");
  608. bgObj.setAttribute('id', 'bgDiv');
  609. bgObj.style.zIndex = '9998';
  610. bgObj.style.position = "absolute";
  611. bgObj.style.top = "0px";
  612. bgObj.style.background = "#888";
  613. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  614. bgObj.style.opacity = "0.6";
  615. bgObj.style.left = "0px";
  616. bgObj.style.width = sWidth + "px";
  617. bgObj.style.height = sHeight + "px";
  618. document.body.appendChild(bgObj);
  619. //信息提示层div
  620. var msgObj = document.createElement("div");
  621. msgObj.classList.add('progress');
  622. msgObj.style.zIndex = '9999';
  623. msgObj.style.position = "absolute";
  624. msgObj.setAttribute("id", "progressDiv");
  625. msgObj.style.height = "2px";
  626. msgObj.style.width = "600px";
  627. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  628. msgObj.style.left = (sWidth - 600) / 2 + "px";
  629. document.body.appendChild(msgObj);
  630. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  631. }
  632. function setUploadFileProgress(pos) {
  633. const processObj = $('.progress-bar');
  634. processObj.attr('aria-valuenow', pos);
  635. processObj.width(pos + '%');
  636. }
  637. /**
  638. * 设置本地缓存
  639. *
  640. * @param {String} key
  641. * @param {String|Number} value
  642. * @return {void}
  643. */
  644. function setLocalCache(key, value) {
  645. const storage = window.localStorage;
  646. if (!storage || key === '' || value === '') {
  647. return;
  648. }
  649. storage.setItem(key, value);
  650. }
  651. /**
  652. * 获取本地缓存
  653. *
  654. * @param {String} key
  655. * @return {String}
  656. */
  657. function getLocalCache(key) {
  658. const storage = window.localStorage;
  659. if (!storage || key === '') {
  660. return null;
  661. }
  662. return storage.getItem(key);
  663. }
  664. /**
  665. * 移除本地缓存
  666. * @param {String} key
  667. * @returns {Boolean}
  668. */
  669. function removeLocalCache(key) {
  670. const storage = window.localStorage;
  671. if (!storage || key === '') {
  672. return null;
  673. }
  674. return storage.removeItem(key);
  675. }
  676. //params: 需要复制的对象(元素)
  677. function copyToClipboard( text ) {
  678. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  679. var aux = document.createElement('textarea');// 创建元素用于复制
  680. // Prevent zooming on iOS
  681. aux.style.fontSize = '12pt';
  682. // Reset box model
  683. aux.style.border = '0';
  684. aux.style.padding = '0';
  685. aux.style.margin = '0';
  686. // Move element out of screen horizontally
  687. aux.style.position = 'absolute';
  688. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  689. // Move element to the same position vertically
  690. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  691. aux.style.top = yPosition + 'px';
  692. aux.setAttribute('readonly', '');
  693. // 设置元素内容
  694. aux.value = text;
  695. // 将元素插入页面进行调用
  696. document.body.appendChild(aux);
  697. // 复制内容
  698. aux.select();
  699. aux.setSelectionRange(0, text.length);
  700. // 将内容复制到剪贴板
  701. document.execCommand("copy", true);
  702. // 删除创建元素
  703. document.body.removeChild(aux);
  704. }
  705. function toastMessageUniq (obj) {
  706. if (!obj.msg || !obj.type) return;
  707. if (!obj.once) {
  708. switch (obj.type) {
  709. case 'error':
  710. toastr.error(obj.msg);
  711. break;
  712. case 'warning':
  713. toastr.warning(obj.msg);
  714. break;
  715. case 'info':
  716. toastr.info(obj.msg);
  717. break;
  718. case 'success':
  719. toastr.success(obj.msg);
  720. break;
  721. }
  722. obj.once = true;
  723. }
  724. }
  725. function trimInvalidChar(str) {
  726. return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
  727. }
  728. function cleanSymbols(str) {
  729. return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
  730. }
  731. jQuery.bootstrapLoading = {
  732. isLoading: function () {
  733. return $('#loadingPage').is(':visible');
  734. },
  735. start: function (options) {
  736. if(this.isLoading()){
  737. return;
  738. }
  739. var defaults = {
  740. opacity: 0.5,
  741. //loading页面透明度
  742. // backgroundColor: "#FFFFFF",
  743. //loading页面背景色
  744. borderColor: "#bbb",
  745. //提示边框颜色
  746. borderWidth: 1,
  747. //提示边框宽度
  748. borderStyle: "solid",
  749. //提示边框样式
  750. loadingTips: "Loading, please wait...",
  751. //提示文本
  752. TipsColor: "#fff",
  753. //提示颜色
  754. delayTime: 500,
  755. //页面加载完成后,加载页面渐出速度
  756. zindex: 2000,
  757. //loading页面层次
  758. sleep: 0
  759. //设置挂起,等于0时则无需挂起
  760. }
  761. var options = $.extend(defaults, options);
  762. //获取页面宽高
  763. var _PageHeight = document.documentElement.clientHeight,
  764. _PageWidth = document.documentElement.clientWidth;
  765. //在页面未加载完毕之前显示的loading Html自定义内容
  766. //var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;border-color:' + options.borderColor + ';border-style:' + options.borderStyle + ';border-width:' + options.borderWidth + 'px; height:80px; line-height:80px; padding-left:80px; padding-right: 5px;border-radius:10px; background: ' + options.backgroundColor + ' url(/Content/bootstrap-loading/images/loading.gif) no-repeat 5px center; color:' + options.TipsColor + ';font-size:20px;">' + options.loadingTips + '</div></div>';
  767. var _LoadingHtml = '<div id="loadingPage" style="position:fixed;left:0;top:0;_position: absolute;width:100%;height:' + _PageHeight + 'px;background:' + options.backgroundColor + ';opacity:' + options.opacity + ';filter:alpha(opacity=' + options.opacity * 100 + ');z-index:' + options.zindex + ';"><div id="loadingTips" style="position: absolute; cursor1: wait; width: auto;">' +'<div class="text-green"><i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i> <span class="sr-only">Loading...</span> </div> </div></div>';
  768. //呈现loading效果
  769. $("body").append(_LoadingHtml);
  770. //获取loading提示框宽高
  771. var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
  772. _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
  773. //计算距离,让loading提示框保持在屏幕上下左右居中
  774. var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
  775. _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
  776. $("#loadingTips").css({
  777. "left": _LoadingLeft + "px",
  778. "top": _LoadingTop + "px"
  779. });
  780. //监听页面加载状态
  781. document.onreadystatechange = PageLoaded;
  782. //当页面加载完成后执行
  783. function PageLoaded() {
  784. if (document.readyState == "complete") {
  785. var loadingMask = $('#loadingPage');
  786. setTimeout(function () {
  787. loadingMask.animate({
  788. "opacity": 0
  789. },
  790. options.delayTime,
  791. function () {
  792. $(this).hide();
  793. });
  794. },
  795. options.sleep);
  796. }
  797. }
  798. },
  799. end: function () {
  800. $("#loadingPage").remove();
  801. },
  802. progressStop:true,
  803. progressStart:async function(title="导出文件",autoBar = false){
  804. if($("#progressModal").length == 0){
  805. let phtml = `<div class="modal fade" id="progressModal" data-backdrop="static">
  806. <div class="modal-dialog" role="document">
  807. <div class="modal-content">
  808. <div class="modal-header">
  809. <h5 class="modal-title" id="progress_modal_title">${title}</h5>
  810. </div>
  811. <div class="modal-body">
  812. <!--正在生成-->
  813. <h5 class="my-3" id="progress_modal_body">正在${title}</h5>
  814. <div class="progress mb-3">
  815. <div id="progress_modal_bar" class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 10%"></div>
  816. </div>
  817. </div>
  818. </div>
  819. </div>
  820. </div>`;
  821. $("body").append(phtml);
  822. }else {
  823. $("#progress_modal_title").text(title);
  824. $("#progress_modal_body").text(`正在${title}`);
  825. }
  826. $("#progress_modal_bar").css('width','0%');
  827. $("#progressModal").modal('show');
  828. if(autoBar == true){//假的进度条
  829. $.bootstrapLoading.progressStop = false;
  830. let width = 0;
  831. while ($.bootstrapLoading.progressStop == false){
  832. await setTimeoutSync(null,1000);
  833. width += 5;
  834. if(width > 90) width -= 50;
  835. $("#progress_modal_bar").css('width',`${width}%`);
  836. }
  837. }
  838. },
  839. progressEnd:function () {
  840. $("#progress_modal_bar").css('width','100%');
  841. $.bootstrapLoading.progressStop = true;
  842. $("#progressModal").modal('hide');
  843. }
  844. };
  845. // 光标插入button内容
  846. $.fn.extend({
  847. insertAtCaret: function(myValue){
  848. var $t=$(this)[0];
  849. if (document.selection) {
  850. this.focus();
  851. sel = document.selection.createRange();
  852. sel.text = myValue;
  853. this.focus();
  854. }
  855. else
  856. if ($t.selectionStart || $t.selectionStart == '0') {
  857. var startPos = $t.selectionStart;
  858. var endPos = $t.selectionEnd;
  859. var scrollTop = $t.scrollTop;
  860. $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
  861. this.focus();
  862. $t.selectionStart = startPos + myValue.length;
  863. $t.selectionEnd = startPos + myValue.length;
  864. $t.scrollTop = scrollTop;
  865. }
  866. else {
  867. this.value += myValue;
  868. this.focus();
  869. }
  870. }
  871. });
  872. const checkUtils = {
  873. posOver(data) {
  874. if (!data) return false;
  875. if (!data.quantity) return !!data.end_contract_qty;
  876. return data.quantity > 0
  877. ? data.end_contract_qty > data.quantity
  878. : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
  879. },
  880. billsOver(data, isTz, relaPos) {
  881. if (!data) return false;
  882. if (isTz) {
  883. const posRange = relaPos.ledgerPos[itemsPre + data.id] || [];
  884. if (posRange.length > 0) {
  885. for (const p of posRange) {
  886. if (checkUtils.posOver(p)) return true;
  887. }
  888. return false;
  889. }
  890. if (data.is_tp) {
  891. if (!data.total_price) return !!data.end_contract_tp;
  892. return data.total_price > 0
  893. ? data.end_contract_tp > data.total_price
  894. : data.end_contract_tp < data.total_price || data.end_contract_tp > 0;
  895. } else {
  896. if (!data.quantity) return !!data.end_contract_qty;
  897. return data.quantity > 0
  898. ? data.end_contract_qty > data.quantity
  899. : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
  900. }
  901. } else {
  902. if (data.is_tp) {
  903. if (!data.deal_tp) return !!data.end_contract_tp;
  904. return data.deal_tp > 0
  905. ? data.end_contract_tp > data.deal_tp
  906. : data.end_contract_tp < data.deal_tp || data.end_contract_tp > 0;
  907. } else {
  908. if (!data.deal_qty) return !!data.end_contract_qty;
  909. return data.deal_qty > 0
  910. ? data.end_contract_qty > data.deal_qty
  911. : data.end_contract_qty < data.deal_qty || data.end_contract_qty > 0;
  912. }
  913. }
  914. }
  915. };
  916. Number.prototype.format2Str = function (pattern) {
  917. var strarr = this?this.toString().split('.'):['0'];
  918. var fmtarr = pattern?pattern.split('.'):[''];
  919. var retstr='';
  920. // 整数部分
  921. var str = strarr[0];
  922. var fmt = fmtarr[0];
  923. var i = str.length-1;
  924. var comma = false;
  925. for(var f=fmt.length-1;f>=0;f--){
  926. switch(fmt.substr(f,1)){
  927. case '#':
  928. if(i>=0 ) retstr = str.substr(i--,1) + retstr;
  929. break;
  930. case '0':
  931. if(i>=0) retstr = str.substr(i--,1) + retstr;
  932. else retstr = '0' + retstr;
  933. break;
  934. case ',':
  935. comma = true;
  936. retstr=','+retstr;
  937. break;
  938. }
  939. }
  940. if(i>=0){
  941. if(comma){
  942. var l = str.length;
  943. for(;i>=0;i--){
  944. retstr = str.substr(i,1) + retstr;
  945. if(i>0 && ((l-i)%3)==0) retstr = ',' + retstr;
  946. }
  947. }
  948. else retstr = str.substr(0,i+1) + retstr;
  949. }
  950. retstr = retstr+'.';
  951. // 处理小数部分
  952. str=strarr.length>1?strarr[1]:'';
  953. fmt=fmtarr.length>1?fmtarr[1]:'';
  954. i=0;
  955. for(var f=0;f<fmt.length;f++){
  956. switch(fmt.substr(f,1)){
  957. case '#':
  958. if(i<str.length) retstr+=str.substr(i++,1);
  959. break;
  960. case '0':
  961. if(i<str.length) retstr+= str.substr(i++,1);
  962. else retstr+='0';
  963. break;
  964. }
  965. }
  966. return retstr.replace(/^,+/,'').replace(/\.$/,'');
  967. };
  968. function transFormToChinese(num) {
  969. const changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  970. const unit = ["", "十", "百", "千", "万"];
  971. num = parseInt(num);
  972. let getWan = (temp) => {
  973. let strArr = temp.toString().split("").reverse();
  974. let newNum = "";
  975. for (var i = 0; i < strArr.length; i++) {
  976. newNum = (i == 0 && strArr[i] == 0 ? "" : (i > 0 && strArr[i] == 0 && strArr[i - 1] == 0 ? "" : changeNum[strArr[i]] + (strArr[i] == 0 ? unit[0] : unit[i]))) + newNum;
  977. }
  978. return strArr.length === 2 && newNum.indexOf("一十") !== -1 ? newNum.replace('一十', '十') : newNum;
  979. }
  980. let overWan = Math.floor(num / 10000);
  981. let noWan = num % 10000;
  982. if (noWan.toString().length < 4) noWan = "0" + noWan;
  983. return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
  984. }