global.js 39 KB

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