compilation.js 46 KB

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