compilation.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089
  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. /**
  556. * 初始化
  557. *
  558. * @return {void|boolean}
  559. */
  560. function initCompilation() {
  561. let billListData = billList === undefined ? [] : JSON.parse(billList);
  562. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  563. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  564. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  565. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  566. let programData = programList === undefined ? [] : JSON.parse(programList);
  567. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  568. let billTemplateData = billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  569. let mainTreeColData= mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  570. let featureData = featureList == undefined?[]: JSON.parse(featureList);
  571. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  572. let progressiveData = progressiveList == undefined?[]: JSON.parse(progressiveList);
  573. let vvTaxData = vvTaxList == undefined?[]: JSON.parse(vvTaxList);
  574. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  575. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  576. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  577. // 初始化 造价书列设置
  578. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  579. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  580. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  581. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  582. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  583. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  584. }*/
  585. /*
  586. if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  587. return false;
  588. } */
  589. // 标准清单
  590. let html = '';
  591. for(let tmp of billListData) {
  592. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  593. html += tmpHtml;
  594. }
  595. $("select[name='standard_bill']").children("option").first().after(html);
  596. // 定额库
  597. html = '';
  598. for(let tmp of rationLibData) {
  599. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  600. html += tmpHtml;
  601. }
  602. $("select[name='ration_lib']").html(html);
  603. // 工料机库
  604. html = '';
  605. for(let tmp of gljLibData) {
  606. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  607. html += tmpHtml;
  608. }
  609. $("select[name='glj_lib']").children("option").first().after(html);
  610. // 清单指引库
  611. html = '';
  612. for(let tmp of billsGuidanceData) {
  613. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  614. html += tmpHtml;
  615. }
  616. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  617. // 人工系数标准库
  618. html = '';
  619. for(let tmp of artificialCoefficientData) {
  620. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  621. html += tmpHtml;
  622. }
  623. $("select[name='artificial_lib']").children("option").first().after(html);
  624. // 计算程序标准库
  625. html = '';
  626. for(let tmp of programData) {
  627. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.displayName + '</option>';
  628. html += tmpHtml;
  629. }
  630. $("select[name='program_lib']").children("option").first().after(html);
  631. //模板库
  632. html = '';
  633. for(let tmp of billTemplateData) {
  634. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  635. html += tmpHtml;
  636. }
  637. $("select[name='template_lib']").children("option").first().after(html);
  638. //列设置
  639. html = '';
  640. for(let tmp of mainTreeColData) {
  641. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  642. html += tmpHtml;
  643. }
  644. $("select[name='col_lib']").children("option").first().after(html);
  645. // 费率标准库
  646. html = '';
  647. for(let tmp of feeLibData) {
  648. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  649. html += tmpHtml;
  650. }
  651. $("select[name='fee_lib']").children("option").first().after(html);
  652. //工程特征库
  653. html = '';
  654. for(let tmp of featureData){
  655. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  656. html += tmpHtml;
  657. }
  658. $("select[name='feature_lib']").children("option").first().after(html);//工程特征库
  659. //基本信息库
  660. html = '';
  661. for(let tmp of infoData){
  662. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  663. html += tmpHtml;
  664. }
  665. $("select[name='info_lib']").children("option").first().after(html);
  666. //累进区间库
  667. html = '';
  668. for(let tmp of progressiveData){
  669. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  670. html += tmpHtml;
  671. }
  672. $("select[name='progressive_lib']").children("option").first().after(html);
  673. //车船税文件
  674. html = '';
  675. for(let tmp of vvTaxData){
  676. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  677. html += tmpHtml;
  678. }
  679. $("select[name='vvTax_lib']").children("option").first().after(html);
  680. }
  681. /**
  682. * 校验数据
  683. *
  684. * @param {String} model
  685. * @return {Object}
  686. */
  687. function getAndValidData(model) {
  688. let name = $("input[name='compilation_name']").val();
  689. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  690. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  691. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  692. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  693. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  694. let programLib = $("select[name='program_lib']").children("option:selected").val();
  695. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  696. let featureLib = $("select[name='feature_lib']").children("option:selected").val();
  697. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  698. let progressiveLib = $("select[name='progressive_lib']").children("option:selected").val();
  699. let vvTaxLib = $("select[name='vvTax_lib']").children("option:selected").val();
  700. if (name === '' && model === 'all') {
  701. throw '编办名字不能为空';
  702. }
  703. if ( model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  704. throw '请选择标准清单库';
  705. }
  706. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  707. throw '请选择定额库';
  708. }
  709. if (model === 'feature' && (featureLib === '' || featureLib === undefined)) {
  710. throw '请选择工程特征库';
  711. }
  712. if (model === 'progressive' && (progressiveLib === '' || progressiveLib === undefined)) {
  713. throw '请选择累进区间库';
  714. }
  715. if (model === 'vvTax' && (vvTaxLib === '' || vvTaxLib === undefined)) {
  716. throw '请选择车船税文件';
  717. }
  718. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  719. throw '请选择人材机库';
  720. }
  721. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  722. throw '请选择人工系数库';
  723. }
  724. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  725. throw '请选择计算程序';
  726. }
  727. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  728. throw '请选择清单指引库';
  729. }
  730. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  731. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  732. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  733. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  734. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  735. let programString = $("select[name='program_lib']").children("option:selected").text();
  736. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  737. let featrueString = $("select[name='feature_lib']").children("option:selected").text();
  738. let infoString = $("select[name='info_lib']").children("option:selected").text();
  739. let progressiveString = $("select[name='progressive_lib']").children("option:selected").text();
  740. let vvTaxString = $("select[name='vvTax_lib']").children("option:selected").text();
  741. let result = {
  742. name: name,
  743. bill: {
  744. id: standardBill,
  745. name: standardBillString
  746. },
  747. ration: {
  748. id: rationLib,
  749. name: rationLibString
  750. },
  751. glj: {
  752. id: gljLib,
  753. name: gljLibString
  754. },
  755. /* fee: {
  756. id: feeLib,
  757. name: feeLibString
  758. },*/
  759. artificial: {
  760. id: artificialLib,
  761. name: artificialString
  762. },
  763. program: {
  764. id: programLib,
  765. name: programString
  766. },
  767. billsGuidance: {
  768. id: billsGuidanceLib,
  769. name: billsGuidanceString
  770. },
  771. feature:{
  772. id:featureLib,
  773. name:featrueString
  774. },
  775. info: {
  776. id: infoLib,
  777. name: infoString
  778. },
  779. progressive:{
  780. id:progressiveLib,
  781. name:progressiveString
  782. },
  783. vvTax: {
  784. id: vvTaxLib,
  785. name: vvTaxString
  786. }
  787. };
  788. return result;
  789. }
  790. /**
  791. * 验证标准库数据
  792. *
  793. * @return {boolean}
  794. */
  795. function validLib() {
  796. let result = false;
  797. try {
  798. let valuationName = $("input[name='name']").val();
  799. if (valuationName === '') {
  800. throw '请填写计价规则名称';
  801. }
  802. let engineering = $("select[name='engineering']").val();
  803. if (engineering === '' || engineering <= 0) {
  804. throw '请选择工程专业';
  805. }
  806. //按新需求,清单库、定额库等不做非空验证
  807. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  808. throw '请添加标准清单';
  809. }
  810. if ($("input:hidden[name='ration_lib']").length <= 0) {
  811. throw '请添加定额库';
  812. }
  813. if ($("input:hidden[name='glj_lib']").length <= 0) {
  814. throw '请添加人材机库';
  815. }
  816. if ($("input:hidden[name='fee_lib']").length <= 0) {
  817. throw '请添加费率标准';
  818. }
  819. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  820. throw '请添加人工系数';
  821. }
  822. if ($("input:hidden[name='program_lib']").length <= 0) {
  823. throw '请添加计算程序';
  824. }
  825. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  826. throw '请添加清单指引库';
  827. }*/
  828. result = true;
  829. } catch (error) {
  830. alert(error);
  831. result = false;
  832. }
  833. return result;
  834. }
  835. /**
  836. * 切换switch效果
  837. *
  838. * @param {Object} element
  839. * @return {boolean}
  840. */
  841. function switchChange(element) {
  842. // 第一个元素判断当前的状态
  843. let firstButton = element.children("button").first();
  844. let secondButton = element.children("button").eq(1);
  845. let currentStatus = firstButton.is(":disabled");
  846. if (currentStatus) {
  847. // 当前为true切换到false
  848. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  849. firstButton.text('开启');
  850. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  851. secondButton.text('已禁用');
  852. } else {
  853. // 当前false切换到true
  854. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  855. firstButton.text('已开启');
  856. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  857. secondButton.text('禁用');
  858. }
  859. return !currentStatus;
  860. }
  861. function editEngineer(selector) {
  862. let engineerName = $(selector).prev("span").text();
  863. let parentDiv = $(selector).parent("div");
  864. parentDiv.next("div").find("input").val(engineerName);
  865. parentDiv.hide();
  866. parentDiv.next("div").show();
  867. }
  868. function confirmUpdate(selector,engineerID) {
  869. let inputDiv = $(selector).parents(".input_group_div");
  870. let input = $(selector).parent(".input-group-btn").prev("input");
  871. let oldValue = inputDiv.prev("div").find("span").text();
  872. let newValue = input.val();
  873. let key = input.attr("name");
  874. if(newValue == "" || newValue==oldValue || !engineerID){
  875. inputDiv.prev("div").show();
  876. inputDiv.hide();
  877. return;
  878. }
  879. let updateData = {};
  880. updateData[key] = newValue;
  881. updateEngineer(engineerID,updateData,function () {
  882. inputDiv.prev("div").find("span").text(newValue);
  883. });
  884. inputDiv.prev("div").show();
  885. inputDiv.hide();
  886. }
  887. function deleteEngineerClick(engineerID,element) {
  888. hintBox.infoBox('操作确认', '是否删除所选工程专业?', 2, async function () {
  889. try {
  890. let result = await ajaxPost('/compilation/delete-engineer',{id:engineerID});
  891. $(element).parent("td").parent("tr").remove();
  892. }catch (err){
  893. console.log(err);
  894. }
  895. }, null,['确定','取消'],false);
  896. }
  897. function engineerVisibleChange(checkBox,engineerID) {
  898. if(engineerID){
  899. updateEngineer(engineerID,{visible:checkBox.checked});
  900. }
  901. }
  902. function updateEngineer(engineerID,data,callback) {
  903. CommonAjax.post('/compilation/update-engineer',{id:engineerID,updateData:data},function (data) {
  904. if(callback){
  905. callback();
  906. }
  907. })
  908. }
  909. function editTaxGroup(ele) {
  910. $('#groupEditType').val("modify");
  911. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  912. groupData = JSON.parse(groupData);
  913. if(!_.isEmpty(groupData)){
  914. $("#taxType").val(groupData.taxType?groupData.taxType:"");
  915. $("#program_lib").val(groupData.program_lib?groupData.program_lib.id:"");
  916. $("#template_lib").val(groupData.template_lib?groupData.template_lib.id:"");
  917. $("#col_lib").val(groupData.col_lib?groupData.col_lib.id:"");
  918. $("#fee_lib").val(groupData.fee_lib?groupData.fee_lib.id:"");
  919. }else {
  920. $("#taxType").val("");
  921. $("#program_lib").val("");
  922. $("#template_lib").val("");
  923. $("#col_lib").val("");
  924. $("#fee_lib").val("");
  925. }
  926. $("#groupIndex").val(getGroupIndex(groupData));
  927. $("#addTaxGroup").modal({show:true});
  928. }
  929. function deleteTableTr(ele,classString) {
  930. let parentTr = $(ele).parents(`.${classString}`);
  931. parentTr.remove();
  932. }
  933. function getGroupIndex(groupData) {//用来做唯一标识
  934. let index = "";
  935. if(groupData){
  936. if(groupData.taxType) index = index + groupData.taxType;
  937. if(groupData.program_lib) index = index + groupData.program_lib.id;
  938. if(groupData.template_lib) index = index + groupData.template_lib.id;
  939. if(groupData.col_lib) index = index + groupData.col_lib.id;
  940. if(groupData.fee_lib) index = index + groupData.fee_lib.id;
  941. }
  942. return index;
  943. }
  944. function getTaxGroupData() {
  945. let programData = programList === undefined ? [] : _.indexBy(JSON.parse(programList), 'id');
  946. let billTemplateData = billTemplateList == undefined ? [] : _.indexBy(JSON.parse(billTemplateList),'ID');
  947. let mainTreeColData= mainTreeColList == undefined ? [] : _.indexBy(JSON.parse(mainTreeColList),'ID');
  948. let feeLibData = feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList),'id');
  949. let groupData = {};
  950. if($("#taxType").val() !==""){
  951. groupData.taxType = $("#taxType").val();
  952. }
  953. if($("#program_lib").val() !==""){
  954. let program = programData[$("#program_lib").val()];
  955. if(program){
  956. groupData.program_lib = {
  957. id:program.id,
  958. name:program.name,
  959. displayName:program.displayName
  960. }
  961. }
  962. }
  963. if($("#template_lib").val() !==""){
  964. let template = billTemplateData[$("#template_lib").val()];
  965. if(template){
  966. groupData.template_lib = {
  967. id:template.ID,
  968. name:template.name
  969. }
  970. }
  971. }
  972. if($("#col_lib").val() !==""){
  973. let col = mainTreeColData[$("#col_lib").val()];
  974. if(col){
  975. groupData.col_lib = {
  976. id:col.ID,
  977. name:col.name
  978. }
  979. }
  980. }
  981. if($("#fee_lib").val() !==""){
  982. let feeRate = feeLibData[$("#fee_lib").val()];
  983. if(feeRate){
  984. groupData.fee_lib = {
  985. id:feeRate.id,
  986. name:feeRate.name
  987. }
  988. }
  989. }
  990. return groupData;
  991. }
  992. function intChecking(e,elemt) {//限制输入正整数
  993. let code = e.which || e.keyCode;
  994. if(code == 46 || code == 45){//不能输入小数点和-号
  995. e.preventDefault();
  996. }
  997. if( elemt.value == ""&&code == 48){//当输入框为空时不能输入0
  998. e.preventDefault();
  999. }
  1000. }