compilation.js 44 KB

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