compilation.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /**
  2. * 编办管理相关js
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/7/28
  6. * @version
  7. */
  8. $(document).ready(function() {
  9. let isAdding = false;
  10. let model = '';
  11. let section = 'bill';
  12. let id = $("#compilation-id").val();
  13. // 计价规则页面初始化数据
  14. if ($("#save-lib").length > 0) {
  15. initCompilation();
  16. }
  17. // 计价类型选择
  18. $(".nav-tabs li > a").click(function() {
  19. section = $(this).attr("aria-controls");
  20. });
  21. // 新增编办
  22. $("#add-compilation").click(function() {
  23. try {
  24. let data = getAndValidData(model);
  25. let url = '/compilation/add'
  26. if (model === 'all') {
  27. // 新增编办操作
  28. $.ajax({
  29. url: url,
  30. type: 'post',
  31. data: {name: data.name},
  32. error: function() {
  33. isAdding = false;
  34. },
  35. beforeSend: function() {
  36. isAdding = true;
  37. },
  38. success: function(response) {
  39. isAdding = false;
  40. if (response.err === 0) {
  41. window.location.reload();
  42. } else {
  43. let msg = response.msg === undefined ? '未知错误' : response.msg;
  44. alert(msg);
  45. }
  46. }
  47. });
  48. } else {
  49. // 新增标准清单/定额库
  50. let addLib = {
  51. name: data[model].name,
  52. id: data[model].id
  53. };
  54. // 判断是否有重复的数据
  55. if ($("input:hidden[name='"+ model +"_lib'][data-id='"+ addLib.id +"']").length > 0) {
  56. alert('重复添加数据!');
  57. return false;
  58. }
  59. let removeHtml = '<a class="pull-right text-danger remove-lib" data-model="bill" ' +
  60. 'title="移除"><span class="glyphicon glyphicon-remove"></span></a>';
  61. let tmpHtml = '<p class="form-control-static">' + removeHtml + addLib.name +
  62. '<input type="hidden" data-id="'+ addLib.id +'" name=\'' + model + '_lib\' value=\'' + JSON.stringify(addLib) + '\'>' + '</p>';
  63. $("." + model + "-list").append(tmpHtml);
  64. $('#addcompilation').modal('hide');
  65. }
  66. } catch (error) {
  67. alert(error);
  68. }
  69. });
  70. // 新增计价规则
  71. $("#add-valuation").click(function() {
  72. try {
  73. if (id === '') {
  74. throw '页面数据有误';
  75. }
  76. let name = $("input[name='valuation_name']").val();
  77. if (name === '') {
  78. throw '请填写计价规则名称';
  79. }
  80. $.ajax({
  81. url: '/compilation/add-valuation',
  82. type: 'post',
  83. data: {name: name, id: id, section: section},
  84. error: function() {
  85. isAdding = false;
  86. },
  87. beforeSend: function() {
  88. isAdding = true;
  89. },
  90. success: function(response) {
  91. isAdding = false;
  92. if (response.err === 0) {
  93. window.location.reload();
  94. } else {
  95. let msg = response.msg === undefined ? '未知错误' : response.msg;
  96. alert(msg);
  97. }
  98. }
  99. });
  100. } catch (error) {
  101. alert(error);
  102. return false;
  103. }
  104. });
  105. // 添加
  106. $(".add-compilation").click(function() {
  107. model = $(this).data('model');
  108. $("#addcompilation .modal-body > div").hide();
  109. switch (model) {
  110. case 'all':
  111. $("#name-area").show();
  112. $("#add-compilation-title").text('添加新编办');
  113. break;
  114. case 'bill':
  115. $("#bill-area").show();
  116. $("#add-compilation-title").text('添加标准清单');
  117. break;
  118. case 'ration':
  119. $("#ration-area").show();
  120. $("#add-compilation-title").text('添加定额库');
  121. break;
  122. case 'glj':
  123. $("#glj-area").show();
  124. $("#add-compilation-title").text('添加定额库');
  125. break;
  126. case 'billsGuidance':
  127. $("#billsGuidance-area").show();
  128. $("#add-compilation-title").text('添加清单指引库');
  129. break;
  130. case 'fee':
  131. $("#fee-area").show();
  132. $("#add-compilation-title").text('添加费率标准');
  133. break;
  134. case 'artificial':
  135. $("#artificial-area").show();
  136. $("#add-compilation-title").text('添加人工系数');
  137. break;
  138. case 'program':
  139. $("#program-area").show();
  140. $("#add-compilation-title").text('添加计算程序');
  141. break;
  142. }
  143. $("#addcompilation").modal('show');
  144. });
  145. // 保存专业工程标准库
  146. $("#save-lib").click(function() {
  147. if (validLib()) {
  148. $("form").submit();
  149. }
  150. });
  151. // 保存计价规则
  152. $("#save-valuation").click(function() {
  153. $("form").submit();
  154. });
  155. // 移除操作
  156. $(".bill-list, .ration-list, .glj-list, .fee-list, .artificial-list, .program-list, .billsGuidance-list").on("click", ".remove-lib", function() {
  157. $(this).parent().remove();
  158. });
  159. //更改描述
  160. $('#description').change(function () {
  161. let description = $(this).val();
  162. $.ajax({
  163. url: '/compilation/setDescription',
  164. type: 'post',
  165. dataType: "json",
  166. data: {id: id, description: description},
  167. success: function(response) {
  168. if (response.err !== 0) {
  169. alert('更改失败');
  170. }
  171. }
  172. });
  173. });
  174. // 计价规则启用/禁止
  175. $(".enable").click(function() {
  176. let goingChangeStatus = switchChange($(this));
  177. let id = $(this).data('id');
  178. if (id === undefined || id === '' || isAdding) {
  179. return false;
  180. }
  181. $.ajax({
  182. url: '/compilation/valuation/' + section + '/enable',
  183. type: 'post',
  184. dataType: "json",
  185. data: {id: id, enable: goingChangeStatus},
  186. error: function() {
  187. isAdding = false;
  188. switchChange($(this));
  189. },
  190. beforeSend: function() {
  191. isAdding = true;
  192. },
  193. success: function(response) {
  194. isAdding = false;
  195. if (response.err !== 0) {
  196. switchChange($(this));
  197. alert('更改失败');
  198. }
  199. }
  200. });
  201. });
  202. //计价规则删除
  203. $('#delete-confirm').click(function () {
  204. let id = $('#del').attr('selectedId');
  205. if (id === undefined || id === '') {
  206. return false;
  207. }
  208. window.location.href = `/compilation/valuation/bill/delete/${id}`;
  209. });
  210. // 发布编办
  211. $("#release").click(function() {
  212. let id = $(this).data("id");
  213. let status = $(this).data("status");
  214. status = parseInt(status);
  215. if (isAdding || id === '' || isNaN(status)) {
  216. return false;
  217. }
  218. $.ajax({
  219. url: '/compilation/release',
  220. type: 'post',
  221. data: {id: id, status: status},
  222. dataType: "json",
  223. error: function() {
  224. isAdding = false;
  225. },
  226. beforeSend: function() {
  227. isAdding = true;
  228. },
  229. success: function(response) {
  230. isAdding = false;
  231. if (response.err === 0) {
  232. window.location.reload();
  233. } else {
  234. let msg = response.msg === undefined ? "未知错误" : response.msg;
  235. alert(msg);
  236. }
  237. }
  238. });
  239. });
  240. });
  241. /**
  242. * 初始化
  243. *
  244. * @return {void|boolean}
  245. */
  246. function initCompilation() {
  247. let billListData = billList === undefined ? [] : JSON.parse(billList);
  248. let rationLibData = rationList === undefined ? [] : JSON.parse(rationList);
  249. let gljLibData = gljList === undefined ? [] : JSON.parse(gljList);
  250. let feeLibData = feeRateList === undefined ? [] : JSON.parse(feeRateList);
  251. let artificialCoefficientData = artificialCoefficientList === undefined ? [] : JSON.parse(artificialCoefficientList);
  252. let programData = programList === undefined ? [] : JSON.parse(programList);
  253. let billsGuidanceData = billsGuidanceList === undefined ? [] : JSON.parse(billsGuidanceList);
  254. mainTreeCol = mainTreeCol !== '' ? mainTreeCol.replace(/\n/g, '\\n') : mainTreeCol;
  255. billsTemplateData = billsTemplateData.replace(/\n/g, '\\n');
  256. let mainTreeColObj = mainTreeCol === '' ? {} : JSON.parse(mainTreeCol);
  257. // 初始化 造价书列设置
  258. colSpread = TREE_SHEET_HELPER.createNewSpread($('#main-tree-col')[0]);
  259. let billsTemplateTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1});
  260. billsTemplateTree.loadDatas(JSON.parse(billsTemplateData));
  261. if (mainTreeCol !== '') {
  262. TREE_SHEET_HELPER.loadSheetHeader(mainTreeColObj, colSpread.getActiveSheet());
  263. TREE_SHEET_HELPER.showTreeData(mainTreeColObj, colSpread.getActiveSheet(), billsTemplateTree);
  264. }
  265. if (billListData.length <= 0 || rationLibData.length <= 0 || gljLibData.length <= 0) {
  266. return false;
  267. }
  268. // 标准清单
  269. let html = '';
  270. for(let tmp of billListData) {
  271. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  272. html += tmpHtml;
  273. }
  274. $("select[name='standard_bill']").children("option").first().after(html);
  275. // 定额库
  276. html = '';
  277. for(let tmp of rationLibData) {
  278. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  279. html += tmpHtml;
  280. }
  281. $("select[name='ration_lib']").children("option").first().after(html);
  282. // 工料机库
  283. html = '';
  284. for(let tmp of gljLibData) {
  285. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  286. html += tmpHtml;
  287. }
  288. $("select[name='glj_lib']").children("option").first().after(html);
  289. // 清单指引库
  290. html = '';
  291. for(let tmp of billsGuidanceData) {
  292. let tmpHtml = '<option value="' + tmp.ID + '">' + tmp.name + '</option>';
  293. html += tmpHtml;
  294. }
  295. $("select[name='billsGuidance_lib']").children("option").first().after(html);
  296. // 费率标准库
  297. html = '';
  298. for(let tmp of feeLibData) {
  299. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  300. html += tmpHtml;
  301. }
  302. $("select[name='fee_lib']").children("option").first().after(html);
  303. // 人工系数标准库
  304. html = '';
  305. for(let tmp of artificialCoefficientData) {
  306. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  307. html += tmpHtml;
  308. }
  309. $("select[name='artificial_lib']").children("option").first().after(html);
  310. // 计算程序标准库
  311. html = '';
  312. for(let tmp of programData) {
  313. let tmpHtml = '<option value="' + tmp.id + '">' + tmp.name + '</option>';
  314. html += tmpHtml;
  315. }
  316. $("select[name='program_lib']").children("option").first().after(html);
  317. }
  318. /**
  319. * 校验数据
  320. *
  321. * @param {String} model
  322. * @return {Object}
  323. */
  324. function getAndValidData(model) {
  325. let name = $("input[name='compilation_name']").val();
  326. let standardBill = $("select[name='standard_bill']").children("option:selected").val();
  327. let rationLib = $("select[name='ration_lib']").children("option:selected").val();
  328. let gljLib = $("select[name='glj_lib']").children("option:selected").val();
  329. let feeLib = $("select[name='fee_lib']").children("option:selected").val();
  330. let artificialLib = $("select[name='artificial_lib']").children("option:selected").val();
  331. let programLib = $("select[name='program_lib']").children("option:selected").val();
  332. let billsGuidanceLib = $("select[name='billsGuidance_lib']").children("option:selected").val();
  333. if (name === '' && model === 'all') {
  334. throw '编办名字不能为空';
  335. }
  336. if ( model === 'bill' && (standardBill === '' || standardBill === undefined)) {
  337. throw '请选择标准清单库';
  338. }
  339. if (model === 'ration' && (rationLib === '' || rationLib === undefined)) {
  340. throw '请选择定额库';
  341. }
  342. if (model === 'glj' && (gljLib === '' || gljLib === undefined)) {
  343. throw '请选择人材机库';
  344. }
  345. if (model === 'fee' && (feeLib === '' || feeLib === undefined)) {
  346. throw '请选择费率标准';
  347. }
  348. if (model === 'artificial' && (artificialLib === '' || artificialLib === undefined)) {
  349. throw '请选择费率库';
  350. }
  351. if (model === 'program' && (programLib === '' || programLib === undefined)) {
  352. throw '请选择计算程序';
  353. }
  354. if (model === 'billsGuidance' && (billsGuidanceLib === '' || billsGuidanceLib === undefined)) {
  355. throw '请选择清单指引库';
  356. }
  357. let standardBillString = $("select[name='standard_bill']").children("option:selected").text();
  358. let rationLibString = $("select[name='ration_lib']").children("option:selected").text();
  359. let gljLibString = $("select[name='glj_lib']").children("option:selected").text();
  360. let feeLibString = $("select[name='fee_lib']").children("option:selected").text();
  361. let artificialString = $("select[name='artificial_lib']").children("option:selected").text();
  362. let programString = $("select[name='program_lib']").children("option:selected").text();
  363. let billsGuidanceString = $("select[name='billsGuidance_lib']").children("option:selected").text();
  364. let result = {
  365. name: name,
  366. bill: {
  367. id: standardBill,
  368. name: standardBillString
  369. },
  370. ration: {
  371. id: rationLib,
  372. name: rationLibString
  373. },
  374. glj: {
  375. id: gljLib,
  376. name: gljLibString
  377. },
  378. fee: {
  379. id: feeLib,
  380. name: feeLibString
  381. },
  382. artificial: {
  383. id: artificialLib,
  384. name: artificialString
  385. },
  386. program: {
  387. id: programLib,
  388. name: programString
  389. },
  390. billsGuidance: {
  391. id: billsGuidanceLib,
  392. name: billsGuidanceString
  393. }
  394. };
  395. return result;
  396. }
  397. /**
  398. * 验证标准库数据
  399. *
  400. * @return {boolean}
  401. */
  402. function validLib() {
  403. let result = false;
  404. try {
  405. let valuationName = $("input[name='name']").val();
  406. if (valuationName === '') {
  407. throw '请填写计价规则名称';
  408. }
  409. let engineering = $("select[name='engineering']").val();
  410. if (engineering === '' || engineering <= 0) {
  411. throw '请选择工程专业';
  412. }
  413. if ($("input:hidden[name='bill_lib']").length <= 0) {
  414. throw '请添加标准清单';
  415. }
  416. if ($("input:hidden[name='ration_lib']").length <= 0) {
  417. throw '请添加定额库';
  418. }
  419. if ($("input:hidden[name='glj_lib']").length <= 0) {
  420. throw '请添加人材机库';
  421. }
  422. if ($("input:hidden[name='fee_lib']").length <= 0) {
  423. throw '请添加费率标准';
  424. }
  425. if ($("input:hidden[name='artificial_lib']").length <= 0) {
  426. throw '请添加人工系数';
  427. }
  428. if ($("input:hidden[name='program_lib']").length <= 0) {
  429. throw '请添加计算程序';
  430. }
  431. if ($("input:hidden[name='billsGuidance_lib']").length <= 0) {
  432. throw '请添加清单指引库';
  433. }
  434. result = true;
  435. } catch (error) {
  436. alert(error);
  437. result = false;
  438. }
  439. return result;
  440. }
  441. /**
  442. * 切换switch效果
  443. *
  444. * @param {Object} element
  445. * @return {boolean}
  446. */
  447. function switchChange(element) {
  448. // 第一个元素判断当前的状态
  449. let firstButton = element.children("button").first();
  450. let secondButton = element.children("button").eq(1);
  451. let currentStatus = firstButton.is(":disabled");
  452. if (currentStatus) {
  453. // 当前为true切换到false
  454. firstButton.removeClass('btn-success').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  455. firstButton.text('开启');
  456. secondButton.removeClass("btn-default").addClass("btn-danger").addClass("disabled").attr("disabled", "disabled");
  457. secondButton.text('已禁用');
  458. } else {
  459. // 当前false切换到true
  460. firstButton.removeClass("btn-default").addClass("btn-success").addClass("disabled").attr("disabled", "disabled");
  461. firstButton.text('已开启');
  462. secondButton.removeClass('btn-danger').removeClass('disabled').addClass('btn-default').removeAttr("disabled");
  463. secondButton.text('禁用');
  464. }
  465. return !currentStatus;
  466. }