global.js 51 KB

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