change_project.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date 2018/8/21
  7. * @version
  8. */
  9. // 向后端请求中间计量号
  10. function getNewCode() {
  11. postData('/tender/'+ tenderId +'/change/newCode', { type: rulesType }, function (code) {
  12. if (code !== '') {
  13. $('#bj-code').val(code);
  14. }
  15. });
  16. }
  17. class codeRuleSet {
  18. constructor (obj) {
  19. this.body = obj;
  20. // 切换规则组件类型
  21. $('.rule-change', obj).change(function () {
  22. const codeType = this.selectedIndex-1;
  23. if (codeType === ruleConst.ruleType.addNo) {
  24. $('#format', obj).show();
  25. $('#text', obj).show();
  26. $('#text>label', obj).text('起始编号');
  27. $('#text>input', obj).val('001');
  28. const s = '0000000000' + 1;
  29. $('#text>input', obj).val(s.substr(s.length - $('#format>input', obj).val()));
  30. } else if (codeType === ruleConst.ruleType.text) {
  31. $('#format', obj).hide();
  32. $('#text', obj).show();
  33. $('#text>label', obj).text('文本');
  34. $('#text>input', obj).val('').attr('placeholder', '请在这里输入需要的文本');
  35. } else {
  36. $('#format', obj).hide();
  37. $('#text', obj).hide();
  38. }
  39. });
  40. // 修改编号位数
  41. $('#format>input', obj).change(function () {
  42. const s = '0000000000' + parseInt($('#text>input', obj).val());
  43. $('#text>input', obj).val(s.substr(s.length - $(this).val()));
  44. });
  45. // 修改连接符
  46. $('.connector-change', obj).change(function () {
  47. const connectorType = this.options[this.selectedIndex].text;
  48. const rules = $('span>span', obj), ruleText = [];
  49. for (const r of rules) {
  50. ruleText.push($.trim(r.innerText));
  51. }
  52. if (connectorType === '无') {
  53. $('#preview', obj).text(ruleText.join(''));
  54. } else {
  55. $('#preview', obj).text(ruleText.join(connectorType));
  56. }
  57. connectorRule = this.options[this.selectedIndex].value;
  58. });
  59. // 新增规则组件
  60. $('#addRule', obj).click(function () {
  61. const codeType = $('select', obj)[1].selectedIndex-1;
  62. const rule = {rule_type: codeType}, html = [];
  63. let preview;
  64. switch (codeType) {
  65. case ruleConst.ruleType.dealCode: {
  66. if (dealCode === '') {
  67. toastr.error('当前标段合同编号为空,请选择其他组件。');
  68. return false;
  69. }
  70. preview = dealCode;
  71. break;
  72. }
  73. case ruleConst.ruleType.tenderName: {
  74. preview = tenderName;
  75. break;
  76. }
  77. case ruleConst.ruleType.text: {
  78. rule.text = $('#text>input', obj).val();
  79. if (rule.text === '') {
  80. toastr.error('文本内容不允许为空。');
  81. return false;
  82. }
  83. preview = rule.text;
  84. break;
  85. }
  86. case ruleConst.ruleType.inDate: {
  87. preview = moment().format('YYYY');
  88. break;
  89. }
  90. case ruleConst.ruleType.addNo: {
  91. rule.format = parseInt($('#format>input', obj).val());
  92. rule.start = parseInt($('#text>input', obj).val());
  93. if ($('#text>input', obj).val().length !== rule.format) {
  94. toastr.error('起始编号位数和自动编号位数不一致。');
  95. return false;
  96. }
  97. const s = '0000000000';
  98. preview = s.substr(s.length - rule.format);
  99. break;
  100. }
  101. default: {
  102. toastr.error('请选择组件再添加');
  103. return false;
  104. }
  105. }
  106. // 更新规则
  107. codeRule.push(rule);
  108. // 更新规则显示
  109. html.push('<span class="badge badge-light" title="' + ruleConst.ruleString[codeType] + '" rule="' + JSON.stringify(rule) + '">');
  110. html.push('<span>' + preview + '</span>');
  111. html.push('<a href="javascript: void(0);" class="text-danger" title="移除"><i class="fa fa-remove"></i></a>');
  112. html.push('</span>');
  113. const part = $('#ruleParts', obj).append(html.join(''));
  114. // 更新规则预览
  115. const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
  116. const previewtext = $.trim($('#preview', obj).text()) === '' ? preview : $.trim($('#preview', obj).text()) + connectorType + preview;
  117. $('#preview', obj).text(previewtext);
  118. });
  119. // 删除规则组件
  120. $($('#ruleParts', obj)).on('click', 'a', function () {
  121. const index = $('a', obj).index(this);
  122. codeRule.splice(index-1, 1);
  123. $(this).parent().remove();
  124. const rules = $('span>span', obj), ruleText = [];
  125. for (const r of rules) {
  126. ruleText.push($.trim(r.innerText));
  127. }
  128. const connectorType = connectorRule !== '' && parseInt(connectorRule) !== ruleConst.connectorType.nothing ? ruleConst.connectorString[connectorRule] : '';
  129. $('#preview', obj).text(ruleText.join(connectorType));
  130. });
  131. }
  132. }
  133. /**
  134. * 期计量 - 期列表页面 js
  135. *
  136. * @author Mai
  137. * @date 2018/12/7
  138. * @version
  139. */
  140. const getGroupAuditHtml = function (group) {
  141. return group.map(u => { return `<small class="d-inline-block text-dark mx-1" title="${u.role}" data-auditorId="${u.aid}">${u.name}</small>`; }).join('');
  142. };
  143. const getAuditTypeHtml = function (type) {
  144. if (type === auditType.key.common) return '';
  145. return `<div class="li-subscript"><span class="badge badge-pill badge-${auditType.info[type].class} p-1 badge-bg-small"><small>${auditType.info[type].short}</small></span></div>`;
  146. };
  147. const getAuditTypeText = function (type) {
  148. if (type === auditType.key.common) return '';
  149. return `<span class="text-${auditType.info[type].class}">${auditType.info[type].long}</span>`;
  150. };
  151. $(document).ready(() => {
  152. $('#audit-list').on('click', 'a', function() {
  153. const type = $(this).data('target')
  154. const auditCard = $(this).parent().parent()
  155. if (type === 'show') {
  156. $(this).data('target', 'hide')
  157. auditCard.find('.fold-card').slideDown('swing', () => {
  158. auditCard.find('#end-target').text($(this).data('idx') + '#')
  159. auditCard.find('#fold-btn').text('收起历史审核记录')
  160. })
  161. } else {
  162. $(this).data('target', 'show')
  163. auditCard.find('.fold-card').slideUp('swing', () => {
  164. auditCard.find('#end-target').text('1#')
  165. auditCard.find('#fold-btn').text('展开历史审核记录')
  166. })
  167. }
  168. });
  169. // 获取审批流程
  170. $('a[data-target="#sp-list" ]').on('click', function () {
  171. const data = {
  172. id: $(this).attr('c-id'),
  173. };
  174. postData('/tender/' + tenderId + '/change/project/auditors', data, function (result) {
  175. const { auditHistory, auditors2, user } = result;
  176. let auditorsHTML = [];
  177. auditors2.forEach((group, idx) => {
  178. if (idx === 0) {
  179. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  180. <span class="mr-1"><i class="fa fa fa-play-circle fa-rotate-90"></i></span>
  181. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  182. <span class="badge badge-light badge-pill ml-auto"><small>原报</small></span>
  183. </li>`);
  184. } else if(idx === auditors2.length -1 && idx !== 0) {
  185. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  186. <span class="mr-1"><i class="fa fa fa-stop-circle fa-rotate-90"></i></span>
  187. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  188. <div class="d-flex ml-auto">
  189. ${getAuditTypeHtml(group[0].audit_type)}
  190. <span class="badge badge-light badge-pill ml-auto"><small>终审</small></span>
  191. </div>
  192. </li>`);
  193. } else {
  194. auditorsHTML.push(`<li class="list-group-item d-flex justify-content-between align-items-center">
  195. <span class="mr-1"><i class="fa fa fa-chevron-circle-down"></i></span>
  196. <span class="text-muted">${getGroupAuditHtml(group)}</span>
  197. <div class="d-flex ml-auto">
  198. ${getAuditTypeHtml(group[0].audit_type)}
  199. <span class="badge badge-light badge-pill"><small>${transFormToChinese(idx)}审</small></span>
  200. </div>
  201. </li>`);
  202. }
  203. });
  204. $('#auditor-list').empty();
  205. $('#auditor-list').append(auditorsHTML.join(''));
  206. let historyHTML = [];
  207. auditHistory.forEach((his, idx) => {
  208. if (idx === auditHistory.length - 1 && auditHistory.length !== 1) {
  209. historyHTML.push(`<div class="text-right"><a href="javascript: void(0);" id="fold-btn" data-target="show">展开历史审批流程</a></div>`);
  210. }
  211. historyHTML.push(`<div class="${idx < auditHistory.length - 1 ? 'fold-card' : ''}">`);
  212. historyHTML.push(`<div class="text-center text-muted">${idx+1}#</div>`);
  213. historyHTML.push(`<ul class="timeline-list list-unstyled mt-2 ${ idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'last-auditor-list' : '' }">`);
  214. his.forEach((group, index) => {
  215. if (index === 0) {
  216. historyHTML.push(`<li class="timeline-list-item pb-2">
  217. <div class="timeline-item-date">
  218. ${group.beginYear}
  219. <span>${group.beginDate}</span>
  220. <span>${group.beginTime}</span>
  221. </div>
  222. <div class="timeline-item-tail"></div>
  223. <div class="timeline-item-icon bg-success text-light"><i class="fa fa-caret-down"></i></div>
  224. <div class="timeline-item-content">
  225. <div class="py-1">
  226. <span class="text-black-50">原报</span>
  227. <span class="pull-right text-success">${idx !== 0 ? '重新' : '' }上报审批</span>
  228. </div>
  229. <div class="card">
  230. <div class="card-body px-3 py-0">
  231. <div class="card-text p-2 py-3 row">
  232. <div class="col">
  233. <span class="h6">${user.name}</span>
  234. <span class="text-muted ml-1">${user.role}</span>
  235. </div>
  236. <div class="col">
  237. <span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>
  238. </div>
  239. </div>
  240. </div>
  241. </div>
  242. </div>
  243. </li>`);
  244. }
  245. historyHTML.push(`<li class="timeline-list-item pb-2 ${ group.status === auditConst.status.uncheck && idx === auditHistory.length - 1 && auditHistory.length !== 1 ? 'is_uncheck' : ''}">`);
  246. if (group.endYear) {
  247. historyHTML.push(`<div class="timeline-item-date">${group.endYear}<span>${group.endDate}</span><span>${group.endTime}</span></div>`);
  248. }
  249. if (index < his.length - 1) {
  250. historyHTML.push('<div class="timeline-item-tail"></div>');
  251. }
  252. if (group.status === auditConst.status.checked || group.status === auditConst.status.cancelRevise) {
  253. historyHTML.push('<div class="timeline-item-icon bg-success text-light"><i class="fa fa-check"></i></div>');
  254. } else if (group.status === auditConst.status.back || group.status === auditConst.status.revise || group.status === auditConst.status.checkCancel) {
  255. historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-level-up"></i></div>');
  256. } else if (group.status === auditConst.status.checking) {
  257. historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-ellipsis-h"></i></div>');
  258. } else if (group.status === auditConst.status.checkNo) {
  259. historyHTML.push('<div class="timeline-item-icon bg-danger text-light"><i class="fa fa-stop"></i></div>');
  260. } else if(group.status === auditConst.status.checkAgain) {
  261. historyHTML.push('<div class="timeline-item-icon bg-warning text-light"><i class="fa fa-check"></i></div>');
  262. } else {
  263. historyHTML.push('<div class="timeline-item-icon bg-secondary text-light"></div>');
  264. }
  265. historyHTML.push('<div class="timeline-item-content">');
  266. historyHTML.push('<div class="py-1">');
  267. const statuStr = group.status !== auditConst.status.uncheck ?
  268. `<span class="pull-right ${auditConst.statusClass[group.status]}">${auditConst.statusString[group.status]}</span>` : '';
  269. historyHTML.push(`
  270. <span class="text-black-50">
  271. ${ group.audit_order === 0 ? '原报' : !group.is_final ? group.audit_order + '审' : '终审' } ${getAuditTypeText(group.audit_type)}
  272. </span>
  273. ${statuStr}`);
  274. historyHTML.push('</div>');
  275. historyHTML.push('<div class="card"><div class="card-body px-3 py-0">');
  276. for (const [i, auditor] of group.auditors.entries()) {
  277. historyHTML.push(`<div class="card-text p-2 py-3 row ${ ( i > 0 ? 'border-top' : '') }">`);
  278. historyHTML.push(`<div class="col"><span class="h6">${auditor.name}</span><span class="text-muted ml-1">${auditor.role}</span></div>`);
  279. historyHTML.push('<div class="col">');
  280. if (auditor.status === auditConst.status.checked || group.status === auditConst.status.cancelRevise) {
  281. historyHTML.push('<span class="pull-right text-success"><i class="fa fa-check-circle"></i></span>');
  282. } else if (auditor.status === auditConst.status.back || group.status === auditConst.status.revise || auditor.status === auditConst.status.checkCancel) {
  283. historyHTML.push('<span class="pull-right text-warning"><i class="fa fa-share-square fa-rotate-270"></i></span>');
  284. } else if (auditor.status === auditConst.status.checking) {
  285. historyHTML.push('<span class="pull-right text-warning"><i class="fa fa-commenting"></i></span>');
  286. } else if (auditor.status === auditConst.status.checkNo) {
  287. historyHTML.push('<span class="pull-right text-danger"><i class="fa fa-stop-circle"></i></span>');
  288. } else if (auditor.status === auditConst.status.checkAgain) {
  289. historyHTML.push('<span class="pull-right text-warning"><i class="fa fa-check"></i></span>');
  290. }
  291. historyHTML.push('</div>');
  292. if (auditor.opinion) {
  293. historyHTML.push(`<div class="col-12 py-1 bg-light"><i class="fa fa-commenting-o mr-1"></i>${auditor.opinion}</div>`);
  294. }
  295. historyHTML.push('</div>');
  296. }
  297. historyHTML.push('</div></div>');
  298. historyHTML.push('</div>');
  299. historyHTML.push('</li>');
  300. });
  301. historyHTML.push('</div>');
  302. historyHTML.push('</ul>');
  303. });
  304. $('#audit-list').empty();
  305. $('#audit-list').append(historyHTML.join(''));
  306. });
  307. });
  308. // 首次进入设置
  309. let showNoNeed = false;
  310. if (cRuleFirst) {
  311. codeRule = [];
  312. showNoNeed = true;
  313. $('#setting').modal('show');
  314. }
  315. // else if ($('#changeList').children.length === 0) {
  316. // $('#add-bj').modal('show');
  317. // }
  318. // 设置
  319. const ruleSet = new codeRuleSet($('div.modal-body', '#setting'));
  320. $('#setRule', '#setting').bind('click', function () {
  321. const data = {
  322. rule: ruleType,
  323. type: rulesType,
  324. connector: connectorRule,
  325. data: JSON.stringify(codeRule),
  326. };
  327. if (codeRule.length !== 0) {
  328. $('#autoCodeShow').show();
  329. }
  330. postData('/tender/rule', data, function () {
  331. if (cRuleFirst && showNoNeed) {
  332. $('#changeFirst').click();
  333. $('.ml-auto a[href="#add-bj"]').click();
  334. // $('#add-bj-modal').modal('show');
  335. } else {
  336. $('#setting').modal('hide');
  337. }
  338. });
  339. })
  340. $('.ml-auto').on('click', 'a', function () {
  341. const content = $(this).attr('href');
  342. if (content === '#add-bj') {
  343. $('#add-bj-modal').modal('show')
  344. getNewCode();
  345. if ($('#changeList').children.length === 0) {
  346. $('#addCancel').hide();
  347. } else {
  348. $('#addCancel').show();
  349. }
  350. $('#bj-code').removeClass('is-invalid');
  351. }
  352. });
  353. // 获取最新可用变更令号
  354. $('#autoCode').click(getNewCode);
  355. // 新增变更令 确认
  356. $('#addOk').click(function () {
  357. $(this).attr('disabled', true);
  358. if ($('#bj-name').val().length === 0) {
  359. $('#bj-name').addClass('is-invalid');
  360. $('#name_error_msg').show();
  361. $('#name_error_msg').text('变更工程名称不能为空。');
  362. $(this).attr('disabled', false);
  363. setTimeout(function () {
  364. $('#bj-name').removeClass('is-invalid');
  365. $('#name_error_msg').hide();
  366. }, 2000);
  367. return;
  368. }
  369. if ($('#bj-name').val().length > 100) {
  370. $('#bj-name').addClass('is-invalid');
  371. $('#name_error_msg').show();
  372. $('#name_error_msg').text('名称超过100个字,请缩减名称。');
  373. $(this).attr('disabled', false);
  374. setTimeout(function () {
  375. $('#bj-name').removeClass('is-invalid');
  376. $('#name_error_msg').hide();
  377. }, 2000);
  378. return;
  379. }
  380. const data = {
  381. code: $('#bj-code').val(),
  382. name: $('#bj-name').val(),
  383. };
  384. if (data.code || data.code !== '' || data.name || data.name !== '') {
  385. postData('/tender/'+ tenderId +'/change/project/add', data, function (rst) {
  386. $('#bj-code').removeClass('is-invalid');
  387. $('#mj-add').modal('hide');
  388. $(this).attr('disabled', false);
  389. window.location.href = '/tender/'+ tenderId +'/change/project/' + rst.id + '/information';
  390. }, function () {
  391. $('#mj-code').addClass('is-invalid');
  392. $('#mj-Hint').show();
  393. $(this).attr('disabled', false);
  394. });
  395. }
  396. });
  397. //状态切换
  398. $('#status_select a').on('click', function () {
  399. const status = $(this).data('val');
  400. let url = '/tender/'+ tenderId +'/change/project';
  401. if (status !== 0) {
  402. url += '/status/'+ status;
  403. }
  404. const filterString = setChangeFilterData('change-project-'+ tenderId +'-list-order');
  405. if (filterString) url = url + filterString;
  406. window.location.href = url;
  407. });
  408. // 不再显示首次使用
  409. $('#changeFirst').click(function () {
  410. showNoNeed = false;
  411. $('#changeFirst').remove();
  412. $('#hide_modal').show();
  413. $('#setting').modal('hide');
  414. postData('/tender/'+ tenderId +'/rule/first', { type: rulesType }, function () {
  415. });
  416. });
  417. // 弹出删除变更框赋值
  418. $('.delete-cpid-modal').on('click', function () {
  419. $('#delete-cpid').val($(this).attr('cpid'));
  420. });
  421. // 排序初始化
  422. let orderSetting = getLocalCache('change-project-'+ tenderId +'-list-order');
  423. if (!orderSetting) orderSetting = 'time|desc';
  424. const orders = orderSetting.split('|');
  425. $("#sort-radio input[value='"+ orders[0] +"']").prop('checked', true);
  426. $("#order-radio input[value='"+ orders[1] +"']").prop('checked', true);
  427. if (orders[0] === 'time') {
  428. $('#bpaixu').text('排序:发起时间');
  429. } else {
  430. $('#bpaixu').text('排序:变更立项书编号');
  431. }
  432. // let sortSetting = getLocalCache('change-'+ $('#tenderId').val() +'-list-sort');
  433. // if (sortSetting && parseInt(sortSetting) === 1) {
  434. // $('#bpaixu').click();
  435. // }
  436. // $('#sort-dropdown').on('shown.bs.dropdown', function () {
  437. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  438. // });
  439. // $('#sort-dropdown').on('hidden.bs.dropdown', function () {
  440. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 0);
  441. // });
  442. $('#sort-radio input[name="paizhi"]').click(function () {
  443. const orderStr = $(this).val() + '|' + $('#order-radio input[name="paixu"]:checked').val();
  444. setLocalCache('change-project-'+ tenderId +'-list-order', orderStr);
  445. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  446. let link = window.location.origin + window.location.pathname + '?sort='+ $(this).val() + '&order=' + $('#order-radio input[name="paixu"]:checked').val();
  447. if (getLocalCache('account-pageSize')) {
  448. link += '&pageSize=' + getLocalCache('account-pageSize');
  449. }
  450. window.location.href = link;
  451. });
  452. $('#order-radio input[name="paixu"]').click(function () {
  453. const orderStr = $('#sort-radio input[name="paizhi"]:checked').val() + '|' + $(this).val();
  454. setLocalCache('change-project-'+ tenderId +'-list-order', orderStr);
  455. // setLocalCache('change-'+ $('#tenderId').val() +'-list-sort', 1);
  456. let link = window.location.origin + window.location.pathname + '?sort='+ $('#sort-radio input[name="paizhi"]:checked').val() + '&order=' + $(this).val();
  457. if (getLocalCache('account-pageSize')) {
  458. link += '&pageSize=' + getLocalCache('account-pageSize');
  459. }
  460. window.location.href = link;
  461. })
  462. $.subMenu({
  463. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  464. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  465. key: 'menu.1.0.0',
  466. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  467. callback: function (info) {
  468. if (info.mini) {
  469. $('.panel-title').addClass('fluid');
  470. $('#sub-menu').removeClass('panel-sidebar');
  471. } else {
  472. $('.panel-title').removeClass('fluid');
  473. $('#sub-menu').addClass('panel-sidebar');
  474. }
  475. autoFlashHeight();
  476. }
  477. });
  478. });