shenpi.js 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Ellisran
  6. * @date 2020/10/09
  7. * @version
  8. */
  9. // 冲突解决,要把这里丢tenderTree改成tenderTree2
  10. const tenderTree2 = [];
  11. let parentId2 = 0;
  12. let selects;
  13. let auditUtils;
  14. const needYB = ['advance', 'ledger', 'revise', 'change', 'audit-ass'];
  15. // 查询方法
  16. function findNode2 (key, value, arr) {
  17. for (const a of arr) {
  18. if (a[key] && a[key] === value) {
  19. return a;
  20. }
  21. }
  22. }
  23. // 分类数据排序
  24. function sortCategory2() {
  25. category.sort(function (a, b) {
  26. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  27. });
  28. }
  29. // 初始化TenderTree数据
  30. function initTenderTree2 () {
  31. const levelCategory = category.filter(function (c) {
  32. return c.level && c.level > 0;
  33. });
  34. function findCategoryNode2(cid, value, array) {
  35. for (const a of array) {
  36. if (a.cid === cid && a.vid === value) {
  37. return a;
  38. }
  39. }
  40. }
  41. function getCategoryNode2(category, value, parent, i = null) {
  42. const array = parent ? parent.children : tenderTree2;
  43. let cate = findCategoryNode2(category.id, value, array);
  44. if (!cate) {
  45. const cateValue = findNode2('id', value, category.value);
  46. if (!cateValue) return null;
  47. cate = {
  48. cid: category.id,
  49. vid: value,
  50. name: cateValue.value,
  51. children: [],
  52. level: i ? i : category.level,
  53. sort_id: ++parentId2,
  54. sort: cateValue.sort,
  55. };
  56. array.push(cate);
  57. }
  58. return cate;
  59. }
  60. function loadTenderCategory2 (tender) {
  61. let tenderCategory = null;
  62. for (const [index,lc] of levelCategory.entries()) {
  63. const tenderCate = findNode2('cid', lc.id, tender.category);
  64. if (tenderCate) {
  65. tenderCategory = getCategoryNode2(lc, tenderCate.value, tenderCategory);
  66. } else {
  67. if (index === 0 && tender.category) {
  68. for (const [i,c] of tender.category.entries()) {
  69. const cate = findNode2('id', c.cid, category);
  70. if (cate) tenderCategory = getCategoryNode2(cate, c.value, tenderCategory, i+1);
  71. }
  72. }
  73. return tenderCategory;
  74. }
  75. }
  76. return tenderCategory;
  77. }
  78. function calculateTender2(tender) {
  79. if (tender.lastStage) {
  80. tender.gather_tp = ZhCalc.add(tender.lastStage.contract_tp, tender.lastStage.qc_tp);
  81. tender.end_contract_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.contract_tp);
  82. tender.end_qc_tp = ZhCalc.add(tender.lastStage.pre_qc_tp, tender.lastStage.qc_tp);
  83. tender.end_gather_tp = ZhCalc.add(tender.end_contract_tp, tender.end_qc_tp);
  84. tender.pre_gather_tp = ZhCalc.add(tender.lastStage.pre_contract_tp, tender.lastStage.pre_qc_tp);
  85. tender.yf_tp = ZhCalc.add(tender.lastStage.yf_tp);
  86. tender.end_yf_tp = ZhCalc.add(tender.lastStage.pre_yf_tp, tender.yf_tp);
  87. }
  88. }
  89. tenderTree2.splice(0, tenderTree2.length);
  90. for (const t of tenders) {
  91. calculateTender2(t);
  92. t.valid = true;
  93. delete t.level;
  94. if (t.category && levelCategory.length > 0) {
  95. const parent = loadTenderCategory2(t);
  96. if (parent) {
  97. t.level = parent.level + 1;
  98. parent.children.push(t);
  99. } else {
  100. tenderTree2.push(t);
  101. }
  102. } else {
  103. tenderTree2.push(t);
  104. }
  105. }
  106. sortTenderTree(tenderTree2);
  107. console.log(tenderTree2);
  108. }
  109. function recursiveGetTenderNodeHtml2 (node, arr, pid, this_code, this_status, aidList = []) {
  110. const html = [];
  111. html.push('<tr pid="' + pid + '">');
  112. // 名称
  113. html.push('<td class="in-' + node.level + '">');
  114. if (node.cid) {
  115. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  116. } else {
  117. html.push('<span class="text-muted mr-2">');
  118. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  119. html.push('</span>');
  120. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  121. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  122. }
  123. html.push('</td>');
  124. // 创建人
  125. // html.push('<td>', sp_status_list[node.shenpiInfo[shenpi_type]].name, '</td>');
  126. html.push('<td>');
  127. if (!node.cid) {
  128. if(cur_tenderid === node.id) {
  129. html.push(sp_status_list[this_status].name);
  130. } else {
  131. html.push(sp_status_list[node.shenpiInfo[this_code]].name);
  132. }
  133. }
  134. html.push('</td>');
  135. html.push('<td>');
  136. if (!node.cid) {
  137. let auditList = [];
  138. let tender_status = 1;
  139. if(cur_tenderid === node.id) {
  140. auditList = aidList;
  141. tender_status = this_status;
  142. } else {
  143. auditList = node.shenpiauditList[this_code];
  144. tender_status = node.shenpiInfo[this_code];
  145. }
  146. if(tender_status === sp_status.gdspl || tender_status === sp_status.gdzs) {
  147. const nameList = [];
  148. if(auditList) {
  149. for (const uid of auditList) {
  150. const user = _.find(accountList, { id: uid });
  151. if (user) nameList.push(user.name);
  152. }
  153. }
  154. // html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  155. // 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  156. html.push(nameList.length > 0 ? nameList.join('-') : '');
  157. }
  158. }
  159. html.push('</td>');
  160. html.push('<td>');
  161. if (!node.cid) {
  162. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  163. }
  164. html.push('</td>');
  165. html.push('</tr>');
  166. if (node.children) {
  167. for (const c of node.children) {
  168. html.push(recursiveGetTenderNodeHtml2(c, node.children, node.sort_id, this_code, this_status, aidList));
  169. }
  170. }
  171. return html.join('');
  172. }
  173. // 根据TenderTree数据获取Html代码
  174. function getTenderTreeHtml2 (this_code, this_status, aidList = []) {
  175. if (tenderTree2.length > 0) {
  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="80">流程模式</th>');
  181. html.push('<th>详细流程</th>');
  182. html.push('<th width="40">选择</th>');
  183. html.push('</tr>', '</thead>');
  184. parentId2 = 0;
  185. for (const t of tenderTree2) {
  186. html.push(recursiveGetTenderNodeHtml2(t, tenderTree2, '', this_code, this_status, aidList));
  187. }
  188. html.push('</table>');
  189. return html.join('');
  190. } else {
  191. return EmptyTenderHtml.join('');
  192. }
  193. }
  194. function getShenpiHtml (this_code) {
  195. const html = [];
  196. html.push('<table class="table table-hover table-bordered">');
  197. html.push('<thead>', '<tr>');
  198. html.push('<th>名称</th>');
  199. html.push('<th width="100">审批流程</th>');
  200. html.push('<th width="40">选择</th>');
  201. html.push('</tr>', '</thead>');
  202. for (const sp of sp_lc) {
  203. html.push('<tr>');
  204. html.push('<td>', sp.name, '</td>');
  205. html.push('<td>');
  206. const this_status = parseInt($('.' + sp.code + '_div').children('.lc-show').siblings('.form-group').find('input:checked').val());
  207. html.push(sp_status_list[this_status].name);
  208. if(this_status !== sp_status.sqspr) {
  209. const nameList = [];
  210. const aid_num = $('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').length;
  211. const aidList = [];
  212. for (let i = 0; i < aid_num; i++) {
  213. const aid = parseInt($('.' + sp.code + '_div').children('.lc-show').children('ul').find('.remove-audit').eq(i).data('id'));
  214. aidList.push(aid);
  215. }
  216. if(aidList.length > 0) {
  217. for (const uid of aidList) {
  218. const user = _.find(accountList, { id: uid });
  219. nameList.push(user.name);
  220. }
  221. }
  222. html.push('<i class="fa fa-question-circle text-primary" data-container="body" data-toggle="tooltip" data-placement="bottom" ' +
  223. 'data-original-title="'+ (nameList.length > 0 ? nameList.join('-') : '') +'"></i>');
  224. }
  225. html.push('</td>');
  226. html.push('<td>', this_code !== sp.code ? '<input type="checkbox" data-code="'+ sp.code +'"' + (sp.groupList && sp.groupList.length > 0 ? 'disabled' : '') + '>' : '', '</td>');
  227. html.push('</tr>');
  228. }
  229. html.push('</table>');
  230. return html.join('');
  231. }
  232. $(document).ready(function () {
  233. auditUtils = {
  234. getAuditHtml: function(audit) {
  235. return '<span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  236. ' <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' +
  237. ' <div class="dropdown-menu">\n' +
  238. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  239. ' <div class="dropdown-divider"></div>\n' +
  240. ' <div class="px-2 py-1 text-center">\n' +
  241. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  242. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  243. ' </div>\n' +
  244. ' </div>\n' +
  245. ' </span> ' +
  246. ' </span></span>\n'
  247. },
  248. getAuditTypeHtml: function(code, type) {
  249. const html = [];
  250. html.push(`<span class="d-inline-block"><select class="form-control form-control-sm audit-type-key" data-type="${type}">`);
  251. for (const t of auditType.types) {
  252. if (t.valid && t.valid.indexOf(code) < 0) continue;
  253. html.push(`<option value="${t.value}" ${t.value === type ? 'selected' : ''}>${t.name}</option>`);
  254. }
  255. html.push('</select></span> ');
  256. return html.join('');
  257. },
  258. getSelectAuditHtml: function (code) {
  259. let divhtml = '';
  260. accountGroup.forEach((group, idx) => {
  261. let didivhtml = '';
  262. if(group) {
  263. group.groupList.forEach(item => {
  264. 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' +
  265. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  266. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  267. ' <span class="text-muted">' + item.role + '</span>\n' +
  268. ' </dd>\n' : '';
  269. });
  270. 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' +
  271. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  272. ' </div>\n';
  273. }
  274. });
  275. const html =
  276. ' <span class="d-inline-block">\n' +
  277. ' <div class="dropdown text-right">\n' +
  278. ' <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' +
  279. ' 选择审批人\n' +
  280. ' </button>\n' +
  281. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  282. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  283. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  284. ' <dl class="list-unstyled book-list">\n' + divhtml +
  285. ' </dl>\n' +
  286. ' </div>\n' +
  287. ' </div>\n' +
  288. ' </span>\n';
  289. return html;
  290. },
  291. // 以下i从1开始
  292. getAuditGroupInnerHtml: function(code, auditGroup, i) {
  293. const html = [];
  294. const type = auditGroup.length > 0 ? auditGroup[0].audit_type : auditType.key.common;
  295. html.push(`<span class="col-auto">${transFormToChinese(i)}审</span><span class="col-7 spr-span">`);
  296. html.push(this.getAuditTypeHtml(code, type));
  297. for (const audit of auditGroup) {
  298. html.push(this.getAuditHtml(audit));
  299. }
  300. if (type !== auditType.key.common || auditGroup.length === 0) {
  301. html.push(this.getSelectAuditHtml(code));
  302. }
  303. if (type === auditType.key.union && auditGroup.length > 0) {
  304. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="union-set">协同设置</button>`);
  305. }
  306. html.push('</span>');
  307. return html.join('');
  308. },
  309. getAuditGroupHtml: function (code, auditGroup, i) {
  310. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  311. },
  312. getFinalAuditHtml: function (audit) {
  313. const html = [];
  314. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  315. html.push(this.getAuditHtml(audit));
  316. html.push('</span></span></li>');
  317. return html.join('');
  318. },
  319. getGroupHtml: function (flow, this_code) {
  320. let html = '';
  321. if (flow && flow.groupList && flow.groupList.length > 0) {
  322. let groupSelectHtml = '';
  323. for (const group of flow.groupList) {
  324. groupSelectHtml += `<option value="${group.id}" ${group.is_select === 1 ? 'selected' : ''}>${group.name}</option>`;
  325. }
  326. const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
  327. html += '<div class="d-flex justify-content-start align-items-center mb-3">\n' +
  328. ' <span class="col-auto">当前审批组:</span>\n' +
  329. ' <span style="width: 200px;">\n' +
  330. ' <select class="form-control form-control-sm group-list">\n' +
  331. groupSelectHtml +
  332. ' </select>\n' +
  333. ' </span>\n' +
  334. ` <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave edit-spzsave" data-group="${selectGroup.id}" data-code="${this_code}"><i class="fa fa-edit"></i> 编辑审批组</a></span>\n` +
  335. ` <span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-plus"></i> 添加审批组</a></span>\n` +
  336. ' </div>';
  337. }
  338. return html;
  339. },
  340. getgdsplHtml(flow, this_code) {
  341. let addhtml = '';
  342. if (flow.auditGroupList.length !== 0) {
  343. for(const [i, auditGroup] of flow.auditGroupList.entries()) {
  344. addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
  345. }
  346. const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  347. `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
  348. addhtml += '<li>\n' +
  349. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  350. ' </li>';
  351. } else {
  352. addhtml += this.getAuditGroupHtml(this_code, [], 1);
  353. }
  354. return addhtml;
  355. },
  356. // 以下i从0开始
  357. addAudit: function (code, user, i) {
  358. const flow = sp_lc.find(x => { return x.code === code });
  359. if (!flow.auditGroupList) flow.auditGroupList = [];
  360. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  361. flow.auditGroupList[i].push(user);
  362. return flow.auditGroupList[i];
  363. },
  364. removeAudit: function (code, audit_id, i) {
  365. const flow = sp_lc.find(x => { return x.code === code });
  366. if (flow.auditGroupList[i].length === 1) {
  367. flow.auditGroupList.splice(i, 1);
  368. return null;
  369. }
  370. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  371. return flow.auditGroupList[i];
  372. },
  373. setAuditType: function (code, audit_type, i) {
  374. const flow = sp_lc.find(x => { return x.code === code });
  375. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  376. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  377. return flow.auditGroupList[i];
  378. }
  379. };
  380. let timer = null;
  381. let oldSearchVal = null;
  382. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  383. oldSearchVal = e.target.value;
  384. timer && clearTimeout(timer);
  385. timer = setTimeout(() => {
  386. const newVal = $(this).val();
  387. const code = $(this).attr('data-code');
  388. let html = '';
  389. if (newVal && newVal === oldSearchVal) {
  390. 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 => {
  391. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  392. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  393. class="ml-auto">${item.mobile || ''}</span></p>
  394. <span class="text-muted">${item.role || ''}</span>
  395. </dd>`
  396. });
  397. $('#' + code + '_dropdownMenu .book-list').empty();
  398. $('#' + code + '_dropdownMenu .book-list').append(html);
  399. } else {
  400. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  401. accountGroup.forEach((group, idx) => {
  402. if (!group) return;
  403. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  404. </a> ${group.groupName}</dt>
  405. <div class="dd-content" data-toggleid="${idx}">`;
  406. group.groupList.forEach(item => {
  407. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  408. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  409. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  410. class="ml-auto">${item.mobile || ''}</span></p>
  411. <span class="text-muted">${item.role || ''}</span>
  412. </dd>`;
  413. }
  414. });
  415. html += '</div>';
  416. });
  417. $('#' + code + '_dropdownMenu .book-list').empty();
  418. $('#' + code + '_dropdownMenu .book-list').append(html);
  419. }
  420. }
  421. }, 400);
  422. });
  423. // 添加审批流程按钮逻辑
  424. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  425. const idx = $(this).find('.acc-btn').attr('data-groupid');
  426. const type = $(this).find('.acc-btn').attr('data-type');
  427. if (type === 'hide') {
  428. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  429. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  430. $(this).find('.acc-btn').attr('data-type', 'show');
  431. })
  432. } else {
  433. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  434. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  435. $(this).find('.acc-btn').attr('data-type', 'hide');
  436. })
  437. }
  438. return false;
  439. });
  440. // 更改审批流程状态
  441. $('body').on('change', '.form-check input[type="radio"]', function () {
  442. // 获取所有审批的checked值并更新
  443. const this_status = parseInt($(this).val());
  444. const this_code = $(this).data('code');
  445. const spt = sp_status_list[this_status];
  446. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  447. // 拼接post json
  448. const prop = {
  449. code: this_code,
  450. status: this_status
  451. };
  452. const _self = $(this);
  453. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  454. if (this_status === sp_status.sqspr) {
  455. _self.parents('.form-group').siblings('.lc-show').html('');
  456. } else if (this_status === sp_status.gdspl) {
  457. const flow = sp_lc.find(x => { return x.code === this_code; });
  458. flow.auditGroupList = data.auditList;
  459. flow.groupList = data.groupList;
  460. let addhtml = auditUtils.getGroupHtml(flow, this_code);
  461. addhtml += '<ul class="list-unstyled">\n';
  462. addhtml += auditUtils.getgdsplHtml(flow, this_code);
  463. addhtml += '</ul>\n';
  464. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  465. } else if (this_status === sp_status.gdzs) {
  466. let addhtml = '<ul class="list-unstyled">\n' +
  467. ' <li class="d-flex justify-content-start mb-3">\n' +
  468. ' <span class="col-auto">授权审批人</span>\n' +
  469. ' <span class="col-7">\n' +
  470. ' <span class="d-inline-block"></span>\n' +
  471. ' </span>\n' +
  472. ' </li>\n';
  473. addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
  474. addhtml += '</ul>\n';
  475. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  476. }
  477. if(this_code === 'stage') {
  478. if(this_status === sp_status.gdspl) {
  479. $('#stage_cooperation').show();
  480. } else {
  481. $('#stage_cooperation').hide();
  482. }
  483. }
  484. });
  485. });
  486. // 选中审批人
  487. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  488. const id = parseInt($(this).data('id'));
  489. if (!id) return;
  490. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  491. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  492. const user = _.find(accountList, function (item) {
  493. return item.id === id;
  494. });
  495. if (this_code === 'audit-ass') {
  496. auditAss.setAuditAssist(user);
  497. } else {
  498. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  499. if (this_status === sp_status.gdspl) {
  500. // 判断是否已存在审批人
  501. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  502. for (let i = 0; i < aid_num; i++) {
  503. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  504. if (aid === id) {
  505. toastr.warning('该审核人已存在,请勿重复添加');
  506. return;
  507. }
  508. }
  509. }
  510. const prop = {
  511. status: this_status,
  512. code: sp_type[this_code],
  513. audit_id: id,
  514. type: 'add',
  515. };
  516. if (this_status === sp_status.gdspl) {
  517. prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
  518. prop.audit_order = $(this).parents('li').index() + 1;
  519. }
  520. const _self = $(this);
  521. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  522. if (this_status === sp_status.gdspl) {
  523. const auditGroup = auditUtils.addAudit(this_code, { audit_id: data.audit_id, name: user.name, audit_type: data.audit_type, audit_order: data.audit_order }, prop.audit_order - 1);
  524. if (_self.parents('ul').find('.add-audit').length === 0) {
  525. const flow = sp_lc.find(x => { return x.code === this_code; });
  526. const addGroupHtml = this_code === 'change' && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  527. `<span class="pl-3"><a href="javascript:void(0);" class="show-spzsave" data-code="${this_code}"><i class="fa fa-save"></i> 存为审批组</a></span>\n` : '';
  528. _self.parents('ul').append('<li>\n' +
  529. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  530. ' </li>');
  531. }
  532. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  533. } else {
  534. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  535. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  536. ' <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' +
  537. ' <div class="dropdown-menu">\n' +
  538. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  539. ' <div class="dropdown-divider"></div>\n' +
  540. ' <div class="px-2 py-1 text-center">\n' +
  541. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  542. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  543. ' </div>\n' +
  544. ' </div>\n' +
  545. ' </span> ' +
  546. ' </span></span></span>\n');
  547. }
  548. });
  549. }
  550. });
  551. // 移除审批人
  552. $('body').on('click', '.remove-audit', function () {
  553. const id = parseInt($(this).data('id'));
  554. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  555. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  556. const prop = {
  557. status: this_status,
  558. code: sp_type[this_code],
  559. audit_id: id,
  560. type: 'del',
  561. };
  562. const _self = $(this);
  563. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  564. if (this_status === sp_status.gdspl) {
  565. const index = _self.parents('li').index();
  566. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  567. if (auditGroup) {
  568. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  569. } else {
  570. const _selflc = _self.parents('.lc-show');
  571. _self.parents('li').remove();
  572. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  573. if (aid_num === 0) {
  574. _selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  575. } else {
  576. for (let i = 0; i < aid_num; i++) {
  577. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  578. }
  579. }
  580. }
  581. } else if (this_status === sp_status.gdzs) {
  582. let addhtml = '<ul class="list-unstyled">\n' +
  583. ' <li class="d-flex justify-content-start mb-3">\n' +
  584. ' <span class="col-auto">授权审批人</span>\n' +
  585. ' <span class="col-7">\n' +
  586. ' <span class="d-inline-block"></span>\n' +
  587. ' </span>\n' +
  588. ' </li>\n';
  589. addhtml += makeSelectAudit(this_code);
  590. addhtml += '</ul>\n';
  591. _self.parents('.lc-show').html(addhtml);
  592. }
  593. })
  594. });
  595. // 固定审批流-添加流程
  596. $('body').on('click', '.add-audit', function () {
  597. const num = $(this).parents('ul').children('li').length;
  598. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  599. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  600. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  601. $(this).parents('ul').append(addhtml);
  602. $(this).parents('li').remove();
  603. });
  604. sortCategory2();
  605. initTenderTree2();
  606. $('body').on('click', '.set-otherTender', function () {
  607. const this_code = $(this).data('code');
  608. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  609. const lis = $(this).siblings('.lc-show').find('li');
  610. const auditList = [], aidList = [];
  611. lis.each((i, li) => {
  612. const removes = $(li).find('.remove-audit');
  613. if (removes.length === 0) return;
  614. const select = $(li).find('select[class*="audit-type-key"]');
  615. const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  616. for (const remove of removes) {
  617. auditList.push({ audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 });
  618. aidList.push(parseInt(remove.getAttribute('data-id')));
  619. }
  620. });
  621. const html = getTenderTreeHtml2(this_code, this_status, aidList);
  622. $('#shenpi-name').text($(this).data('name'));
  623. $('#shenpi_code').val(this_code);
  624. $('#shenpi_status').val(this_status);
  625. $('#shenpi_auditors').val(JSON.stringify(auditList));
  626. $('#tender-list').html(html);
  627. $('#search-audit').val('');
  628. $('#search-result').text('0/0');
  629. $('#up-search').attr('disabled', true);
  630. $('#down-search').attr('disabled', true);
  631. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  632. });
  633. $('#save-other-tender').click(function () {
  634. $(this).attr('disabled', true);
  635. const num = $('#tender-list input:checked').length;
  636. if (num < 2) {
  637. toastr.warning('请选择需要设置审批同步的标段');
  638. $(this).removeAttr('disabled');
  639. return;
  640. }
  641. const data = {
  642. type: 'copy2ot',
  643. status: parseInt($('#shenpi_status').val()),
  644. code: $('#shenpi_code').val(),
  645. };
  646. if(data.status !== shenpi_status.gdspl) {
  647. data.auditList = JSON.parse($('#shenpi_auditors').val());
  648. }
  649. // 获取已选中的标段
  650. const tenderList = [];
  651. for (let i = 0; i < num; i++) {
  652. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  653. if (tid !== cur_tenderid) {
  654. tenderList.push(tid);
  655. }
  656. }
  657. data.tidList = tenderList.join(',');
  658. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  659. toastr.success('设置成功');
  660. setTimeout(function () {
  661. window.location.reload();
  662. }, 1000)
  663. })
  664. });
  665. $('body').on('click', '.set-otherShenpi', function () {
  666. let canSetOther = true;
  667. const this_code = $(this).data('code');
  668. // if (['stage', 'change'].indexOf(this_code) !== -1) {
  669. // const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
  670. // select.each((i, s) => {
  671. // if (s.value !== '1') canSetOther = false;
  672. // });
  673. // }
  674. // if (!canSetOther) {
  675. // toastr.warning('该流程含有会签或签,不可同步至其他流程');
  676. // $('#batch2').modal('hide');
  677. // return;
  678. // }
  679. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  680. const copyFlow = [];
  681. const flow = $('li.d-flex', $(this).siblings('.lc-show'));
  682. for (const f of flow) {
  683. const audit_type = $('select', f).val() || 1;
  684. const auditors = $('.remove-audit', f);
  685. if (auditors.length === 0) continue;
  686. const aid = [];
  687. for (const a of auditors) {
  688. aid.push(a.getAttribute('data-id'));
  689. }
  690. copyFlow.push(`${audit_type}:${aid.join(',')}`);
  691. }
  692. const html = getShenpiHtml(this_code);
  693. $('#shenpi-name2').text($(this).data('name'));
  694. $('#shenpi_code2').val(this_code);
  695. $('#shenpi_status2').val(this_status);
  696. $('#shenpi_auditors2').val(copyFlow.join(';'));
  697. $('#shenpi-list').html(html);
  698. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  699. $('#batch2').modal('show');
  700. });
  701. $('#save-other-shenpi').click(function () {
  702. $(this).attr('disabled', true);
  703. const num = $('#shenpi-list input:checked').length;
  704. if (num < 1) {
  705. toastr.warning('请选择需要设置审批同步的流程');
  706. $(this).removeAttr('disabled');
  707. return;
  708. }
  709. const data = {
  710. type: 'copy2os',
  711. status: parseInt($('#shenpi_status2').val()),
  712. code: $('#shenpi_code2').val(),
  713. };
  714. if(data.status !== shenpi_status.gdspl) {
  715. data.flowList = $('#shenpi_auditors2').val();
  716. }
  717. // 获取已选中的标段
  718. const shenpiList = [];
  719. for (let i = 0; i < num; i++) {
  720. const code = $('#shenpi-list input:checked').eq(i).data('code');
  721. shenpiList.push(code);
  722. }
  723. data.shenpiList = shenpiList.join(',');
  724. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  725. toastr.success('设置成功');
  726. setTimeout(function () {
  727. window.location.reload();
  728. }, 1000)
  729. })
  730. });
  731. // 设置会签、或签
  732. $('body').on('change', 'select[class*="audit-type-key"]', function() {
  733. const removes = $(this).parents('.d-flex').find('.remove-audit');
  734. if (removes.length === 0) return;
  735. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  736. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  737. const ids = [];
  738. const liParent = $(this).parents('li');
  739. removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
  740. const prop = {
  741. status: this_status,
  742. code: sp_type[this_code],
  743. audit_id: ids,
  744. audit_type: parseInt(this.value),
  745. type: 'audit-type',
  746. };
  747. if (prop.audit_type === auditType.key.common && ids.length > 1) {
  748. toastr.warning('设置个人审批前请先删除多余的审批人');
  749. this.value = this.getAttribute('data-type');
  750. return;
  751. }
  752. const _self = this;
  753. postData('/tender/'+ cur_tenderid +'/shenpi/audit/save', prop, function () {
  754. _self.setAttribute('data-type', _self.value);
  755. const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
  756. liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
  757. });
  758. });
  759. class AuditAss {
  760. constructor() {
  761. this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  762. this.sheet = this.spread.getActiveSheet();
  763. this.tree = createNewPathTree('base', {
  764. id: 'ledger_id',
  765. pid: 'ledger_pid',
  766. order: 'order',
  767. level: 'level',
  768. rootId: -1,
  769. });
  770. this.spreadSetting = {
  771. cols: [
  772. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
  773. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  774. {title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
  775. ],
  776. emptyRows: 0,
  777. headRows: 1,
  778. headRowHeight: [25, 25],
  779. defaultRowHeight: 21,
  780. headerFont: '12px 微软雅黑',
  781. font: '12px 微软雅黑',
  782. readOnly: true,
  783. localCache: {
  784. key: 'ledger-cooperation',
  785. colWidth: true,
  786. }
  787. };
  788. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  789. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  790. const self = this;
  791. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  792. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  793. this.spread.bind(spreadNS.Events.SelectionChanged, function() {
  794. self.refreshOperate();
  795. });
  796. $('#stage_audits').change(function () {
  797. self.uid = $(this).val();
  798. });
  799. // 多人协同
  800. $('#cooperation').on('shown.bs.modal', function () {
  801. // 执行一些动作...
  802. // 更新新的多人协同表格信息
  803. const newUidList = [];
  804. $('.stage_div ul li').each(function (k, v) {
  805. const audit_type = parseInt($(v).find('select').val());
  806. if (audit_type !== auditType.key.common) return;
  807. const uid = $(v).find('button').eq(0).data('id');
  808. if(uid) newUidList.push({ order: k + 1, audit_id: uid });
  809. });
  810. const yb = _.find(accountList, { 'id': cur_uid });
  811. let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
  812. if(newUidList.length > 0) {
  813. for (const id of newUidList) {
  814. const audit = _.find(accountList, { 'id': id.audit_id });
  815. newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(id.order) + '审)</option>';
  816. }
  817. }
  818. $('#stage_audits').html(newhtml);
  819. self.uid = cur_uid;
  820. self.initLedgerTree(cur_uid);
  821. });
  822. $('#del-audit-ass').click(function () {
  823. self.setAuditAssist();
  824. });
  825. $('body').on('click', 'button[asid]', function () {
  826. self.removeAuditAss(parseInt(this.getAttribute('asid')));
  827. });
  828. }
  829. set uid(id) {
  830. this._uid = parseInt(id);
  831. this._refreshAss();
  832. }
  833. get uid() {
  834. return this._uid;
  835. }
  836. _refreshAssTable(){
  837. $('#stage_audit').text($("#stage_audits option:selected").text());
  838. const html = [];
  839. for (const sa of this.showAssList) {
  840. const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  841. 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>`);
  842. }
  843. $('#coo_table').html(html.join(''));
  844. }
  845. _refreshAssTree() {
  846. const ledgerAss = {};
  847. for (const sa of this.showAssList) {
  848. const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  849. ledger.forEach(l => { ledgerAss[l] = sa; });
  850. }
  851. for (const n of this.tree.nodes) {
  852. const la = ledgerAss[n.ledger_id];
  853. n.ass_audit_id = la ? la.ass_user_id : null;
  854. n.ass_name = la ? la.name : '';
  855. }
  856. SpreadJsObj.reloadColData(this.sheet, 2);
  857. }
  858. _refreshAss() {
  859. this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
  860. this._refreshAssTable();
  861. this._refreshAssTree();
  862. }
  863. initLedgerTree(uid) {
  864. if (this.loaded && this.tid && this.tid === cur_tenderid) return;
  865. this.spread.refresh();
  866. const self = this;
  867. postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
  868. self.loaded = true;
  869. self.tid = cur_tenderid;
  870. self.assList = data.auditAssList;
  871. self.tree.loadDatas(data.ledgerList);
  872. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  873. self.uid = uid;
  874. self.refreshOperate();
  875. }, null, true);
  876. }
  877. loadPostData(data) {
  878. if (data.add) {
  879. this.assList.push(data.add);
  880. }
  881. if (data.del) {
  882. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  883. }
  884. if (data.update) {
  885. for (const d of data.update) {
  886. const od = this.assList.find(x => { return x.id === d.id });
  887. if (!od) continue;
  888. od.ass_ledger_id = d.ass_ledger_id;
  889. }
  890. }
  891. this._refreshAss();
  892. }
  893. setAuditAssist(assist){
  894. const node = SpreadJsObj.getSelectObject(this.sheet);
  895. if (assist && node.ass_audit_id === assist.id) return;
  896. if (assist && assist.id === this.uid) {
  897. toastr.warning('请勿添加本人');
  898. return;
  899. }
  900. const self = this;
  901. const data = { type: 'audit-ass'};
  902. if (assist) {
  903. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  904. if (!newAss) {
  905. 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 + '' };
  906. } else {
  907. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  908. }
  909. }
  910. if (node.ass_audit_id) {
  911. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  912. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  913. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  914. if (rela_lid.length === 0) {
  915. data.del = { id: orgAss.id };
  916. } else {
  917. if (!data.update) data.update = [];
  918. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  919. }
  920. }
  921. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  922. self.loadPostData(result);
  923. self.refreshOperate();
  924. });
  925. }
  926. removeAuditAss(assistId) {
  927. const self = this;
  928. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  929. self.loadPostData(result);
  930. self.refreshOperate();
  931. });
  932. }
  933. refreshOperate() {
  934. const node = SpreadJsObj.getSelectObject(this.sheet);
  935. if (node && node.ass_audit_id) {
  936. $('#del-audit-ass').show();
  937. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  938. } else {
  939. $('#del-audit-ass').hide();
  940. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  941. }
  942. }
  943. }
  944. const auditAss = new AuditAss();
  945. class AuditUnion {
  946. constructor() {
  947. this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
  948. this.sheet = this.spread.getActiveSheet();
  949. this.tree = createNewPathTree('base', {
  950. id: 'ledger_id',
  951. pid: 'ledger_pid',
  952. order: 'order',
  953. level: 'level',
  954. rootId: -1,
  955. });
  956. this.selectUnion = [{ value: 0, text: '' }];
  957. this.spreadSetting = {
  958. cols: [
  959. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
  960. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
  961. {title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
  962. ],
  963. emptyRows: 0,
  964. headRows: 1,
  965. headRowHeight: [32],
  966. defaultRowHeight: 21,
  967. headerFont: '12px 微软雅黑',
  968. font: '12px 微软雅黑',
  969. };
  970. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  971. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  972. const self = this;
  973. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  974. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  975. this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
  976. const node = SpreadJsObj.getSelectObject(info.sheet);
  977. if (!node) return;
  978. const refreshAuditId = [];
  979. if (node.audit_id) refreshAuditId.push(node.audit_id);
  980. const col = info.sheet.zh_setting.cols[info.col];
  981. node[col.field] = info.editingText;
  982. if (node.audit_id) refreshAuditId.push(node.audit_id);
  983. self.refreshUnionCount(refreshAuditId);
  984. });
  985. $('#union').on('shown.bs.modal', function() {
  986. self.spread.refresh();
  987. });
  988. $('#union-ok').click(function() {
  989. const data = self.getUnionAuditLedgerData();
  990. postData(`/tender/${cur_tenderid}/shenpi/union/save`, data, function(result) {
  991. $('#union').modal('hide');
  992. });
  993. });
  994. $('body').on('click', '[name=clear-union]', function() {
  995. const aid = parseInt(this.getAttribute('aid'));
  996. for (const node of self.tree.nodes) {
  997. if (node.audit_id === aid) node.audit_id = 0;
  998. }
  999. SpreadJsObj.reloadColData(self.sheet, 2);
  1000. self.refreshUnionCount(aid);
  1001. });
  1002. }
  1003. _refreshUnionTree() {
  1004. const ledgerAss = {};
  1005. for (const a of this.auditors) {
  1006. a.lid.forEach(l => { ledgerAss[l] = a; });
  1007. }
  1008. for (const n of this.tree.nodes) {
  1009. const la = ledgerAss[n.ledger_id];
  1010. n.audit_id = la ? la.audit_id : 0;
  1011. n.audit_name = la ? la.name : '';
  1012. }
  1013. SpreadJsObj.reloadColData(this.sheet, 2);
  1014. }
  1015. setUnionAuditors(auditors) {
  1016. this.auditors = auditors;
  1017. this.selectUnion.length = 1;
  1018. const html = [];
  1019. for (const auditor of auditors) {
  1020. auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
  1021. html.push(`<tr><td>${auditor.name}</td><td>${auditor.company}</td><td><span aid="${auditor.audit_id}">${auditor.lid.length}</span><button class="ml-2 btn btn-sm btn-outline-danger" name="clear-union" aid="${auditor.audit_id}">清空</button></td></tr>`);
  1022. this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
  1023. }
  1024. $('#union_table').html(html.join(''));
  1025. this._refreshUnionTree();
  1026. }
  1027. refreshUnionCount(auditId) {
  1028. const auditIds = auditId instanceof Array ? auditId : [auditId];
  1029. for (const aid of auditIds) {
  1030. const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
  1031. $(`span[aid=${aid}]`).html(unionNodes.length);
  1032. }
  1033. }
  1034. loadUnionData(sp_type, audit_order) {
  1035. const data = { sp_type, audit_order };
  1036. if (!this.loaded) data.ledger = 1;
  1037. const self = this;
  1038. postData(`/tender/${cur_tenderid}/shenpi/union/load`, data, function(result) {
  1039. self.loaded = true;
  1040. if (result.ledgerList) {
  1041. self.tree.loadDatas(result.ledgerList);
  1042. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  1043. }
  1044. self.setUnionAuditors(result.unionAuditors);
  1045. if (self.auditors.length > 0) {
  1046. $('#union').modal('show');
  1047. } else {
  1048. toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
  1049. }
  1050. });
  1051. }
  1052. getUnionAuditLedgerData() {
  1053. this.auditors.forEach(a => { a.lid = []; });
  1054. for (const node of this.tree.nodes) {
  1055. if (node.audit_id > 0) {
  1056. const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
  1057. if (relaAudit) relaAudit.lid.push(node.ledger_id);
  1058. }
  1059. }
  1060. return this.auditors.map(a => {
  1061. return { id: a.id, audit_ledger_id: a.lid.join(',') };
  1062. });
  1063. }
  1064. }
  1065. const auditUnion = new AuditUnion();
  1066. $('body').on('click', '[name=union-set]', function() {
  1067. auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
  1068. });
  1069. $.subMenu({
  1070. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1071. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1072. key: 'menu.1.0.0',
  1073. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1074. callback: function (info) {
  1075. if (info.mini) {
  1076. $('.panel-title').addClass('fluid');
  1077. $('#sub-menu').removeClass('panel-sidebar');
  1078. } else {
  1079. $('.panel-title').removeClass('fluid');
  1080. $('#sub-menu').addClass('panel-sidebar');
  1081. }
  1082. autoFlashHeight();
  1083. }
  1084. });
  1085. let timer2 = null;
  1086. let oldSearchVal2 = null;
  1087. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  1088. oldSearchVal2 = e.target.value;
  1089. timer2 && clearTimeout(timer2);
  1090. timer2 = setTimeout(() => {
  1091. const newVal = $(this).val();
  1092. const resultLength = $('#tender-list').find('.result').length;
  1093. if (resultLength > 0) {
  1094. let content = $('#tender-list').html();
  1095. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  1096. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  1097. content = content.replace(regExp2, replaceStr);
  1098. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  1099. content = content.replace(regExp3, replaceStr);
  1100. $('#tender-list').html(content);
  1101. }
  1102. $('#search-result').text('0/0');
  1103. $('#up-search').attr('disabled', true);
  1104. $('#down-search').attr('disabled', true);
  1105. if (newVal && newVal === oldSearchVal2) {
  1106. const regExp = new RegExp(newVal, 'g');
  1107. for (let i = 0; i < $('#tender-list tr').length; i++) {
  1108. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  1109. $('#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>'))
  1110. }
  1111. }
  1112. const resultLength2 = $('#tender-list').find('.result').length;
  1113. if (resultLength2 > 0) {
  1114. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  1115. $('#search-result').text('1/' + resultLength2);
  1116. $('#up-search').attr('disabled', false);
  1117. $('#down-search').attr('disabled', false);
  1118. }
  1119. }
  1120. if($('#tender-list').find('.result').length > 0) {
  1121. const X = $('#tender-list').find('.result').eq(0).offset().top;
  1122. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1123. }
  1124. }, 400);
  1125. });
  1126. $('#up-search').on('click', function () {
  1127. const cur = parseInt($('#search-result').text().split('/')[0]);
  1128. const total = parseInt($('#search-result').text().split('/')[1]);
  1129. const now = cur - 1 !== 0 ? cur - 1: total;
  1130. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1131. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1132. // $('#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;">'))
  1133. // $('#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;">'))
  1134. $('#search-result').text(now + '/' + total);
  1135. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1136. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1137. });
  1138. $('#down-search').on('click', function () {
  1139. const cur = parseInt($('#search-result').text().split('/')[0]);
  1140. const total = parseInt($('#search-result').text().split('/')[1]);
  1141. const now = cur + 1 > total ? 1: cur + 1;
  1142. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1143. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1144. // $('#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;">'))
  1145. // $('#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;">'))
  1146. $('#search-result').text(now + '/' + total);
  1147. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1148. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  1149. });
  1150. // 审批组
  1151. $('body').on('click', '.show-spzsave', function () {
  1152. const this_code = $(this).attr('data-code');
  1153. const groupId = $(this).attr('data-group') || null;
  1154. const flow = sp_lc.find(x => { return x.code === this_code; });
  1155. $('#save-code').val(this_code);
  1156. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1157. if (group) {
  1158. $('#save-group-id').val(group.id);
  1159. $('#spzsave input[name="group_name"]').val(group.name);
  1160. $('#show-delete-group-btn').show();
  1161. } else {
  1162. $('#save-group-id').val('');
  1163. $('#spzsave input[name="group_name"]').val('');
  1164. $('#show-delete-group-btn').hide();
  1165. }
  1166. if (this_code === 'change') {
  1167. if (group) {
  1168. $('#show-change-type input').each(function () {
  1169. if (group.change_type[$(this).data('type')]) {
  1170. $(this).prop('checked', true);
  1171. } else {
  1172. $(this).prop('checked', false);
  1173. }
  1174. });
  1175. } else {
  1176. $('#show-change-type input').each(function () {
  1177. $(this).prop('checked', false);
  1178. });
  1179. $('#show-change-type input[data-type="change"]').prop('checked', true);
  1180. }
  1181. $('#show-change-type input').removeAttr('disabled');
  1182. $('#show-change-type').show();
  1183. } else {
  1184. $('#show-change-type input').attr('disabled', true);
  1185. $('#show-change-type').hide();
  1186. }
  1187. $('#spzsave').modal('show');
  1188. });
  1189. $('#save-group-btn').click(function () {
  1190. const name = _.trim($('#spzsave input[name="group_name"]').val());
  1191. if (!name) {
  1192. toastr.error('审批组名称不能为空');
  1193. return false;
  1194. }
  1195. if (name.length > 50) {
  1196. toastr.error('审批组名称不能超过50个字符');
  1197. return false;
  1198. }
  1199. const code = $('#save-code').val();
  1200. const prop = {
  1201. type: 'save-group',
  1202. name,
  1203. code,
  1204. }
  1205. const groupId = $('#save-group-id').val();
  1206. const flow = sp_lc.find(x => { return x.code === code; });
  1207. if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
  1208. return item.name === name && item.id !== parseInt(groupId);
  1209. }) !== -1) {
  1210. toastr.error('审批组名称已存在, 请更改名称');
  1211. return false;
  1212. }
  1213. if (groupId) {
  1214. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1215. if (!group) {
  1216. toastr.error('审批组不存在');
  1217. return false;
  1218. }
  1219. prop.groupId = group.id;
  1220. }
  1221. if (code === 'change') {
  1222. const change_type = {};
  1223. let change_flag = false;
  1224. $('#show-change-type input').each(function () {
  1225. change_type[$(this).data('type')] = $(this).prop('checked');
  1226. if ($(this).prop('checked')) {
  1227. change_flag = true;
  1228. }
  1229. });
  1230. if (!change_flag) {
  1231. toastr.error('请至少选择一种变更显示模块');
  1232. return false;
  1233. }
  1234. prop.change_type = change_type;
  1235. }
  1236. console.log(prop);
  1237. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1238. flow.auditGroupList = data.group.auditGroupList || [];
  1239. if (groupId) {
  1240. const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
  1241. flow.groupList[index] = data.group;
  1242. } else {
  1243. if (!flow.groupList) flow.groupList = [];
  1244. for (const g of flow.groupList) {
  1245. g.is_select = 0;
  1246. }
  1247. flow.groupList.push(data.group);
  1248. }
  1249. // 配置页面
  1250. let addhtml = auditUtils.getGroupHtml(flow, code);
  1251. addhtml += '<ul class="list-unstyled">\n';
  1252. addhtml += auditUtils.getgdsplHtml(flow, code);
  1253. addhtml += '</ul>\n';
  1254. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1255. $('#spzsave').modal('hide');
  1256. });
  1257. });
  1258. // 切换审批组
  1259. $('body').on('change', '.group-list', function () {
  1260. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  1261. const flow = sp_lc.find(x => { return x.code === this_code; });
  1262. const groupId = parseInt($(this).val());
  1263. const _self = $(this);
  1264. const prop = {
  1265. type: 'change-group',
  1266. groupId,
  1267. }
  1268. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1269. flow.groupList.forEach(function (item) {
  1270. item.is_select = 0;
  1271. });
  1272. const group = flow.groupList.find(x => { return x.id === groupId; });
  1273. group.is_select = 1;
  1274. flow.auditGroupList = group.auditGroupList;
  1275. const addhtml = auditUtils.getgdsplHtml(flow, this_code);
  1276. _self.parents('.lc-show').children('ul').html(addhtml);
  1277. _self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
  1278. });
  1279. });
  1280. $('#show-delete-group-btn').click(function () {
  1281. const code = $('#save-code').val();
  1282. const groupId = $('#save-group-id').val();
  1283. const flow = sp_lc.find(x => { return x.code === code; });
  1284. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1285. if (!group) {
  1286. toastr.error('该审批组不存在');
  1287. return false;
  1288. }
  1289. $('#delete-group-name').text(group.name);
  1290. $('#delete-group-id').val(group.id);
  1291. $('#delete-code').val(code);
  1292. $('#spzsave').modal('hide');
  1293. $('#spzdelete').modal('show');
  1294. });
  1295. $('#delete-group-btn').click(function () {
  1296. const code = $('#delete-code').val();
  1297. const groupId = $('#delete-group-id').val();
  1298. const flow = sp_lc.find(x => { return x.code === code; });
  1299. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1300. if (!group) {
  1301. toastr.error('该审批组不存在');
  1302. return false;
  1303. }
  1304. const prop = {
  1305. type: 'delete-group',
  1306. groupId: group.id,
  1307. }
  1308. console.log(prop);
  1309. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1310. // const flow = findSplc(code);
  1311. const index = flow.groupList.findIndex(x => { return x.id === group.id; });
  1312. flow.groupList.splice(index, 1);
  1313. flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
  1314. if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
  1315. // 配置页面
  1316. let addhtml = auditUtils.getGroupHtml(flow, code);
  1317. addhtml += '<ul class="list-unstyled">\n';
  1318. addhtml += auditUtils.getgdsplHtml(flow, code);
  1319. addhtml += '</ul>\n';
  1320. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1321. $('#spzdelete').modal('hide');
  1322. });
  1323. });
  1324. });
  1325. // 审批流程-审批人html 生成
  1326. function makeAudit(audit, i = '终') {
  1327. return '<li class="d-flex justify-content-start mb-3">\n' +
  1328. ' <span class="col-auto">'+ i +'审</span>\n' +
  1329. ' <span class="col-7 spr-span">\n' +
  1330. ' <span class="d-inline-block"></span>\n' +
  1331. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  1332. ' <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' +
  1333. ' <div class="dropdown-menu">\n' +
  1334. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  1335. ' <div class="dropdown-divider"></div>\n' +
  1336. ' <div class="px-2 py-1 text-center">\n' +
  1337. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  1338. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  1339. ' </div>\n' +
  1340. ' </div>\n' +
  1341. ' </span> ' +
  1342. // '<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' +
  1343. ' </span></span></span>\n' +
  1344. ' </li>';
  1345. }
  1346. // 审批流程-选择审批人html 生成
  1347. function makeSelectAudit(code, i = '终') {
  1348. let divhtml = '';
  1349. accountGroup.forEach((group, idx) => {
  1350. let didivhtml = '';
  1351. if(group) {
  1352. group.groupList.forEach(item => {
  1353. 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' +
  1354. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  1355. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1356. ' <span class="text-muted">' + item.role + '</span>\n' +
  1357. ' </dd>\n' : '';
  1358. });
  1359. 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' +
  1360. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  1361. ' </div>\n';
  1362. }
  1363. });
  1364. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  1365. ' <span class="col-auto">' + i + '审</span>\n' +
  1366. ' <span class="col-7 spr-span">\n' +
  1367. ' <span class="d-inline-block">\n' +
  1368. ' <div class="dropdown text-right">\n' +
  1369. ' <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' +
  1370. ' 选择审批人\n' +
  1371. ' </button>\n' +
  1372. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  1373. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  1374. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  1375. ' <dl class="list-unstyled book-list">\n' + divhtml +
  1376. ' </dl>\n' +
  1377. ' </div>\n' +
  1378. ' </div>\n' +
  1379. ' </span>\n' +
  1380. ' </span>\n' +
  1381. ' </li>';
  1382. return html;
  1383. }