global.js 36 KB

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