compilation.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  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 "item_increase":
  510. $("#item-increase-area").show();
  511. $("#add-compilation-title").text("添加子目增加费");
  512. break;
  513. case "progressive":
  514. $("#progressive-area").show();
  515. $("#add-compilation-title").text("添加累进区间");
  516. break;
  517. case "engineer_info":
  518. $("#engineer-info-area").show();
  519. $("#add-compilation-title").text("添加工程信息");
  520. break;
  521. case "engineer_feature":
  522. $("#engineer-feature-area").show();
  523. $("#add-compilation-title").text("添加工程特征指标");
  524. break;
  525. case "material":
  526. $("#material-area").show();
  527. $("#add-compilation-title").text("添加主要工料指标");
  528. break;
  529. case "main_quantity":
  530. $("#main-quantity-area").show();
  531. $("#add-compilation-title").text("添加主要工程量指标");
  532. break;
  533. case "economic":
  534. $("#economic-area").show();
  535. $("#add-compilation-title").text("添加主要经济指标");
  536. break;
  537. case "over_height":
  538. $("#over-height-area").show();
  539. $("#add-compilation-title").text("添加超高降效");
  540. break;
  541. }
  542. $("#addcompilation").modal("show");
  543. });
  544. // 保存专业工程标准库
  545. $("#save-lib").click(function () {
  546. if (validLib()) {
  547. $("form").submit();
  548. }
  549. });
  550. // 保存计价规则
  551. $("#save-valuation").click(function () {
  552. $("#saveValuation").submit();
  553. });
  554. // 移除操作
  555. /*$(".remove-lib").on("click", function() {
  556. $(this).parent().remove();
  557. })*/
  558. $(
  559. ".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,.item_increase-list",
  560. ).on("click", ".remove-lib", function () {
  561. $(this).parent().remove();
  562. });
  563. //更改描述
  564. $("#description").change(function () {
  565. let description = $(this).val();
  566. $.ajax({
  567. url: "/compilation/setDescription",
  568. type: "post",
  569. dataType: "json",
  570. data: { id: id, description: description },
  571. success: function (response) {
  572. if (response.err !== 0) {
  573. alert("更改失败");
  574. }
  575. },
  576. });
  577. });
  578. //更改版本号
  579. $("#edition").change(function () {
  580. let edition = $(this).val();
  581. $.ajax({
  582. url: "/compilation/setEdition",
  583. type: "post",
  584. dataType: "json",
  585. data: { id: id, edition: edition },
  586. success: function (response) {
  587. if (response.err !== 0) {
  588. alert("更改失败");
  589. }
  590. },
  591. });
  592. });
  593. //更改编办地区
  594. $("#compilationArea").change(function () {
  595. let compilationArea = $(this).val();
  596. $.ajax({
  597. url: "/compilation/setCompilationArea",
  598. type: "post",
  599. dataType: "json",
  600. data: { id, compilationArea },
  601. success: function (response) {
  602. if (response.err !== 0) {
  603. alert("更改失败");
  604. }
  605. },
  606. });
  607. });
  608. //更改序号
  609. $("#serialNumber").change(function () {
  610. let serialNumber = Number($(this).val());
  611. $.ajax({
  612. url: "/compilation/setSerialNumber",
  613. type: "post",
  614. dataType: "json",
  615. data: { id: id, serialNumber: serialNumber },
  616. success: function (response) {
  617. if (response.err !== 0) {
  618. alert("更改失败");
  619. }
  620. },
  621. });
  622. });
  623. //更改代码覆盖路径
  624. $("#overWriteUrl").change(function () {
  625. let overWriteUrl = $(this).val();
  626. if (overWriteUrl == "") overWriteUrl = undefined;
  627. $.ajax({
  628. url: "/compilation/setOverWriteUrl",
  629. type: "post",
  630. dataType: "json",
  631. data: { id: id, overWriteUrl: overWriteUrl },
  632. success: function (response) {
  633. if (response.err !== 0) {
  634. alert("更改失败");
  635. }
  636. },
  637. });
  638. });
  639. //例题建设项目ID, 用英文字符;分隔建设项目ID
  640. $("#example").keyup(function () {
  641. let exampleVal = $(this).val();
  642. let example = exampleVal.split(/[;,;]/g);
  643. example = Array.from(new Set(example));
  644. delayKeyup(function () {
  645. $.ajax({
  646. url: "/compilation/setExample",
  647. type: "post",
  648. dataType: "json",
  649. data: { id: id, example: example },
  650. success: function (response) {
  651. if (response.err !== 0) {
  652. alert("更改失败");
  653. }
  654. },
  655. });
  656. });
  657. });
  658. // 计价规则启用/禁止
  659. $(".enable").click(function () {
  660. let goingChangeStatus = switchChange($(this));
  661. let id = $(this).data("id");
  662. if (id === undefined || id === "" || isAdding) {
  663. return false;
  664. }
  665. $.ajax({
  666. url: "/compilation/valuation/" + section + "/enable",
  667. type: "post",
  668. dataType: "json",
  669. data: { id: id, enable: goingChangeStatus },
  670. error: function () {
  671. isAdding = false;
  672. switchChange($(this));
  673. },
  674. beforeSend: function () {
  675. isAdding = true;
  676. },
  677. success: function (response) {
  678. isAdding = false;
  679. if (response.err !== 0) {
  680. switchChange($(this));
  681. alert("更改失败");
  682. }
  683. },
  684. });
  685. });
  686. // 设置适用类型
  687. $(".fileType").change(function () {
  688. let id = $(this).data("id");
  689. if (id === undefined || id === "" || isAdding) {
  690. return false;
  691. }
  692. let fileTypes = [];
  693. let oldVal = $(this).attr("checked");
  694. if (oldVal) {
  695. $(this).removeAttr("checked");
  696. } else {
  697. $(this).attr("checked", "checked");
  698. }
  699. if ($("#" + id + "_gusuan").attr("checked")) fileTypes.push(15);
  700. if ($("#" + id + "_estimate").attr("checked")) fileTypes.push(5);
  701. if ($("#" + id + "_submission").attr("checked")) fileTypes.push(1);
  702. if ($("#" + id + "_changeBudget").attr("checked")) fileTypes.push(4);
  703. if ($("#" + id + "_settlement").attr("checked")) fileTypes.push(10);
  704. if ($("#" + id + "_finalSettlement").attr("checked")) fileTypes.push(21);
  705. let current = $(this);
  706. console.log(id, this);
  707. $.ajax({
  708. url: "/compilation/valuation/" + section + "/fileTypes",
  709. type: "post",
  710. dataType: "json",
  711. data: { id: id, fileTypes: fileTypes },
  712. error: function () {
  713. //恢复原值
  714. if (oldVal) {
  715. current.attr("checked", "checked");
  716. } else {
  717. current.removeAttr("checked");
  718. }
  719. },
  720. success: function (response) {
  721. if (response.err !== 0) {
  722. switchChange($(this));
  723. alert("更改失败");
  724. }
  725. },
  726. });
  727. });
  728. //计价规则删除
  729. $("#delete-confirm").click(function () {
  730. let id = $("#del").attr("selectedId");
  731. if (id === undefined || id === "") {
  732. return false;
  733. }
  734. window.location.href = `/compilation/valuation/bill/delete/${id}`;
  735. });
  736. // 发布编办
  737. $("#release").click(function () {
  738. let id = $(this).data("id");
  739. let status = $(this).data("status");
  740. status = parseInt(status);
  741. if (isAdding || id === "" || isNaN(status)) {
  742. return false;
  743. }
  744. $.ajax({
  745. url: "/compilation/release",
  746. type: "post",
  747. data: { id: id, status: status },
  748. dataType: "json",
  749. error: function () {
  750. isAdding = false;
  751. },
  752. beforeSend: function () {
  753. isAdding = true;
  754. },
  755. success: function (response) {
  756. isAdding = false;
  757. if (response.err === 0) {
  758. window.location.reload();
  759. } else {
  760. let msg = response.msg === undefined ? "未知错误" : response.msg;
  761. alert(msg);
  762. }
  763. },
  764. });
  765. });
  766. //添加工程专业
  767. $("#addEngineerConfirm").click(async function () {
  768. if ($("#name").val() == "") {
  769. $("#nameError").show();
  770. return;
  771. }
  772. if ($("#feeName").val() == "") {
  773. $("#feeNameError").show();
  774. return;
  775. }
  776. if ($("#engineeringInput").val() == "") {
  777. $("#engineeringError").show();
  778. return;
  779. }
  780. if ($("#projectEngineering").val() == "") {
  781. $("#projectError").show();
  782. return;
  783. }
  784. $("#addEngineerConfirm").attr("disabled", true); //防止重复提交
  785. $("#addEngineerForm").submit();
  786. });
  787. //
  788. // CLD 办事处选择 - 多级子菜单
  789. (function () {
  790. function buildTree(list) {
  791. var map = {};
  792. var roots = [];
  793. list.forEach(function (item) {
  794. map[item.id] = { data: item, children: [] };
  795. });
  796. list.forEach(function (item) {
  797. if (item.parentId && item.parentId !== "0" && map[item.parentId]) {
  798. map[item.parentId].children.push(map[item.id]);
  799. } else {
  800. roots.push(map[item.id]);
  801. }
  802. });
  803. return roots;
  804. }
  805. function renderTree(nodes, depth) {
  806. depth = depth || 0;
  807. var html = "";
  808. nodes.forEach(function (node) {
  809. var hasChildren = node.children.length > 0;
  810. var paddingLeft = depth * 16 + 10 + "px";
  811. html += '<li style="padding:0;">';
  812. html +=
  813. '<div class="category-node" data-id="' +
  814. node.data.id +
  815. '" data-name="' +
  816. node.data.name +
  817. '" style="padding:5px 10px 5px ' +
  818. paddingLeft +
  819. '; cursor:pointer; white-space:nowrap; display:flex; align-items:center; justify-content:space-between; user-select:none;">';
  820. html += "<span>" + node.data.name + "</span>";
  821. if (hasChildren) {
  822. html +=
  823. '<span class="category-toggle" style="margin-left:8px; font-size:12px; color:#555; cursor:pointer;">' +
  824. (depth === 0 ? "&#9660;" : "&#9654;") +
  825. "</span>";
  826. }
  827. html += "</div>";
  828. if (hasChildren) {
  829. html +=
  830. '<ul style="list-style:none; padding:0; margin:0; display:' +
  831. (depth === 0 ? "block" : "none") +
  832. ';">';
  833. html += renderTree(node.children, depth + 1);
  834. html += "</ul>";
  835. }
  836. html += "</li>";
  837. });
  838. return html;
  839. }
  840. if (typeof categoryListData === "undefined") {
  841. categoryListData = JSON.parse(
  842. document.getElementById("category-list-json").value || "[]",
  843. );
  844. currentCategoryID =
  845. document.getElementById("category-current-id").value || "";
  846. }
  847. if (categoryListData.length) {
  848. var tree = buildTree(categoryListData);
  849. $("#category-tree").html(renderTree(tree));
  850. if (currentCategoryID) {
  851. var found = categoryListData.find(function (item) {
  852. return item.id == currentCategoryID;
  853. });
  854. if (found) $("#category-label").text(found.name);
  855. }
  856. }
  857. $(document).on("click", "#category-tree .category-toggle", function (e) {
  858. var $children = $(this).closest("li").children("ul");
  859. $children.toggle();
  860. $(this).html($children.is(":visible") ? "&#9660;" : "&#9654;");
  861. });
  862. $(document).on("click", "#category-tree .category-node", function (e) {
  863. if ($(e.target).hasClass("category-toggle")) return;
  864. var categoryId = $(this).data("id");
  865. var categoryName = $(this).data("name");
  866. $("#category-label").text(categoryName);
  867. $("#category-select").val(categoryId);
  868. $("#category-panel").hide();
  869. $.ajax({
  870. url: "/compilation/changeCategory",
  871. type: "post",
  872. data: { id: id, category: categoryId },
  873. dataType: "json",
  874. success: function (response) {
  875. if (response.error !== 0) {
  876. alert("更改失败");
  877. }
  878. },
  879. });
  880. });
  881. $("#category-dropdown-btn").on("click", function (e) {
  882. e.stopPropagation();
  883. $("#category-panel").toggle();
  884. });
  885. $(document).on("click", function (e) {
  886. if (!$(e.target).closest("#category-dropdown-wrap").length) {
  887. $("#category-panel").hide();
  888. }
  889. });
  890. })();
  891. // 选择默认所在地
  892. $("#location-select").change(function () {
  893. $.ajax({
  894. url: "/compilation/changeLocation",
  895. type: "post",
  896. data: { id: id, location: $(this).val() },
  897. dataType: "json",
  898. success: function (response) {
  899. if (response.error !== 0) {
  900. alert("更改失败");
  901. }
  902. },
  903. });
  904. });
  905. // 修改是否提供免费版
  906. $("#freeUse").change(function () {
  907. $.ajax({
  908. url: "/compilation/changeFreeUse",
  909. type: "post",
  910. data: { id: id, freeUse: $(this).val() },
  911. dataType: "json",
  912. success: function (response) {
  913. if (response.error !== 0) {
  914. alert("更改失败");
  915. }
  916. },
  917. });
  918. });
  919. // 选择编办类型
  920. $("#customMade").change(function () {
  921. $.ajax({
  922. url: "/compilation/changeCompilation",
  923. type: "post",
  924. data: { id: id, update: { customMade: $(this).prop("checked") } },
  925. dataType: "json",
  926. success: function (response) {
  927. if (response.error !== 0) {
  928. alert("更改失败");
  929. }
  930. },
  931. });
  932. });
  933. });
  934. /**
  935. * 初始化
  936. *
  937. * @return {void|boolean}
  938. */
  939. function libUp(id) {
  940. const $item = $(`#list_${id}`).closest(".billLibItem");
  941. const $prevItem = $item.prev();
  942. if ($prevItem.length) {
  943. $item.fadeOut(200, function () {
  944. $prevItem.before($item);
  945. $item.fadeIn(200);
  946. });
  947. }
  948. }
  949. function libDown(id) {
  950. const $item = $(`#list_${id}`).closest(".billLibItem");
  951. const $nextItem = $item.next();
  952. if ($nextItem.length) {
  953. $item.fadeOut(200, function () {
  954. $nextItem.after($item);
  955. $item.fadeIn(200);
  956. });
  957. }
  958. }
  959. function initCompilation() {
  960. let billListData = billList === undefined ? [] : JSON.parse(billList);
  961. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  962. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  963. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  964. let artificialCoefficientData =
  965. artificialCoefficientList === undefined
  966. ? []
  967. : JSON.parse(artificialCoefficientList);
  968. let programData = programList === undefined ? [] : JSON.parse(programList);
  969. let billsGuidanceData =
  970. billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  971. let billTemplateData =
  972. billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  973. let mainTreeColData =
  974. mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  975. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  976. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  977. let itemIncreaseData =
  978. itemIncreaseList == undefined ? [] : JSON.parse(itemIncreaseList);
  979. let progressiveData =
  980. progressiveList == undefined ? [] : JSON.parse(progressiveList);
  981. let engineerInfoData =
  982. engineerInfoList == undefined ? [] : JSON.parse(engineerInfoList);
  983. let engineerFeatureData =
  984. engineerFeatureList == undefined ? [] : JSON.parse(engineerFeatureList);
  985. let materialData = materialList == undefined ? [] : JSON.parse(materialList);
  986. let mainQuantityData =
  987. mainQuantityList == undefined ? [] : JSON.parse(mainQuantityList);
  988. let economicData = economicList == undefined ? [] : JSON.parse(economicList);
  989. let overHeightData =
  990. overHeightList == undefined ? [] : JSON.parse(overHeightList);
  991. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  992. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  993. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  994. // 初始化 造价书列设置
  995. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  996. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  997. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  998. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  999. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  1000. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  1001. }*/
  1002. /* if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  1003. return false;
  1004. } */
  1005. // 标准清单
  1006. let html = "";
  1007. for (let tmp of billListData) {
  1008. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  1009. html += tmpHtml;
  1010. }
  1011. $("select[name='standard_bill']").children("option").first().after(html);
  1012. // 定额库
  1013. html = "";
  1014. for (let tmp of rationLibData) {
  1015. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  1016. html += tmpHtml;
  1017. }
  1018. $("select[name='ration_lib']").html(html);
  1019. // 工料机库
  1020. html = "";
  1021. for (let tmp of gljLibData) {
  1022. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  1023. html += tmpHtml;
  1024. }
  1025. $("select[name='glj_lib']").children("option").first().after(html);
  1026. // 清单指引库
  1027. html = "";
  1028. for (let tmp of billsGuidanceData) {
  1029. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1030. html += tmpHtml;
  1031. }
  1032. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  1033. // 人工系数标准库
  1034. html = "";
  1035. for (let tmp of artificialCoefficientData) {
  1036. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  1037. html += tmpHtml;
  1038. }
  1039. $("select[name='artificial_lib']").children("option").first().after(html);
  1040. // 计算程序标准库
  1041. html = "";
  1042. for (let tmp of programData) {
  1043. let tmpHtml =
  1044. '<option value="' + tmp.id + '">' + tmp.displayName + "</option>";
  1045. html += tmpHtml;
  1046. }
  1047. $("select[name='program_lib']").children("option").first().after(html);
  1048. //模板库
  1049. html = "";
  1050. for (let tmp of billTemplateData) {
  1051. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1052. html += tmpHtml;
  1053. }
  1054. $("select[name='template_lib']").children("option").first().after(html);
  1055. //列设置
  1056. html = "";
  1057. for (let tmp of mainTreeColData) {
  1058. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1059. html += tmpHtml;
  1060. }
  1061. $("select[name='col_lib']").children("option").first().after(html);
  1062. // 费率标准库
  1063. html = "";
  1064. for (let tmp of feeLibData) {
  1065. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  1066. html += tmpHtml;
  1067. }
  1068. $("select[name='fee_lib']").children("option").first().after(html);
  1069. //工程特征库
  1070. html = "";
  1071. for (let tmp of featureData) {
  1072. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1073. html += tmpHtml;
  1074. }
  1075. $("select[name='feature_lib']").children("option").first().after(html);
  1076. //基本信息库
  1077. html = "";
  1078. for (let tmp of infoData) {
  1079. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1080. html += tmpHtml;
  1081. }
  1082. $("select[name='info_lib']").children("option").first().after(html);
  1083. //基本信息库
  1084. html = "";
  1085. for (let tmp of itemIncreaseData) {
  1086. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1087. html += tmpHtml;
  1088. }
  1089. $("select[name='item_increase_lib']").children("option").first().after(html);
  1090. //累进区间库
  1091. html = "";
  1092. for (let tmp of progressiveData) {
  1093. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1094. html += tmpHtml;
  1095. }
  1096. $("select[name='progressive_lib']").children("option").first().after(html);
  1097. //工程信息库
  1098. html = "";
  1099. for (let tmp of engineerInfoData) {
  1100. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1101. html += tmpHtml;
  1102. }
  1103. $("select[name='engineer_info_lib']").children("option").first().after(html);
  1104. //工程特征指标库
  1105. html = "";
  1106. for (let tmp of engineerFeatureData) {
  1107. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1108. html += tmpHtml;
  1109. }
  1110. $("select[name='engineer_feature_lib']")
  1111. .children("option")
  1112. .first()
  1113. .after(html);
  1114. //主要工料指标库
  1115. html = "";
  1116. for (let tmp of materialData) {
  1117. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1118. html += tmpHtml;
  1119. }
  1120. $("select[name='material_lib']").children("option").first().after(html);
  1121. //主要工程量指标库
  1122. html = "";
  1123. for (let tmp of mainQuantityData) {
  1124. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1125. html += tmpHtml;
  1126. }
  1127. $("select[name='main_quantity_lib']").children("option").first().after(html);
  1128. //主要经济指标库
  1129. html = "";
  1130. for (let tmp of economicData) {
  1131. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1132. html += tmpHtml;
  1133. }
  1134. $("select[name='economic_lib']").children("option").first().after(html);
  1135. //超高降效
  1136. html = "";
  1137. for (let tmp of overHeightData) {
  1138. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1139. html += tmpHtml;
  1140. }
  1141. $("select[name='over_height_lib']").children("option").first().after(html);
  1142. }
  1143. /**
  1144. * 校验数据
  1145. *
  1146. * @param {String} model
  1147. * @return {Object}
  1148. */
  1149. function getAndValidData(model) {
  1150. let name = $("input[name='compilation_name']").val();
  1151. let standardBill = $("select[name='standard_bill']")
  1152. .children("option:selected")
  1153. .val();
  1154. let rationLib = $("select[name='ration_lib']")
  1155. .children("option:selected")
  1156. .val();
  1157. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  1158. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  1159. let artificialLib = $("select[name='artificial_lib']")
  1160. .children("option:selected")
  1161. .val();
  1162. let programLib = $("select[name='program_lib']")
  1163. .children("option:selected")
  1164. .val();
  1165. let billsGuidanceLib = $("select[name='billsGuidance_lib']")
  1166. .children("option:selected")
  1167. .val();
  1168. let featureLib = $("select[name='feature_lib']")
  1169. .children("option:selected")
  1170. .val();
  1171. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  1172. let itemIncreaseLib = $("select[name='item_increase_lib']")
  1173. .children("option:selected")
  1174. .val();
  1175. let progressiveLib = $("select[name='progressive_lib']")
  1176. .children("option:selected")
  1177. .val();
  1178. let engineerInfoLib = $("select[name='engineer_info_lib']")
  1179. .children("option:selected")
  1180. .val();
  1181. let engineerFeatureLib = $("select[name='engineer_feature_lib']")
  1182. .children("option:selected")
  1183. .val();
  1184. let materialLib = $("select[name='material_lib']")
  1185. .children("option:selected")
  1186. .val();
  1187. let mainQuantityLib = $("select[name='main_quantity_lib']")
  1188. .children("option:selected")
  1189. .val();
  1190. let economicLib = $("select[name='economic_lib']")
  1191. .children("option:selected")
  1192. .val();
  1193. let overHeightLib = $("select[name='over_height_lib']")
  1194. .children("option:selected")
  1195. .val();
  1196. if (name === "" && model === "all") {
  1197. throw "编办名字不能为空";
  1198. }
  1199. if (model === "bill" && (standardBill === "" || standardBill === undefined)) {
  1200. throw "请选择标准清单库";
  1201. }
  1202. if (model === "ration" && (rationLib === "" || rationLib === undefined)) {
  1203. throw "请选择定额库";
  1204. }
  1205. if (model === "feature" && (featureLib === "" || featureLib === undefined)) {
  1206. throw "请选择工程特征库";
  1207. }
  1208. if (model === "glj" && (gljLib === "" || gljLib === undefined)) {
  1209. throw "请选择人材机库";
  1210. }
  1211. if (
  1212. model === "artificial" &&
  1213. (artificialLib === "" || artificialLib === undefined)
  1214. ) {
  1215. throw "请选择人工系数库";
  1216. }
  1217. if (model === "program" && (programLib === "" || programLib === undefined)) {
  1218. throw "请选择计算程序";
  1219. }
  1220. if (
  1221. model === "billsGuidance" &&
  1222. (billsGuidanceLib === "" || billsGuidanceLib === undefined)
  1223. ) {
  1224. throw "请选择清单指引库";
  1225. }
  1226. let standardBillString = $("select[name='standard_bill']")
  1227. .children("option:selected")
  1228. .text();
  1229. let rationLibString = $("select[name='ration_lib']")
  1230. .children("option:selected")
  1231. .text();
  1232. let gljLibString = $("select[name='glj_lib']")
  1233. .children("option:selected")
  1234. .text();
  1235. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  1236. let artificialString = $("select[name='artificial_lib']")
  1237. .children("option:selected")
  1238. .text();
  1239. let programString = $("select[name='program_lib']")
  1240. .children("option:selected")
  1241. .text();
  1242. let billsGuidanceString = $("select[name='billsGuidance_lib']")
  1243. .children("option:selected")
  1244. .text();
  1245. let featrueString = $("select[name='feature_lib']")
  1246. .children("option:selected")
  1247. .text();
  1248. let infoString = $("select[name='info_lib']")
  1249. .children("option:selected")
  1250. .text();
  1251. let itemIncreaseString = $("select[name='item_increase_lib']")
  1252. .children("option:selected")
  1253. .text();
  1254. let progressiveString = $("select[name='progressive_lib']")
  1255. .children("option:selected")
  1256. .text();
  1257. let engineerInfoString = $("select[name='engineer_info_lib']")
  1258. .children("option:selected")
  1259. .text();
  1260. let engineerFeatureString = $("select[name='engineer_feature_lib']")
  1261. .children("option:selected")
  1262. .text();
  1263. let materialString = $("select[name='material_lib']")
  1264. .children("option:selected")
  1265. .text();
  1266. let mainQuantityString = $("select[name='main_quantity_lib']")
  1267. .children("option:selected")
  1268. .text();
  1269. let economicString = $("select[name='economic_lib']")
  1270. .children("option:selected")
  1271. .text();
  1272. let overHeightString = $("select[name='over_height_lib']")
  1273. .children("option:selected")
  1274. .text();
  1275. let result = {
  1276. name: name,
  1277. bill: {
  1278. id: standardBill,
  1279. name: standardBillString,
  1280. },
  1281. ration: {
  1282. id: rationLib,
  1283. name: rationLibString,
  1284. },
  1285. glj: {
  1286. id: gljLib,
  1287. name: gljLibString,
  1288. },
  1289. /* fee: {
  1290. id: feeLib,
  1291. name: feeLibString
  1292. },*/
  1293. artificial: {
  1294. id: artificialLib,
  1295. name: artificialString,
  1296. },
  1297. program: {
  1298. id: programLib,
  1299. name: programString,
  1300. },
  1301. billsGuidance: {
  1302. id: billsGuidanceLib,
  1303. name: billsGuidanceString,
  1304. },
  1305. feature: {
  1306. id: featureLib,
  1307. name: featrueString,
  1308. },
  1309. info: {
  1310. id: infoLib,
  1311. name: infoString,
  1312. },
  1313. item_increase: {
  1314. id: itemIncreaseLib,
  1315. name: itemIncreaseString,
  1316. },
  1317. progressive: {
  1318. id: progressiveLib,
  1319. name: progressiveString,
  1320. },
  1321. engineer_info: {
  1322. id: engineerInfoLib,
  1323. name: engineerInfoString,
  1324. },
  1325. engineer_feature: {
  1326. id: engineerFeatureLib,
  1327. name: engineerFeatureString,
  1328. },
  1329. material: {
  1330. id: materialLib,
  1331. name: materialString,
  1332. },
  1333. main_quantity: {
  1334. id: mainQuantityLib,
  1335. name: mainQuantityString,
  1336. },
  1337. economic: {
  1338. id: economicLib,
  1339. name: economicString,
  1340. },
  1341. over_height: {
  1342. id: overHeightLib,
  1343. name: overHeightString,
  1344. },
  1345. };
  1346. return result;
  1347. }
  1348. /**
  1349. * 验证标准库数据
  1350. *
  1351. * @return {boolean}
  1352. */
  1353. function validLib() {
  1354. let result = false;
  1355. try {
  1356. let valuationName = $("input[name='name']").val();
  1357. if (valuationName === "") {
  1358. throw "请填写计价规则名称";
  1359. }
  1360. let engineering = $("select[name='engineering']").val();
  1361. if (engineering === "" || engineering <= 0) {
  1362. throw "请选择工程专业";
  1363. }
  1364. //按新需求,清单库、定额库等不做非空验证
  1365. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  1366. throw '请添加标准清单';
  1367. }
  1368. if ($("input:hidden[name='ration_lib']").length <= 0) {
  1369. throw '请添加定额库';
  1370. }
  1371. if ($("input:hidden[name='glj_lib']").length <= 0) {
  1372. throw '请添加人材机库';
  1373. }
  1374. if ($("input:hidden[name='fee_lib']").length <= 0) {
  1375. throw '请添加费率标准';
  1376. }
  1377. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  1378. throw '请添加人工系数';
  1379. }
  1380. if ($("input:hidden[name='program_lib']").length <= 0) {
  1381. throw '请添加计算程序';
  1382. }
  1383. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  1384. throw '请添加清单指引库';
  1385. }*/
  1386. result = true;
  1387. } catch (error) {
  1388. alert(error);
  1389. result = false;
  1390. }
  1391. return result;
  1392. }
  1393. /**
  1394. * 切换switch效果
  1395. *
  1396. * @param {Object} element
  1397. * @return {boolean}
  1398. */
  1399. function switchChange(element) {
  1400. // 第一个元素判断当前的状态
  1401. let firstButton = element.children("button").first();
  1402. let secondButton = element.children("button").eq(1);
  1403. let currentStatus = firstButton.is(":disabled");
  1404. if (currentStatus) {
  1405. // 当前为true切换到false
  1406. firstButton
  1407. .removeClass("btn-success")
  1408. .removeClass("disabled")
  1409. .addClass("btn-default")
  1410. .removeAttr("disabled");
  1411. firstButton.text("开启");
  1412. secondButton
  1413. .removeClass("btn-default")
  1414. .addClass("btn-danger")
  1415. .addClass("disabled")
  1416. .attr("disabled", "disabled");
  1417. secondButton.text("已禁用");
  1418. } else {
  1419. // 当前false切换到true
  1420. firstButton
  1421. .removeClass("btn-default")
  1422. .addClass("btn-success")
  1423. .addClass("disabled")
  1424. .attr("disabled", "disabled");
  1425. firstButton.text("已开启");
  1426. secondButton
  1427. .removeClass("btn-danger")
  1428. .removeClass("disabled")
  1429. .addClass("btn-default")
  1430. .removeAttr("disabled");
  1431. secondButton.text("禁用");
  1432. }
  1433. return !currentStatus;
  1434. }
  1435. function editEngineer(selector, key) {
  1436. let editText = $(selector).prev("span").text();
  1437. let parentDiv = $(selector).parent("div");
  1438. let width = key == "seq" ? 70 : 200;
  1439. parentDiv.next("div").css("width", width);
  1440. parentDiv.next("div").find("input").val(editText);
  1441. parentDiv.hide();
  1442. parentDiv.next("div").show();
  1443. }
  1444. function confirmUpdate(selector, engineerID) {
  1445. let inputDiv = $(selector).parents(".input_group_div");
  1446. let input = $(selector).parent(".input-group-btn").prev("input");
  1447. let oldValue = inputDiv.prev("div").find("span").text();
  1448. let newValue = input.val();
  1449. let key = input.attr("name");
  1450. if (newValue == oldValue || !engineerID) {
  1451. //不做非空判断
  1452. inputDiv.prev("div").show();
  1453. inputDiv.hide();
  1454. return;
  1455. }
  1456. let updateData = {};
  1457. updateData[key] = newValue;
  1458. updateEngineer(engineerID, updateData, function () {
  1459. if (key == "seq") {
  1460. window.location.reload();
  1461. } else {
  1462. inputDiv.prev("div").find("span").text(newValue);
  1463. }
  1464. });
  1465. inputDiv.prev("div").show();
  1466. inputDiv.hide();
  1467. }
  1468. function deleteEngineerClick(engineerID, element) {
  1469. hintBox.infoBox(
  1470. "操作确认",
  1471. "是否删除所选工程专业?",
  1472. 2,
  1473. async function () {
  1474. try {
  1475. let result = await ajaxPost("/compilation/delete-engineer", {
  1476. id: engineerID,
  1477. });
  1478. $(element).parent("td").parent("tr").remove();
  1479. } catch (err) {
  1480. console.log(err);
  1481. }
  1482. },
  1483. null,
  1484. ["确定", "取消"],
  1485. false,
  1486. );
  1487. }
  1488. function copyEngineerClick(engineerID) {
  1489. hintBox.infoBox(
  1490. "操作确认",
  1491. "是否拷贝所选工程专业?",
  1492. 2,
  1493. async function () {
  1494. try {
  1495. await ajaxPost("/compilation/copy-engineer", { id: engineerID });
  1496. window.location.reload();
  1497. } catch (err) {
  1498. console.log(err);
  1499. }
  1500. },
  1501. null,
  1502. ["确定", "取消"],
  1503. false,
  1504. );
  1505. }
  1506. function engineerVisibleChange(checkBox, engineerID) {
  1507. if (engineerID) {
  1508. updateEngineer(engineerID, { visible: checkBox.checked });
  1509. }
  1510. }
  1511. function engineerSummaryChange(checkBox, engineerID) {
  1512. if (engineerID) {
  1513. updateEngineer(engineerID, { isSummary: checkBox.checked });
  1514. }
  1515. }
  1516. function updateEngineer(engineerID, data, callback) {
  1517. CommonAjax.post(
  1518. "/compilation/update-engineer",
  1519. { id: engineerID, updateData: data },
  1520. function (data) {
  1521. if (callback) {
  1522. callback();
  1523. }
  1524. },
  1525. );
  1526. }
  1527. function editTaxGroup(ele) {
  1528. $("#groupEditType").val("modify");
  1529. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1530. groupData = JSON.parse(groupData);
  1531. if (!_.isEmpty(groupData)) {
  1532. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1533. $("#program_lib").val(
  1534. groupData.program_lib ? groupData.program_lib.id : "",
  1535. );
  1536. $("#norm_lib").val(groupData.norm_lib ? groupData.norm_lib : "");
  1537. $("#template_lib").val(
  1538. groupData.template_lib ? groupData.template_lib.id : "",
  1539. );
  1540. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1541. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1542. } else {
  1543. $("#taxType").val("");
  1544. $("#program_lib").val("");
  1545. $("#template_lib").val("");
  1546. $("#col_lib").val("");
  1547. $("#fee_lib").val("");
  1548. $("#norm_lib").val("");
  1549. }
  1550. $("#groupIndex").val(getGroupIndex(groupData));
  1551. $("#addTaxGroup").modal({ show: true });
  1552. }
  1553. function deleteTableTr(ele, classString) {
  1554. let parentTr = $(ele).parents(`.${classString}`);
  1555. parentTr.remove();
  1556. }
  1557. function getGroupIndex(groupData) {
  1558. //用来做唯一标识
  1559. let index = "";
  1560. if (groupData) {
  1561. if (groupData.taxType) index = index + groupData.taxType;
  1562. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1563. if (groupData.norm_lib) index = index + groupData.norm_lib;
  1564. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1565. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1566. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1567. }
  1568. return index;
  1569. }
  1570. function getTaxGroupData() {
  1571. let programData =
  1572. programList === undefined ? [] : _.keyBy(JSON.parse(programList), "id");
  1573. let billTemplateData =
  1574. billTemplateList == undefined
  1575. ? []
  1576. : _.keyBy(JSON.parse(billTemplateList), "ID");
  1577. let mainTreeColData =
  1578. mainTreeColList == undefined
  1579. ? []
  1580. : _.keyBy(JSON.parse(mainTreeColList), "ID");
  1581. let feeLibData =
  1582. feeRateList === undefined ? [] : _.keyBy(JSON.parse(feeRateList), "id");
  1583. let groupData = {};
  1584. if ($("#taxType").val() !== "") {
  1585. groupData.taxType = $("#taxType").val();
  1586. }
  1587. if ($("#norm_lib").val() !== "") {
  1588. groupData.norm_lib = $("#norm_lib").val();
  1589. }
  1590. if ($("#program_lib").val() !== "") {
  1591. let program = programData[$("#program_lib").val()];
  1592. if (program) {
  1593. groupData.program_lib = {
  1594. id: program.id,
  1595. name: program.name,
  1596. displayName: program.displayName,
  1597. };
  1598. }
  1599. }
  1600. if ($("#template_lib").val() !== "") {
  1601. let template = billTemplateData[$("#template_lib").val()];
  1602. if (template) {
  1603. groupData.template_lib = {
  1604. id: template.ID,
  1605. name: template.name,
  1606. };
  1607. }
  1608. }
  1609. if ($("#col_lib").val() !== "") {
  1610. let col = mainTreeColData[$("#col_lib").val()];
  1611. if (col) {
  1612. groupData.col_lib = {
  1613. id: col.ID,
  1614. name: col.name,
  1615. };
  1616. }
  1617. }
  1618. if ($("#fee_lib").val() !== "") {
  1619. let feeRate = feeLibData[$("#fee_lib").val()];
  1620. if (feeRate) {
  1621. groupData.fee_lib = {
  1622. id: feeRate.id,
  1623. name: feeRate.name,
  1624. };
  1625. }
  1626. }
  1627. return groupData;
  1628. }
  1629. function intChecking(e, elemt) {
  1630. //限制输入正整数
  1631. let code = e.which || e.keyCode;
  1632. if (code == 46 || code == 45) {
  1633. //不能输入小数点和-号
  1634. e.preventDefault();
  1635. }
  1636. if (elemt.value == "" && code == 48) {
  1637. //当输入框为空时不能输入0
  1638. e.preventDefault();
  1639. }
  1640. }