compilation.js 37 KB

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