compilation.js 44 KB

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