global.js 42 KB

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