compilation.js 39 KB

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