compilation.js 43 KB

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