compilation.js 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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 ($("input:hidden[name='" + model + "_lib'][data-id='" + addLib.id + "']").length > 0) {
  67. alert('重复添加数据!');
  68. return false;
  69. }
  70. let removeHtml = '<a class="pull-right text-danger remove-lib" data-model="' + model + '" ' +
  71. 'title="移除"><span class="glyphicon glyphicon-remove"></span></a>';
  72. let tmpHtml = '<p class="form-control-static">' + removeHtml + addLib.name +
  73. '<input type="hidden" data-id="' + addLib.id + '" name=\'' + model + '_lib\' value=\'' + JSON.stringify(addLib) + '\'>' + '</p>';
  74. $("." + model + "-list").append(tmpHtml);
  75. $('#addcompilation').modal('hide');
  76. }
  77. } catch (error) {
  78. alert(error);
  79. }
  80. });
  81. $("#addTaxGroupBtn").click(function () {
  82. $('#groupEditType').val("add");
  83. $("#taxType").val("");
  84. $("#program_lib").val("");
  85. $("#template_lib").val("");
  86. $("#col_lib").val("");
  87. $("#fee_lib").val("");
  88. $("#norm_lib").val("");
  89. });
  90. //新增计税组合
  91. $("#add-group").click(function () {
  92. let taxMap = { "1": "一般计税", "2": "简易计税" };
  93. let actionType = $('#groupEditType').val();
  94. let normValue = $('#norm_lib').val();
  95. let groupData = getTaxGroupData();
  96. let groupIndex = getGroupIndex(groupData);//用来做重复判断
  97. if (!_.isEmpty(groupData)) {
  98. //重复判断 todo
  99. if ($("input[data-id = " + groupIndex + "]").length <= 0) {
  100. let taxName = groupData.taxType ? taxMap[groupData.taxType] : '';
  101. let p_name = groupData.program_lib ? groupData.program_lib.displayName : "";
  102. let t_name = groupData.template_lib ? groupData.template_lib.name : "";
  103. let c_name = groupData.col_lib ? groupData.col_lib.name : "";
  104. let f_name = groupData.fee_lib ? groupData.fee_lib.name : "";
  105. let htmlString = "<tr class='taxGroup_tr'><td><span>" + taxName + "</span></td>" +
  106. "<td><span>" + p_name + "</span></td>" +
  107. "<td><span>" + normValue + "</span></td>" +
  108. "<td><span>" + t_name + "</span></td>" +
  109. "<td><span>" + c_name + "</span></td>" +
  110. "<td><span>" + f_name + "</span></td>" +
  111. "<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> " +
  112. "<input type='hidden' name='tax_group' data-id ='" + groupIndex + "' value='" + JSON.stringify(groupData) + "'>" +
  113. "</td>" +
  114. "</tr>";
  115. if (actionType == "add") {
  116. $("#tax_group_tbody").append(htmlString);
  117. } else if (actionType == "modify") {
  118. let oldIndex = $("#groupIndex").val();
  119. let parentTr = $("input[data-id = " + oldIndex + "]").parents(".taxGroup_tr");
  120. parentTr.after(htmlString);
  121. parentTr.remove();
  122. }
  123. } else {
  124. alert("已存在相同的组合!");
  125. }
  126. }
  127. $("#addTaxGroup").modal('hide');
  128. });
  129. //新增定额库
  130. /* $("#add-ration").click(function () {
  131. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  132. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  133. if (rationLib == undefined || rationLib == '') {
  134. alert("请选择定额库");
  135. return;
  136. }
  137. if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length <= 0) {
  138. let tem = {
  139. id: rationLib,
  140. name: rationLibString,
  141. isDefault: false
  142. };
  143. let htmlString = `
  144. <tr class='ration_tr' draggable="true">
  145. <td><span class="cursor-default">${tem.name}</span></td>
  146. <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault" value="${tem.id}" type="radio"></td>
  147. <td>
  148. <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
  149. <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
  150. </td>
  151. </tr>`
  152. $("#ration_tbody").append(htmlString);
  153. } else {
  154. alert('已存在相同的定额库')
  155. }
  156. $("#addRation").modal('hide');
  157. }); */
  158. $("#add-ration").click(function () {
  159. const options = $("select[name='ration_lib']").children("option:selected");
  160. let alertArr = [];
  161. let htmlString = '';
  162. for (const option of options) {
  163. const rationLib = $(option).val();
  164. const rationLibString = $(option).text();
  165. if (!rationLib) {
  166. alertString.push(`“${rationLibString}”为无效定额库`);
  167. continue;
  168. }
  169. if ($("input:hidden[name=ration_lib][data-id = " + rationLib + "]").length > 0) {
  170. alertArr.push(`“${rationLibString}”已存在`);
  171. continue;
  172. }
  173. const tem = {
  174. id: rationLib,
  175. name: rationLibString,
  176. isDefault: false
  177. };
  178. htmlString += `
  179. <tr class='ration_tr' draggable="true">
  180. <td><span class="cursor-default">${tem.name}</span></td>
  181. <td><label class="form-check-label"> <input class="form-check-input" name="ration_isDefault" value="${tem.id}" type="radio"></td>
  182. <td>
  183. <a class='btn btn-link btn-sm ' style="padding: 0px" onclick='deleteTableTr(this,"ration_tr")'>删除</a>
  184. <input type="hidden" name="ration_lib" data-id="${tem.id}" value='${JSON.stringify(tem)}'>
  185. </td>
  186. </tr>`;
  187. }
  188. if (alertArr.length) {
  189. alert(alertArr.join('\n'));
  190. } else {
  191. $("#ration_tbody").append(htmlString);
  192. $("#addRation").modal('hide');
  193. }
  194. });
  195. // 复制定额库
  196. $('#copy-lib-confirm').click(async function () {
  197. try {
  198. $.bootstrapLoading.start();
  199. const [valuationID, engineeringID] = window.location.pathname.split('/').slice(-2);
  200. await ajaxPost('/compilation/copyRationLibs', { valuationID, engineeringID });
  201. } catch (err) {
  202. console.log(err);
  203. } finally {
  204. $.bootstrapLoading.end();
  205. }
  206. });
  207. // 复制计价规则
  208. let orgValuationID;
  209. let valuationType;
  210. $('.copy-bill-valuation').click(function () {
  211. valuationType = 'bill_valuation';
  212. orgValuationID = $(this).data('id');
  213. console.log(orgValuationID);
  214. $('#copy-valuation-modal').modal('show');
  215. });
  216. $('.copy-ration-valuation').click(function () {
  217. valuationType = 'ration_valuation';
  218. orgValuationID = $(this).data('id');
  219. console.log(orgValuationID);
  220. $('#copy-valuation-modal').modal('show');
  221. });
  222. $('#copy-valuation-confirm').click(async function () {
  223. const newName = $('#valuation-name').val();
  224. console.log(newName);
  225. if (!newName) {
  226. alert('请输入计价规则');
  227. return;
  228. }
  229. const compilationID = window.location.search.replace('?id=', '');
  230. $.bootstrapLoading.start();
  231. await ajaxPost('/compilation/copyValuation', { compilationID, valuationType, orgValuationID, newName });
  232. $.bootstrapLoading.end();
  233. window.location.reload();
  234. })
  235. // 拖动排序
  236. const dragSelector = '.ration_tr[draggable=true]';
  237. const rationBodySelector = '#ration_tbody';
  238. const wrapper = $('.panel-content')[0];
  239. let dragged;
  240. let rID = null;
  241. const scrollStep = 6;
  242. // 表格数据过多的时候,靠下方的条目想要移动到上方,需要滚动条滚动到相应位置,滚动条向上滚动需要代码自行处理
  243. function scroll(ele, step) {
  244. wrapper.scrollTop -= step;
  245. rID = window.requestAnimationFrame(() => {
  246. scroll(ele, step);
  247. });
  248. }
  249. // 动态绑定(新增的也能监听到)
  250. $(rationBodySelector).on('drag', dragSelector, function (ev) {
  251. const { clientX, clientY } = ev;
  252. const dom = document.elementFromPoint(clientX, clientY);
  253. if (dom.tagName === 'H2' && !rID) {
  254. rID = window.requestAnimationFrame(() => {
  255. scroll(wrapper, scrollStep);
  256. })
  257. } else if (dom.tagName !== 'H2' && rID) {
  258. window.cancelAnimationFrame(rID);
  259. rID = null;
  260. }
  261. });
  262. $(rationBodySelector).on('dragstart', dragSelector, function (ev) {
  263. dragged = this;
  264. $(this).addClass('dragging');
  265. ev.originalEvent.dataTransfer.effectAllowed = 'move';
  266. });
  267. $(rationBodySelector).on('dragend', dragSelector, function (ev) {
  268. $(this).removeClass('dragging');
  269. if (rID) {
  270. window.cancelAnimationFrame(rID);
  271. rID = null;
  272. }
  273. });
  274. $(rationBodySelector).on('dragover', dragSelector, function (ev) {
  275. ev.preventDefault(); // 必须调用此方法,否则drop事件不触发
  276. });
  277. $(rationBodySelector).on('dragenter', dragSelector, function (ev) {
  278. if (this !== dragged) {
  279. $(this).addClass('highlight');
  280. }
  281. });
  282. $(rationBodySelector).on('dragleave', dragSelector, function (ev) {
  283. if (this !== dragged) {
  284. $(this).removeClass('highlight');
  285. }
  286. });
  287. $(rationBodySelector).on('drop', dragSelector, function (ev) {
  288. $(this).removeClass('highlight');
  289. $(this).after($(dragged));
  290. });
  291. // 新增计价规则
  292. $("#add-valuation").click(function () {
  293. try {
  294. if (id === '') {
  295. throw '页面数据有误';
  296. }
  297. let name = $("input[name='valuation_name']").val();
  298. if (name === '') {
  299. throw '请填写计价规则名称';
  300. }
  301. $.ajax({
  302. url: '/compilation/add-valuation',
  303. type: 'post',
  304. data: { name: name, id: id, section: section },
  305. error: function () {
  306. isAdding = false;
  307. },
  308. beforeSend: function () {
  309. isAdding = true;
  310. },
  311. success: function (response) {
  312. isAdding = false;
  313. if (response.err === 0) {
  314. window.location.reload();
  315. } else {
  316. let msg = response.msg === undefined ? '未知错误' : response.msg;
  317. alert(msg);
  318. }
  319. }
  320. });
  321. } catch (error) {
  322. alert(error);
  323. return false;
  324. }
  325. });
  326. // 添加
  327. $(".add-compilation").click(function () {
  328. model = $(this).data('model');
  329. $("#addcompilation .modal-body > div").hide();
  330. switch (model) {
  331. case 'all':
  332. $("#name-area").show();
  333. $("#add-compilation-title").text('添加新费用定额');
  334. break;
  335. case 'bill':
  336. $("#bill-area").show();
  337. $("#add-compilation-title").text('添加标准清单');
  338. break;
  339. case 'ration':
  340. $("#ration-area").show();
  341. $("#add-compilation-title").text('添加定额库');
  342. break;
  343. case 'glj':
  344. $("#glj-area").show();
  345. $("#add-compilation-title").text('添加定额库');
  346. break;
  347. case 'billsGuidance':
  348. $("#billsGuidance-area").show();
  349. $("#add-compilation-title").text('添加清单指引库');
  350. break;
  351. case 'fee':
  352. $("#fee-area").show();
  353. $("#add-compilation-title").text('添加费率标准');
  354. break;
  355. case 'artificial':
  356. $("#artificial-area").show();
  357. $("#add-compilation-title").text('添加人工系数');
  358. break;
  359. case 'program':
  360. $("#program-area").show();
  361. $("#add-compilation-title").text('添加计算程序');
  362. break;
  363. case 'feature':
  364. $("#feature-area").show();
  365. $("#add-compilation-title").text('添加工程特征');
  366. break;
  367. case 'info':
  368. $('#info-area').show();
  369. $('#add-compilation-title').text('添加基本信息');
  370. break;
  371. case 'progressive':
  372. $("#progressive-area").show();
  373. $("#add-compilation-title").text('添加累进区间');
  374. break;
  375. case 'engineer_info':
  376. $('#engineer-info-area').show();
  377. $('#add-compilation-title').text('添加工程信息');
  378. break;
  379. case 'engineer_feature':
  380. $('#engineer-feature-area').show();
  381. $('#add-compilation-title').text('添加工程特征指标');
  382. break;
  383. case 'material':
  384. $('#material-area').show();
  385. $('#add-compilation-title').text('添加主要工料指标');
  386. break;
  387. case 'main_quantity':
  388. $('#main-quantity-area').show();
  389. $('#add-compilation-title').text('添加主要工程量指标');
  390. break;
  391. case 'economic':
  392. $('#economic-area').show();
  393. $('#add-compilation-title').text('添加主要经济指标');
  394. break;
  395. case 'over_height':
  396. $('#over-height-area').show();
  397. $('#add-compilation-title').text('添加超高降效');
  398. break;
  399. }
  400. $("#addcompilation").modal('show');
  401. });
  402. // 保存专业工程标准库
  403. $("#save-lib").click(function () {
  404. if (validLib()) {
  405. $("form").submit();
  406. }
  407. });
  408. // 保存计价规则
  409. $("#save-valuation").click(function () {
  410. $("#saveValuation").submit();
  411. });
  412. // 移除操作
  413. /*$(".remove-lib").on("click", function() {
  414. $(this).parent().remove();
  415. })*/
  416. $(".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").on("click", ".remove-lib", function () {
  417. $(this).parent().remove();
  418. });
  419. //更改描述
  420. $('#description').change(function () {
  421. let description = $(this).val();
  422. $.ajax({
  423. url: '/compilation/setDescription',
  424. type: 'post',
  425. dataType: "json",
  426. data: { id: id, description: description },
  427. success: function (response) {
  428. if (response.err !== 0) {
  429. alert('更改失败');
  430. }
  431. }
  432. });
  433. });
  434. //更改版本号
  435. $('#edition').change(function () {
  436. let edition = $(this).val();
  437. $.ajax({
  438. url: '/compilation/setEdition',
  439. type: 'post',
  440. dataType: "json",
  441. data: { id: id, edition: edition },
  442. success: function (response) {
  443. if (response.err !== 0) {
  444. alert('更改失败');
  445. }
  446. }
  447. });
  448. });
  449. //更改代码覆盖路径
  450. $('#overWriteUrl').change(function () {
  451. let overWriteUrl = $(this).val();
  452. if (overWriteUrl == "") overWriteUrl = undefined;
  453. $.ajax({
  454. url: '/compilation/setOverWriteUrl',
  455. type: 'post',
  456. dataType: "json",
  457. data: { id: id, overWriteUrl: overWriteUrl },
  458. success: function (response) {
  459. if (response.err !== 0) {
  460. alert('更改失败');
  461. }
  462. }
  463. });
  464. });
  465. //例题建设项目ID, 用英文字符;分隔建设项目ID
  466. $('#example').keyup(function () {
  467. let exampleVal = $(this).val();
  468. let example = exampleVal.split(/[;,;]/g);
  469. example = Array.from(new Set(example));
  470. delayKeyup(function () {
  471. $.ajax({
  472. url: '/compilation/setExample',
  473. type: 'post',
  474. dataType: "json",
  475. data: { id: id, example: example },
  476. success: function (response) {
  477. if (response.err !== 0) {
  478. alert('更改失败');
  479. }
  480. }
  481. });
  482. });
  483. });
  484. // 计价规则启用/禁止
  485. $(".enable").click(function () {
  486. let goingChangeStatus = switchChange($(this));
  487. let id = $(this).data('id');
  488. if (id === undefined || id === '' || isAdding) {
  489. return false;
  490. }
  491. $.ajax({
  492. url: '/compilation/valuation/' + section + '/enable',
  493. type: 'post',
  494. dataType: "json",
  495. data: { id: id, enable: goingChangeStatus },
  496. error: function () {
  497. isAdding = false;
  498. switchChange($(this));
  499. },
  500. beforeSend: function () {
  501. isAdding = true;
  502. },
  503. success: function (response) {
  504. isAdding = false;
  505. if (response.err !== 0) {
  506. switchChange($(this));
  507. alert('更改失败');
  508. }
  509. }
  510. });
  511. });
  512. // 设置适用类型
  513. $(".fileType").change(function () {
  514. let id = $(this).data('id');
  515. if (id === undefined || id === '' || isAdding) {
  516. return false;
  517. }
  518. let fileTypes = [];
  519. let oldVal = $(this).attr("checked");
  520. if (oldVal) {
  521. $(this).removeAttr("checked")
  522. } else {
  523. $(this).attr("checked", "checked")
  524. }
  525. if ($('#' + id + '_gusuan').attr("checked")) fileTypes.push(15);
  526. if ($('#' + id + '_estimate').attr("checked")) fileTypes.push(5);
  527. if ($('#' + id + '_submission').attr("checked")) fileTypes.push(1);
  528. if ($('#' + id + '_changeBudget').attr("checked")) fileTypes.push(4);
  529. if($('#'+id+'_settlement').attr("checked")) fileTypes.push(10);
  530. let current = $(this);
  531. console.log(id, this);
  532. $.ajax({
  533. url: '/compilation/valuation/' + section + '/fileTypes',
  534. type: 'post',
  535. dataType: "json",
  536. data: { id: id, fileTypes: fileTypes },
  537. error: function () {
  538. //恢复原值
  539. if (oldVal) {
  540. current.attr("checked", "checked")
  541. } else {
  542. current.removeAttr("checked")
  543. }
  544. },
  545. success: function (response) {
  546. if (response.err !== 0) {
  547. switchChange($(this));
  548. alert('更改失败');
  549. }
  550. }
  551. });
  552. });
  553. //计价规则删除
  554. $('#delete-confirm').click(function () {
  555. let id = $('#del').attr('selectedId');
  556. if (id === undefined || id === '') {
  557. return false;
  558. }
  559. window.location.href = `/compilation/valuation/bill/delete/${id}`;
  560. });
  561. // 发布编办
  562. $("#release").click(function () {
  563. let id = $(this).data("id");
  564. let status = $(this).data("status");
  565. status = parseInt(status);
  566. if (isAdding || id === '' || isNaN(status)) {
  567. return false;
  568. }
  569. $.ajax({
  570. url: '/compilation/release',
  571. type: 'post',
  572. data: { id: id, status: status },
  573. dataType: "json",
  574. error: function () {
  575. isAdding = false;
  576. },
  577. beforeSend: function () {
  578. isAdding = true;
  579. },
  580. success: function (response) {
  581. isAdding = false;
  582. if (response.err === 0) {
  583. window.location.reload();
  584. } else {
  585. let msg = response.msg === undefined ? "未知错误" : response.msg;
  586. alert(msg);
  587. }
  588. }
  589. });
  590. });
  591. //添加工程专业
  592. $("#addEngineerConfirm").click(async function () {
  593. if ($('#name').val() == '') {
  594. $("#nameError").show();
  595. return;
  596. }
  597. if ($('#feeName').val() == '') {
  598. $("#feeNameError").show();
  599. return;
  600. }
  601. if ($('#engineeringInput').val() == '') {
  602. $("#engineeringError").show();
  603. return;
  604. }
  605. if ($('#projectEngineering').val() == '') {
  606. $("#projectError").show();
  607. return;
  608. }
  609. $("#addEngineerConfirm").attr("disabled", true);//防止重复提交
  610. $("#addEngineerForm").submit();
  611. });
  612. //
  613. // CLD 办事处选择
  614. $('#category-select').change(function () {
  615. $.ajax({
  616. url: '/compilation/changeCategory',
  617. type: 'post',
  618. data: { id: id, category: $(this).val() },
  619. dataType: "json",
  620. success: function (response) {
  621. if (response.error !== 0) {
  622. alert('更改失败');
  623. }
  624. }
  625. });
  626. })
  627. });
  628. /**
  629. * 初始化
  630. *
  631. * @return {void|boolean}
  632. */
  633. function initCompilation() {
  634. let billListData = billList === undefined ? [] : JSON.parse(billList);
  635. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  636. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  637. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  638. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  639. let programData = programList === undefined ? [] : JSON.parse(programList);
  640. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  641. let billTemplateData = billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  642. let mainTreeColData = mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  643. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  644. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  645. let progressiveData = progressiveList == undefined ? [] : JSON.parse(progressiveList);
  646. let engineerInfoData = engineerInfoList == undefined ? [] : JSON.parse(engineerInfoList);
  647. let engineerFeatureData = engineerFeatureList == undefined ? [] : JSON.parse(engineerFeatureList);
  648. let materialData = materialList == undefined ? [] : JSON.parse(materialList);
  649. let mainQuantityData = mainQuantityList == undefined ? [] : JSON.parse(mainQuantityList);
  650. let economicData = economicList == undefined ? [] : JSON.parse(economicList);
  651. let overHeightData = overHeightList == undefined ? [] : JSON.parse(overHeightList);
  652. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  653. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  654. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  655. // 初始化 造价书列设置
  656. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  657. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  658. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  659. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  660. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  661. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  662. }*/
  663. /* if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  664. return false;
  665. } */
  666. // 标准清单
  667. let html = '';
  668. for (let tmp of billListData) {
  669. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  670. html += tmpHtml;
  671. }
  672. $("select[name='standard_bill']").children("option").first().after(html);
  673. // 定额库
  674. html = '';
  675. for (let tmp of rationLibData) {
  676. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  677. html += tmpHtml;
  678. }
  679. $("select[name='ration_lib']").html(html);
  680. // 工料机库
  681. html = '';
  682. for (let tmp of gljLibData) {
  683. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  684. html += tmpHtml;
  685. }
  686. $("select[name='glj_lib']").children("option").first().after(html);
  687. // 清单指引库
  688. html = '';
  689. for (let tmp of billsGuidanceData) {
  690. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  691. html += tmpHtml;
  692. }
  693. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  694. // 人工系数标准库
  695. html = '';
  696. for (let tmp of artificialCoefficientData) {
  697. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  698. html += tmpHtml;
  699. }
  700. $("select[name='artificial_lib']").children("option").first().after(html);
  701. // 计算程序标准库
  702. html = '';
  703. for (let tmp of programData) {
  704. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.displayName + '</option>';
  705. html += tmpHtml;
  706. }
  707. $("select[name='program_lib']").children("option").first().after(html);
  708. //模板库
  709. html = '';
  710. for (let tmp of billTemplateData) {
  711. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  712. html += tmpHtml;
  713. }
  714. $("select[name='template_lib']").children("option").first().after(html);
  715. //列设置
  716. html = '';
  717. for (let tmp of mainTreeColData) {
  718. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  719. html += tmpHtml;
  720. }
  721. $("select[name='col_lib']").children("option").first().after(html);
  722. // 费率标准库
  723. html = '';
  724. for (let tmp of feeLibData) {
  725. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  726. html += tmpHtml;
  727. }
  728. $("select[name='fee_lib']").children("option").first().after(html);
  729. //工程特征库
  730. html = '';
  731. for (let tmp of featureData) {
  732. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  733. html += tmpHtml;
  734. }
  735. $("select[name='feature_lib']").children("option").first().after(html);
  736. //基本信息库
  737. html = '';
  738. for (let tmp of infoData) {
  739. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  740. html += tmpHtml;
  741. }
  742. $("select[name='info_lib']").children("option").first().after(html);
  743. //累进区间库
  744. html = '';
  745. for (let tmp of progressiveData) {
  746. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  747. html += tmpHtml;
  748. }
  749. $("select[name='progressive_lib']").children("option").first().after(html);
  750. //工程信息库
  751. html = '';
  752. for (let tmp of engineerInfoData) {
  753. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  754. html += tmpHtml;
  755. }
  756. $("select[name='engineer_info_lib']").children("option").first().after(html);
  757. //工程特征指标库
  758. html = '';
  759. for (let tmp of engineerFeatureData) {
  760. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  761. html += tmpHtml;
  762. }
  763. $("select[name='engineer_feature_lib']").children("option").first().after(html);
  764. //主要工料指标库
  765. html = '';
  766. for (let tmp of materialData) {
  767. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  768. html += tmpHtml;
  769. }
  770. $("select[name='material_lib']").children("option").first().after(html);
  771. //主要工程量指标库
  772. html = '';
  773. for (let tmp of mainQuantityData) {
  774. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  775. html += tmpHtml;
  776. }
  777. $("select[name='main_quantity_lib']").children("option").first().after(html);
  778. //主要经济指标库
  779. html = '';
  780. for (let tmp of economicData) {
  781. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  782. html += tmpHtml;
  783. }
  784. $("select[name='economic_lib']").children("option").first().after(html);
  785. //超高降效
  786. html = '';
  787. for (let tmp of overHeightData) {
  788. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  789. html += tmpHtml;
  790. }
  791. $("select[name='over_height_lib']").children("option").first().after(html);
  792. }
  793. /**
  794. * 校验数据
  795. *
  796. * @param {String} model
  797. * @return {Object}
  798. */
  799. function getAndValidData(model) {
  800. let name = $("input[name='compilation_name']").val();
  801. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  802. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  803. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  804. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  805. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  806. let programLib = $("select[name='program_lib']").children("option:selected").val();
  807. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  808. let featureLib = $("select[name='feature_lib']").children("option:selected").val();
  809. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  810. let progressiveLib = $("select[name='progressive_lib']").children("option:selected").val();
  811. let engineerInfoLib = $("select[name='engineer_info_lib']").children("option:selected").val();
  812. let engineerFeatureLib = $("select[name='engineer_feature_lib']").children("option:selected").val();
  813. let materialLib = $("select[name='material_lib']").children("option:selected").val();
  814. let mainQuantityLib = $("select[name='main_quantity_lib']").children("option:selected").val();
  815. let economicLib = $("select[name='economic_lib']").children("option:selected").val();
  816. let overHeightLib = $("select[name='over_height_lib']").children("option:selected").val();
  817. if (name === '' && model === 'all') {
  818. throw '编办名字不能为空';
  819. }
  820. if (model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  821. throw '请选择标准清单库';
  822. }
  823. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  824. throw '请选择定额库';
  825. }
  826. if (model === 'feature' && (featureLib === '' || featureLib === undefined)) {
  827. throw '请选择工程特征库';
  828. }
  829. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  830. throw '请选择人材机库';
  831. }
  832. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  833. throw '请选择人工系数库';
  834. }
  835. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  836. throw '请选择计算程序';
  837. }
  838. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  839. throw '请选择清单指引库';
  840. }
  841. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  842. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  843. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  844. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  845. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  846. let programString = $("select[name='program_lib']").children("option:selected").text();
  847. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  848. let featrueString = $("select[name='feature_lib']").children("option:selected").text();
  849. let infoString = $("select[name='info_lib']").children("option:selected").text();
  850. let progressiveString = $("select[name='progressive_lib']").children("option:selected").text();
  851. let engineerInfoString = $("select[name='engineer_info_lib']").children("option:selected").text();
  852. let engineerFeatureString = $("select[name='engineer_feature_lib']").children("option:selected").text();
  853. let materialString = $("select[name='material_lib']").children("option:selected").text();
  854. let mainQuantityString = $("select[name='main_quantity_lib']").children("option:selected").text();
  855. let economicString = $("select[name='economic_lib']").children("option:selected").text();
  856. let overHeightString = $("select[name='over_height_lib']").children("option:selected").text();
  857. let result = {
  858. name: name,
  859. bill: {
  860. id: standardBill,
  861. name: standardBillString
  862. },
  863. ration: {
  864. id: rationLib,
  865. name: rationLibString
  866. },
  867. glj: {
  868. id: gljLib,
  869. name: gljLibString
  870. },
  871. /* fee: {
  872. id: feeLib,
  873. name: feeLibString
  874. },*/
  875. artificial: {
  876. id: artificialLib,
  877. name: artificialString
  878. },
  879. program: {
  880. id: programLib,
  881. name: programString
  882. },
  883. billsGuidance: {
  884. id: billsGuidanceLib,
  885. name: billsGuidanceString
  886. },
  887. feature: {
  888. id: featureLib,
  889. name: featrueString
  890. },
  891. info: {
  892. id: infoLib,
  893. name: infoString
  894. },
  895. progressive: {
  896. id: progressiveLib,
  897. name: progressiveString
  898. },
  899. engineer_info: {
  900. id: engineerInfoLib,
  901. name: engineerInfoString
  902. },
  903. engineer_feature: {
  904. id: engineerFeatureLib,
  905. name: engineerFeatureString
  906. },
  907. material: {
  908. id: materialLib,
  909. name: materialString
  910. },
  911. main_quantity: {
  912. id: mainQuantityLib,
  913. name: mainQuantityString
  914. },
  915. economic: {
  916. id: economicLib,
  917. name: economicString
  918. },
  919. over_height: {
  920. id: overHeightLib,
  921. name: overHeightString
  922. }
  923. };
  924. return result;
  925. }
  926. /**
  927. * 验证标准库数据
  928. *
  929. * @return {boolean}
  930. */
  931. function validLib() {
  932. let result = false;
  933. try {
  934. let valuationName = $("input[name='name']").val();
  935. if (valuationName === '') {
  936. throw '请填写计价规则名称';
  937. }
  938. let engineering = $("select[name='engineering']").val();
  939. if (engineering === '' || engineering <= 0) {
  940. throw '请选择工程专业';
  941. }
  942. //按新需求,清单库、定额库等不做非空验证
  943. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  944. throw '请添加标准清单';
  945. }
  946. if ($("input:hidden[name='ration_lib']").length <= 0) {
  947. throw '请添加定额库';
  948. }
  949. if ($("input:hidden[name='glj_lib']").length <= 0) {
  950. throw '请添加人材机库';
  951. }
  952. if ($("input:hidden[name='fee_lib']").length <= 0) {
  953. throw '请添加费率标准';
  954. }
  955. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  956. throw '请添加人工系数';
  957. }
  958. if ($("input:hidden[name='program_lib']").length <= 0) {
  959. throw '请添加计算程序';
  960. }
  961. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  962. throw '请添加清单指引库';
  963. }*/
  964. result = true;
  965. } catch (error) {
  966. alert(error);
  967. result = false;
  968. }
  969. return result;
  970. }
  971. /**
  972. * 切换switch效果
  973. *
  974. * @param {Object} element
  975. * @return {boolean}
  976. */
  977. function switchChange(element) {
  978. // 第一个元素判断当前的状态
  979. let firstButton = element.children("button").first();
  980. let secondButton = element.children("button").eq(1);
  981. let currentStatus = firstButton.is(":disabled");
  982. if (currentStatus) {
  983. // 当前为true切换到false
  984. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  985. firstButton.text('开启');
  986. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  987. secondButton.text('已禁用');
  988. } else {
  989. // 当前false切换到true
  990. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  991. firstButton.text('已开启');
  992. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  993. secondButton.text('禁用');
  994. }
  995. return !currentStatus;
  996. }
  997. function editEngineer(selector, key) {
  998. let editText = $(selector).prev("span").text();
  999. let parentDiv = $(selector).parent("div");
  1000. let width = key == 'seq' ? 70 : 200;
  1001. parentDiv.next("div").css('width', width);
  1002. parentDiv.next("div").find("input").val(editText);
  1003. parentDiv.hide();
  1004. parentDiv.next("div").show();
  1005. }
  1006. function confirmUpdate(selector, engineerID) {
  1007. let inputDiv = $(selector).parents(".input_group_div");
  1008. let input = $(selector).parent(".input-group-btn").prev("input");
  1009. let oldValue = inputDiv.prev("div").find("span").text();
  1010. let newValue = input.val();
  1011. let key = input.attr("name");
  1012. if (newValue == oldValue || !engineerID) {//不做非空判断
  1013. inputDiv.prev("div").show();
  1014. inputDiv.hide();
  1015. return;
  1016. }
  1017. let updateData = {};
  1018. updateData[key] = newValue;
  1019. updateEngineer(engineerID, updateData, function () {
  1020. if (key == 'seq') {
  1021. window.location.reload();
  1022. } else {
  1023. inputDiv.prev("div").find("span").text(newValue);
  1024. }
  1025. });
  1026. inputDiv.prev("div").show();
  1027. inputDiv.hide();
  1028. }
  1029. function deleteEngineerClick(engineerID, element) {
  1030. hintBox.infoBox('操作确认', '是否删除所选工程专业?', 2, async function () {
  1031. try {
  1032. let result = await ajaxPost('/compilation/delete-engineer', { id: engineerID });
  1033. $(element).parent("td").parent("tr").remove();
  1034. } catch (err) {
  1035. console.log(err);
  1036. }
  1037. }, null, ['确定', '取消'], false);
  1038. }
  1039. function engineerVisibleChange(checkBox, engineerID) {
  1040. if (engineerID) {
  1041. updateEngineer(engineerID, { visible: checkBox.checked });
  1042. }
  1043. }
  1044. function updateEngineer(engineerID, data, callback) {
  1045. CommonAjax.post('/compilation/update-engineer', { id: engineerID, updateData: data }, function (data) {
  1046. if (callback) {
  1047. callback();
  1048. }
  1049. })
  1050. }
  1051. function editTaxGroup(ele) {
  1052. $('#groupEditType').val("modify");
  1053. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1054. groupData = JSON.parse(groupData);
  1055. if (!_.isEmpty(groupData)) {
  1056. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1057. $("#program_lib").val(groupData.program_lib ? groupData.program_lib.id : "");
  1058. $("#norm_lib").val(groupData.norm_lib ? groupData.norm_lib : "");
  1059. $("#template_lib").val(groupData.template_lib ? groupData.template_lib.id : "");
  1060. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1061. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1062. } else {
  1063. $("#taxType").val("");
  1064. $("#program_lib").val("");
  1065. $("#template_lib").val("");
  1066. $("#col_lib").val("");
  1067. $("#fee_lib").val("");
  1068. $("#norm_lib").val("");
  1069. }
  1070. $("#groupIndex").val(getGroupIndex(groupData));
  1071. $("#addTaxGroup").modal({ show: true });
  1072. }
  1073. function deleteTableTr(ele, classString) {
  1074. let parentTr = $(ele).parents(`.${classString}`);
  1075. parentTr.remove();
  1076. }
  1077. function getGroupIndex(groupData) {//用来做唯一标识
  1078. let index = "";
  1079. if (groupData) {
  1080. if (groupData.taxType) index = index + groupData.taxType;
  1081. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1082. if (groupData.norm_lib) index = index + groupData.norm_lib;
  1083. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1084. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1085. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1086. }
  1087. return index;
  1088. }
  1089. function getTaxGroupData() {
  1090. let programData = programList === undefined ? [] : _.keyBy(JSON.parse(programList), 'id');
  1091. let billTemplateData = billTemplateList == undefined ? [] : _.keyBy(JSON.parse(billTemplateList), 'ID');
  1092. let mainTreeColData = mainTreeColList == undefined ? [] : _.keyBy(JSON.parse(mainTreeColList), 'ID');
  1093. let feeLibData = feeRateList === undefined ? [] : _.keyBy(JSON.parse(feeRateList), 'id');
  1094. let groupData = {};
  1095. if ($("#taxType").val() !== "") {
  1096. groupData.taxType = $("#taxType").val();
  1097. }
  1098. if ($("#norm_lib").val() !== "") {
  1099. groupData.norm_lib = $('#norm_lib').val();
  1100. }
  1101. if ($("#program_lib").val() !== "") {
  1102. let program = programData[$("#program_lib").val()];
  1103. if (program) {
  1104. groupData.program_lib = {
  1105. id: program.id,
  1106. name: program.name,
  1107. displayName: program.displayName
  1108. }
  1109. }
  1110. }
  1111. if ($("#template_lib").val() !== "") {
  1112. let template = billTemplateData[$("#template_lib").val()];
  1113. if (template) {
  1114. groupData.template_lib = {
  1115. id: template.ID,
  1116. name: template.name
  1117. }
  1118. }
  1119. }
  1120. if ($("#col_lib").val() !== "") {
  1121. let col = mainTreeColData[$("#col_lib").val()];
  1122. if (col) {
  1123. groupData.col_lib = {
  1124. id: col.ID,
  1125. name: col.name
  1126. }
  1127. }
  1128. }
  1129. if ($("#fee_lib").val() !== "") {
  1130. let feeRate = feeLibData[$("#fee_lib").val()];
  1131. if (feeRate) {
  1132. groupData.fee_lib = {
  1133. id: feeRate.id,
  1134. name: feeRate.name
  1135. }
  1136. }
  1137. }
  1138. return groupData;
  1139. }
  1140. function intChecking(e, elemt) {//限制输入正整数
  1141. let code = e.which || e.keyCode;
  1142. if (code == 46 || code == 45) {//不能输入小数点和-号
  1143. e.preventDefault();
  1144. }
  1145. if (elemt.value == "" && code == 48) {//当输入框为空时不能输入0
  1146. e.preventDefault();
  1147. }
  1148. }