compilation.js 37 KB

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