compilation.js 44 KB

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