global.js 39 KB

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