global.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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: 180000,
  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. console.log(jqXHR, textStatus, errorThrown);
  390. toastr.error('error: ' + textStatus + " " + errorThrown);
  391. if (errorCallBack) {
  392. errorCallBack();
  393. }
  394. }
  395. });
  396. }
  397. /**
  398. * 获取url中参数
  399. * @param variable
  400. * @returns {*}
  401. */
  402. function getQueryVariable(variable) {
  403. var query = window.location.search.substring(1);
  404. var vars = query.split("&");
  405. for (var i=0;i<vars.length;i++) {
  406. var pair = vars[i].split("=");
  407. if(pair[0] == variable){return pair[1];}
  408. }
  409. return(false);
  410. }
  411. const zeroRange = 0.00000001;
  412. function checkZero(value) {
  413. return value === null || value === undefined || (_.isNumber(value) && Math.abs(value) < zeroRange);
  414. }
  415. function checkFieldChange(o, n) {
  416. return o == n || ((!o || o === '') && (n === ''));
  417. }
  418. var bShowWaiting = false, beginWaitingTime;
  419. //关闭等待窗口
  420. function closeWaitingView() {
  421. bShowWaiting = false;
  422. const time = parseInt(new Date());
  423. setTimeout(function () {
  424. var bgDiv = document.getElementById("bgDiv");
  425. var msgDiv = document.getElementById("msgDiv");
  426. //移除背景遮罩层div
  427. if(bgDiv != null){
  428. document.body.removeChild(bgDiv);
  429. }
  430. //移除中间信息提示层div
  431. if(msgDiv != null){
  432. document.body.removeChild(msgDiv);
  433. }
  434. }, Math.max(beginWaitingTime - time + 500, 0));
  435. }
  436. //显示等待窗口
  437. function showWaitingView() {
  438. // bShowWaiting = true;
  439. // setTimeout(function () {
  440. // if (!bShowWaiting) return;
  441. // beginWaitingTime = parseInt(new Date());
  442. // var msgw = 300; //提示窗口的宽度
  443. // var msgh = 100; //提示窗口的高度
  444. //
  445. // var sWidth, sHeight;
  446. // sWidth = document.body.clientWidth;
  447. // sHeight = document.body.clientHeight;
  448. //
  449. // //背景遮罩层div
  450. // var bgObj = document.createElement("div");
  451. // bgObj.setAttribute('id', 'bgDiv');
  452. // bgObj.style.zIndex = '9998';
  453. // bgObj.style.position = "absolute";
  454. // bgObj.style.top = "0px";
  455. // bgObj.style.background = "#888";
  456. // bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  457. // bgObj.style.opacity = "0.6";
  458. // bgObj.style.left = "0px";
  459. // bgObj.style.width = sWidth + "px";
  460. // bgObj.style.height = sHeight + "px";
  461. // document.body.appendChild(bgObj);
  462. //
  463. // //信息提示层div
  464. // var msgObj = document.createElement("div");
  465. // msgObj.style.zIndex = '9999';
  466. // msgObj.setAttribute("id", "msgDiv");
  467. // msgObj.setAttribute("align", "center");
  468. // msgObj.style.position = "absolute";
  469. // msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  470. // msgObj.style.width = msgw + "px";
  471. // msgObj.style.height = msgh + "px";
  472. // msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  473. // msgObj.style.left = (sWidth - msgw) / 2 + "px";
  474. // document.body.appendChild(msgObj);
  475. //
  476. // //中间等待图标
  477. // document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  478. // }, 1000);
  479. beginWaitingTime = parseInt(new Date());
  480. var msgw = 300; //提示窗口的宽度
  481. var msgh = 100; //提示窗口的高度
  482. var sWidth, sHeight;
  483. sWidth = document.body.clientWidth;
  484. sHeight = document.body.clientHeight;
  485. //背景遮罩层div
  486. var bgObj = document.createElement("div");
  487. bgObj.setAttribute('id', 'bgDiv');
  488. bgObj.style.zIndex = '9998';
  489. bgObj.style.position = "absolute";
  490. bgObj.style.top = "0px";
  491. // bgObj.style.background = "#888";
  492. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  493. bgObj.style.opacity = "0.6";
  494. bgObj.style.left = "0px";
  495. bgObj.style.width = sWidth + "px";
  496. bgObj.style.height = sHeight + "px";
  497. document.body.appendChild(bgObj);
  498. //信息提示层div
  499. var msgObj = document.createElement("div");
  500. msgObj.style.zIndex = '9999';
  501. msgObj.setAttribute("id", "msgDiv");
  502. msgObj.setAttribute("align", "center");
  503. msgObj.style.position = "absolute";
  504. msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
  505. msgObj.style.width = msgw + "px";
  506. msgObj.style.height = msgh + "px";
  507. msgObj.style.top = (document.documentElement.scrollTop + (sHeight - msgh) / 2) + "px";
  508. msgObj.style.left = (sWidth - msgw) / 2 + "px";
  509. document.body.appendChild(msgObj);
  510. //中间等待图标
  511. document.getElementById("msgDiv").innerHTML = '<i class="fa fa-spinner fa-pulse fa-3x fa-fw"></i>';
  512. }
  513. let progressInterval;
  514. function showProgress() {
  515. var sWidth, sHeight;
  516. sWidth = document.body.clientWidth;
  517. sHeight = document.body.clientHeight;
  518. //背景遮罩层div
  519. var bgObj = document.createElement("div");
  520. bgObj.setAttribute('id', 'bgDiv');
  521. bgObj.style.zIndex = '9998';
  522. bgObj.style.position = "absolute";
  523. bgObj.style.top = "0px";
  524. bgObj.style.background = "#888";
  525. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  526. bgObj.style.opacity = "0.6";
  527. bgObj.style.left = "0px";
  528. bgObj.style.width = sWidth + "px";
  529. bgObj.style.height = sHeight + "px";
  530. document.body.appendChild(bgObj);
  531. //信息提示层div
  532. var msgObj = document.createElement("div");
  533. msgObj.classList.add('progress');
  534. msgObj.style.zIndex = '9999';
  535. msgObj.style.position = "absolute";
  536. msgObj.setAttribute("id", "progressDiv");
  537. msgObj.style.height = "2px";
  538. msgObj.style.width = "600px";
  539. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  540. msgObj.style.left = (sWidth - 600) / 2 + "px";
  541. document.body.appendChild(msgObj);
  542. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  543. const processObj = $('.progress-bar');
  544. let count = 0;
  545. progressInterval = setInterval(function () {
  546. const pos = parseInt(processObj.attr('aria-valuenow'));
  547. if (pos < 20) { // 1
  548. processObj.attr('aria-valuenow', pos + 2);
  549. processObj.width((pos + 2) + '%');
  550. } else if (pos < 40) { // 2
  551. processObj.attr('aria-valuenow', pos + 1);
  552. processObj.width((pos + 1) + '%');
  553. } else if (pos < 60) { // 4
  554. count += 1;
  555. if (count % 2 === 0) {
  556. processObj.attr('aria-valuenow', pos + 1);
  557. processObj.width((pos + 1) + '%');
  558. }
  559. } else if (pos < 80) { // 10
  560. count += 1;
  561. if (count % 5 === 0) {
  562. processObj.attr('aria-valuenow', pos + 1);
  563. processObj.width((pos + 1) + '%');
  564. }
  565. } else if (pos < 90) { // 15
  566. count += 1;
  567. if (count % 15 === 0) {
  568. processObj.attr('aria-valuenow', pos + 1);
  569. processObj.width((pos + 1) + '%');
  570. }
  571. } else if (pos < 95) { // 20
  572. count += 1;
  573. if (count % 40 === 0) {
  574. processObj.attr('aria-valuenow', pos + 1);
  575. processObj.width((pos + 1) + '%');
  576. }
  577. } else if (pos < 100) { // 30
  578. count += 1;
  579. if (count % 60 === 0) {
  580. processObj.attr('aria-valuenow', pos + 1);
  581. }
  582. }
  583. }, 100);
  584. }
  585. function doneProgress() {
  586. clearInterval(progressInterval);
  587. $('.progress-bar').attr('aria-valuenow', 100).width('100%');
  588. }
  589. function closeProgress() {
  590. setTimeout(function () {
  591. var bgDiv = document.getElementById("bgDiv");
  592. var msgDiv = document.getElementById("progressDiv");
  593. //移除背景遮罩层div
  594. if(bgDiv != null){
  595. document.body.removeChild(bgDiv);
  596. }
  597. //移除中间信息提示层div
  598. if(msgDiv != null){
  599. document.body.removeChild(msgDiv);
  600. }
  601. }, 500);
  602. }
  603. function showUploadFileProgress() {
  604. var sWidth, sHeight;
  605. sWidth = document.body.clientWidth;
  606. sHeight = document.body.clientHeight;
  607. //背景遮罩层div
  608. var bgObj = document.createElement("div");
  609. bgObj.setAttribute('id', 'bgDiv');
  610. bgObj.style.zIndex = '9998';
  611. bgObj.style.position = "absolute";
  612. bgObj.style.top = "0px";
  613. bgObj.style.background = "#888";
  614. bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
  615. bgObj.style.opacity = "0.6";
  616. bgObj.style.left = "0px";
  617. bgObj.style.width = sWidth + "px";
  618. bgObj.style.height = sHeight + "px";
  619. document.body.appendChild(bgObj);
  620. //信息提示层div
  621. var msgObj = document.createElement("div");
  622. msgObj.classList.add('progress');
  623. msgObj.style.zIndex = '9999';
  624. msgObj.style.position = "absolute";
  625. msgObj.setAttribute("id", "progressDiv");
  626. msgObj.style.height = "2px";
  627. msgObj.style.width = "600px";
  628. msgObj.style.top = (document.documentElement.scrollTop + sHeight / 2) + "px";
  629. msgObj.style.left = (sWidth - 600) / 2 + "px";
  630. document.body.appendChild(msgObj);
  631. msgObj.innerHTML = '<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>';
  632. }
  633. function setUploadFileProgress(pos) {
  634. const processObj = $('.progress-bar');
  635. processObj.attr('aria-valuenow', pos);
  636. processObj.width(pos + '%');
  637. }
  638. /**
  639. * 设置本地缓存
  640. *
  641. * @param {String} key
  642. * @param {String|Number} value
  643. * @return {void}
  644. */
  645. function setLocalCache(key, value) {
  646. const storage = window.localStorage;
  647. if (!storage || key === '' || value === '') {
  648. return;
  649. }
  650. storage.setItem(key, value);
  651. }
  652. /**
  653. * 获取本地缓存
  654. *
  655. * @param {String} key
  656. * @return {String}
  657. */
  658. function getLocalCache(key) {
  659. const storage = window.localStorage;
  660. if (!storage || key === '') {
  661. return null;
  662. }
  663. return storage.getItem(key);
  664. }
  665. /**
  666. * 移除本地缓存
  667. * @param {String} key
  668. * @returns {Boolean}
  669. */
  670. function removeLocalCache(key) {
  671. const storage = window.localStorage;
  672. if (!storage || key === '') {
  673. return null;
  674. }
  675. return storage.removeItem(key);
  676. }
  677. //params: 需要复制的对象(元素)
  678. function copyToClipboard( text ) {
  679. var isRTL = document.documentElement.getAttribute('dir') == 'rtl';
  680. var aux = document.createElement('textarea');// 创建元素用于复制
  681. // Prevent zooming on iOS
  682. aux.style.fontSize = '12pt';
  683. // Reset box model
  684. aux.style.border = '0';
  685. aux.style.padding = '0';
  686. aux.style.margin = '0';
  687. // Move element out of screen horizontally
  688. aux.style.position = 'absolute';
  689. aux.style[isRTL ? 'right' : 'left'] = '-9999px';
  690. // Move element to the same position vertically
  691. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  692. aux.style.top = yPosition + 'px';
  693. aux.setAttribute('readonly', '');
  694. // 设置元素内容
  695. aux.value = text;
  696. // 将元素插入页面进行调用
  697. document.body.appendChild(aux);
  698. // 复制内容
  699. aux.select();
  700. aux.setSelectionRange(0, text.length);
  701. // 将内容复制到剪贴板
  702. document.execCommand("copy", true);
  703. // 删除创建元素
  704. document.body.removeChild(aux);
  705. }
  706. function toastMessageUniq (obj) {
  707. if (!obj.msg || !obj.type) return;
  708. if (!obj.once) {
  709. switch (obj.type) {
  710. case 'error':
  711. toastr.error(obj.msg);
  712. break;
  713. case 'warning':
  714. toastr.warning(obj.msg);
  715. break;
  716. case 'info':
  717. toastr.info(obj.msg);
  718. break;
  719. case 'success':
  720. toastr.success(obj.msg);
  721. break;
  722. }
  723. obj.once = true;
  724. }
  725. }
  726. function trimInvalidChar(str) {
  727. return $.trim(str).replace(/\n/g, '').replace(/\r/g, '').replace(/\t/g, '');
  728. }
  729. function cleanSymbols(str) {
  730. return $.trim(str).replace(/\\/g, '').replace(/\'/g, '').replace(/\"/g, '').replace(/\</g, '').replace(/\|/g, '');
  731. }
  732. jQuery.bootstrapLoading = {
  733. isLoading: function () {
  734. return $('#loadingPage').is(':visible');
  735. },
  736. start: function (options) {
  737. if(this.isLoading()){
  738. return;
  739. }
  740. var defaults = {
  741. opacity: 0.5,
  742. //loading页面透明度
  743. // backgroundColor: "#FFFFFF",
  744. //loading页面背景色
  745. borderColor: "#bbb",
  746. //提示边框颜色
  747. borderWidth: 1,
  748. //提示边框宽度
  749. borderStyle: "solid",
  750. //提示边框样式
  751. loadingTips: "Loading, please wait...",
  752. //提示文本
  753. TipsColor: "#fff",
  754. //提示颜色
  755. delayTime: 500,
  756. //页面加载完成后,加载页面渐出速度
  757. zindex: 2000,
  758. //loading页面层次
  759. sleep: 0
  760. //设置挂起,等于0时则无需挂起
  761. }
  762. var options = $.extend(defaults, options);
  763. //获取页面宽高
  764. var _PageHeight = document.documentElement.clientHeight,
  765. _PageWidth = document.documentElement.clientWidth;
  766. //在页面未加载完毕之前显示的loading Html自定义内容
  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;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>';
  768. 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>';
  769. //呈现loading效果
  770. $("body").append(_LoadingHtml);
  771. //获取loading提示框宽高
  772. var _LoadingTipsH = document.getElementById("loadingTips").clientHeight,
  773. _LoadingTipsW = document.getElementById("loadingTips").clientWidth;
  774. //计算距离,让loading提示框保持在屏幕上下左右居中
  775. var _LoadingTop = _PageHeight > _LoadingTipsH ? (_PageHeight - _LoadingTipsH) / 2 : 0,
  776. _LoadingLeft = _PageWidth > _LoadingTipsW ? (_PageWidth - _LoadingTipsW) / 2 : 0;
  777. $("#loadingTips").css({
  778. "left": _LoadingLeft + "px",
  779. "top": _LoadingTop + "px"
  780. });
  781. //监听页面加载状态
  782. document.onreadystatechange = PageLoaded;
  783. //当页面加载完成后执行
  784. function PageLoaded() {
  785. if (document.readyState == "complete") {
  786. var loadingMask = $('#loadingPage');
  787. setTimeout(function () {
  788. loadingMask.animate({
  789. "opacity": 0
  790. },
  791. options.delayTime,
  792. function () {
  793. $(this).hide();
  794. });
  795. },
  796. options.sleep);
  797. }
  798. }
  799. },
  800. end: function () {
  801. $("#loadingPage").remove();
  802. },
  803. progressStop:true,
  804. progressStart:async function(title="导出文件",autoBar = false){
  805. if($("#progressModal").length == 0){
  806. let phtml = `<div class="modal fade" id="progressModal" data-backdrop="static">
  807. <div class="modal-dialog" role="document">
  808. <div class="modal-content">
  809. <div class="modal-header">
  810. <h5 class="modal-title" id="progress_modal_title">${title}</h5>
  811. </div>
  812. <div class="modal-body">
  813. <!--正在生成-->
  814. <h5 class="my-3" id="progress_modal_body">正在${title}</h5>
  815. <div class="progress mb-3">
  816. <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>
  817. </div>
  818. </div>
  819. </div>
  820. </div>
  821. </div>`;
  822. $("body").append(phtml);
  823. }else {
  824. $("#progress_modal_title").text(title);
  825. $("#progress_modal_body").text(`正在${title}`);
  826. }
  827. $("#progress_modal_bar").css('width','0%');
  828. $("#progressModal").modal('show');
  829. if(autoBar == true){//假的进度条
  830. $.bootstrapLoading.progressStop = false;
  831. let width = 0;
  832. while ($.bootstrapLoading.progressStop == false){
  833. await setTimeoutSync(null,1000);
  834. width += 5;
  835. if(width > 90) width -= 50;
  836. $("#progress_modal_bar").css('width',`${width}%`);
  837. }
  838. }
  839. },
  840. progressEnd:function () {
  841. $("#progress_modal_bar").css('width','100%');
  842. $.bootstrapLoading.progressStop = true;
  843. $("#progressModal").modal('hide');
  844. }
  845. };
  846. // 光标插入button内容
  847. $.fn.extend({
  848. insertAtCaret: function(myValue){
  849. var $t=$(this)[0];
  850. if (document.selection) {
  851. this.focus();
  852. sel = document.selection.createRange();
  853. sel.text = myValue;
  854. this.focus();
  855. }
  856. else
  857. if ($t.selectionStart || $t.selectionStart == '0') {
  858. var startPos = $t.selectionStart;
  859. var endPos = $t.selectionEnd;
  860. var scrollTop = $t.scrollTop;
  861. $t.value = $t.value.substring(0, startPos) + myValue + $t.value.substring(endPos, $t.value.length);
  862. this.focus();
  863. $t.selectionStart = startPos + myValue.length;
  864. $t.selectionEnd = startPos + myValue.length;
  865. $t.scrollTop = scrollTop;
  866. }
  867. else {
  868. this.value += myValue;
  869. this.focus();
  870. }
  871. }
  872. });
  873. const checkUtils = {
  874. posOver(data) {
  875. if (!data) return false;
  876. if (!data.quantity) return !!data.end_contract_qty;
  877. return data.quantity > 0
  878. ? data.end_contract_qty > data.quantity
  879. : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
  880. },
  881. billsOver(data, isTz, relaPos) {
  882. if (!data) return false;
  883. if (isTz) {
  884. const posRange = relaPos.ledgerPos[itemsPre + data.id] || [];
  885. if (posRange.length > 0) {
  886. for (const p of posRange) {
  887. if (checkUtils.posOver(p)) return true;
  888. }
  889. return false;
  890. }
  891. if (data.is_tp) {
  892. if (!data.total_price) return !!data.end_contract_tp;
  893. return data.total_price > 0
  894. ? data.end_contract_tp > data.total_price
  895. : data.end_contract_tp < data.total_price || data.end_contract_tp > 0;
  896. } else {
  897. if (!data.quantity) return !!data.end_contract_qty;
  898. return data.quantity > 0
  899. ? data.end_contract_qty > data.quantity
  900. : data.end_contract_qty < data.quantity || data.end_contract_qty > 0;
  901. }
  902. } else {
  903. if (data.is_tp) {
  904. if (!data.deal_tp) return !!data.end_contract_tp;
  905. return data.deal_tp > 0
  906. ? data.end_contract_tp > data.deal_tp
  907. : data.end_contract_tp < data.deal_tp || data.end_contract_tp > 0;
  908. } else {
  909. if (!data.deal_qty) return !!data.end_contract_qty;
  910. return data.deal_qty > 0
  911. ? data.end_contract_qty > data.deal_qty
  912. : data.end_contract_qty < data.deal_qty || data.end_contract_qty > 0;
  913. }
  914. }
  915. }
  916. };
  917. Number.prototype.format2Str = function (pattern) {
  918. var strarr = this?this.toString().split('.'):['0'];
  919. var fmtarr = pattern?pattern.split('.'):[''];
  920. var retstr='';
  921. // 整数部分
  922. var str = strarr[0];
  923. var fmt = fmtarr[0];
  924. var i = str.length-1;
  925. var comma = false;
  926. for(var f=fmt.length-1;f>=0;f--){
  927. switch(fmt.substr(f,1)){
  928. case '#':
  929. if(i>=0 ) retstr = str.substr(i--,1) + retstr;
  930. break;
  931. case '0':
  932. if(i>=0) retstr = str.substr(i--,1) + retstr;
  933. else retstr = '0' + retstr;
  934. break;
  935. case ',':
  936. comma = true;
  937. retstr=','+retstr;
  938. break;
  939. }
  940. }
  941. if(i>=0){
  942. if(comma){
  943. var l = str.length;
  944. for(;i>=0;i--){
  945. retstr = str.substr(i,1) + retstr;
  946. if(i>0 && ((l-i)%3)==0) retstr = ',' + retstr;
  947. }
  948. }
  949. else retstr = str.substr(0,i+1) + retstr;
  950. }
  951. retstr = retstr+'.';
  952. // 处理小数部分
  953. str=strarr.length>1?strarr[1]:'';
  954. fmt=fmtarr.length>1?fmtarr[1]:'';
  955. i=0;
  956. for(var f=0;f<fmt.length;f++){
  957. switch(fmt.substr(f,1)){
  958. case '#':
  959. if(i<str.length) retstr+=str.substr(i++,1);
  960. break;
  961. case '0':
  962. if(i<str.length) retstr+= str.substr(i++,1);
  963. else retstr+='0';
  964. break;
  965. }
  966. }
  967. return retstr.replace(/^,+/,'').replace(/\.$/,'');
  968. };
  969. function transFormToChinese(num) {
  970. const changeNum = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
  971. const unit = ["", "十", "百", "千", "万"];
  972. num = parseInt(num);
  973. let getWan = (temp) => {
  974. let strArr = temp.toString().split("").reverse();
  975. let newNum = "";
  976. for (var i = 0; i < strArr.length; i++) {
  977. 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;
  978. }
  979. return strArr.length === 2 && newNum.indexOf("一十") !== -1 ? newNum.replace('一十', '十') : newNum;
  980. }
  981. let overWan = Math.floor(num / 10000);
  982. let noWan = num % 10000;
  983. if (noWan.toString().length < 4) noWan = "0" + noWan;
  984. return overWan ? getWan(overWan) + "万" + getWan(noWan) : getWan(num);
  985. }