compilation.js 47 KB

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