compilation.js 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. case 'billCode':
  321. $("#billCode-area").show();
  322. $("#add-compilation-title").text('添加递延清单库');
  323. break;
  324. }
  325. $("#addcompilation").modal('show');
  326. });
  327. // 保存专业工程标准库
  328. $("#save-lib").click(function () {
  329. if (validLib()) {
  330. $("form").submit();
  331. }
  332. });
  333. // 保存计价规则
  334. $("#save-valuation").click(function () {
  335. $("#saveValuation").submit();
  336. });
  337. // 移除操作
  338. $(".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list, .billsGuidance-list,.feature-list,.info-list,.progressive-list,.vvTax-list,.billCode-list").on("click", ".remove-lib", function () {
  339. $(this).parent().remove();
  340. });
  341. //更改描述
  342. $('#description').change(function () {
  343. let description = $(this).val();
  344. $.ajax({
  345. url: '/compilation/setDescription',
  346. type: 'post',
  347. dataType: "json",
  348. data: { id: id, description: description },
  349. success: function (response) {
  350. if (response.err !== 0) {
  351. alert('更改失败');
  352. }
  353. }
  354. });
  355. });
  356. //更改代码覆盖路径
  357. $('#overWriteUrl').change(function () {
  358. let overWriteUrl = $(this).val();
  359. if (overWriteUrl == "") overWriteUrl = undefined;
  360. $.ajax({
  361. url: '/compilation/setOverWriteUrl',
  362. type: 'post',
  363. dataType: "json",
  364. data: { id: id, overWriteUrl: overWriteUrl },
  365. success: function (response) {
  366. if (response.err !== 0) {
  367. alert('更改失败');
  368. }
  369. }
  370. });
  371. });
  372. //例题建设项目ID, 用英文字符;分隔建设项目ID
  373. $('#example').keyup(function () {
  374. let exampleVal = $(this).val();
  375. let tempExample = exampleVal.split(/[;,;]/g),
  376. example = [];
  377. for (let te of tempExample) {
  378. let intTe = parseInt(te);
  379. if (!isNaN(intTe)) {
  380. example.push(intTe);
  381. }
  382. }
  383. example = Array.from(new Set(example));
  384. delayKeyup(function () {
  385. $.ajax({
  386. url: '/compilation/setExample',
  387. type: 'post',
  388. dataType: "json",
  389. data: { id: id, example: example },
  390. success: function (response) {
  391. if (response.err !== 0) {
  392. alert('更改失败');
  393. }
  394. }
  395. });
  396. });
  397. });
  398. // 计价规则启用/禁止
  399. $(".enable").click(function () {
  400. let goingChangeStatus = switchChange($(this));
  401. let id = $(this).data('id');
  402. if (id === undefined || id === '' || isAdding) {
  403. return false;
  404. }
  405. $.ajax({
  406. url: '/compilation/valuation/' + section + '/enable',
  407. type: 'post',
  408. dataType: "json",
  409. data: { id: id, enable: goingChangeStatus },
  410. error: function () {
  411. isAdding = false;
  412. switchChange($(this));
  413. },
  414. beforeSend: function () {
  415. isAdding = true;
  416. },
  417. success: function (response) {
  418. isAdding = false;
  419. if (response.err !== 0) {
  420. switchChange($(this));
  421. alert('更改失败');
  422. }
  423. }
  424. });
  425. });
  426. // 设置适用类型
  427. $(".fileType").change(function () {
  428. let id = $(this).data('id');
  429. if (id === undefined || id === '' || isAdding) {
  430. return false;
  431. }
  432. let fileTypes = [];
  433. let oldVal = $(this).attr("checked");
  434. if (oldVal) {
  435. $(this).removeAttr("checked")
  436. } else {
  437. $(this).attr("checked", "checked")
  438. }
  439. if ($('#' + id + '_suggest_gusuan').attr("checked")) fileTypes.push(16);
  440. if ($('#' + id + '_gusuan').attr("checked")) fileTypes.push(15);
  441. if ($('#' + id + '_estimate').attr("checked")) fileTypes.push(5);
  442. if ($('#' + id + '_submission').attr("checked")) fileTypes.push(1);
  443. if ($('#' + id + '_three_bill_budget').attr("checked")) fileTypes.push(18);
  444. if ($('#' + id + '_bill_budget').attr("checked")) fileTypes.push(19);
  445. if ($('#' + id + '_changeBudget').attr("checked")) fileTypes.push(4);
  446. if ($('#' + id + '_settlement').attr("checked")) fileTypes.push(10);
  447. let current = $(this);
  448. console.log(id, this);
  449. $.ajax({
  450. url: '/compilation/valuation/' + section + '/fileTypes',
  451. type: 'post',
  452. dataType: "json",
  453. data: { id: id, fileTypes: fileTypes },
  454. error: function () {
  455. //恢复原值
  456. if (oldVal) {
  457. current.attr("checked", "checked")
  458. } else {
  459. current.removeAttr("checked")
  460. }
  461. },
  462. success: function (response) {
  463. if (response.err !== 0) {
  464. switchChange($(this));
  465. alert('更改失败');
  466. }
  467. }
  468. });
  469. });
  470. //计价规则删除
  471. $('#delete-confirm').click(function () {
  472. let id = $('#del').attr('selectedId');
  473. if (id === undefined || id === '') {
  474. return false;
  475. }
  476. window.location.href = `/compilation/valuation/${section}/delete/${id}`;
  477. });
  478. // 发布编办
  479. $("#release").click(function () {
  480. let id = $(this).data("id");
  481. let status = $(this).data("status");
  482. status = parseInt(status);
  483. if (isAdding || id === '' || isNaN(status)) {
  484. return false;
  485. }
  486. $.ajax({
  487. url: '/compilation/release',
  488. type: 'post',
  489. data: { id: id, status: status },
  490. dataType: "json",
  491. error: function () {
  492. isAdding = false;
  493. },
  494. beforeSend: function () {
  495. isAdding = true;
  496. },
  497. success: function (response) {
  498. isAdding = false;
  499. if (response.err === 0) {
  500. window.location.reload();
  501. } else {
  502. let msg = response.msg === undefined ? "未知错误" : response.msg;
  503. alert(msg);
  504. }
  505. }
  506. });
  507. });
  508. //添加工程专业
  509. $("#addEngineerConfirm").click(async function () {
  510. if ($('#name').val() == '') {
  511. $("#nameError").show();
  512. return;
  513. }
  514. if ($('#feeName').val() == '') {
  515. $("#feeNameError").show();
  516. return;
  517. }
  518. if ($('#engineeringInput').val() == '') {
  519. $("#engineeringError").show();
  520. return;
  521. }
  522. if ($('#projectEngineering').val() == '') {
  523. $("#projectError").show();
  524. return;
  525. }
  526. $("#addEngineerConfirm").attr("disabled", true);//防止重复提交
  527. $("#addEngineerForm").submit();
  528. });
  529. //
  530. // CLD 办事处选择
  531. $('#category-select').change(function () {
  532. $.ajax({
  533. url: '/compilation/changeCategory',
  534. type: 'post',
  535. data: { id: id, category: $(this).val() },
  536. dataType: "json",
  537. success: function (response) {
  538. if (response.error !== 0) {
  539. alert('更改失败');
  540. }
  541. }
  542. });
  543. })
  544. // 选择默认所在地
  545. $('#location-select').change(function () {
  546. $.ajax({
  547. url: '/compilation/changeLocation',
  548. type: 'post',
  549. data: { id: id, location: $(this).val() },
  550. dataType: "json",
  551. success: function (response) {
  552. if (response.error !== 0) {
  553. alert('更改失败');
  554. }
  555. }
  556. });
  557. })
  558. // 选择编办类型
  559. $('#type-select').change(function () {
  560. $.ajax({
  561. url: '/compilation/changeCompilation',
  562. type: 'post',
  563. data: { id: id, update:{type: $(this).val()} },
  564. dataType: "json",
  565. success: function (response) {
  566. if (response.error !== 0) {
  567. alert('更改失败');
  568. }
  569. }
  570. });
  571. })
  572. // 修改是否提供免费版
  573. $('#freeUse').change(function (val) {
  574. $.ajax({
  575. url: '/compilation/changeFreeUse',
  576. type: 'post',
  577. data: { id: id, freeUse: $(this).prop('checked') },
  578. dataType: "json",
  579. success: function (response) {
  580. if (response.error !== 0) {
  581. alert('更改失败');
  582. }
  583. }
  584. });
  585. })
  586. //更改版本号
  587. $('#edition').change(function () {
  588. let edition = $(this).val();
  589. $.ajax({
  590. url: '/compilation/setEdition',
  591. type: 'post',
  592. dataType: "json",
  593. data: { id: id, edition: edition },
  594. success: function (response) {
  595. if (response.err !== 0) {
  596. alert('更改失败');
  597. }
  598. }
  599. });
  600. });
  601. //更改序号
  602. $('#serialNumber').change(function () {
  603. let serialNumber = Number($(this).val());
  604. $.ajax({
  605. url: '/compilation/setSerialNumber',
  606. type: 'post',
  607. dataType: "json",
  608. data: { id: id, serialNumber: serialNumber },
  609. success: function (response) {
  610. if (response.err !== 0) {
  611. alert('更改失败');
  612. }
  613. }
  614. });
  615. });
  616. });
  617. /**
  618. * 初始化
  619. *
  620. * @return {void|boolean}
  621. */
  622. function initCompilation() {
  623. let billListData = billList === undefined ? [] : JSON.parse(billList);
  624. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  625. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  626. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  627. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  628. let programData = programList === undefined ? [] : JSON.parse(programList);
  629. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  630. let billTemplateData = billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  631. let mainTreeColData = mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  632. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  633. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  634. let progressiveData = progressiveList == undefined ? [] : JSON.parse(progressiveList);
  635. let vvTaxData = vvTaxList == undefined ? [] : JSON.parse(vvTaxList);
  636. let billCodeData = billCodeList == undefined ? [] : JSON.parse(billCodeList);
  637. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  638. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  639. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  640. // 初始化 造价书列设置
  641. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  642. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  643. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  644. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  645. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  646. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  647. }*/
  648. /*
  649. if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  650. return false;
  651. } */
  652. // 标准清单
  653. let html = '';
  654. for (let tmp of billListData) {
  655. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  656. html += tmpHtml;
  657. }
  658. $("select[name='standard_bill']").children("option").first().after(html);
  659. // 定额库
  660. html = '';
  661. for (let tmp of rationLibData) {
  662. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  663. html += tmpHtml;
  664. }
  665. $("select[name='ration_lib']").html(html);
  666. // 工料机库
  667. html = '';
  668. for (let tmp of gljLibData) {
  669. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  670. html += tmpHtml;
  671. }
  672. $("select[name='glj_lib']").children("option").first().after(html);
  673. // 清单指引库
  674. html = '';
  675. for (let tmp of billsGuidanceData) {
  676. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  677. html += tmpHtml;
  678. }
  679. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  680. // 人工系数标准库
  681. html = '';
  682. for (let tmp of artificialCoefficientData) {
  683. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  684. html += tmpHtml;
  685. }
  686. $("select[name='artificial_lib']").children("option").first().after(html);
  687. // 计算程序标准库
  688. html = '';
  689. for (let tmp of programData) {
  690. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.displayName + '</option>';
  691. html += tmpHtml;
  692. }
  693. $("select[name='program_lib']").children("option").first().after(html);
  694. //模板库
  695. html = '';
  696. for (let tmp of billTemplateData) {
  697. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  698. html += tmpHtml;
  699. }
  700. $("select[name='template_lib']").children("option").first().after(html);
  701. //列设置
  702. html = '';
  703. for (let tmp of mainTreeColData) {
  704. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  705. html += tmpHtml;
  706. }
  707. $("select[name='col_lib']").children("option").first().after(html);
  708. // 费率标准库
  709. html = '';
  710. for (let tmp of feeLibData) {
  711. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  712. html += tmpHtml;
  713. }
  714. $("select[name='fee_lib']").children("option").first().after(html);
  715. //工程特征库
  716. html = '';
  717. for (let tmp of featureData) {
  718. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  719. html += tmpHtml;
  720. }
  721. $("select[name='feature_lib']").children("option").first().after(html);//工程特征库
  722. //基本信息库
  723. html = '';
  724. for (let tmp of infoData) {
  725. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  726. html += tmpHtml;
  727. }
  728. $("select[name='info_lib']").children("option").first().after(html);
  729. //累进区间库
  730. html = '';
  731. for (let tmp of progressiveData) {
  732. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  733. html += tmpHtml;
  734. }
  735. $("select[name='progressive_lib']").children("option").first().after(html);
  736. //车船税文件
  737. html = '';
  738. for (let tmp of vvTaxData) {
  739. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  740. html += tmpHtml;
  741. }
  742. $("select[name='vvTax_lib']").children("option").first().after(html);
  743. //递延清单库文件
  744. html = '';
  745. for (let tmp of billCodeData) {
  746. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  747. html += tmpHtml;
  748. }
  749. $("select[name='billCode_lib']").children("option").first().after(html);
  750. }
  751. /**
  752. * 校验数据
  753. *
  754. * @param {String} model
  755. * @return {Object}
  756. */
  757. function getAndValidData(model) {
  758. let name = $("input[name='compilation_name']").val();
  759. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  760. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  761. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  762. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  763. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  764. let programLib = $("select[name='program_lib']").children("option:selected").val();
  765. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  766. let featureLib = $("select[name='feature_lib']").children("option:selected").val();
  767. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  768. let progressiveLib = $("select[name='progressive_lib']").children("option:selected").val();
  769. let vvTaxLib = $("select[name='vvTax_lib']").children("option:selected").val();
  770. let billCodeLib = $("select[name='billCode_lib']").children("option:selected").val();
  771. if (name === '' && model === 'all') {
  772. throw '编办名字不能为空';
  773. }
  774. if (model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  775. throw '请选择标准清单库';
  776. }
  777. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  778. throw '请选择定额库';
  779. }
  780. if (model === 'feature' && (featureLib === '' || featureLib === undefined)) {
  781. throw '请选择工程特征库';
  782. }
  783. if (model === 'progressive' && (progressiveLib === '' || progressiveLib === undefined)) {
  784. throw '请选择累进区间库';
  785. }
  786. if (model === 'vvTax' && (vvTaxLib === '' || vvTaxLib === undefined)) {
  787. throw '请选择车船税文件';
  788. }
  789. if (model === 'billCode' && (billCodeLib === '' || billCodeLib === undefined)) {
  790. throw '请选择递延清单库文件';
  791. }
  792. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  793. throw '请选择人材机库';
  794. }
  795. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  796. throw '请选择人工系数库';
  797. }
  798. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  799. throw '请选择计算程序';
  800. }
  801. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  802. throw '请选择清单指引库';
  803. }
  804. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  805. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  806. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  807. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  808. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  809. let programString = $("select[name='program_lib']").children("option:selected").text();
  810. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  811. let featrueString = $("select[name='feature_lib']").children("option:selected").text();
  812. let infoString = $("select[name='info_lib']").children("option:selected").text();
  813. let progressiveString = $("select[name='progressive_lib']").children("option:selected").text();
  814. let vvTaxString = $("select[name='vvTax_lib']").children("option:selected").text();
  815. let billCodeLibString = $("select[name='billCode_lib']").children("option:selected").text();
  816. let result = {
  817. name: name,
  818. bill: {
  819. id: standardBill,
  820. name: standardBillString
  821. },
  822. ration: {
  823. id: rationLib,
  824. name: rationLibString
  825. },
  826. glj: {
  827. id: gljLib,
  828. name: gljLibString
  829. },
  830. /* fee: {
  831. id: feeLib,
  832. name: feeLibString
  833. },*/
  834. artificial: {
  835. id: artificialLib,
  836. name: artificialString
  837. },
  838. program: {
  839. id: programLib,
  840. name: programString
  841. },
  842. billsGuidance: {
  843. id: billsGuidanceLib,
  844. name: billsGuidanceString
  845. },
  846. feature: {
  847. id: featureLib,
  848. name: featrueString
  849. },
  850. info: {
  851. id: infoLib,
  852. name: infoString
  853. },
  854. progressive: {
  855. id: progressiveLib,
  856. name: progressiveString
  857. },
  858. vvTax: {
  859. id: vvTaxLib,
  860. name: vvTaxString
  861. },
  862. billCode: {
  863. id: billCodeLib,
  864. name: billCodeLibString
  865. }
  866. };
  867. return result;
  868. }
  869. /**
  870. * 验证标准库数据
  871. *
  872. * @return {boolean}
  873. */
  874. function validLib() {
  875. let result = false;
  876. try {
  877. let valuationName = $("input[name='name']").val();
  878. if (valuationName === '') {
  879. throw '请填写计价规则名称';
  880. }
  881. let engineering = $("select[name='engineering']").val();
  882. if (engineering === '' || engineering <= 0) {
  883. throw '请选择工程专业';
  884. }
  885. //按新需求,清单库、定额库等不做非空验证
  886. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  887. throw '请添加标准清单';
  888. }
  889. if ($("input:hidden[name='ration_lib']").length <= 0) {
  890. throw '请添加定额库';
  891. }
  892. if ($("input:hidden[name='glj_lib']").length <= 0) {
  893. throw '请添加人材机库';
  894. }
  895. if ($("input:hidden[name='fee_lib']").length <= 0) {
  896. throw '请添加费率标准';
  897. }
  898. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  899. throw '请添加人工系数';
  900. }
  901. if ($("input:hidden[name='program_lib']").length <= 0) {
  902. throw '请添加计算程序';
  903. }
  904. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  905. throw '请添加清单指引库';
  906. }*/
  907. result = true;
  908. } catch (error) {
  909. alert(error);
  910. result = false;
  911. }
  912. return result;
  913. }
  914. /**
  915. * 切换switch效果
  916. *
  917. * @param {Object} element
  918. * @return {boolean}
  919. */
  920. function switchChange(element) {
  921. // 第一个元素判断当前的状态
  922. let firstButton = element.children("button").first();
  923. let secondButton = element.children("button").eq(1);
  924. let currentStatus = firstButton.is(":disabled");
  925. if (currentStatus) {
  926. // 当前为true切换到false
  927. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  928. firstButton.text('开启');
  929. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  930. secondButton.text('已禁用');
  931. } else {
  932. // 当前false切换到true
  933. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  934. firstButton.text('已开启');
  935. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  936. secondButton.text('禁用');
  937. }
  938. return !currentStatus;
  939. }
  940. /* function editEngineer(selector) {
  941. let engineerName = $(selector).prev("span").text();
  942. let parentDiv = $(selector).parent("div");
  943. parentDiv.next("div").find("input").val(engineerName);
  944. parentDiv.hide();
  945. parentDiv.next("div").show();
  946. } */
  947. function editEngineer(selector, key) {
  948. let editText = $(selector).prev("span").text();
  949. let parentDiv = $(selector).parent("div");
  950. let width = key == 'seq' ? 70 : 200;
  951. parentDiv.next("div").css('width', width);
  952. parentDiv.next("div").find("input").val(editText);
  953. parentDiv.hide();
  954. parentDiv.next("div").show();
  955. }
  956. /* function confirmUpdate(selector, engineerID) {
  957. let inputDiv = $(selector).parents(".input_group_div");
  958. let input = $(selector).parent(".input-group-btn").prev("input");
  959. let oldValue = inputDiv.prev("div").find("span").text();
  960. let newValue = input.val();
  961. let key = input.attr("name");
  962. if (newValue == "" || newValue == oldValue || !engineerID) {
  963. inputDiv.prev("div").show();
  964. inputDiv.hide();
  965. return;
  966. }
  967. let updateData = {};
  968. updateData[key] = newValue;
  969. updateEngineer(engineerID, updateData, function () {
  970. inputDiv.prev("div").find("span").text(newValue);
  971. });
  972. inputDiv.prev("div").show();
  973. inputDiv.hide();
  974. } */
  975. function confirmUpdate(selector, engineerID) {
  976. let inputDiv = $(selector).parents(".input_group_div");
  977. let input = $(selector).parent(".input-group-btn").prev("input");
  978. let oldValue = inputDiv.prev("div").find("span").text();
  979. let newValue = input.val();
  980. let key = input.attr("name");
  981. if (newValue == oldValue || !engineerID) {//不做非空判断
  982. inputDiv.prev("div").show();
  983. inputDiv.hide();
  984. return;
  985. }
  986. let updateData = {};
  987. updateData[key] = newValue;
  988. updateEngineer(engineerID, updateData, function () {
  989. if (key == 'seq') {
  990. window.location.reload();
  991. } else {
  992. inputDiv.prev("div").find("span").text(newValue);
  993. }
  994. });
  995. inputDiv.prev("div").show();
  996. inputDiv.hide();
  997. }
  998. function deleteEngineerClick(engineerID, element) {
  999. hintBox.infoBox('操作确认', '是否删除所选工程专业?', 2, async function () {
  1000. try {
  1001. let result = await ajaxPost('/compilation/delete-engineer', { id: engineerID });
  1002. $(element).parent("td").parent("tr").remove();
  1003. } catch (err) {
  1004. console.log(err);
  1005. }
  1006. }, null, ['确定', '取消'], false);
  1007. }
  1008. function copyEngineerClick(engineerID) {
  1009. hintBox.infoBox('操作确认', '是否拷贝所选工程专业?', 2, async function () {
  1010. try {
  1011. await ajaxPost('/compilation/copy-engineer', { id: engineerID });
  1012. window.location.reload();
  1013. } catch (err) {
  1014. console.log(err);
  1015. }
  1016. }, null, ['确定', '取消'], false);
  1017. }
  1018. function engineerVisibleChange(checkBox, engineerID) {
  1019. if (engineerID) {
  1020. updateEngineer(engineerID, { visible: checkBox.checked });
  1021. }
  1022. }
  1023. function updateEngineer(engineerID, data, callback) {
  1024. CommonAjax.post('/compilation/update-engineer', { id: engineerID, updateData: data }, function (data) {
  1025. if (callback) {
  1026. callback();
  1027. }
  1028. })
  1029. }
  1030. function editTaxGroup(ele) {
  1031. $('#groupEditType').val("modify");
  1032. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1033. groupData = JSON.parse(groupData);
  1034. if (!_.isEmpty(groupData)) {
  1035. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1036. $("#program_lib").val(groupData.program_lib ? groupData.program_lib.id : "");
  1037. $("#template_lib").val(groupData.template_lib ? groupData.template_lib.id : "");
  1038. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1039. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1040. } else {
  1041. $("#taxType").val("");
  1042. $("#program_lib").val("");
  1043. $("#template_lib").val("");
  1044. $("#col_lib").val("");
  1045. $("#fee_lib").val("");
  1046. }
  1047. $("#groupIndex").val(getGroupIndex(groupData));
  1048. $("#addTaxGroup").modal({ show: true });
  1049. }
  1050. function deleteTableTr(ele, classString) {
  1051. let parentTr = $(ele).parents(`.${classString}`);
  1052. parentTr.remove();
  1053. }
  1054. function getGroupIndex(groupData) {//用来做唯一标识
  1055. let index = "";
  1056. if (groupData) {
  1057. if (groupData.taxType) index = index + groupData.taxType;
  1058. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1059. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1060. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1061. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1062. }
  1063. return index;
  1064. }
  1065. function getTaxGroupData() {
  1066. let programData = programList === undefined ? [] : _.indexBy(JSON.parse(programList), 'id');
  1067. let billTemplateData = billTemplateList == undefined ? [] : _.indexBy(JSON.parse(billTemplateList), 'ID');
  1068. let mainTreeColData = mainTreeColList == undefined ? [] : _.indexBy(JSON.parse(mainTreeColList), 'ID');
  1069. let feeLibData = feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList), 'id');
  1070. let groupData = {};
  1071. if ($("#taxType").val() !== "") {
  1072. groupData.taxType = $("#taxType").val();
  1073. }
  1074. if ($("#program_lib").val() !== "") {
  1075. let program = programData[$("#program_lib").val()];
  1076. if (program) {
  1077. groupData.program_lib = {
  1078. id: program.id,
  1079. name: program.name,
  1080. displayName: program.displayName
  1081. }
  1082. }
  1083. }
  1084. if ($("#template_lib").val() !== "") {
  1085. let template = billTemplateData[$("#template_lib").val()];
  1086. if (template) {
  1087. groupData.template_lib = {
  1088. id: template.ID,
  1089. name: template.name
  1090. }
  1091. }
  1092. }
  1093. if ($("#col_lib").val() !== "") {
  1094. let col = mainTreeColData[$("#col_lib").val()];
  1095. if (col) {
  1096. groupData.col_lib = {
  1097. id: col.ID,
  1098. name: col.name
  1099. }
  1100. }
  1101. }
  1102. if ($("#fee_lib").val() !== "") {
  1103. let feeRate = feeLibData[$("#fee_lib").val()];
  1104. if (feeRate) {
  1105. groupData.fee_lib = {
  1106. id: feeRate.id,
  1107. name: feeRate.name
  1108. }
  1109. }
  1110. }
  1111. return groupData;
  1112. }
  1113. function intChecking(e, elemt) {//限制输入正整数
  1114. let code = e.which || e.keyCode;
  1115. if (code == 46 || code == 45) {//不能输入小数点和-号
  1116. e.preventDefault();
  1117. }
  1118. if (elemt.value == "" && code == 48) {//当输入框为空时不能输入0
  1119. e.preventDefault();
  1120. }
  1121. }