global.js 40 KB

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