compilation.js 47 KB

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