compilation.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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. let current = $(this);
  530. console.log(id, this);
  531. $.ajax({
  532. url: '/compilation/valuation/' + section + '/fileTypes',
  533. type: 'post',
  534. dataType: "json",
  535. data: { id: id, fileTypes: fileTypes },
  536. error: function () {
  537. //恢复原值
  538. if (oldVal) {
  539. current.attr("checked", "checked")
  540. } else {
  541. current.removeAttr("checked")
  542. }
  543. },
  544. success: function (response) {
  545. if (response.err !== 0) {
  546. switchChange($(this));
  547. alert('更改失败');
  548. }
  549. }
  550. });
  551. });
  552. //计价规则删除
  553. $('#delete-confirm').click(function () {
  554. let id = $('#del').attr('selectedId');
  555. if (id === undefined || id === '') {
  556. return false;
  557. }
  558. window.location.href = `/compilation/valuation/bill/delete/${id}`;
  559. });
  560. // 发布编办
  561. $("#release").click(function () {
  562. let id = $(this).data("id");
  563. let status = $(this).data("status");
  564. status = parseInt(status);
  565. if (isAdding || id === '' || isNaN(status)) {
  566. return false;
  567. }
  568. $.ajax({
  569. url: '/compilation/release',
  570. type: 'post',
  571. data: { id: id, status: status },
  572. dataType: "json",
  573. error: function () {
  574. isAdding = false;
  575. },
  576. beforeSend: function () {
  577. isAdding = true;
  578. },
  579. success: function (response) {
  580. isAdding = false;
  581. if (response.err === 0) {
  582. window.location.reload();
  583. } else {
  584. let msg = response.msg === undefined ? "未知错误" : response.msg;
  585. alert(msg);
  586. }
  587. }
  588. });
  589. });
  590. //添加工程专业
  591. $("#addEngineerConfirm").click(async function () {
  592. if ($('#name').val() == '') {
  593. $("#nameError").show();
  594. return;
  595. }
  596. if ($('#feeName').val() == '') {
  597. $("#feeNameError").show();
  598. return;
  599. }
  600. if ($('#engineeringInput').val() == '') {
  601. $("#engineeringError").show();
  602. return;
  603. }
  604. if ($('#projectEngineering').val() == '') {
  605. $("#projectError").show();
  606. return;
  607. }
  608. $("#addEngineerConfirm").attr("disabled", true);//防止重复提交
  609. $("#addEngineerForm").submit();
  610. });
  611. //
  612. // CLD 办事处选择
  613. $('#category-select').change(function () {
  614. $.ajax({
  615. url: '/compilation/changeCategory',
  616. type: 'post',
  617. data: { id: id, category: $(this).val() },
  618. dataType: "json",
  619. success: function (response) {
  620. if (response.error !== 0) {
  621. alert('更改失败');
  622. }
  623. }
  624. });
  625. })
  626. });
  627. /**
  628. * 初始化
  629. *
  630. * @return {void|boolean}
  631. */
  632. function initCompilation() {
  633. let billListData = billList === undefined ? [] : JSON.parse(billList);
  634. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  635. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  636. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  637. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  638. let programData = programList === undefined ? [] : JSON.parse(programList);
  639. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  640. let billTemplateData = billTemplateList == undefined ? [] : JSON.parse(billTemplateList);
  641. let mainTreeColData = mainTreeColList == undefined ? [] : JSON.parse(mainTreeColList);
  642. let featureData = featureList == undefined ? [] : JSON.parse(featureList);
  643. let infoData = infoList == undefined ? [] : JSON.parse(infoList);
  644. let progressiveData = progressiveList == undefined ? [] : JSON.parse(progressiveList);
  645. let engineerInfoData = engineerInfoList == undefined ? [] : JSON.parse(engineerInfoList);
  646. let engineerFeatureData = engineerFeatureList == undefined ? [] : JSON.parse(engineerFeatureList);
  647. let materialData = materialList == undefined ? [] : JSON.parse(materialList);
  648. let mainQuantityData = mainQuantityList == undefined ? [] : JSON.parse(mainQuantityList);
  649. let economicData = economicList == undefined ? [] : JSON.parse(economicList);
  650. let overHeightData = overHeightList == undefined ? [] : JSON.parse(overHeightList);
  651. /*mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  652. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  653. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  654. // 初始化 造价书列设置
  655. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  656. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  657. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  658. if (mainTreeCol !== '' && mainTreeColObj.cols.length > 0) {
  659. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  660. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  661. }*/
  662. /* if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  663. return false;
  664. } */
  665. // 标准清单
  666. let html = '';
  667. for (let tmp of billListData) {
  668. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  669. html += tmpHtml;
  670. }
  671. $("select[name='standard_bill']").children("option").first().after(html);
  672. // 定额库
  673. html = '';
  674. for (let tmp of rationLibData) {
  675. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  676. html += tmpHtml;
  677. }
  678. $("select[name='ration_lib']").html(html);
  679. // 工料机库
  680. html = '';
  681. for (let tmp of gljLibData) {
  682. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  683. html += tmpHtml;
  684. }
  685. $("select[name='glj_lib']").children("option").first().after(html);
  686. // 清单指引库
  687. html = '';
  688. for (let tmp of billsGuidanceData) {
  689. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  690. html += tmpHtml;
  691. }
  692. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  693. // 人工系数标准库
  694. html = '';
  695. for (let tmp of artificialCoefficientData) {
  696. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  697. html += tmpHtml;
  698. }
  699. $("select[name='artificial_lib']").children("option").first().after(html);
  700. // 计算程序标准库
  701. html = '';
  702. for (let tmp of programData) {
  703. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.displayName + '</option>';
  704. html += tmpHtml;
  705. }
  706. $("select[name='program_lib']").children("option").first().after(html);
  707. //模板库
  708. html = '';
  709. for (let tmp of billTemplateData) {
  710. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  711. html += tmpHtml;
  712. }
  713. $("select[name='template_lib']").children("option").first().after(html);
  714. //列设置
  715. html = '';
  716. for (let tmp of mainTreeColData) {
  717. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  718. html += tmpHtml;
  719. }
  720. $("select[name='col_lib']").children("option").first().after(html);
  721. // 费率标准库
  722. html = '';
  723. for (let tmp of feeLibData) {
  724. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  725. html += tmpHtml;
  726. }
  727. $("select[name='fee_lib']").children("option").first().after(html);
  728. //工程特征库
  729. html = '';
  730. for (let tmp of featureData) {
  731. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  732. html += tmpHtml;
  733. }
  734. $("select[name='feature_lib']").children("option").first().after(html);
  735. //基本信息库
  736. html = '';
  737. for (let tmp of infoData) {
  738. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  739. html += tmpHtml;
  740. }
  741. $("select[name='info_lib']").children("option").first().after(html);
  742. //累进区间库
  743. html = '';
  744. for (let tmp of progressiveData) {
  745. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  746. html += tmpHtml;
  747. }
  748. $("select[name='progressive_lib']").children("option").first().after(html);
  749. //工程信息库
  750. html = '';
  751. for (let tmp of engineerInfoData) {
  752. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  753. html += tmpHtml;
  754. }
  755. $("select[name='engineer_info_lib']").children("option").first().after(html);
  756. //工程特征指标库
  757. html = '';
  758. for (let tmp of engineerFeatureData) {
  759. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  760. html += tmpHtml;
  761. }
  762. $("select[name='engineer_feature_lib']").children("option").first().after(html);
  763. //主要工料指标库
  764. html = '';
  765. for (let tmp of materialData) {
  766. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  767. html += tmpHtml;
  768. }
  769. $("select[name='material_lib']").children("option").first().after(html);
  770. //主要工程量指标库
  771. html = '';
  772. for (let tmp of mainQuantityData) {
  773. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  774. html += tmpHtml;
  775. }
  776. $("select[name='main_quantity_lib']").children("option").first().after(html);
  777. //主要经济指标库
  778. html = '';
  779. for (let tmp of economicData) {
  780. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  781. html += tmpHtml;
  782. }
  783. $("select[name='economic_lib']").children("option").first().after(html);
  784. //超高降效
  785. html = '';
  786. for (let tmp of overHeightData) {
  787. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  788. html += tmpHtml;
  789. }
  790. $("select[name='over_height_lib']").children("option").first().after(html);
  791. }
  792. /**
  793. * 校验数据
  794. *
  795. * @param {String} model
  796. * @return {Object}
  797. */
  798. function getAndValidData(model) {
  799. let name = $("input[name='compilation_name']").val();
  800. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  801. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  802. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  803. // let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  804. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  805. let programLib = $("select[name='program_lib']").children("option:selected").val();
  806. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  807. let featureLib = $("select[name='feature_lib']").children("option:selected").val();
  808. let infoLib = $("select[name='info_lib']").children("option:selected").val();
  809. let progressiveLib = $("select[name='progressive_lib']").children("option:selected").val();
  810. let engineerInfoLib = $("select[name='engineer_info_lib']").children("option:selected").val();
  811. let engineerFeatureLib = $("select[name='engineer_feature_lib']").children("option:selected").val();
  812. let materialLib = $("select[name='material_lib']").children("option:selected").val();
  813. let mainQuantityLib = $("select[name='main_quantity_lib']").children("option:selected").val();
  814. let economicLib = $("select[name='economic_lib']").children("option:selected").val();
  815. let overHeightLib = $("select[name='over_height_lib']").children("option:selected").val();
  816. if (name === '' && model === 'all') {
  817. throw '编办名字不能为空';
  818. }
  819. if (model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  820. throw '请选择标准清单库';
  821. }
  822. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  823. throw '请选择定额库';
  824. }
  825. if (model === 'feature' && (featureLib === '' || featureLib === undefined)) {
  826. throw '请选择工程特征库';
  827. }
  828. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  829. throw '请选择人材机库';
  830. }
  831. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  832. throw '请选择人工系数库';
  833. }
  834. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  835. throw '请选择计算程序';
  836. }
  837. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  838. throw '请选择清单指引库';
  839. }
  840. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  841. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  842. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  843. // let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  844. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  845. let programString = $("select[name='program_lib']").children("option:selected").text();
  846. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  847. let featrueString = $("select[name='feature_lib']").children("option:selected").text();
  848. let infoString = $("select[name='info_lib']").children("option:selected").text();
  849. let progressiveString = $("select[name='progressive_lib']").children("option:selected").text();
  850. let engineerInfoString = $("select[name='engineer_info_lib']").children("option:selected").text();
  851. let engineerFeatureString = $("select[name='engineer_feature_lib']").children("option:selected").text();
  852. let materialString = $("select[name='material_lib']").children("option:selected").text();
  853. let mainQuantityString = $("select[name='main_quantity_lib']").children("option:selected").text();
  854. let economicString = $("select[name='economic_lib']").children("option:selected").text();
  855. let overHeightString = $("select[name='over_height_lib']").children("option:selected").text();
  856. let result = {
  857. name: name,
  858. bill: {
  859. id: standardBill,
  860. name: standardBillString
  861. },
  862. ration: {
  863. id: rationLib,
  864. name: rationLibString
  865. },
  866. glj: {
  867. id: gljLib,
  868. name: gljLibString
  869. },
  870. /* fee: {
  871. id: feeLib,
  872. name: feeLibString
  873. },*/
  874. artificial: {
  875. id: artificialLib,
  876. name: artificialString
  877. },
  878. program: {
  879. id: programLib,
  880. name: programString
  881. },
  882. billsGuidance: {
  883. id: billsGuidanceLib,
  884. name: billsGuidanceString
  885. },
  886. feature: {
  887. id: featureLib,
  888. name: featrueString
  889. },
  890. info: {
  891. id: infoLib,
  892. name: infoString
  893. },
  894. progressive: {
  895. id: progressiveLib,
  896. name: progressiveString
  897. },
  898. engineer_info: {
  899. id: engineerInfoLib,
  900. name: engineerInfoString
  901. },
  902. engineer_feature: {
  903. id: engineerFeatureLib,
  904. name: engineerFeatureString
  905. },
  906. material: {
  907. id: materialLib,
  908. name: materialString
  909. },
  910. main_quantity: {
  911. id: mainQuantityLib,
  912. name: mainQuantityString
  913. },
  914. economic: {
  915. id: economicLib,
  916. name: economicString
  917. },
  918. over_height: {
  919. id: overHeightLib,
  920. name: overHeightString
  921. }
  922. };
  923. return result;
  924. }
  925. /**
  926. * 验证标准库数据
  927. *
  928. * @return {boolean}
  929. */
  930. function validLib() {
  931. let result = false;
  932. try {
  933. let valuationName = $("input[name='name']").val();
  934. if (valuationName === '') {
  935. throw '请填写计价规则名称';
  936. }
  937. let engineering = $("select[name='engineering']").val();
  938. if (engineering === '' || engineering <= 0) {
  939. throw '请选择工程专业';
  940. }
  941. //按新需求,清单库、定额库等不做非空验证
  942. /* if ($("input:hidden[name='bill_lib']").length <= 0) {
  943. throw '请添加标准清单';
  944. }
  945. if ($("input:hidden[name='ration_lib']").length <= 0) {
  946. throw '请添加定额库';
  947. }
  948. if ($("input:hidden[name='glj_lib']").length <= 0) {
  949. throw '请添加人材机库';
  950. }
  951. if ($("input:hidden[name='fee_lib']").length <= 0) {
  952. throw '请添加费率标准';
  953. }
  954. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  955. throw '请添加人工系数';
  956. }
  957. if ($("input:hidden[name='program_lib']").length <= 0) {
  958. throw '请添加计算程序';
  959. }
  960. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  961. throw '请添加清单指引库';
  962. }*/
  963. result = true;
  964. } catch (error) {
  965. alert(error);
  966. result = false;
  967. }
  968. return result;
  969. }
  970. /**
  971. * 切换switch效果
  972. *
  973. * @param {Object} element
  974. * @return {boolean}
  975. */
  976. function switchChange(element) {
  977. // 第一个元素判断当前的状态
  978. let firstButton = element.children("button").first();
  979. let secondButton = element.children("button").eq(1);
  980. let currentStatus = firstButton.is(":disabled");
  981. if (currentStatus) {
  982. // 当前为true切换到false
  983. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  984. firstButton.text('开启');
  985. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  986. secondButton.text('已禁用');
  987. } else {
  988. // 当前false切换到true
  989. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  990. firstButton.text('已开启');
  991. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  992. secondButton.text('禁用');
  993. }
  994. return !currentStatus;
  995. }
  996. function editEngineer(selector, key) {
  997. let editText = $(selector).prev("span").text();
  998. let parentDiv = $(selector).parent("div");
  999. let width = key == 'seq' ? 70 : 200;
  1000. parentDiv.next("div").css('width', width);
  1001. parentDiv.next("div").find("input").val(editText);
  1002. parentDiv.hide();
  1003. parentDiv.next("div").show();
  1004. }
  1005. function confirmUpdate(selector, engineerID) {
  1006. let inputDiv = $(selector).parents(".input_group_div");
  1007. let input = $(selector).parent(".input-group-btn").prev("input");
  1008. let oldValue = inputDiv.prev("div").find("span").text();
  1009. let newValue = input.val();
  1010. let key = input.attr("name");
  1011. if (newValue == oldValue || !engineerID) {//不做非空判断
  1012. inputDiv.prev("div").show();
  1013. inputDiv.hide();
  1014. return;
  1015. }
  1016. let updateData = {};
  1017. updateData[key] = newValue;
  1018. updateEngineer(engineerID, updateData, function () {
  1019. if (key == 'seq') {
  1020. window.location.reload();
  1021. } else {
  1022. inputDiv.prev("div").find("span").text(newValue);
  1023. }
  1024. });
  1025. inputDiv.prev("div").show();
  1026. inputDiv.hide();
  1027. }
  1028. function deleteEngineerClick(engineerID, element) {
  1029. hintBox.infoBox('操作确认', '是否删除所选工程专业?', 2, async function () {
  1030. try {
  1031. let result = await ajaxPost('/compilation/delete-engineer', { id: engineerID });
  1032. $(element).parent("td").parent("tr").remove();
  1033. } catch (err) {
  1034. console.log(err);
  1035. }
  1036. }, null, ['确定', '取消'], false);
  1037. }
  1038. function engineerVisibleChange(checkBox, engineerID) {
  1039. if (engineerID) {
  1040. updateEngineer(engineerID, { visible: checkBox.checked });
  1041. }
  1042. }
  1043. function updateEngineer(engineerID, data, callback) {
  1044. CommonAjax.post('/compilation/update-engineer', { id: engineerID, updateData: data }, function (data) {
  1045. if (callback) {
  1046. callback();
  1047. }
  1048. })
  1049. }
  1050. function editTaxGroup(ele) {
  1051. $('#groupEditType').val("modify");
  1052. let groupData = $(ele).nextAll("input[name = 'tax_group']").val();
  1053. groupData = JSON.parse(groupData);
  1054. if (!_.isEmpty(groupData)) {
  1055. $("#taxType").val(groupData.taxType ? groupData.taxType : "");
  1056. $("#program_lib").val(groupData.program_lib ? groupData.program_lib.id : "");
  1057. $("#norm_lib").val(groupData.norm_lib ? groupData.norm_lib : "");
  1058. $("#template_lib").val(groupData.template_lib ? groupData.template_lib.id : "");
  1059. $("#col_lib").val(groupData.col_lib ? groupData.col_lib.id : "");
  1060. $("#fee_lib").val(groupData.fee_lib ? groupData.fee_lib.id : "");
  1061. } else {
  1062. $("#taxType").val("");
  1063. $("#program_lib").val("");
  1064. $("#template_lib").val("");
  1065. $("#col_lib").val("");
  1066. $("#fee_lib").val("");
  1067. $("#norm_lib").val("");
  1068. }
  1069. $("#groupIndex").val(getGroupIndex(groupData));
  1070. $("#addTaxGroup").modal({ show: true });
  1071. }
  1072. function deleteTableTr(ele, classString) {
  1073. let parentTr = $(ele).parents(`.${classString}`);
  1074. parentTr.remove();
  1075. }
  1076. function getGroupIndex(groupData) {//用来做唯一标识
  1077. let index = "";
  1078. if (groupData) {
  1079. if (groupData.taxType) index = index + groupData.taxType;
  1080. if (groupData.program_lib) index = index + groupData.program_lib.id;
  1081. if (groupData.norm_lib) index = index + groupData.norm_lib;
  1082. if (groupData.template_lib) index = index + groupData.template_lib.id;
  1083. if (groupData.col_lib) index = index + groupData.col_lib.id;
  1084. if (groupData.fee_lib) index = index + groupData.fee_lib.id;
  1085. }
  1086. return index;
  1087. }
  1088. function getTaxGroupData() {
  1089. let programData = programList === undefined ? [] : _.keyBy(JSON.parse(programList), 'id');
  1090. let billTemplateData = billTemplateList == undefined ? [] : _.keyBy(JSON.parse(billTemplateList), 'ID');
  1091. let mainTreeColData = mainTreeColList == undefined ? [] : _.keyBy(JSON.parse(mainTreeColList), 'ID');
  1092. let feeLibData = feeRateList === undefined ? [] : _.keyBy(JSON.parse(feeRateList), 'id');
  1093. let groupData = {};
  1094. if ($("#taxType").val() !== "") {
  1095. groupData.taxType = $("#taxType").val();
  1096. }
  1097. if ($("#norm_lib").val() !== "") {
  1098. groupData.norm_lib = $('#norm_lib').val();
  1099. }
  1100. if ($("#program_lib").val() !== "") {
  1101. let program = programData[$("#program_lib").val()];
  1102. if (program) {
  1103. groupData.program_lib = {
  1104. id: program.id,
  1105. name: program.name,
  1106. displayName: program.displayName
  1107. }
  1108. }
  1109. }
  1110. if ($("#template_lib").val() !== "") {
  1111. let template = billTemplateData[$("#template_lib").val()];
  1112. if (template) {
  1113. groupData.template_lib = {
  1114. id: template.ID,
  1115. name: template.name
  1116. }
  1117. }
  1118. }
  1119. if ($("#col_lib").val() !== "") {
  1120. let col = mainTreeColData[$("#col_lib").val()];
  1121. if (col) {
  1122. groupData.col_lib = {
  1123. id: col.ID,
  1124. name: col.name
  1125. }
  1126. }
  1127. }
  1128. if ($("#fee_lib").val() !== "") {
  1129. let feeRate = feeLibData[$("#fee_lib").val()];
  1130. if (feeRate) {
  1131. groupData.fee_lib = {
  1132. id: feeRate.id,
  1133. name: feeRate.name
  1134. }
  1135. }
  1136. }
  1137. return groupData;
  1138. }
  1139. function intChecking(e, elemt) {//限制输入正整数
  1140. let code = e.which || e.keyCode;
  1141. if (code == 46 || code == 45) {//不能输入小数点和-号
  1142. e.preventDefault();
  1143. }
  1144. if (elemt.value == "" && code == 48) {//当输入框为空时不能输入0
  1145. e.preventDefault();
  1146. }
  1147. }