compilation.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120
  1. /**
  2. * 编办管理相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/7/28
  6. * @version
  7. */
  8. const delayTime = 500;
  9. let keyupTime;
  10. function delayKeyup(callback) {
  11. let nowTime = Date.now();
  12. keyupTime = nowTime;
  13. setTimeout(function () {
  14. if (nowTime - keyupTime == 0 && callback) {
  15. callback();
  16. }
  17. }, delayTime);
  18. }
  19. $(document).ready(function() {
  20. let isAdding = false;
  21. let model = '';
  22. let section = $(".nav-tabs li.active > a").text() === '建议估算' ? 'suggestion' : 'bill';
  23. let id = $("#compilation-id").val();
  24. // 计价规则页面初始化数据
  25. if ($("#save-lib").length > 0) {
  26. initCompilation();
  27. }
  28. // 计价类型选择
  29. $(".nav-tabs li > a").click(function() {
  30. section = $(this).attr("aria-controls");
  31. });
  32. // 新增编办
  33. $("#add-compilation").click(function() {
  34. try {
  35. let data = getAndValidData(model);
  36. let url = '/compilation/add'
  37. if (model === 'all') {
  38. // 新增编办操作
  39. $.ajax({
  40. url: url,
  41. type: 'post',
  42. data: {name: data.name},
  43. error: function() {
  44. isAdding = false;
  45. },
  46. beforeSend: function() {
  47. isAdding = true;
  48. },
  49. success: function(response) {
  50. isAdding = false;
  51. if (response.err === 0) {
  52. window.location.reload();
  53. } else {
  54. let msg = response.msg === undefined ? '未知错误' : response.msg;
  55. alert(msg);
  56. }
  57. }
  58. });
  59. } else {
  60. // 新增标准清单/定额库
  61. let addLib = {
  62. name: data[model].name,
  63. id: data[model].id
  64. };
  65. // 判断是否有重复的数据
  66. if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
  67. alert('重复添加数据!');
  68. return false;
  69. }
  70. let removeHtml = '<a class="pull-right text-danger remove-lib" data-model="'+model+'" ' +
  71. 'title="移除"><span class="glyphicon glyphicon-remove"></span></a>';
  72. let tmpHtml = '<p class="form-control-static">' + removeHtml + addLib.name +
  73. '<input type="hidden" data-id="'+ addLib.id +'" name=\'' + model + '_lib\' value=\'' + JSON.stringify(addLib) + '\'>' + '</p>';
  74. $("." + model + "-list").append(tmpHtml);
  75. $('#addcompilation').modal('hide');
  76. }
  77. } catch (error) {
  78. alert(error);
  79. }
  80. });
  81. $("#addTaxGroupBtn").click(function () {
  82. $('#groupEditType').val("add");
  83. $("#taxType").val("");
  84. $("#program_lib").val("");
  85. $("#template_lib").val("");
  86. $("#col_lib").val("");
  87. $("#fee_lib").val("");
  88. });
  89. //新增计税组合
  90. $("#add-group").click(function() {
  91. let taxMap = {"1":"一般计税","2":"简易计税" };
  92. let actionType = $('#groupEditType').val();
  93. let groupData = getTaxGroupData();
  94. let groupIndex = getGroupIndex(groupData);//用来做重复判断
  95. if(!_.isEmpty(groupData)){
  96. //重复判断 todo
  97. if($("input[data-id = "+groupIndex+"]").length <= 0){
  98. let taxName = groupData.taxType?taxMap[groupData.taxType]:'';
  99. let p_name = groupData.program_lib?groupData.program_lib.displayName:"";
  100. let t_name = groupData.template_lib?groupData.template_lib.name:"";
  101. let c_name = groupData.col_lib?groupData.col_lib.name:"";
  102. let f_name = groupData.fee_lib?groupData.fee_lib.name:"";
  103. let htmlString = "<tr class='taxGroup_tr'><td><span>"+taxName+"</span></td>" +
  104. "<td><span>"+p_name+"</span></td>" +
  105. "<td><span>"+t_name+"</span></td>" +
  106. "<td><span>"+c_name+"</span></td>" +
  107. "<td><span>"+f_name+"</span></td>" +
  108. "<td> <a class='btn btn-link btn-sm' style='padding: 0px' onclick='editTaxGroup(this)'> 编辑</a>/<a class='btn btn-link btn-sm ' style='padding: 0px' onclick='deleteTableTr(this,\"taxGroup_tr\")'>删除</a> " +
  109. "<input type='hidden' name='tax_group' data-id ='"+groupIndex+"' value='"+JSON.stringify(groupData)+"'>"+
  110. "</td>" +
  111. "</tr>";
  112. if(actionType == "add"){
  113. $("#tax_group_tbody").append(htmlString);
  114. }else if(actionType == "modify"){
  115. let oldIndex = $("#groupIndex").val();
  116. let parentTr = $("input[data-id = "+oldIndex+"]").parents(".taxGroup_tr");
  117. parentTr.after(htmlString);
  118. parentTr.remove();
  119. }
  120. }else {
  121. alert("已存在相同的组合!");
  122. }
  123. }
  124. $("#addTaxGroup").modal('hide');
  125. });
  126. //新增定额库
  127. $("#add-ration").click(function () {
  128. const options = $("select[name='ration_lib']").children("option:selected");
  129. let alertArr = [];
  130. let htmlString = '';
  131. for (const option of options) {
  132. const rationLib = $(option).val();
  133. const rationLibString = $(option).text();
  134. if (!rationLib) {
  135. alertString.push(`“${rationLibString}”为无效定额库`);
  136. continue;
  137. }
  138. if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length > 0) {
  139. alertArr.push(`“${rationLibString}”已存在`);
  140. continue;
  141. }
  142. const tem = {
  143. id: rationLib,
  144. name: rationLibString,
  145. isDefault: false
  146. };
  147. htmlString += `
  148. <tr class='ration_tr' draggable="true">
  149. <td><span class="cursor-default">${tem.name}</span></td>
  150. <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault" value="${tem.id}" type="radio"></td>
  151. <td>
  152. <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
  153. <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
  154. </td>
  155. </tr>`;
  156. }
  157. if (alertArr.length) {
  158. alert(alertArr.join('\n'));
  159. } else {
  160. $("#ration_tbody").append(htmlString);
  161. $("#addRation").modal('hide');
  162. }
  163. });
  164. // 复制定额库
  165. $('#copy-lib-confirm').click(async function () {
  166. try {
  167. $.bootstrapLoading.start();
  168. const [valuationID, engineeringID] = window.location.pathname.split('/').slice(-2);
  169. await ajaxPost('/compilation/copyRationLibs', { valuationID, engineeringID });
  170. } catch (err) {
  171. console.log(err);
  172. } finally {
  173. $.bootstrapLoading.end();
  174. }
  175. });
  176. // 拖动排序
  177. const dragSelector = '.ration_tr[draggable=true]';
  178. const rationBodySelector = '#ration_tbody';
  179. const wrapper = $('.panel-content')[0];
  180. let dragged;
  181. let rID = null;
  182. const scrollStep = 6;
  183. // 表格数据过多的时候,靠下方的条目想要移动到上方,需要滚动条滚动到相应位置,滚动条向上滚动需要代码自行处理
  184. function scroll(ele, step) {
  185. wrapper.scrollTop -= step;
  186. rID = window.requestAnimationFrame(() => {
  187. scroll(ele, step);
  188. });
  189. }
  190. // 动态绑定(新增的也能监听到)
  191. $(rationBodySelector).on('drag', dragSelector, function (ev) {
  192. const { clientX, clientY } = ev;
  193. const dom = document.elementFromPoint(clientX, clientY);
  194. if (dom.tagName === 'H2' && !rID) {
  195. rID = window.requestAnimationFrame(() => {
  196. scroll(wrapper, scrollStep);
  197. })
  198. } else if (dom.tagName !== 'H2' && rID) {
  199. window.cancelAnimationFrame(rID);
  200. rID = null;
  201. }
  202. });
  203. $(rationBodySelector).on('dragstart', dragSelector, function (ev) {
  204. dragged = this;
  205. $(this).addClass('dragging');
  206. ev.originalEvent.dataTransfer.effectAllowed = 'move';
  207. });
  208. $(rationBodySelector).on('dragend', dragSelector, function (ev) {
  209. $(this).removeClass('dragging');
  210. if (rID) {
  211. window.cancelAnimationFrame(rID);
  212. rID = null;
  213. }
  214. });
  215. $(rationBodySelector).on('dragover', dragSelector, function (ev) {
  216. ev.preventDefault(); // 必须调用此方法,否则drop事件不触发
  217. });
  218. $(rationBodySelector).on('dragenter', dragSelector, function (ev) {
  219. if (this !== dragged) {
  220. $(this).addClass('highlight');
  221. }
  222. });
  223. $(rationBodySelector).on('dragleave', dragSelector, function (ev) {
  224. if (this !== dragged) {
  225. $(this).removeClass('highlight');
  226. }
  227. });
  228. $(rationBodySelector).on('drop', dragSelector, function (ev) {
  229. $(this).removeClass('highlight');
  230. $(this).after($(dragged));
  231. });
  232. // 新增计价规则
  233. $("#add-valuation").click(function() {
  234. try {
  235. if (id === '') {
  236. throw '页面数据有误';
  237. }
  238. let name = $("input[name='valuation_name']").val();
  239. if (name === '') {
  240. throw '请填写计价规则名称';
  241. }
  242. $.ajax({
  243. url: '/compilation/add-valuation',
  244. type: 'post',
  245. data: {name: name, id: id, section: section},
  246. error: function() {
  247. isAdding = false;
  248. },
  249. beforeSend: function() {
  250. isAdding = true;
  251. },
  252. success: function(response) {
  253. isAdding = false;
  254. if (response.err === 0) {
  255. window.location.reload();
  256. } else {
  257. let msg = response.msg === undefined ? '未知错误' : response.msg;
  258. alert(msg);
  259. }
  260. }
  261. });
  262. } catch (error) {
  263. alert(error);
  264. return false;
  265. }
  266. });
  267. // 添加
  268. $(".add-compilation").click(function() {
  269. model = $(this).data('model');
  270. $("#addcompilation .modal-body > div").hide();
  271. switch (model) {
  272. case 'all':
  273. $("#name-area").show();
  274. $("#add-compilation-title").text('添加新费用定额');
  275. break;
  276. case 'bill':
  277. $("#bill-area").show();
  278. $("#add-compilation-title").text('添加标准清单');
  279. break;
  280. case 'ration':
  281. $("#ration-area").show();
  282. $("#add-compilation-title").text('添加定额库');
  283. break;
  284. case 'glj':
  285. $("#glj-area").show();
  286. $("#add-compilation-title").text('添加定额库');
  287. break;
  288. case 'billsGuidance':
  289. $("#billsGuidance-area").show();
  290. $("#add-compilation-title").text('添加清单指引库');
  291. break;
  292. case 'fee':
  293. $("#fee-area").show();
  294. $("#add-compilation-title").text('添加费率标准');
  295. break;
  296. case 'artificial':
  297. $("#artificial-area").show();
  298. $("#add-compilation-title").text('添加人工系数');
  299. break;
  300. case 'program':
  301. $("#program-area").show();
  302. $("#add-compilation-title").text('添加计算程序');
  303. break;
  304. case 'feature':
  305. $("#feature-area").show();
  306. $("#add-compilation-title").text('添加工程特征');
  307. break;
  308. case 'info':
  309. $('#info-area').show();
  310. $('#add-compilation-title').text('添加基本信息');
  311. break;
  312. case 'progressive':
  313. $("#progressive-area").show();
  314. $("#add-compilation-title").text('添加累进区间');
  315. break;
  316. case 'vvTax':
  317. $("#vvTax-area").show();
  318. $("#add-compilation-title").text('添加车船税');
  319. break;
  320. }
  321. $("#addcompilation").modal('show');
  322. });
  323. // 保存专业工程标准库
  324. $("#save-lib").click(function() {
  325. if (validLib()) {
  326. $("form").submit();
  327. }
  328. });
  329. // 保存计价规则
  330. $("#save-valuation").click(function() {
  331. $("#saveValuation").submit();
  332. });
  333. // 移除操作
  334. $(".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list, .billsGuidance-list,.feature-list,.info-list,.progressive-list,.vvTax-list").on("click", ".remove-lib", function() {
  335. $(this).parent().remove();
  336. });
  337. //更改描述
  338. $('#description').change(function () {
  339. let description = $(this).val();
  340. $.ajax({
  341. url: '/compilation/setDescription',
  342. type: 'post',
  343. dataType: "json",
  344. data: {id: id, description: description},
  345. success: function(response) {
  346. if (response.err !== 0) {
  347. alert('更改失败');
  348. }
  349. }
  350. });
  351. });
  352. //更改代码覆盖路径
  353. $('#overWriteUrl').change(function () {
  354. let overWriteUrl = $(this).val();
  355. if(overWriteUrl=="") overWriteUrl = undefined;
  356. $.ajax({
  357. url: '/compilation/setOverWriteUrl',
  358. type: 'post',
  359. dataType: "json",
  360. data: {id: id, overWriteUrl: overWriteUrl},
  361. success: function(response) {
  362. if (response.err !== 0) {
  363. alert('更改失败');
  364. }
  365. }
  366. });
  367. });
  368. //例题建设项目ID, 用英文字符;分隔建设项目ID
  369. $('#example').keyup(function () {
  370. let exampleVal = $(this).val();
  371. let tempExample = exampleVal.split(/[;,;]/g),
  372. example = [];
  373. for (let te of tempExample) {
  374. let intTe = parseInt(te);
  375. if (!isNaN(intTe)) {
  376. example.push(intTe);
  377. }
  378. }
  379. example = Array.from(new Set(example));
  380. delayKeyup(function () {
  381. $.ajax({
  382. url: '/compilation/setExample',
  383. type: 'post',
  384. dataType: "json",
  385. data: {id: id, example: example},
  386. success: function(response) {
  387. if (response.err !== 0) {
  388. alert('更改失败');
  389. }
  390. }
  391. });
  392. });
  393. });
  394. // 计价规则启用/禁止
  395. $(".enable").click(function() {
  396. let goingChangeStatus = switchChange($(this));
  397. let id = $(this).data('id');
  398. if (id === undefined || id === '' || isAdding) {
  399. return false;
  400. }
  401. $.ajax({
  402. url: '/compilation/valuation/' + section + '/enable',
  403. type: 'post',
  404. dataType: "json",
  405. data: {id: id, enable: goingChangeStatus},
  406. error: function() {
  407. isAdding = false;
  408. switchChange($(this));
  409. },
  410. beforeSend: function() {
  411. isAdding = true;
  412. },
  413. success: function(response) {
  414. isAdding = false;
  415. if (response.err !== 0) {
  416. switchChange($(this));
  417. alert('更改失败');
  418. }
  419. }
  420. });
  421. });
  422. // 设置适用类型
  423. $(".fileType").change(function() {
  424. let id = $(this).data('id');
  425. if (id === undefined || id === '' || isAdding) {
  426. return false;
  427. }
  428. let fileTypes = [];
  429. let oldVal = $(this).attr("checked");
  430. if(oldVal){
  431. $(this).removeAttr("checked")
  432. }else{
  433. $(this).attr("checked","checked")
  434. }
  435. if($('#'+id+'_suggest_gusuan').attr("checked")) fileTypes.push(16);
  436. if($('#'+id+'_gusuan').attr("checked")) fileTypes.push(15);
  437. if($('#'+id+'_estimate').attr("checked")) fileTypes.push(5);
  438. if($('#'+id+'_submission').attr("checked")) fileTypes.push(1);
  439. if($('#'+id+'_three_bill_budget').attr("checked")) fileTypes.push(18);
  440. if($('#'+id+'_bill_budget').attr("checked")) fileTypes.push(19);
  441. if($('#'+id+'_changeBudget').attr("checked")) fileTypes.push(4);
  442. if($('#'+id+'_settlement').attr("checked")) fileTypes.push(10);
  443. let current = $(this);
  444. console.log(id,this);
  445. $.ajax({
  446. url: '/compilation/valuation/' + section + '/fileTypes',
  447. type: 'post',
  448. dataType: "json",
  449. data: {id: id, fileTypes: fileTypes},
  450. error: function() {
  451. //恢复原值
  452. if(oldVal){
  453. current.attr("checked","checked")
  454. }else{
  455. current.removeAttr("checked")
  456. }
  457. },
  458. success: function(response) {
  459. if (response.err !== 0) {
  460. switchChange($(this));
  461. alert('更改失败');
  462. }
  463. }
  464. });
  465. });
  466. //计价规则删除
  467. $('#delete-confirm').click(function () {
  468. let id = $('#del').attr('selectedId');
  469. if (id === undefined || id === '') {
  470. return false;
  471. }
  472. window.location.href = `/compilation/valuation/${section}/delete/${id}`;
  473. });
  474. // 发布编办
  475. $("#release").click(function() {
  476. let id = $(this).data("id");
  477. let status = $(this).data("status");
  478. status = parseInt(status);
  479. if (isAdding || id === '' || isNaN(status)) {
  480. return false;
  481. }
  482. $.ajax({
  483. url: '/compilation/release',
  484. type: 'post',
  485. data: {id: id, status: status},
  486. dataType: "json",
  487. error: function() {
  488. isAdding = false;
  489. },
  490. beforeSend: function() {
  491. isAdding = true;
  492. },
  493. success: function(response) {
  494. isAdding = false;
  495. if (response.err === 0) {
  496. window.location.reload();
  497. } else {
  498. let msg = response.msg === undefined ? "未知错误" : response.msg;
  499. alert(msg);
  500. }
  501. }
  502. });
  503. });
  504. //添加工程专业
  505. $("#addEngineerConfirm").click(async function() {
  506. if($('#name').val() == ''){
  507. $("#nameError").show();
  508. return;
  509. }
  510. if($('#feeName').val() == ''){
  511. $("#feeNameError").show();
  512. return;
  513. }
  514. if($('#engineeringInput').val() == ''){
  515. $("#engineeringError").show();
  516. return;
  517. }
  518. if($('#projectEngineering').val() == ''){
  519. $("#projectError").show();
  520. return;
  521. }
  522. $("#addEngineerConfirm").attr("disabled",true);//防止重复提交
  523. $("#addEngineerForm").submit();
  524. });
  525. //
  526. // CLD 办事处选择
  527. $('#category-select').change(function () {
  528. $.ajax({
  529. url: '/compilation/changeCategory',
  530. type: 'post',
  531. data: {id: id, category: $(this).val()},
  532. dataType: "json",
  533. success: function(response) {
  534. if (response.error !== 0) {
  535. alert('更改失败');
  536. }
  537. }
  538. });
  539. })
  540. // 选择默认所在地
  541. $('#location-select').change(function () {
  542. $.ajax({
  543. url: '/compilation/changeLocation',
  544. type: 'post',
  545. data: {id: id, location: $(this).val()},
  546. dataType: "json",
  547. success: function(response) {
  548. if (response.error !== 0) {
  549. alert('更改失败');
  550. }
  551. }
  552. });
  553. })
  554. // 修改是否提供免费版
  555. $('#freeUse').change(function (val) {
  556. $.ajax({
  557. url: '/compilation/changeFreeUse',
  558. type: 'post',
  559. data: {id: id, freeUse: $(this).prop('checked')},
  560. dataType: "json",
  561. success: function(response) {
  562. if (response.error !== 0) {
  563. alert('更改失败');
  564. }
  565. }
  566. });
  567. })
  568. //更改版本号
  569. $('#edition').change(function () {
  570. let edition = $(this).val();
  571. $.ajax({
  572. url: '/compilation/setEdition',
  573. type: 'post',
  574. dataType: "json",
  575. data: { id: id, edition: edition },
  576. success: function (response) {
  577. if (response.err !== 0) {
  578. alert('更改失败');
  579. }
  580. }
  581. });
  582. });
  583. });
  584. /**
  585. * 初始化
  586. *
  587. * @return {void|boolean}
  588. */
  589. function initCompilation() {
  590. let billListData = billList === undefined ? [] : JSON.parse(billList);
  591. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  592. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  593. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  594. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  595. let programData = programList === undefined ? [] : JSON.parse(programList);
  596. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  597. let billTemplateData = billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  598. let mainTreeColData= mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  599. let featureData = featureList == undefined?[]: JSON.parse(featureList);
  600. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  601. let progressiveData = progressiveList == undefined?[]: JSON.parse(progressiveList);
  602. let vvTaxData = vvTaxList == undefined?[]: JSON.parse(vvTaxList);
  603. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  604. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  605. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  606. // 初始化 造价书列设置
  607. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  608. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  609. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  610. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  611. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  612. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  613. }*/
  614. /*
  615. if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  616. return false;
  617. } */
  618. // 标准清单
  619. let html = '';
  620. for(let tmp of billListData) {
  621. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  622. html += tmpHtml;
  623. }
  624. $("select[name='standard_bill']").children("option").first().after(html);
  625. // 定额库
  626. html = '';
  627. for(let tmp of rationLibData) {
  628. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  629. html += tmpHtml;
  630. }
  631. $("select[name='ration_lib']").html(html);
  632. // 工料机库
  633. html = '';
  634. for(let tmp of gljLibData) {
  635. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  636. html += tmpHtml;
  637. }
  638. $("select[name='glj_lib']").children("option").first().after(html);
  639. // 清单指引库
  640. html = '';
  641. for(let tmp of billsGuidanceData) {
  642. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  643. html += tmpHtml;
  644. }
  645. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  646. // 人工系数标准库
  647. html = '';
  648. for(let tmp of artificialCoefficientData) {
  649. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  650. html += tmpHtml;
  651. }
  652. $("select[name='artificial_lib']").children("option").first().after(html);
  653. // 计算程序标准库
  654. html = '';
  655. for(let tmp of programData) {
  656. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.displayName + '</option>';
  657. html += tmpHtml;
  658. }
  659. $("select[name='program_lib']").children("option").first().after(html);
  660. //模板库
  661. html = '';
  662. for(let tmp of billTemplateData) {
  663. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  664. html += tmpHtml;
  665. }
  666. $("select[name='template_lib']").children("option").first().after(html);
  667. //列设置
  668. html = '';
  669. for(let tmp of mainTreeColData) {
  670. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  671. html += tmpHtml;
  672. }
  673. $("select[name='col_lib']").children("option").first().after(html);
  674. // 费率标准库
  675. html = '';
  676. for(let tmp of feeLibData) {
  677. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  678. html += tmpHtml;
  679. }
  680. $("select[name='fee_lib']").children("option").first().after(html);
  681. //工程特征库
  682. html = '';
  683. for(let tmp of featureData){
  684. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  685. html += tmpHtml;
  686. }
  687. $("select[name='feature_lib']").children("option").first().after(html);//工程特征库
  688. //基本信息库
  689. html = '';
  690. for(let tmp of infoData){
  691. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  692. html += tmpHtml;
  693. }
  694. $("select[name='info_lib']").children("option").first().after(html);
  695. //累进区间库
  696. html = '';
  697. for(let tmp of progressiveData){
  698. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  699. html += tmpHtml;
  700. }
  701. $("select[name='progressive_lib']").children("option").first().after(html);
  702. //车船税文件
  703. html = '';
  704. for(let tmp of vvTaxData){
  705. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  706. html += tmpHtml;
  707. }
  708. $("select[name='vvTax_lib']").children("option").first().after(html);
  709. }
  710. /**
  711. * 校验数据
  712. *
  713. * @param {String} model
  714. * @return {Object}
  715. */
  716. function getAndValidData(model) {
  717. let name = $("input[name='compilation_name']").val();
  718. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  719. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  720. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  721. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  722. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  723. let programLib = $("select[name='program_lib']").children("option:selected").val();
  724. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  725. let featureLib = $("select[name='feature_lib']").children("option:selected").val();
  726. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  727. let progressiveLib = $("select[name='progressive_lib']").children("option:selected").val();
  728. let vvTaxLib = $("select[name='vvTax_lib']").children("option:selected").val();
  729. if (name === '' && model === 'all') {
  730. throw '编办名字不能为空';
  731. }
  732. if ( model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  733. throw '请选择标准清单库';
  734. }
  735. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  736. throw '请选择定额库';
  737. }
  738. if (model === 'feature' && (featureLib === '' || featureLib === undefined)) {
  739. throw '请选择工程特征库';
  740. }
  741. if (model === 'progressive' && (progressiveLib === '' || progressiveLib === undefined)) {
  742. throw '请选择累进区间库';
  743. }
  744. if (model === 'vvTax' && (vvTaxLib === '' || vvTaxLib === undefined)) {
  745. throw '请选择车船税文件';
  746. }
  747. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  748. throw '请选择人材机库';
  749. }
  750. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  751. throw '请选择人工系数库';
  752. }
  753. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  754. throw '请选择计算程序';
  755. }
  756. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  757. throw '请选择清单指引库';
  758. }
  759. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  760. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  761. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  762. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  763. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  764. let programString = $("select[name='program_lib']").children("option:selected").text();
  765. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  766. let featrueString = $("select[name='feature_lib']").children("option:selected").text();
  767. let infoString = $("select[name='info_lib']").children("option:selected").text();
  768. let progressiveString = $("select[name='progressive_lib']").children("option:selected").text();
  769. let vvTaxString = $("select[name='vvTax_lib']").children("option:selected").text();
  770. let result = {
  771. name: name,
  772. bill: {
  773. id: standardBill,
  774. name: standardBillString
  775. },
  776. ration: {
  777. id: rationLib,
  778. name: rationLibString
  779. },
  780. glj: {
  781. id: gljLib,
  782. name: gljLibString
  783. },
  784. /* fee: {
  785. id: feeLib,
  786. name: feeLibString
  787. },*/
  788. artificial: {
  789. id: artificialLib,
  790. name: artificialString
  791. },
  792. program: {
  793. id: programLib,
  794. name: programString
  795. },
  796. billsGuidance: {
  797. id: billsGuidanceLib,
  798. name: billsGuidanceString
  799. },
  800. feature:{
  801. id:featureLib,
  802. name:featrueString
  803. },
  804. info: {
  805. id: infoLib,
  806. name: infoString
  807. },
  808. progressive:{
  809. id:progressiveLib,
  810. name:progressiveString
  811. },
  812. vvTax: {
  813. id: vvTaxLib,
  814. name: vvTaxString
  815. }
  816. };
  817. return result;
  818. }
  819. /**
  820. * 验证标准库数据
  821. *
  822. * @return {boolean}
  823. */
  824. function validLib() {
  825. let result = false;
  826. try {
  827. let valuationName = $("input[name='name']").val();
  828. if (valuationName === '') {
  829. throw '请填写计价规则名称';
  830. }
  831. let engineering = $("select[name='engineering']").val();
  832. if (engineering === '' || engineering <= 0) {
  833. throw '请选择工程专业';
  834. }
  835. //按新需求,清单库、定额库等不做非空验证
  836. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  837. throw '请添加标准清单';
  838. }
  839. if ($("input:hidden[name='ration_lib']").length <= 0) {
  840. throw '请添加定额库';
  841. }
  842. if ($("input:hidden[name='glj_lib']").length <= 0) {
  843. throw '请添加人材机库';
  844. }
  845. if ($("input:hidden[name='fee_lib']").length <= 0) {
  846. throw '请添加费率标准';
  847. }
  848. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  849. throw '请添加人工系数';
  850. }
  851. if ($("input:hidden[name='program_lib']").length <= 0) {
  852. throw '请添加计算程序';
  853. }
  854. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  855. throw '请添加清单指引库';
  856. }*/
  857. result = true;
  858. } catch (error) {
  859. alert(error);
  860. result = false;
  861. }
  862. return result;
  863. }
  864. /**
  865. * 切换switch效果
  866. *
  867. * @param {Object} element
  868. * @return {boolean}
  869. */
  870. function switchChange(element) {
  871. // 第一个元素判断当前的状态
  872. let firstButton = element.children("button").first();
  873. let secondButton = element.children("button").eq(1);
  874. let currentStatus = firstButton.is(":disabled");
  875. if (currentStatus) {
  876. // 当前为true切换到false
  877. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  878. firstButton.text('开启');
  879. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  880. secondButton.text('已禁用');
  881. } else {
  882. // 当前false切换到true
  883. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  884. firstButton.text('已开启');
  885. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  886. secondButton.text('禁用');
  887. }
  888. return !currentStatus;
  889. }
  890. function editEngineer(selector) {
  891. let engineerName = $(selector).prev("span").text();
  892. let parentDiv = $(selector).parent("div");
  893. parentDiv.next("div").find("input").val(engineerName);
  894. parentDiv.hide();
  895. parentDiv.next("div").show();
  896. }
  897. function confirmUpdate(selector,engineerID) {
  898. let inputDiv = $(selector).parents(".input_group_div");
  899. let input = $(selector).parent(".input-group-btn").prev("input");
  900. let oldValue = inputDiv.prev("div").find("span").text();
  901. let newValue = input.val();
  902. let key = input.attr("name");
  903. if(newValue == "" || newValue==oldValue || !engineerID){
  904. inputDiv.prev("div").show();
  905. inputDiv.hide();
  906. return;
  907. }
  908. let updateData = {};
  909. updateData[key] = newValue;
  910. updateEngineer(engineerID,updateData,function () {
  911. inputDiv.prev("div").find("span").text(newValue);
  912. });
  913. inputDiv.prev("div").show();
  914. inputDiv.hide();
  915. }
  916. function deleteEngineerClick(engineerID,element) {
  917. hintBox.infoBox('操作确认', '是否删除所选工程专业?', 2, async function () {
  918. try {
  919. let result = await ajaxPost('/compilation/delete-engineer',{id:engineerID});
  920. $(element).parent("td").parent("tr").remove();
  921. }catch (err){
  922. console.log(err);
  923. }
  924. }, null,['确定','取消'],false);
  925. }
  926. function engineerVisibleChange(checkBox,engineerID) {
  927. if(engineerID){
  928. updateEngineer(engineerID,{visible:checkBox.checked});
  929. }
  930. }
  931. function updateEngineer(engineerID,data,callback) {
  932. CommonAjax.post('/compilation/update-engineer',{id:engineerID,updateData:data},function (data) {
  933. if(callback){
  934. callback();
  935. }
  936. })
  937. }
  938. function editTaxGroup(ele) {
  939. $('#groupEditType').val("modify");
  940. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  941. groupData = JSON.parse(groupData);
  942. if(!_.isEmpty(groupData)){
  943. $("#taxType").val(groupData.taxType?groupData.taxType:"");
  944. $("#program_lib").val(groupData.program_lib?groupData.program_lib.id:"");
  945. $("#template_lib").val(groupData.template_lib?groupData.template_lib.id:"");
  946. $("#col_lib").val(groupData.col_lib?groupData.col_lib.id:"");
  947. $("#fee_lib").val(groupData.fee_lib?groupData.fee_lib.id:"");
  948. }else {
  949. $("#taxType").val("");
  950. $("#program_lib").val("");
  951. $("#template_lib").val("");
  952. $("#col_lib").val("");
  953. $("#fee_lib").val("");
  954. }
  955. $("#groupIndex").val(getGroupIndex(groupData));
  956. $("#addTaxGroup").modal({show:true});
  957. }
  958. function deleteTableTr(ele,classString) {
  959. let parentTr = $(ele).parents(`.${classString}`);
  960. parentTr.remove();
  961. }
  962. function getGroupIndex(groupData) {//用来做唯一标识
  963. let index = "";
  964. if(groupData){
  965. if(groupData.taxType) index = index + groupData.taxType;
  966. if(groupData.program_lib) index = index + groupData.program_lib.id;
  967. if(groupData.template_lib) index = index + groupData.template_lib.id;
  968. if(groupData.col_lib) index = index + groupData.col_lib.id;
  969. if(groupData.fee_lib) index = index + groupData.fee_lib.id;
  970. }
  971. return index;
  972. }
  973. function getTaxGroupData() {
  974. let programData = programList === undefined ? [] : _.indexBy(JSON.parse(programList), 'id');
  975. let billTemplateData = billTemplateList == undefined ? [] : _.indexBy(JSON.parse(billTemplateList),'ID');
  976. let mainTreeColData= mainTreeColList == undefined ? [] : _.indexBy(JSON.parse(mainTreeColList),'ID');
  977. let feeLibData = feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList),'id');
  978. let groupData = {};
  979. if($("#taxType").val() !==""){
  980. groupData.taxType = $("#taxType").val();
  981. }
  982. if($("#program_lib").val() !==""){
  983. let program = programData[$("#program_lib").val()];
  984. if(program){
  985. groupData.program_lib = {
  986. id:program.id,
  987. name:program.name,
  988. displayName:program.displayName
  989. }
  990. }
  991. }
  992. if($("#template_lib").val() !==""){
  993. let template = billTemplateData[$("#template_lib").val()];
  994. if(template){
  995. groupData.template_lib = {
  996. id:template.ID,
  997. name:template.name
  998. }
  999. }
  1000. }
  1001. if($("#col_lib").val() !==""){
  1002. let col = mainTreeColData[$("#col_lib").val()];
  1003. if(col){
  1004. groupData.col_lib = {
  1005. id:col.ID,
  1006. name:col.name
  1007. }
  1008. }
  1009. }
  1010. if($("#fee_lib").val() !==""){
  1011. let feeRate = feeLibData[$("#fee_lib").val()];
  1012. if(feeRate){
  1013. groupData.fee_lib = {
  1014. id:feeRate.id,
  1015. name:feeRate.name
  1016. }
  1017. }
  1018. }
  1019. return groupData;
  1020. }
  1021. function intChecking(e,elemt) {//限制输入正整数
  1022. let code = e.which || e.keyCode;
  1023. if(code == 46 || code == 45){//不能输入小数点和-号
  1024. e.preventDefault();
  1025. }
  1026. if( elemt.value == ""&&code == 48){//当输入框为空时不能输入0
  1027. e.preventDefault();
  1028. }
  1029. }