global.js 45 KB

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