global.js 40 KB

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