shenpi.js 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. const tenderTree = [];
  10. let parentId = 0;
  11. let selects;
  12. // 查询方法
  13. function findNode (key, value, arr) {
  14. for (const a of arr) {
  15. if (a[key] && a[key] === value) {
  16. return a;
  17. }
  18. }
  19. }
  20. // 初始化TenderTree数据
  21. function initTenderTree () {
  22. const levelCategory = category.filter(function (c) {
  23. return c.level && c.level > 0;
  24. });
  25. function findCategoryNode(cid, value, array) {
  26. for (const a of array) {
  27. if (a.cid === cid && a.vid === value) {
  28. return a;
  29. }
  30. }
  31. }
  32. function getCategoryNode(category, value, parent, i = null) {
  33. const array = parent ? parent.children : tenderTree;
  34. let cate = findCategoryNode(category.id, value, array);
  35. if (!cate) {
  36. const cateValue = findNode('id', value, category.value);
  37. if (!cateValue) return null;
  38. cate = {
  39. cid: category.id,
  40. vid: value,
  41. name: cateValue.value,
  42. children: [],
  43. level: i ? i : category.level,
  44. sort_id: ++parentId,
  45. sort: cateValue.sort,
  46. };
  47. array.push(cate);
  48. }
  49. return cate;
  50. }
  51. function loadTenderCategory (tender) {
  52. let tenderCategory = null;
  53. for (const [index,lc] of levelCategory.entries()) {
  54. const tenderCate = findNode('cid', lc.id, tender.category);
  55. if (tenderCate) {
  56. tenderCategory = getCategoryNode(lc, tenderCate.value, tenderCategory);
  57. } else {
  58. if (index === 0 && tender.category) {
  59. for (const [i,c] of tender.category.entries()) {
  60. const cate = findNode('id', c.cid, category);
  61. if (cate) tenderCategory = getCategoryNode(cate, c.value, tenderCategory, i+1);
  62. }
  63. }
  64. return tenderCategory;
  65. }
  66. }
  67. return tenderCategory;
  68. }
  69. function calculateTender(tender) {
  70. if (tender.lastStage) {
  71. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  72. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  73. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  74. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  75. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  76. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  77. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  78. }
  79. }
  80. tenderTree.splice(0, tenderTree.length);
  81. for (const t of tenders) {
  82. calculateTender(t);
  83. t.valid = true;
  84. delete t.level;
  85. if (t.category && levelCategory.length > 0) {
  86. const parent = loadTenderCategory(t);
  87. if (parent) {
  88. t.level = parent.level + 1;
  89. parent.children.push(t);
  90. } else {
  91. tenderTree.push(t);
  92. }
  93. } else {
  94. tenderTree.push(t);
  95. }
  96. }
  97. sortTenderTree();
  98. }
  99. function recursiveGetTenderNodeHtml (node, arr, pid, this_code, this_status, aidList = []) {
  100. const html = [];
  101. html.push('<tr pid="' + pid + '">');
  102. // 名称
  103. html.push('<td class="in-' + node.level + '">');
  104. if (node.cid) {
  105. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  106. } else {
  107. html.push('<span class="text-muted mr-2">');
  108. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  109. html.push('</span>');
  110. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  111. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  112. }
  113. html.push('</td>');
  114. // 创建人
  115. // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
  116. html.push('<td>');
  117. if (!node.cid) {
  118. if(cur_tenderid === node.id) {
  119. html.push(sp_status_list[this_status].name);
  120. } else {
  121. html.push(sp_status_list[node.shenpiInfo[this_code]].name);
  122. }
  123. }
  124. html.push('</td>');
  125. html.push('<td>');
  126. if (!node.cid) {
  127. let auditList = [];
  128. let tender_status = 1;
  129. if(cur_tenderid === node.id) {
  130. auditList = aidList;
  131. tender_status = this_status;
  132. } else {
  133. auditList = node.shenpiauditList[this_code];
  134. tender_status = node.shenpiInfo[this_code];
  135. }
  136. if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
  137. const nameList = [];
  138. if(auditList) {
  139. for (const uid of auditList) {
  140. const user = _.find(accountList, { id: uid });
  141. nameList.push(user.name);
  142. }
  143. }
  144. // html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  145. // 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  146. html.push(nameList.length > 0 ? nameList.join('-') : '');
  147. }
  148. }
  149. html.push('</td>');
  150. html.push('<td>');
  151. if (!node.cid) {
  152. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  153. }
  154. html.push('</td>');
  155. html.push('</tr>');
  156. if (node.children) {
  157. for (const c of node.children) {
  158. html.push(recursiveGetTenderNodeHtml(c, node.children, node.sort_id, this_code, this_status, aidList));
  159. }
  160. }
  161. return html.join('');
  162. }
  163. // 根据TenderTree数据获取Html代码
  164. function getTenderTreeHtml (this_code, this_status, aidList = []) {
  165. if (tenderTree.length > 0) {
  166. const html = [];
  167. html.push('<table class="table table-hover table-bordered">');
  168. html.push('<thead>', '<tr>');
  169. html.push('<th>名称</th>');
  170. html.push('<th width="80">流程模式</th>');
  171. html.push('<th>详细流程</th>');
  172. html.push('<th width="40">选择</th>');
  173. html.push('</tr>', '</thead>');
  174. parentId = 0;
  175. for (const t of tenderTree) {
  176. html.push(recursiveGetTenderNodeHtml(t, tenderTree, '', this_code, this_status, aidList));
  177. }
  178. html.push('</table>');
  179. return html.join('');
  180. } else {
  181. return EmptyTenderHtml.join('');
  182. }
  183. }
  184. function getShenpiHtml (this_code) {
  185. const html = [];
  186. html.push('<table class="table table-hover table-bordered">');
  187. html.push('<thead>', '<tr>');
  188. html.push('<th>名称</th>');
  189. html.push('<th width="100">审批流程</th>');
  190. html.push('<th width="40">选择</th>');
  191. html.push('</tr>', '</thead>');
  192. for (const sp of sp_lc) {
  193. html.push('<tr>');
  194. html.push('<td>', sp.name, '</td>');
  195. html.push('<td>');
  196. const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
  197. html.push(sp_status_list[this_status].name);
  198. if(this_status !== sp_status.sqspr) {
  199. const nameList = [];
  200. const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
  201. const aidList = [];
  202. for (let i = 0; i < aid_num; i++) {
  203. const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  204. aidList.push(aid);
  205. }
  206. if(aidList.length > 0) {
  207. for (const uid of aidList) {
  208. const user = _.find(accountList, { id: uid });
  209. nameList.push(user.name);
  210. }
  211. }
  212. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  213. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  214. }
  215. html.push('</td>');
  216. html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'">' : '', '</td>');
  217. html.push('</tr>');
  218. }
  219. html.push('</table>');
  220. return html.join('');
  221. }
  222. $(document).ready(function () {
  223. let timer = null;
  224. let oldSearchVal = null;
  225. const needYB = ['advance', 'ledger', 'revise', 'change', 'audit-ass'];
  226. $('body').on('input propertychange', '.gr-search', function(e) {
  227. oldSearchVal = e.target.value;
  228. timer && clearTimeout(timer);
  229. timer = setTimeout(() => {
  230. const newVal = $(this).val();
  231. const code = $(this).attr('data-code');
  232. let html = '';
  233. if (newVal && newVal === oldSearchVal) {
  234. accountList.filter(item => item && (item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1)) && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  235. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  236. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  237. class="ml-auto">${item.mobile || ''}</span></p>
  238. <span class="text-muted">${item.role || ''}</span>
  239. </dd>`
  240. });
  241. $('#' + code + '_dropdownMenu .book-list').empty();
  242. $('#' + code + '_dropdownMenu .book-list').append(html);
  243. } else {
  244. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  245. accountGroup.forEach((group, idx) => {
  246. if (!group) return;
  247. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  248. </a> ${group.groupName}</dt>
  249. <div class="dd-content" data-toggleid="${idx}">`;
  250. group.groupList.forEach(item => {
  251. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  252. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  253. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  254. class="ml-auto">${item.mobile || ''}</span></p>
  255. <span class="text-muted">${item.role || ''}</span>
  256. </dd>`;
  257. }
  258. });
  259. html += '</div>';
  260. });
  261. $('#' + code + '_dropdownMenu .book-list').empty();
  262. $('#' + code + '_dropdownMenu .book-list').append(html);
  263. }
  264. }
  265. }, 400);
  266. });
  267. // 添加审批流程按钮逻辑
  268. $('body').on('click', '.book-list dt', function () {
  269. const idx = $(this).find('.acc-btn').attr('data-groupid');
  270. const type = $(this).find('.acc-btn').attr('data-type');
  271. if (type === 'hide') {
  272. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  273. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  274. $(this).find('.acc-btn').attr('data-type', 'show');
  275. })
  276. } else {
  277. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  278. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  279. $(this).find('.acc-btn').attr('data-type', 'hide');
  280. })
  281. }
  282. return false;
  283. });
  284. // 更改审批流程状态
  285. $('.form-check input').on('change', function () {
  286. // 获取所有审批的checked值并更新
  287. const this_status = parseInt($(this).val());
  288. const this_code = $(this).data('code');
  289. const spt = sp_status_list[this_status];
  290. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  291. // 拼接post json
  292. const prop = {
  293. code: this_code,
  294. status: this_status
  295. };
  296. const _self = $(this);
  297. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  298. if (this_status === sp_status.sqspr) {
  299. _self.parents('.form-group').siblings('.lc-show').html('');
  300. } else if (this_status === sp_status.gdspl) {
  301. let addhtml = '<ul class="list-unstyled">\n';
  302. if (data.length !== 0) {
  303. for(const [i, audit] of data.entries()) {
  304. addhtml += makeAudit(audit, transFormToChinese(i+1));
  305. }
  306. addhtml += '<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>';
  307. } else {
  308. addhtml += makeSelectAudit(this_code, '一');
  309. }
  310. addhtml += '</ul>\n';
  311. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  312. } else if (this_status === sp_status.gdzs) {
  313. let addhtml = '<ul class="list-unstyled">\n' +
  314. ' <li class="d-flex justify-content-start mb-3">\n' +
  315. ' <span class="col-auto">授权审批人</span>\n' +
  316. ' <span class="col-7">\n' +
  317. ' <span class="d-inline-block"></span>\n' +
  318. ' </span>\n' +
  319. ' </li>\n';
  320. addhtml += data ? makeAudit(data) : makeSelectAudit(this_code);
  321. addhtml += '</ul>\n';
  322. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  323. }
  324. if(this_code === 'stage') {
  325. if(this_status === sp_status.gdspl) {
  326. $('#stage_cooperation').show();
  327. } else {
  328. $('#stage_cooperation').hide();
  329. }
  330. }
  331. });
  332. });
  333. // 选中审批人
  334. $('body').on('click', 'dl dd', function () {
  335. const id = parseInt($(this).data('id'));
  336. if (!id) return;
  337. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  338. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  339. const user = _.find(accountList, function (item) {
  340. return item.id === id;
  341. });
  342. if (this_code === 'audit-ass') {
  343. auditAss.setAuditAssist(user);
  344. } else {
  345. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  346. if (this_status === sp_status.gdspl) {
  347. // 判断是否已存在审批人
  348. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  349. for (let i = 0; i < aid_num; i++) {
  350. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  351. if (aid === id) {
  352. toastr.warning('该审核人已存在,请勿重复添加');
  353. return;
  354. }
  355. }
  356. }
  357. const prop = {
  358. status: this_status,
  359. code: sp_type[this_code],
  360. audit_id: id,
  361. type: 'add',
  362. };
  363. const _self = $(this);
  364. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  365. if (this_status === sp_status.gdspl) {
  366. _self.parents('ul').append('<li class="pl-3"><a href="javascript:void(0);" class="add-audit"><i class="fa fa-plus"></i> 添加流程</a></li>');
  367. }
  368. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  369. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  370. ' <a href="javascript:void(0);" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>\n' +
  371. ' <div class="dropdown-menu">\n' +
  372. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  373. ' <div class="dropdown-divider"></div>\n' +
  374. ' <div class="px-2 py-1 text-center">\n' +
  375. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  376. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  377. ' </div>\n' +
  378. ' </div>\n' +
  379. ' </span> ' +
  380. ' </span></span></span>\n');
  381. // <a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ user.id +'"><i class="fa fa-remove"></i></a></span> </span>');
  382. });
  383. }
  384. });
  385. // 移除审批人
  386. $('body').on('click', '.remove-audit', function () {
  387. const id = parseInt($(this).data('id'));
  388. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  389. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  390. const prop = {
  391. status: this_status,
  392. code: sp_type[this_code],
  393. audit_id: id,
  394. type: 'del',
  395. };
  396. const _self = $(this);
  397. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  398. if (this_status === sp_status.gdspl) {
  399. const _selflc = _self.parents('.lc-show');
  400. _self.parents('li').remove();
  401. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  402. if (aid_num === 0) {
  403. let addhtml = '<ul class="list-unstyled">\n';
  404. addhtml += makeSelectAudit(this_code, '一');
  405. addhtml += '</ul>\n';
  406. _selflc.html(addhtml);
  407. } else {
  408. for (let i = 0; i < aid_num; i++) {
  409. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  410. }
  411. }
  412. } else if (this_status === sp_status.gdzs) {
  413. let addhtml = '<ul class="list-unstyled">\n' +
  414. ' <li class="d-flex justify-content-start mb-3">\n' +
  415. ' <span class="col-auto">授权审批人</span>\n' +
  416. ' <span class="col-7">\n' +
  417. ' <span class="d-inline-block"></span>\n' +
  418. ' </span>\n' +
  419. ' </li>\n';
  420. addhtml += makeSelectAudit(this_code);
  421. addhtml += '</ul>\n';
  422. _self.parents('.lc-show').html(addhtml);
  423. }
  424. })
  425. });
  426. // 固定审批流-添加流程
  427. $('body').on('click', '.add-audit', function () {
  428. const num = $(this).parents('ul').children('li').length;
  429. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  430. const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  431. $(this).parents('ul').append(addhtml);
  432. $(this).parents('li').remove();
  433. });
  434. // 审批流程-审批人html 生成
  435. function makeAudit(audit, i = '终') {
  436. return '<li class="d-flex justify-content-start mb-3">\n' +
  437. ' <span class="col-auto">'+ i +'审</span>\n' +
  438. ' <span class="col-7 spr-span">\n' +
  439. ' <span class="d-inline-block"></span>\n' +
  440. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  441. ' <a href="javascript:void(0);" class="btn-sm text-danger px-1" title="移除" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-remove"></i></a>\n' +
  442. ' <div class="dropdown-menu">\n' +
  443. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  444. ' <div class="dropdown-divider"></div>\n' +
  445. ' <div class="px-2 py-1 text-center">\n' +
  446. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  447. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  448. ' </div>\n' +
  449. ' </div>\n' +
  450. ' </span> ' +
  451. // '<a href="javascript:void(0);" class="remove-audit btn-sm text-danger px-1" title="移除" data-id="'+ audit.audit_id +'"><i class="fa fa-remove"></i></a></span> </span>\n' +
  452. ' </span></span></span>\n' +
  453. ' </li>';
  454. }
  455. // 审批流程-选择审批人html 生成
  456. function makeSelectAudit(code, i = '终') {
  457. let divhtml = '';
  458. accountGroup.forEach((group, idx) => {
  459. let didivhtml = '';
  460. if(group) {
  461. group.groupList.forEach(item => {
  462. didivhtml += (item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1)) ? '<dd class="border-bottom p-2 mb-0 " data-id="' + item.id + '" >\n' +
  463. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  464. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  465. ' <span class="text-muted">' + item.role + '</span>\n' +
  466. ' </dd>\n' : '';
  467. });
  468. divhtml += '<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="' + idx + '" data-type="hide"><i class="fa fa-plus-square"></i></a> ' + group.groupName + '</dt>\n' +
  469. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  470. ' </div>\n';
  471. }
  472. });
  473. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  474. ' <span class="col-auto">' + i + '审</span>\n' +
  475. ' <span class="col-7 spr-span">\n' +
  476. ' <span class="d-inline-block">\n' +
  477. ' <div class="dropdown text-right">\n' +
  478. ' <button class="btn btn-outline-primary btn-sm dropdown-toggle" type="button" id="' + code + '_dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">\n' +
  479. ' 选择审批人\n' +
  480. ' </button>\n' +
  481. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  482. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  483. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  484. ' <dl class="list-unstyled book-list">\n' + divhtml +
  485. ' </dl>\n' +
  486. ' </div>\n' +
  487. ' </div>\n' +
  488. ' </span>\n' +
  489. ' </span>\n' +
  490. ' </li>';
  491. return html;
  492. }
  493. initTenderTree();
  494. $('.set-otherTender').on('click', function () {
  495. const this_code = $(this).data('code');
  496. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  497. const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
  498. const aidList = [];
  499. for (let i = 0; i < aid_num; i++) {
  500. const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  501. aidList.push(aid);
  502. }
  503. const html = getTenderTreeHtml(this_code, this_status, aidList);
  504. $('#shenpi-name').text($(this).data('name'));
  505. $('#shenpi_code').val(this_code);
  506. $('#shenpi_status').val(this_status);
  507. $('#shenpi_auditors').val(aidList.join(','));
  508. $('#tender-list').html(html);
  509. $('#search-audit').val('');
  510. $('#search-result').text('0/0');
  511. $('#up-search').attr('disabled', true);
  512. $('#down-search').attr('disabled', true);
  513. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  514. });
  515. $('#save-other-tender').click(function () {
  516. $(this).attr('disabled', true);
  517. const num = $('#tender-list input:checked').length;
  518. if (num < 2) {
  519. toastr.warning('请选择需要设置审批同步的标段');
  520. return;
  521. }
  522. const data = {
  523. type: 'copy2ot',
  524. status: parseInt($('#shenpi_status').val()),
  525. code: $('#shenpi_code').val(),
  526. };
  527. if(data.status !== shenpi_status.gdspl) {
  528. data.aidList = $('#shenpi_auditors').val();
  529. }
  530. // 获取已选中的标段
  531. const tenderList = [];
  532. for (let i = 0; i < num; i++) {
  533. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  534. if (tid !== cur_tenderid) {
  535. tenderList.push(tid);
  536. }
  537. }
  538. data.tidList = tenderList.join(',');
  539. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  540. toastr.success('设置成功');
  541. setTimeout(function () {
  542. window.location.reload();
  543. }, 1000)
  544. })
  545. });
  546. $('.set-otherShenpi').on('click', function () {
  547. const this_code = $(this).data('code');
  548. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  549. const aid_num = $(this).siblings('.lc-show').children('ul').find('.remove-audit').length;
  550. const aidList = [];
  551. for (let i = 0; i < aid_num; i++) {
  552. const aid = parseInt($(this).siblings('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  553. aidList.push(aid);
  554. }
  555. const html = getShenpiHtml(this_code);
  556. $('#shenpi-name2').text($(this).data('name'));
  557. $('#shenpi_code2').val(this_code);
  558. $('#shenpi_status2').val(this_status);
  559. $('#shenpi_auditors2').val(aidList.join(','));
  560. $('#shenpi-list').html(html);
  561. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  562. });
  563. $('#save-other-shenpi').click(function () {
  564. $(this).attr('disabled', true);
  565. const num = $('#shenpi-list input:checked').length;
  566. if (num < 1) {
  567. toastr.warning('请选择需要设置审批同步的流程');
  568. return;
  569. }
  570. const data = {
  571. type: 'copy2os',
  572. status: parseInt($('#shenpi_status2').val()),
  573. code: $('#shenpi_code2').val(),
  574. };
  575. if(data.status !== shenpi_status.gdspl) {
  576. data.aidList = $('#shenpi_auditors2').val();
  577. }
  578. // 获取已选中的标段
  579. const shenpiList = [];
  580. for (let i = 0; i < num; i++) {
  581. const code = $('#shenpi-list input:checked').eq(i).data('code');
  582. shenpiList.push(code);
  583. }
  584. data.shenpiList = shenpiList.join(',');
  585. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  586. toastr.success('设置成功');
  587. setTimeout(function () {
  588. window.location.reload();
  589. }, 1000)
  590. })
  591. });
  592. class AuditAss {
  593. constructor() {
  594. this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  595. this.sheet = this.spread.getActiveSheet();
  596. this.tree = createNewPathTree('base', {
  597. id: 'ledger_id',
  598. pid: 'ledger_pid',
  599. order: 'order',
  600. level: 'level',
  601. rootId: -1,
  602. });
  603. this.spreadSetting = {
  604. cols: [
  605. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
  606. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  607. {title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
  608. ],
  609. emptyRows: 0,
  610. headRows: 1,
  611. headRowHeight: [25, 25],
  612. defaultRowHeight: 21,
  613. headerFont: '12px 微软雅黑',
  614. font: '12px 微软雅黑',
  615. readOnly: true,
  616. localCache: {
  617. key: 'ledger-cooperation',
  618. colWidth: true,
  619. }
  620. };
  621. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  622. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  623. const self = this;
  624. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  625. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  626. this.spread.bind(spreadNS.Events.SelectionChanged, function() {
  627. self.refreshOperate();
  628. });
  629. $('#stage_audits').change(function () {
  630. self.uid = $(this).val();
  631. });
  632. // 多人协同
  633. $('#cooperation').on('shown.bs.modal', function () {
  634. // 执行一些动作...
  635. // 更新新的多人协同表格信息
  636. const newUidList = [];
  637. $('.stage_div ul li').each(function (k, v) {
  638. const uid = $(v).find('button').eq(0).data('id');
  639. if(uid) newUidList.push(uid);
  640. });
  641. const oldUidList = [];
  642. $('#stage_audits option').each(function (k, v) {
  643. const uid = parseInt($(v).val());
  644. if(k !== 0) oldUidList.push(uid);
  645. });
  646. if (!_.isEqual(oldUidList, newUidList)) {
  647. const yb = _.find(accountList, { 'id': cur_uid });
  648. let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
  649. if(newUidList.length > 0) {
  650. for (const [i,id] of newUidList.entries()) {
  651. const audit = _.find(accountList, { 'id': id });
  652. newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(i+1) + '审)</option>';
  653. }
  654. }
  655. $('#stage_audits').html(newhtml);
  656. self.uid = cur_uid;
  657. }
  658. self.initLedgerTree(cur_uid);
  659. });
  660. $('#del-audit-ass').click(function () {
  661. self.setAuditAssist();
  662. });
  663. $('body').on('click', 'button[asid]', function () {
  664. self.removeAuditAss(parseInt(this.getAttribute('asid')));
  665. });
  666. }
  667. set uid(id) {
  668. this._uid = parseInt(id);
  669. this._refreshAss();
  670. }
  671. get uid() {
  672. return this._uid;
  673. }
  674. _refreshAssTable(){
  675. $('#stage_audit').text($("#stage_audits option:selected").text());
  676. const html = [];
  677. for (const sa of this.showAssList) {
  678. const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  679. html.push(`<tr><td>${sa.name}</td><td>${sa.company}</td><td>${lid.length}<button class="ml-2 btn btn-sm btn-outline-danger" asid="${sa.id}">移除</button></td></tr>`);
  680. }
  681. $('#coo_table').html(html.join(''));
  682. }
  683. _refreshAssTree() {
  684. const ledgerAss = {};
  685. for (const sa of this.showAssList) {
  686. const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  687. ledger.forEach(l => { ledgerAss[l] = sa; });
  688. }
  689. for (const n of this.tree.nodes) {
  690. const la = ledgerAss[n.ledger_id];
  691. n.ass_audit_id = la ? la.ass_user_id : null;
  692. n.ass_name = la ? la.name : '';
  693. }
  694. SpreadJsObj.reloadColData(this.sheet, 2);
  695. }
  696. _refreshAss() {
  697. this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
  698. this._refreshAssTable();
  699. this._refreshAssTree();
  700. }
  701. initLedgerTree(uid) {
  702. if (this.loaded) return;
  703. this.spread.refresh();
  704. const self = this;
  705. postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
  706. self.loaded = true;
  707. self.assList = data.auditAssList;
  708. self.tree.loadDatas(data.ledgerList);
  709. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  710. self.uid = uid;
  711. self.refreshOperate();
  712. }, null, true);
  713. }
  714. loadPostData(data) {
  715. if (data.add) {
  716. this.assList.push(data.add);
  717. }
  718. if (data.del) {
  719. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  720. }
  721. if (data.update) {
  722. for (const d of data.update) {
  723. const od = this.assList.find(x => { return x.id === d.id });
  724. if (!od) continue;
  725. od.ass_ledger_id = d.ass_ledger_id;
  726. }
  727. }
  728. this._refreshAss();
  729. }
  730. setAuditAssist(assist){
  731. const node = SpreadJsObj.getSelectObject(this.sheet);
  732. if (assist && node.ass_audit_id === assist.id) return;
  733. if (assist && assist.id === this.uid) {
  734. toastr.warning('请勿添加本人');
  735. return;
  736. }
  737. const self = this;
  738. const data = { type: 'audit-ass'};
  739. if (assist) {
  740. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  741. if (!newAss) {
  742. data.add = { user_id: this.uid, ass_user_id: assist.id, name: assist.name, company: assist.company, role: assist.role, ass_ledger_id: node.ledger_id + '' };
  743. } else {
  744. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  745. }
  746. }
  747. if (node.ass_audit_id) {
  748. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  749. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  750. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  751. if (rela_lid.length === 0) {
  752. data.del = { id: orgAss.id };
  753. } else {
  754. if (!data.update) data.update = [];
  755. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  756. }
  757. }
  758. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  759. self.loadPostData(result);
  760. self.refreshOperate();
  761. });
  762. }
  763. removeAuditAss(assistId) {
  764. const self = this;
  765. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  766. self.loadPostData(result);
  767. self.refreshOperate();
  768. });
  769. }
  770. refreshOperate() {
  771. const node = SpreadJsObj.getSelectObject(this.sheet);
  772. if (node.ass_audit_id) {
  773. $('#del-audit-ass').show();
  774. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  775. } else {
  776. $('#del-audit-ass').hide();
  777. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  778. }
  779. }
  780. }
  781. const auditAss = new AuditAss();
  782. $.subMenu({
  783. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  784. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  785. key: 'menu.1.0.0',
  786. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  787. callback: function (info) {
  788. if (info.mini) {
  789. $('.panel-title').addClass('fluid');
  790. $('#sub-menu').removeClass('panel-sidebar');
  791. } else {
  792. $('.panel-title').removeClass('fluid');
  793. $('#sub-menu').addClass('panel-sidebar');
  794. }
  795. autoFlashHeight();
  796. }
  797. });
  798. let timer2 = null;
  799. let oldSearchVal2 = null;
  800. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  801. oldSearchVal2 = e.target.value;
  802. timer2 && clearTimeout(timer2);
  803. timer2 = setTimeout(() => {
  804. const newVal = $(this).val();
  805. const resultLength = $('#tender-list').find('.result').length;
  806. if (resultLength > 0) {
  807. let content = $('#tender-list').html();
  808. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  809. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  810. content = content.replace(regExp2, replaceStr);
  811. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  812. content = content.replace(regExp3, replaceStr);
  813. $('#tender-list').html(content);
  814. }
  815. $('#search-result').text('0/0');
  816. $('#up-search').attr('disabled', true);
  817. $('#down-search').attr('disabled', true);
  818. if (newVal && newVal === oldSearchVal2) {
  819. const regExp = new RegExp(newVal, 'g');
  820. for (let i = 0; i < $('#tender-list tr').length; i++) {
  821. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  822. $('#tender-list tr').eq(i).children('td').eq(2).html($('#tender-list tr').eq(i).children('td').eq(2).html().replace(regExp, '<span class="result" style="background: yellow;">' + newVal + '</span>'))
  823. }
  824. }
  825. const resultLength2 = $('#tender-list').find('.result').length;
  826. if (resultLength2 > 0) {
  827. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  828. $('#search-result').text('1/' + resultLength2);
  829. $('#up-search').attr('disabled', false);
  830. $('#down-search').attr('disabled', false);
  831. }
  832. }
  833. if($('#tender-list').find('.result').length > 0) {
  834. const X = $('#tender-list').find('.result').eq(0).offset().top;
  835. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  836. }
  837. }, 400);
  838. });
  839. $('#up-search').on('click', function () {
  840. const cur = parseInt($('#search-result').text().split('/')[0]);
  841. const total = parseInt($('#search-result').text().split('/')[1]);
  842. const now = cur - 1 !== 0 ? cur - 1: total;
  843. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  844. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  845. // $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('<span class="result" style="background:orange;">', '<span class="result" style="background:yellow;">'))
  846. // $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('<span class="result" style="background:yellow;">', '<span class="result" style="background:orange;">'))
  847. $('#search-result').text(now + '/' + total);
  848. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  849. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  850. });
  851. $('#down-search').on('click', function () {
  852. const cur = parseInt($('#search-result').text().split('/')[0]);
  853. const total = parseInt($('#search-result').text().split('/')[1]);
  854. const now = cur + 1 > total ? 1: cur + 1;
  855. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  856. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  857. // $('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[cur-1]).children('td').eq(2).html().replace('<span class="result" style="background:orange;">', '<span class="result" style="background:yellow;">'))
  858. // $('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html($('#tender-list tr').eq(searchUser[now-1]).children('td').eq(2).html().replace('<span class="result" style="background:yellow;">', '<span class="result" style="background:orange;">'))
  859. $('#search-result').text(now + '/' + total);
  860. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  861. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  862. });
  863. });