global.js 42 KB

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