compilation.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  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. let current = $(this);
  705. console.log(id, this);
  706. $.ajax({
  707. url: "/compilation/valuation/" + section + "/fileTypes",
  708. type: "post",
  709. dataType: "json",
  710. data: { id: id, fileTypes: fileTypes },
  711. error: function () {
  712. //恢复原值
  713. if (oldVal) {
  714. current.attr("checked", "checked");
  715. } else {
  716. current.removeAttr("checked");
  717. }
  718. },
  719. success: function (response) {
  720. if (response.err !== 0) {
  721. switchChange($(this));
  722. alert("更改失败");
  723. }
  724. },
  725. });
  726. });
  727. //计价规则删除
  728. $("#delete-confirm").click(function () {
  729. let id = $("#del").attr("selectedId");
  730. if (id === undefined || id === "") {
  731. return false;
  732. }
  733. window.location.href = `/compilation/valuation/bill/delete/${id}`;
  734. });
  735. // 发布编办
  736. $("#release").click(function () {
  737. let id = $(this).data("id");
  738. let status = $(this).data("status");
  739. status = parseInt(status);
  740. if (isAdding || id === "" || isNaN(status)) {
  741. return false;
  742. }
  743. $.ajax({
  744. url: "/compilation/release",
  745. type: "post",
  746. data: { id: id, status: status },
  747. dataType: "json",
  748. error: function () {
  749. isAdding = false;
  750. },
  751. beforeSend: function () {
  752. isAdding = true;
  753. },
  754. success: function (response) {
  755. isAdding = false;
  756. if (response.err === 0) {
  757. window.location.reload();
  758. } else {
  759. let msg = response.msg === undefined ? "未知错误" : response.msg;
  760. alert(msg);
  761. }
  762. },
  763. });
  764. });
  765. //添加工程专业
  766. $("#addEngineerConfirm").click(async function () {
  767. if ($("#name").val() == "") {
  768. $("#nameError").show();
  769. return;
  770. }
  771. if ($("#feeName").val() == "") {
  772. $("#feeNameError").show();
  773. return;
  774. }
  775. if ($("#engineeringInput").val() == "") {
  776. $("#engineeringError").show();
  777. return;
  778. }
  779. if ($("#projectEngineering").val() == "") {
  780. $("#projectError").show();
  781. return;
  782. }
  783. $("#addEngineerConfirm").attr("disabled", true); //防止重复提交
  784. $("#addEngineerForm").submit();
  785. });
  786. //
  787. // CLD 办事处选择
  788. $("#category-select").change(function () {
  789. $.ajax({
  790. url: "/compilation/changeCategory",
  791. type: "post",
  792. data: { id: id, category: $(this).val() },
  793. dataType: "json",
  794. success: function (response) {
  795. if (response.error !== 0) {
  796. alert("更改失败");
  797. }
  798. },
  799. });
  800. });
  801. // 选择默认所在地
  802. $("#location-select").change(function () {
  803. $.ajax({
  804. url: "/compilation/changeLocation",
  805. type: "post",
  806. data: { id: id, location: $(this).val() },
  807. dataType: "json",
  808. success: function (response) {
  809. if (response.error !== 0) {
  810. alert("更改失败");
  811. }
  812. },
  813. });
  814. });
  815. // 修改是否提供免费版
  816. $("#freeUse").change(function () {
  817. $.ajax({
  818. url: "/compilation/changeFreeUse",
  819. type: "post",
  820. data: { id: id, freeUse: $(this).val() },
  821. dataType: "json",
  822. success: function (response) {
  823. if (response.error !== 0) {
  824. alert("更改失败");
  825. }
  826. },
  827. });
  828. });
  829. // 选择编办类型
  830. $("#customMade").change(function () {
  831. $.ajax({
  832. url: "/compilation/changeCompilation",
  833. type: "post",
  834. data: { id: id, update: { customMade: $(this).prop("checked") } },
  835. dataType: "json",
  836. success: function (response) {
  837. if (response.error !== 0) {
  838. alert("更改失败");
  839. }
  840. },
  841. });
  842. });
  843. });
  844. /**
  845. * 初始化
  846. *
  847. * @return {void|boolean}
  848. */
  849. function libUp(id) {
  850. const $item = $(`#list_${id}`).closest(".billLibItem");
  851. const $prevItem = $item.prev();
  852. if ($prevItem.length) {
  853. $item.fadeOut(200, function () {
  854. $prevItem.before($item);
  855. $item.fadeIn(200);
  856. });
  857. }
  858. }
  859. function libDown(id) {
  860. const $item = $(`#list_${id}`).closest(".billLibItem");
  861. const $nextItem = $item.next();
  862. if ($nextItem.length) {
  863. $item.fadeOut(200, function () {
  864. $nextItem.after($item);
  865. $item.fadeIn(200);
  866. });
  867. }
  868. }
  869. function initCompilation() {
  870. let billListData = billList === undefined ? [] : JSON.parse(billList);
  871. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  872. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  873. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  874. let artificialCoefficientData =
  875. artificialCoefficientList === undefined
  876. ? []
  877. : JSON.parse(artificialCoefficientList);
  878. let programData = programList === undefined ? [] : JSON.parse(programList);
  879. let billsGuidanceData =
  880. billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  881. let billTemplateData =
  882. billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  883. let mainTreeColData =
  884. mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  885. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  886. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  887. let itemIncreaseData =
  888. itemIncreaseList == undefined ? [] : JSON.parse(itemIncreaseList);
  889. let progressiveData =
  890. progressiveList == undefined ? [] : JSON.parse(progressiveList);
  891. let engineerInfoData =
  892. engineerInfoList == undefined ? [] : JSON.parse(engineerInfoList);
  893. let engineerFeatureData =
  894. engineerFeatureList == undefined ? [] : JSON.parse(engineerFeatureList);
  895. let materialData = materialList == undefined ? [] : JSON.parse(materialList);
  896. let mainQuantityData =
  897. mainQuantityList == undefined ? [] : JSON.parse(mainQuantityList);
  898. let economicData = economicList == undefined ? [] : JSON.parse(economicList);
  899. let overHeightData =
  900. overHeightList == undefined ? [] : JSON.parse(overHeightList);
  901. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  902. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  903. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  904. // 初始化 造价书列设置
  905. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  906. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  907. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  908. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  909. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  910. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  911. }*/
  912. /* if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  913. return false;
  914. } */
  915. // 标准清单
  916. let html = "";
  917. for (let tmp of billListData) {
  918. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  919. html += tmpHtml;
  920. }
  921. $("select[name='standard_bill']").children("option").first().after(html);
  922. // 定额库
  923. html = "";
  924. for (let tmp of rationLibData) {
  925. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  926. html += tmpHtml;
  927. }
  928. $("select[name='ration_lib']").html(html);
  929. // 工料机库
  930. html = "";
  931. for (let tmp of gljLibData) {
  932. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  933. html += tmpHtml;
  934. }
  935. $("select[name='glj_lib']").children("option").first().after(html);
  936. // 清单指引库
  937. html = "";
  938. for (let tmp of billsGuidanceData) {
  939. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  940. html += tmpHtml;
  941. }
  942. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  943. // 人工系数标准库
  944. html = "";
  945. for (let tmp of artificialCoefficientData) {
  946. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  947. html += tmpHtml;
  948. }
  949. $("select[name='artificial_lib']").children("option").first().after(html);
  950. // 计算程序标准库
  951. html = "";
  952. for (let tmp of programData) {
  953. let tmpHtml =
  954. '<option value="' + tmp.id + '">' + tmp.displayName + "</option>";
  955. html += tmpHtml;
  956. }
  957. $("select[name='program_lib']").children("option").first().after(html);
  958. //模板库
  959. html = "";
  960. for (let tmp of billTemplateData) {
  961. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  962. html += tmpHtml;
  963. }
  964. $("select[name='template_lib']").children("option").first().after(html);
  965. //列设置
  966. html = "";
  967. for (let tmp of mainTreeColData) {
  968. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  969. html += tmpHtml;
  970. }
  971. $("select[name='col_lib']").children("option").first().after(html);
  972. // 费率标准库
  973. html = "";
  974. for (let tmp of feeLibData) {
  975. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + "</option>";
  976. html += tmpHtml;
  977. }
  978. $("select[name='fee_lib']").children("option").first().after(html);
  979. //工程特征库
  980. html = "";
  981. for (let tmp of featureData) {
  982. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  983. html += tmpHtml;
  984. }
  985. $("select[name='feature_lib']").children("option").first().after(html);
  986. //基本信息库
  987. html = "";
  988. for (let tmp of infoData) {
  989. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  990. html += tmpHtml;
  991. }
  992. $("select[name='info_lib']").children("option").first().after(html);
  993. //基本信息库
  994. html = "";
  995. for (let tmp of itemIncreaseData) {
  996. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  997. html += tmpHtml;
  998. }
  999. $("select[name='item_increase_lib']").children("option").first().after(html);
  1000. //累进区间库
  1001. html = "";
  1002. for (let tmp of progressiveData) {
  1003. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1004. html += tmpHtml;
  1005. }
  1006. $("select[name='progressive_lib']").children("option").first().after(html);
  1007. //工程信息库
  1008. html = "";
  1009. for (let tmp of engineerInfoData) {
  1010. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1011. html += tmpHtml;
  1012. }
  1013. $("select[name='engineer_info_lib']").children("option").first().after(html);
  1014. //工程特征指标库
  1015. html = "";
  1016. for (let tmp of engineerFeatureData) {
  1017. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1018. html += tmpHtml;
  1019. }
  1020. $("select[name='engineer_feature_lib']")
  1021. .children("option")
  1022. .first()
  1023. .after(html);
  1024. //主要工料指标库
  1025. html = "";
  1026. for (let tmp of materialData) {
  1027. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1028. html += tmpHtml;
  1029. }
  1030. $("select[name='material_lib']").children("option").first().after(html);
  1031. //主要工程量指标库
  1032. html = "";
  1033. for (let tmp of mainQuantityData) {
  1034. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1035. html += tmpHtml;
  1036. }
  1037. $("select[name='main_quantity_lib']").children("option").first().after(html);
  1038. //主要经济指标库
  1039. html = "";
  1040. for (let tmp of economicData) {
  1041. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1042. html += tmpHtml;
  1043. }
  1044. $("select[name='economic_lib']").children("option").first().after(html);
  1045. //超高降效
  1046. html = "";
  1047. for (let tmp of overHeightData) {
  1048. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + "</option>";
  1049. html += tmpHtml;
  1050. }
  1051. $("select[name='over_height_lib']").children("option").first().after(html);
  1052. }
  1053. /**
  1054. * 校验数据
  1055. *
  1056. * @param {String} model
  1057. * @return {Object}
  1058. */
  1059. function getAndValidData(model) {
  1060. let name = $("input[name='compilation_name']").val();
  1061. let standardBill = $("select[name='standard_bill']")
  1062. .children("option:selected")
  1063. .val();
  1064. let rationLib = $("select[name='ration_lib']")
  1065. .children("option:selected")
  1066. .val();
  1067. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  1068. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  1069. let artificialLib = $("select[name='artificial_lib']")
  1070. .children("option:selected")
  1071. .val();
  1072. let programLib = $("select[name='program_lib']")
  1073. .children("option:selected")
  1074. .val();
  1075. let billsGuidanceLib = $("select[name='billsGuidance_lib']")
  1076. .children("option:selected")
  1077. .val();
  1078. let featureLib = $("select[name='feature_lib']")
  1079. .children("option:selected")
  1080. .val();
  1081. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  1082. let itemIncreaseLib = $("select[name='item_increase_lib']")
  1083. .children("option:selected")
  1084. .val();
  1085. let progressiveLib = $("select[name='progressive_lib']")
  1086. .children("option:selected")
  1087. .val();
  1088. let engineerInfoLib = $("select[name='engineer_info_lib']")
  1089. .children("option:selected")
  1090. .val();
  1091. let engineerFeatureLib = $("select[name='engineer_feature_lib']")
  1092. .children("option:selected")
  1093. .val();
  1094. let materialLib = $("select[name='material_lib']")
  1095. .children("option:selected")
  1096. .val();
  1097. let mainQuantityLib = $("select[name='main_quantity_lib']")
  1098. .children("option:selected")
  1099. .val();
  1100. let economicLib = $("select[name='economic_lib']")
  1101. .children("option:selected")
  1102. .val();
  1103. let overHeightLib = $("select[name='over_height_lib']")
  1104. .children("option:selected")
  1105. .val();
  1106. if (name === "" && model === "all") {
  1107. throw "编办名字不能为空";
  1108. }
  1109. if (model === "bill" && (standardBill === "" || standardBill === undefined)) {
  1110. throw "请选择标准清单库";
  1111. }
  1112. if (model === "ration" && (rationLib === "" || rationLib === undefined)) {
  1113. throw "请选择定额库";
  1114. }
  1115. if (model === "feature" && (featureLib === "" || featureLib === undefined)) {
  1116. throw "请选择工程特征库";
  1117. }
  1118. if (model === "glj" && (gljLib === "" || gljLib === undefined)) {
  1119. throw "请选择人材机库";
  1120. }
  1121. if (
  1122. model === "artificial" &&
  1123. (artificialLib === "" || artificialLib === undefined)
  1124. ) {
  1125. throw "请选择人工系数库";
  1126. }
  1127. if (model === "program" && (programLib === "" || programLib === undefined)) {
  1128. throw "请选择计算程序";
  1129. }
  1130. if (
  1131. model === "billsGuidance" &&
  1132. (billsGuidanceLib === "" || billsGuidanceLib === undefined)
  1133. ) {
  1134. throw "请选择清单指引库";
  1135. }
  1136. let standardBillString = $("select[name='standard_bill']")
  1137. .children("option:selected")
  1138. .text();
  1139. let rationLibString = $("select[name='ration_lib']")
  1140. .children("option:selected")
  1141. .text();
  1142. let gljLibString = $("select[name='glj_lib']")
  1143. .children("option:selected")
  1144. .text();
  1145. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  1146. let artificialString = $("select[name='artificial_lib']")
  1147. .children("option:selected")
  1148. .text();
  1149. let programString = $("select[name='program_lib']")
  1150. .children("option:selected")
  1151. .text();
  1152. let billsGuidanceString = $("select[name='billsGuidance_lib']")
  1153. .children("option:selected")
  1154. .text();
  1155. let featrueString = $("select[name='feature_lib']")
  1156. .children("option:selected")
  1157. .text();
  1158. let infoString = $("select[name='info_lib']")
  1159. .children("option:selected")
  1160. .text();
  1161. let itemIncreaseString = $("select[name='item_increase_lib']")
  1162. .children("option:selected")
  1163. .text();
  1164. let progressiveString = $("select[name='progressive_lib']")
  1165. .children("option:selected")
  1166. .text();
  1167. let engineerInfoString = $("select[name='engineer_info_lib']")
  1168. .children("option:selected")
  1169. .text();
  1170. let engineerFeatureString = $("select[name='engineer_feature_lib']")
  1171. .children("option:selected")
  1172. .text();
  1173. let materialString = $("select[name='material_lib']")
  1174. .children("option:selected")
  1175. .text();
  1176. let mainQuantityString = $("select[name='main_quantity_lib']")
  1177. .children("option:selected")
  1178. .text();
  1179. let economicString = $("select[name='economic_lib']")
  1180. .children("option:selected")
  1181. .text();
  1182. let overHeightString = $("select[name='over_height_lib']")
  1183. .children("option:selected")
  1184. .text();
  1185. let result = {
  1186. name: name,
  1187. bill: {
  1188. id: standardBill,
  1189. name: standardBillString,
  1190. },
  1191. ration: {
  1192. id: rationLib,
  1193. name: rationLibString,
  1194. },
  1195. glj: {
  1196. id: gljLib,
  1197. name: gljLibString,
  1198. },
  1199. /* fee: {
  1200. id: feeLib,
  1201. name: feeLibString
  1202. },*/
  1203. artificial: {
  1204. id: artificialLib,
  1205. name: artificialString,
  1206. },
  1207. program: {
  1208. id: programLib,
  1209. name: programString,
  1210. },
  1211. billsGuidance: {
  1212. id: billsGuidanceLib,
  1213. name: billsGuidanceString,
  1214. },
  1215. feature: {
  1216. id: featureLib,
  1217. name: featrueString,
  1218. },
  1219. info: {
  1220. id: infoLib,
  1221. name: infoString,
  1222. },
  1223. item_increase: {
  1224. id: itemIncreaseLib,
  1225. name: itemIncreaseString,
  1226. },
  1227. progressive: {
  1228. id: progressiveLib,
  1229. name: progressiveString,
  1230. },
  1231. engineer_info: {
  1232. id: engineerInfoLib,
  1233. name: engineerInfoString,
  1234. },
  1235. engineer_feature: {
  1236. id: engineerFeatureLib,
  1237. name: engineerFeatureString,
  1238. },
  1239. material: {
  1240. id: materialLib,
  1241. name: materialString,
  1242. },
  1243. main_quantity: {
  1244. id: mainQuantityLib,
  1245. name: mainQuantityString,
  1246. },
  1247. economic: {
  1248. id: economicLib,
  1249. name: economicString,
  1250. },
  1251. over_height: {
  1252. id: overHeightLib,
  1253. name: overHeightString,
  1254. },
  1255. };
  1256. return result;
  1257. }
  1258. /**
  1259. * 验证标准库数据
  1260. *
  1261. * @return {boolean}
  1262. */
  1263. function validLib() {
  1264. let result = false;
  1265. try {
  1266. let valuationName = $("input[name='name']").val();
  1267. if (valuationName === "") {
  1268. throw "请填写计价规则名称";
  1269. }
  1270. let engineering = $("select[name='engineering']").val();
  1271. if (engineering === "" || engineering <= 0) {
  1272. throw "请选择工程专业";
  1273. }
  1274. //按新需求,清单库、定额库等不做非空验证
  1275. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  1276. throw '请添加标准清单';
  1277. }
  1278. if ($("input:hidden[name='ration_lib']").length <= 0) {
  1279. throw '请添加定额库';
  1280. }
  1281. if ($("input:hidden[name='glj_lib']").length <= 0) {
  1282. throw '请添加人材机库';
  1283. }
  1284. if ($("input:hidden[name='fee_lib']").length <= 0) {
  1285. throw '请添加费率标准';
  1286. }
  1287. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  1288. throw '请添加人工系数';
  1289. }
  1290. if ($("input:hidden[name='program_lib']").length <= 0) {
  1291. throw '请添加计算程序';
  1292. }
  1293. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  1294. throw '请添加清单指引库';
  1295. }*/
  1296. result = true;
  1297. } catch (error) {
  1298. alert(error);
  1299. result = false;
  1300. }
  1301. return result;
  1302. }
  1303. /**
  1304. * 切换switch效果
  1305. *
  1306. * @param {Object} element
  1307. * @return {boolean}
  1308. */
  1309. function switchChange(element) {
  1310. // 第一个元素判断当前的状态
  1311. let firstButton = element.children("button").first();
  1312. let secondButton = element.children("button").eq(1);
  1313. let currentStatus = firstButton.is(":disabled");
  1314. if (currentStatus) {
  1315. // 当前为true切换到false
  1316. firstButton
  1317. .removeClass("btn-success")
  1318. .removeClass("disabled")
  1319. .addClass("btn-default")
  1320. .removeAttr("disabled");
  1321. firstButton.text("开启");
  1322. secondButton
  1323. .removeClass("btn-default")
  1324. .addClass("btn-danger")
  1325. .addClass("disabled")
  1326. .attr("disabled", "disabled");
  1327. secondButton.text("已禁用");
  1328. } else {
  1329. // 当前false切换到true
  1330. firstButton
  1331. .removeClass("btn-default")
  1332. .addClass("btn-success")
  1333. .addClass("disabled")
  1334. .attr("disabled", "disabled");
  1335. firstButton.text("已开启");
  1336. secondButton
  1337. .removeClass("btn-danger")
  1338. .removeClass("disabled")
  1339. .addClass("btn-default")
  1340. .removeAttr("disabled");
  1341. secondButton.text("禁用");
  1342. }
  1343. return !currentStatus;
  1344. }
  1345. function editEngineer(selector, key) {
  1346. let editText = $(selector).prev("span").text();
  1347. let parentDiv = $(selector).parent("div");
  1348. let width = key == "seq" ? 70 : 200;
  1349. parentDiv.next("div").css("width", width);
  1350. parentDiv.next("div").find("input").val(editText);
  1351. parentDiv.hide();
  1352. parentDiv.next("div").show();
  1353. }
  1354. function confirmUpdate(selector, engineerID) {
  1355. let inputDiv = $(selector).parents(".input_group_div");
  1356. let input = $(selector).parent(".input-group-btn").prev("input");
  1357. let oldValue = inputDiv.prev("div").find("span").text();
  1358. let newValue = input.val();
  1359. let key = input.attr("name");
  1360. if (newValue == oldValue || !engineerID) {
  1361. //不做非空判断
  1362. inputDiv.prev("div").show();
  1363. inputDiv.hide();
  1364. return;
  1365. }
  1366. let updateData = {};
  1367. updateData[key] = newValue;
  1368. updateEngineer(engineerID, updateData, function () {
  1369. if (key == "seq") {
  1370. window.location.reload();
  1371. } else {
  1372. inputDiv.prev("div").find("span").text(newValue);
  1373. }
  1374. });
  1375. inputDiv.prev("div").show();
  1376. inputDiv.hide();
  1377. }
  1378. function deleteEngineerClick(engineerID, element) {
  1379. hintBox.infoBox(
  1380. "操作确认",
  1381. "是否删除所选工程专业?",
  1382. 2,
  1383. async function () {
  1384. try {
  1385. let result = await ajaxPost("/compilation/delete-engineer", {
  1386. id: engineerID,
  1387. });
  1388. $(element).parent("td").parent("tr").remove();
  1389. } catch (err) {
  1390. console.log(err);
  1391. }
  1392. },
  1393. null,
  1394. ["确定", "取消"],
  1395. false
  1396. );
  1397. }
  1398. function copyEngineerClick(engineerID) {
  1399. hintBox.infoBox(
  1400. "操作确认",
  1401. "是否拷贝所选工程专业?",
  1402. 2,
  1403. async function () {
  1404. try {
  1405. await ajaxPost("/compilation/copy-engineer", { id: engineerID });
  1406. window.location.reload();
  1407. } catch (err) {
  1408. console.log(err);
  1409. }
  1410. },
  1411. null,
  1412. ["确定", "取消"],
  1413. false
  1414. );
  1415. }
  1416. function engineerVisibleChange(checkBox, engineerID) {
  1417. if (engineerID) {
  1418. updateEngineer(engineerID, { visible: checkBox.checked });
  1419. }
  1420. }
  1421. function engineerSummaryChange(checkBox, engineerID) {
  1422. if (engineerID) {
  1423. updateEngineer(engineerID, { isSummary: checkBox.checked });
  1424. }
  1425. }
  1426. function updateEngineer(engineerID, data, callback) {
  1427. CommonAjax.post(
  1428. "/compilation/update-engineer",
  1429. { id: engineerID, updateData: data },
  1430. function (data) {
  1431. if (callback) {
  1432. callback();
  1433. }
  1434. }
  1435. );
  1436. }
  1437. function editTaxGroup(ele) {
  1438. $("#groupEditType").val("modify");
  1439. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1440. groupData = JSON.parse(groupData);
  1441. if (!_.isEmpty(groupData)) {
  1442. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1443. $("#program_lib").val(
  1444. groupData.program_lib ? groupData.program_lib.id : ""
  1445. );
  1446. $("#norm_lib").val(groupData.norm_lib ? groupData.norm_lib : "");
  1447. $("#template_lib").val(
  1448. groupData.template_lib ? groupData.template_lib.id : ""
  1449. );
  1450. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1451. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1452. } else {
  1453. $("#taxType").val("");
  1454. $("#program_lib").val("");
  1455. $("#template_lib").val("");
  1456. $("#col_lib").val("");
  1457. $("#fee_lib").val("");
  1458. $("#norm_lib").val("");
  1459. }
  1460. $("#groupIndex").val(getGroupIndex(groupData));
  1461. $("#addTaxGroup").modal({ show: true });
  1462. }
  1463. function deleteTableTr(ele, classString) {
  1464. let parentTr = $(ele).parents(`.${classString}`);
  1465. parentTr.remove();
  1466. }
  1467. function getGroupIndex(groupData) {
  1468. //用来做唯一标识
  1469. let index = "";
  1470. if (groupData) {
  1471. if (groupData.taxType) index = index + groupData.taxType;
  1472. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1473. if (groupData.norm_lib) index = index + groupData.norm_lib;
  1474. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1475. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1476. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1477. }
  1478. return index;
  1479. }
  1480. function getTaxGroupData() {
  1481. let programData =
  1482. programList === undefined ? [] : _.keyBy(JSON.parse(programList), "id");
  1483. let billTemplateData =
  1484. billTemplateList == undefined
  1485. ? []
  1486. : _.keyBy(JSON.parse(billTemplateList), "ID");
  1487. let mainTreeColData =
  1488. mainTreeColList == undefined
  1489. ? []
  1490. : _.keyBy(JSON.parse(mainTreeColList), "ID");
  1491. let feeLibData =
  1492. feeRateList === undefined ? [] : _.keyBy(JSON.parse(feeRateList), "id");
  1493. let groupData = {};
  1494. if ($("#taxType").val() !== "") {
  1495. groupData.taxType = $("#taxType").val();
  1496. }
  1497. if ($("#norm_lib").val() !== "") {
  1498. groupData.norm_lib = $("#norm_lib").val();
  1499. }
  1500. if ($("#program_lib").val() !== "") {
  1501. let program = programData[$("#program_lib").val()];
  1502. if (program) {
  1503. groupData.program_lib = {
  1504. id: program.id,
  1505. name: program.name,
  1506. displayName: program.displayName,
  1507. };
  1508. }
  1509. }
  1510. if ($("#template_lib").val() !== "") {
  1511. let template = billTemplateData[$("#template_lib").val()];
  1512. if (template) {
  1513. groupData.template_lib = {
  1514. id: template.ID,
  1515. name: template.name,
  1516. };
  1517. }
  1518. }
  1519. if ($("#col_lib").val() !== "") {
  1520. let col = mainTreeColData[$("#col_lib").val()];
  1521. if (col) {
  1522. groupData.col_lib = {
  1523. id: col.ID,
  1524. name: col.name,
  1525. };
  1526. }
  1527. }
  1528. if ($("#fee_lib").val() !== "") {
  1529. let feeRate = feeLibData[$("#fee_lib").val()];
  1530. if (feeRate) {
  1531. groupData.fee_lib = {
  1532. id: feeRate.id,
  1533. name: feeRate.name,
  1534. };
  1535. }
  1536. }
  1537. return groupData;
  1538. }
  1539. function intChecking(e, elemt) {
  1540. //限制输入正整数
  1541. let code = e.which || e.keyCode;
  1542. if (code == 46 || code == 45) {
  1543. //不能输入小数点和-号
  1544. e.preventDefault();
  1545. }
  1546. if (elemt.value == "" && code == 48) {
  1547. //当输入框为空时不能输入0
  1548. e.preventDefault();
  1549. }
  1550. }