compilation.js 44 KB

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