global.js 41 KB

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