global.js 45 KB

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