compilation.js 43 KB

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