compilation.js 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538
  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. $("#compilationArea").change(function () {
  761. let compilationArea = $(this).val();
  762. $.ajax({
  763. url: "/compilation/setCompilationArea",
  764. type: "post",
  765. dataType: "json",
  766. data: { id, compilationArea },
  767. success: function (response) {
  768. if (response.err !== 0) {
  769. alert("更改失败");
  770. }
  771. },
  772. });
  773. });
  774. //更改版本号
  775. $("#edition").change(function () {
  776. let edition = $(this).val();
  777. $.ajax({
  778. url: "/compilation/setEdition",
  779. type: "post",
  780. dataType: "json",
  781. data: { id: id, edition: edition },
  782. success: function (response) {
  783. if (response.err !== 0) {
  784. alert("更改失败");
  785. }
  786. },
  787. });
  788. });
  789. //更改序号
  790. $("#serialNumber").change(function () {
  791. let serialNumber = Number($(this).val());
  792. $.ajax({
  793. url: "/compilation/setSerialNumber",
  794. type: "post",
  795. dataType: "json",
  796. data: { id: id, serialNumber: serialNumber },
  797. success: function (response) {
  798. if (response.err !== 0) {
  799. alert("更改失败");
  800. }
  801. },
  802. });
  803. });
  804. });
  805. function libUp(id) {
  806. const $item = $(`#list_${id}`).closest(".billLibItem");
  807. const $prevItem = $item.prev();
  808. if ($prevItem.length) {
  809. $item.fadeOut(200, function () {
  810. $prevItem.before($item);
  811. $item.fadeIn(200);
  812. });
  813. }
  814. }
  815. function libDown(id) {
  816. const $item = $(`#list_${id}`).closest(".billLibItem");
  817. const $nextItem = $item.next();
  818. if ($nextItem.length) {
  819. $item.fadeOut(200, function () {
  820. $nextItem.after($item);
  821. $item.fadeIn(200);
  822. });
  823. }
  824. }
  825. /**
  826. * 初始化
  827. *
  828. * @return {void|boolean}
  829. */
  830. function initCompilation() {
  831. let billListData = billList === undefined ? [] : JSON.parse(billList);
  832. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  833. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  834. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  835. let artificialCoefficientData =
  836. artificialCoefficientList === undefined
  837. ? []
  838. : JSON.parse(artificialCoefficientList);
  839. let programData = programList === undefined ? [] : JSON.parse(programList);
  840. let billsGuidanceData =
  841. billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  842. let billTemplateData =
  843. billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  844. let mainTreeColData =
  845. mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  846. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  847. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  848. let progressiveData =
  849. progressiveList == undefined ? [] : JSON.parse(progressiveList);
  850. let vvTaxData = vvTaxList == undefined ? [] : JSON.parse(vvTaxList);
  851. let billCodeData = billCodeList == undefined ? [] : JSON.parse(billCodeList);
  852. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  853. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  854. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  855. // 初始化 造价书列设置
  856. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  857. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  858. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  859. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  860. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  861. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  862. }*/
  863. /*
  864. if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  865. return false;
  866. } */
  867. // 标准清单
  868. let html = "";
  869. for (let tmp of billListData) {
  870. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  871. html += tmpHtml;
  872. }
  873. $("select[name='standard_bill']").children("option").first().after(html);
  874. // 定额库
  875. html = "";
  876. for (let tmp of rationLibData) {
  877. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  878. html += tmpHtml;
  879. }
  880. $("select[name='ration_lib']").html(html);
  881. // 工料机库
  882. html = "";
  883. for (let tmp of gljLibData) {
  884. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  885. html += tmpHtml;
  886. }
  887. $("select[name='glj_lib']").children("option").first().after(html);
  888. // 清单指引库
  889. html = "";
  890. for (let tmp of billsGuidanceData) {
  891. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  892. html += tmpHtml;
  893. }
  894. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  895. // 人工系数标准库
  896. html = "";
  897. for (let tmp of artificialCoefficientData) {
  898. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  899. html += tmpHtml;
  900. }
  901. $("select[name='artificial_lib']").children("option").first().after(html);
  902. // 计算程序标准库
  903. html = "";
  904. for (let tmp of programData) {
  905. let tmpHtml =
  906. '<option value="' + tmp.id + '">' + tmp.displayName + "</option>";
  907. html += tmpHtml;
  908. }
  909. $("select[name='program_lib']").children("option").first().after(html);
  910. //模板库
  911. html = "";
  912. for (let tmp of billTemplateData) {
  913. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  914. html += tmpHtml;
  915. }
  916. $("select[name='template_lib']").children("option").first().after(html);
  917. //列设置
  918. html = "";
  919. for (let tmp of mainTreeColData) {
  920. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  921. html += tmpHtml;
  922. }
  923. $("select[name='col_lib']").children("option").first().after(html);
  924. // 费率标准库
  925. html = "";
  926. for (let tmp of feeLibData) {
  927. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  928. html += tmpHtml;
  929. }
  930. $("select[name='fee_lib']").children("option").first().after(html);
  931. //工程特征库
  932. html = "";
  933. for (let tmp of featureData) {
  934. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  935. html += tmpHtml;
  936. }
  937. $("select[name='feature_lib']").children("option").first().after(html); //工程特征库
  938. //基本信息库
  939. html = "";
  940. for (let tmp of infoData) {
  941. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  942. html += tmpHtml;
  943. }
  944. $("select[name='info_lib']").children("option").first().after(html);
  945. //累进区间库
  946. html = "";
  947. for (let tmp of progressiveData) {
  948. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  949. html += tmpHtml;
  950. }
  951. $("select[name='progressive_lib']").children("option").first().after(html);
  952. //车船税文件
  953. html = "";
  954. for (let tmp of vvTaxData) {
  955. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  956. html += tmpHtml;
  957. }
  958. $("select[name='vvTax_lib']").children("option").first().after(html);
  959. //递延清单库文件
  960. html = "";
  961. for (let tmp of billCodeData) {
  962. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  963. html += tmpHtml;
  964. }
  965. $("select[name='billCode_lib']").children("option").first().after(html);
  966. }
  967. /**
  968. * 校验数据
  969. *
  970. * @param {String} model
  971. * @return {Object}
  972. */
  973. function getAndValidData(model) {
  974. let name = $("input[name='compilation_name']").val();
  975. let standardBill = $("select[name='standard_bill']")
  976. .children("option:selected")
  977. .val();
  978. let rationLib = $("select[name='ration_lib']")
  979. .children("option:selected")
  980. .val();
  981. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  982. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  983. let artificialLib = $("select[name='artificial_lib']")
  984. .children("option:selected")
  985. .val();
  986. let programLib = $("select[name='program_lib']")
  987. .children("option:selected")
  988. .val();
  989. let billsGuidanceLib = $("select[name='billsGuidance_lib']")
  990. .children("option:selected")
  991. .val();
  992. let featureLib = $("select[name='feature_lib']")
  993. .children("option:selected")
  994. .val();
  995. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  996. let progressiveLib = $("select[name='progressive_lib']")
  997. .children("option:selected")
  998. .val();
  999. let vvTaxLib = $("select[name='vvTax_lib']")
  1000. .children("option:selected")
  1001. .val();
  1002. let billCodeLib = $("select[name='billCode_lib']")
  1003. .children("option:selected")
  1004. .val();
  1005. if (name === "" && model === "all") {
  1006. throw "编办名字不能为空";
  1007. }
  1008. if (model === "bill" && (standardBill === "" || standardBill === undefined)) {
  1009. throw "请选择标准清单库";
  1010. }
  1011. if (model === "ration" && (rationLib === "" || rationLib === undefined)) {
  1012. throw "请选择定额库";
  1013. }
  1014. if (model === "feature" && (featureLib === "" || featureLib === undefined)) {
  1015. throw "请选择工程特征库";
  1016. }
  1017. if (
  1018. model === "progressive" &&
  1019. (progressiveLib === "" || progressiveLib === undefined)
  1020. ) {
  1021. throw "请选择累进区间库";
  1022. }
  1023. if (model === "vvTax" && (vvTaxLib === "" || vvTaxLib === undefined)) {
  1024. throw "请选择车船税文件";
  1025. }
  1026. if (
  1027. model === "billCode" &&
  1028. (billCodeLib === "" || billCodeLib === undefined)
  1029. ) {
  1030. throw "请选择递延清单库文件";
  1031. }
  1032. if (model === "glj" && (gljLib === "" || gljLib === undefined)) {
  1033. throw "请选择人材机库";
  1034. }
  1035. if (
  1036. model === "artificial" &&
  1037. (artificialLib === "" || artificialLib === undefined)
  1038. ) {
  1039. throw "请选择人工系数库";
  1040. }
  1041. if (model === "program" && (programLib === "" || programLib === undefined)) {
  1042. throw "请选择计算程序";
  1043. }
  1044. if (
  1045. model === "billsGuidance" &&
  1046. (billsGuidanceLib === "" || billsGuidanceLib === undefined)
  1047. ) {
  1048. throw "请选择清单指引库";
  1049. }
  1050. let standardBillString = $("select[name='standard_bill']")
  1051. .children("option:selected")
  1052. .text();
  1053. let rationLibString = $("select[name='ration_lib']")
  1054. .children("option:selected")
  1055. .text();
  1056. let gljLibString = $("select[name='glj_lib']")
  1057. .children("option:selected")
  1058. .text();
  1059. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  1060. let artificialString = $("select[name='artificial_lib']")
  1061. .children("option:selected")
  1062. .text();
  1063. let programString = $("select[name='program_lib']")
  1064. .children("option:selected")
  1065. .text();
  1066. let billsGuidanceString = $("select[name='billsGuidance_lib']")
  1067. .children("option:selected")
  1068. .text();
  1069. let featrueString = $("select[name='feature_lib']")
  1070. .children("option:selected")
  1071. .text();
  1072. let infoString = $("select[name='info_lib']")
  1073. .children("option:selected")
  1074. .text();
  1075. let progressiveString = $("select[name='progressive_lib']")
  1076. .children("option:selected")
  1077. .text();
  1078. let vvTaxString = $("select[name='vvTax_lib']")
  1079. .children("option:selected")
  1080. .text();
  1081. let billCodeLibString = $("select[name='billCode_lib']")
  1082. .children("option:selected")
  1083. .text();
  1084. let result = {
  1085. name: name,
  1086. bill: {
  1087. id: standardBill,
  1088. name: standardBillString,
  1089. },
  1090. ration: {
  1091. id: rationLib,
  1092. name: rationLibString,
  1093. },
  1094. glj: {
  1095. id: gljLib,
  1096. name: gljLibString,
  1097. },
  1098. /* fee: {
  1099. id: feeLib,
  1100. name: feeLibString
  1101. },*/
  1102. artificial: {
  1103. id: artificialLib,
  1104. name: artificialString,
  1105. },
  1106. program: {
  1107. id: programLib,
  1108. name: programString,
  1109. },
  1110. billsGuidance: {
  1111. id: billsGuidanceLib,
  1112. name: billsGuidanceString,
  1113. },
  1114. feature: {
  1115. id: featureLib,
  1116. name: featrueString,
  1117. },
  1118. info: {
  1119. id: infoLib,
  1120. name: infoString,
  1121. },
  1122. progressive: {
  1123. id: progressiveLib,
  1124. name: progressiveString,
  1125. },
  1126. vvTax: {
  1127. id: vvTaxLib,
  1128. name: vvTaxString,
  1129. },
  1130. billCode: {
  1131. id: billCodeLib,
  1132. name: billCodeLibString,
  1133. },
  1134. };
  1135. return result;
  1136. }
  1137. /**
  1138. * 验证标准库数据
  1139. *
  1140. * @return {boolean}
  1141. */
  1142. function validLib() {
  1143. let result = false;
  1144. try {
  1145. let valuationName = $("input[name='name']").val();
  1146. if (valuationName === "") {
  1147. throw "请填写计价规则名称";
  1148. }
  1149. let engineering = $("select[name='engineering']").val();
  1150. if (engineering === "" || engineering <= 0) {
  1151. throw "请选择工程专业";
  1152. }
  1153. //按新需求,清单库、定额库等不做非空验证
  1154. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  1155. throw '请添加标准清单';
  1156. }
  1157. if ($("input:hidden[name='ration_lib']").length <= 0) {
  1158. throw '请添加定额库';
  1159. }
  1160. if ($("input:hidden[name='glj_lib']").length <= 0) {
  1161. throw '请添加人材机库';
  1162. }
  1163. if ($("input:hidden[name='fee_lib']").length <= 0) {
  1164. throw '请添加费率标准';
  1165. }
  1166. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  1167. throw '请添加人工系数';
  1168. }
  1169. if ($("input:hidden[name='program_lib']").length <= 0) {
  1170. throw '请添加计算程序';
  1171. }
  1172. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  1173. throw '请添加清单指引库';
  1174. }*/
  1175. result = true;
  1176. } catch (error) {
  1177. alert(error);
  1178. result = false;
  1179. }
  1180. return result;
  1181. }
  1182. /**
  1183. * 切换switch效果
  1184. *
  1185. * @param {Object} element
  1186. * @return {boolean}
  1187. */
  1188. function switchChange(element) {
  1189. // 第一个元素判断当前的状态
  1190. let firstButton = element.children("button").first();
  1191. let secondButton = element.children("button").eq(1);
  1192. let currentStatus = firstButton.is(":disabled");
  1193. if (currentStatus) {
  1194. // 当前为true切换到false
  1195. firstButton
  1196. .removeClass("btn-success")
  1197. .removeClass("disabled")
  1198. .addClass("btn-default")
  1199. .removeAttr("disabled");
  1200. firstButton.text("开启");
  1201. secondButton
  1202. .removeClass("btn-default")
  1203. .addClass("btn-danger")
  1204. .addClass("disabled")
  1205. .attr("disabled", "disabled");
  1206. secondButton.text("已禁用");
  1207. } else {
  1208. // 当前false切换到true
  1209. firstButton
  1210. .removeClass("btn-default")
  1211. .addClass("btn-success")
  1212. .addClass("disabled")
  1213. .attr("disabled", "disabled");
  1214. firstButton.text("已开启");
  1215. secondButton
  1216. .removeClass("btn-danger")
  1217. .removeClass("disabled")
  1218. .addClass("btn-default")
  1219. .removeAttr("disabled");
  1220. secondButton.text("禁用");
  1221. }
  1222. return !currentStatus;
  1223. }
  1224. /* function editEngineer(selector) {
  1225. let engineerName = $(selector).prev("span").text();
  1226. let parentDiv = $(selector).parent("div");
  1227. parentDiv.next("div").find("input").val(engineerName);
  1228. parentDiv.hide();
  1229. parentDiv.next("div").show();
  1230. } */
  1231. function editEngineer(selector, key) {
  1232. let editText = $(selector).prev("span").text();
  1233. let parentDiv = $(selector).parent("div");
  1234. let width = key == "seq" ? 70 : 200;
  1235. parentDiv.next("div").css("width", width);
  1236. parentDiv.next("div").find("input").val(editText);
  1237. parentDiv.hide();
  1238. parentDiv.next("div").show();
  1239. }
  1240. /* function confirmUpdate(selector, engineerID) {
  1241. let inputDiv = $(selector).parents(".input_group_div");
  1242. let input = $(selector).parent(".input-group-btn").prev("input");
  1243. let oldValue = inputDiv.prev("div").find("span").text();
  1244. let newValue = input.val();
  1245. let key = input.attr("name");
  1246. if (newValue == "" || newValue == oldValue || !engineerID) {
  1247. inputDiv.prev("div").show();
  1248. inputDiv.hide();
  1249. return;
  1250. }
  1251. let updateData = {};
  1252. updateData[key] = newValue;
  1253. updateEngineer(engineerID, updateData, function () {
  1254. inputDiv.prev("div").find("span").text(newValue);
  1255. });
  1256. inputDiv.prev("div").show();
  1257. inputDiv.hide();
  1258. } */
  1259. function confirmUpdate(selector, engineerID) {
  1260. let inputDiv = $(selector).parents(".input_group_div");
  1261. let input = $(selector).parent(".input-group-btn").prev("input");
  1262. let oldValue = inputDiv.prev("div").find("span").text();
  1263. let newValue = input.val();
  1264. let key = input.attr("name");
  1265. if (newValue == oldValue || !engineerID) {
  1266. //不做非空判断
  1267. inputDiv.prev("div").show();
  1268. inputDiv.hide();
  1269. return;
  1270. }
  1271. let updateData = {};
  1272. updateData[key] = newValue;
  1273. updateEngineer(engineerID, updateData, function () {
  1274. if (key == "seq") {
  1275. window.location.reload();
  1276. } else {
  1277. inputDiv.prev("div").find("span").text(newValue);
  1278. }
  1279. });
  1280. inputDiv.prev("div").show();
  1281. inputDiv.hide();
  1282. }
  1283. function deleteEngineerClick(engineerID, element) {
  1284. hintBox.infoBox(
  1285. "操作确认",
  1286. "是否删除所选工程专业?",
  1287. 2,
  1288. async function () {
  1289. try {
  1290. let result = await ajaxPost("/compilation/delete-engineer", {
  1291. id: engineerID,
  1292. });
  1293. $(element).parent("td").parent("tr").remove();
  1294. } catch (err) {
  1295. console.log(err);
  1296. }
  1297. },
  1298. null,
  1299. ["确定", "取消"],
  1300. false
  1301. );
  1302. }
  1303. function copyEngineerClick(engineerID) {
  1304. hintBox.infoBox(
  1305. "操作确认",
  1306. "是否拷贝所选工程专业?",
  1307. 2,
  1308. async function () {
  1309. try {
  1310. await ajaxPost("/compilation/copy-engineer", { id: engineerID });
  1311. window.location.reload();
  1312. } catch (err) {
  1313. console.log(err);
  1314. }
  1315. },
  1316. null,
  1317. ["确定", "取消"],
  1318. false
  1319. );
  1320. }
  1321. function engineerVisibleChange(checkBox, engineerID) {
  1322. if (engineerID) {
  1323. updateEngineer(engineerID, { visible: checkBox.checked });
  1324. }
  1325. }
  1326. function updateEngineer(engineerID, data, callback) {
  1327. CommonAjax.post(
  1328. "/compilation/update-engineer",
  1329. { id: engineerID, updateData: data },
  1330. function (data) {
  1331. if (callback) {
  1332. callback();
  1333. }
  1334. }
  1335. );
  1336. }
  1337. function editTaxGroup(ele) {
  1338. $("#groupEditType").val("modify");
  1339. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1340. groupData = JSON.parse(groupData);
  1341. if (!_.isEmpty(groupData)) {
  1342. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1343. $("#program_lib").val(
  1344. groupData.program_lib ? groupData.program_lib.id : ""
  1345. );
  1346. $("#template_lib").val(
  1347. groupData.template_lib ? groupData.template_lib.id : ""
  1348. );
  1349. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1350. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1351. } else {
  1352. $("#taxType").val("");
  1353. $("#program_lib").val("");
  1354. $("#template_lib").val("");
  1355. $("#col_lib").val("");
  1356. $("#fee_lib").val("");
  1357. }
  1358. $("#groupIndex").val(getGroupIndex(groupData));
  1359. $("#addTaxGroup").modal({ show: true });
  1360. }
  1361. function deleteTableTr(ele, classString) {
  1362. let parentTr = $(ele).parents(`.${classString}`);
  1363. parentTr.remove();
  1364. }
  1365. function getGroupIndex(groupData) {
  1366. //用来做唯一标识
  1367. let index = "";
  1368. if (groupData) {
  1369. if (groupData.taxType) index = index + groupData.taxType;
  1370. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1371. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1372. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1373. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1374. }
  1375. return index;
  1376. }
  1377. function getTaxGroupData() {
  1378. let programData =
  1379. programList === undefined ? [] : _.indexBy(JSON.parse(programList), "id");
  1380. let billTemplateData =
  1381. billTemplateList == undefined
  1382. ? []
  1383. : _.indexBy(JSON.parse(billTemplateList), "ID");
  1384. let mainTreeColData =
  1385. mainTreeColList == undefined
  1386. ? []
  1387. : _.indexBy(JSON.parse(mainTreeColList), "ID");
  1388. let feeLibData =
  1389. feeRateList === undefined ? [] : _.indexBy(JSON.parse(feeRateList), "id");
  1390. let groupData = {};
  1391. if ($("#taxType").val() !== "") {
  1392. groupData.taxType = $("#taxType").val();
  1393. }
  1394. if ($("#program_lib").val() !== "") {
  1395. let program = programData[$("#program_lib").val()];
  1396. if (program) {
  1397. groupData.program_lib = {
  1398. id: program.id,
  1399. name: program.name,
  1400. displayName: program.displayName,
  1401. };
  1402. }
  1403. }
  1404. if ($("#template_lib").val() !== "") {
  1405. let template = billTemplateData[$("#template_lib").val()];
  1406. if (template) {
  1407. groupData.template_lib = {
  1408. id: template.ID,
  1409. name: template.name,
  1410. };
  1411. }
  1412. }
  1413. if ($("#col_lib").val() !== "") {
  1414. let col = mainTreeColData[$("#col_lib").val()];
  1415. if (col) {
  1416. groupData.col_lib = {
  1417. id: col.ID,
  1418. name: col.name,
  1419. };
  1420. }
  1421. }
  1422. if ($("#fee_lib").val() !== "") {
  1423. let feeRate = feeLibData[$("#fee_lib").val()];
  1424. if (feeRate) {
  1425. groupData.fee_lib = {
  1426. id: feeRate.id,
  1427. name: feeRate.name,
  1428. };
  1429. }
  1430. }
  1431. return groupData;
  1432. }
  1433. function intChecking(e, elemt) {
  1434. //限制输入正整数
  1435. let code = e.which || e.keyCode;
  1436. if (code == 46 || code == 45) {
  1437. //不能输入小数点和-号
  1438. e.preventDefault();
  1439. }
  1440. if (elemt.value == "" && code == 48) {
  1441. //当输入框为空时不能输入0
  1442. e.preventDefault();
  1443. }
  1444. }