compilation.js 48 KB

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