shenpi.js 45 KB

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