shenpi.js 81 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581
  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. if (user) 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.and && auditType.info[auditType.key.and].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  304. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="and-set">会签设置</button>`);
  305. }
  306. if (type === auditType.key.or && auditType.info[auditType.key.or].setValid.indexOf(code) >= 0 && auditGroup.length > 0) {
  307. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="or-set">或签设置</button>`);
  308. }
  309. if (type === auditType.key.multi && auditGroup.length > 0) {
  310. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="multi-set">分组设置</button>`);
  311. }
  312. if (type === auditType.key.union && auditGroup.length > 0) {
  313. html.push(`<button class="btn btn-sm btn-outline-primary" sp_type="${code}" audit_order="${i}" name="union-set">协同设置</button>`);
  314. }
  315. html.push('</span>');
  316. return html.join('');
  317. },
  318. getAuditGroupHtml: function (code, auditGroup, i) {
  319. return `<li class="d-flex justify-content-start align-items-center mb-3">${this.getAuditGroupInnerHtml(code, auditGroup, i)}</li>`;
  320. },
  321. getFinalAuditHtml: function (audit) {
  322. const html = [];
  323. html.push('<li class="d-flex justify-content-start mb-3"><span class="col-auto">终审</span><span class="col-7 spr-span">');
  324. html.push(this.getAuditHtml(audit));
  325. html.push('</span></span></li>');
  326. return html.join('');
  327. },
  328. getGroupHtml: function (flow, this_code) {
  329. let html = '';
  330. if (flow && flow.groupList && flow.groupList.length > 0) {
  331. let groupSelectHtml = '';
  332. for (const group of flow.groupList) {
  333. groupSelectHtml += `<option value="${group.id}" ${group.is_select === 1 ? 'selected' : ''}>${group.name}</option>`;
  334. }
  335. const selectGroup = flow.groupList.find(x => { return x.is_select === 1 });
  336. html += '<div class="d-flex justify-content-start align-items-center mb-3">\n' +
  337. ' <span class="col-auto">当前审批组:</span>\n' +
  338. ' <span style="width: 200px;">\n' +
  339. ' <select class="form-control form-control-sm group-list">\n' +
  340. groupSelectHtml +
  341. ' </select>\n' +
  342. ' </span>\n' +
  343. ` <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` +
  344. ` <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` +
  345. ' </div>';
  346. }
  347. return html;
  348. },
  349. getgdsplHtml(flow, this_code) {
  350. let addhtml = '';
  351. if (flow.auditGroupList.length !== 0) {
  352. for(const [i, auditGroup] of flow.auditGroupList.entries()) {
  353. addhtml += this.getAuditGroupHtml(this_code, auditGroup, i + 1);
  354. }
  355. const addGroupHtml = (this_code === 'change' || this_code === 'stage') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  356. `<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` : '';
  357. addhtml += '<li>\n' +
  358. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  359. ' </li>';
  360. } else {
  361. addhtml += this.getAuditGroupHtml(this_code, [], 1);
  362. }
  363. return addhtml;
  364. },
  365. // 以下i从0开始
  366. addAudit: function (code, user, i) {
  367. const flow = sp_lc.find(x => { return x.code === code });
  368. if (!flow.auditGroupList) flow.auditGroupList = [];
  369. if (!flow.auditGroupList[i]) flow.auditGroupList[i] = [];
  370. flow.auditGroupList[i].push(user);
  371. return flow.auditGroupList[i];
  372. },
  373. removeAudit: function (code, audit_id, i) {
  374. const flow = sp_lc.find(x => { return x.code === code });
  375. if (flow.auditGroupList[i].length === 1) {
  376. flow.auditGroupList.splice(i, 1);
  377. return null;
  378. }
  379. flow.auditGroupList[i].splice(flow.auditGroupList[i].findIndex(x => { return x.audit_id === audit_id; }), 1);
  380. return flow.auditGroupList[i];
  381. },
  382. setAuditType: function (code, audit_type, i) {
  383. const flow = sp_lc.find(x => { return x.code === code });
  384. if (!flow || !flow.auditGroupList || !flow.auditGroupList[i]) return;
  385. flow.auditGroupList[i].forEach(x => { x.audit_type = audit_type});
  386. return flow.auditGroupList[i];
  387. }
  388. };
  389. let timer = null;
  390. let oldSearchVal = null;
  391. $('body').on('input propertychange', 'div[id$="_dropdownMenu"] .gr-search', function(e) {
  392. oldSearchVal = e.target.value;
  393. timer && clearTimeout(timer);
  394. timer = setTimeout(() => {
  395. const newVal = $(this).val();
  396. const code = $(this).attr('data-code');
  397. let html = '';
  398. if (newVal && newVal === oldSearchVal) {
  399. 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 => {
  400. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  401. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  402. class="ml-auto">${item.mobile || ''}</span></p>
  403. <span class="text-muted">${item.role || ''}</span>
  404. </dd>`
  405. });
  406. $('#' + code + '_dropdownMenu .book-list').empty();
  407. $('#' + code + '_dropdownMenu .book-list').append(html);
  408. } else {
  409. if (!$('#' + code + '_dropdownMenu .acc-btn').length) {
  410. accountGroup.forEach((group, idx) => {
  411. if (!group) return;
  412. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  413. </a> ${group.groupName}</dt>
  414. <div class="dd-content" data-toggleid="${idx}">`;
  415. group.groupList.forEach(item => {
  416. if ((item.id !== cur_uid || (item.id === cur_uid && needYB.indexOf(code) !== -1))) {
  417. html += `<dd class="border-bottom p-2 mb-0 " data-id="${item.id}" >
  418. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  419. class="ml-auto">${item.mobile || ''}</span></p>
  420. <span class="text-muted">${item.role || ''}</span>
  421. </dd>`;
  422. }
  423. });
  424. html += '</div>';
  425. });
  426. $('#' + code + '_dropdownMenu .book-list').empty();
  427. $('#' + code + '_dropdownMenu .book-list').append(html);
  428. }
  429. }
  430. }, 400);
  431. });
  432. // 添加审批流程按钮逻辑
  433. $('body').on('click', 'div[id$="_dropdownMenu"] .book-list dt', function () {
  434. const idx = $(this).find('.acc-btn').attr('data-groupid');
  435. const type = $(this).find('.acc-btn').attr('data-type');
  436. if (type === 'hide') {
  437. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  438. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  439. $(this).find('.acc-btn').attr('data-type', 'show');
  440. })
  441. } else {
  442. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  443. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  444. $(this).find('.acc-btn').attr('data-type', 'hide');
  445. })
  446. }
  447. return false;
  448. });
  449. // 更改审批流程状态
  450. $('body').on('change', '.form-check input[type="radio"]', function () {
  451. // 获取所有审批的checked值并更新
  452. const this_status = parseInt($(this).val());
  453. const this_code = $(this).data('code');
  454. const spt = sp_status_list[this_status];
  455. $(this).parents('.form-group').siblings('.alert-warning').text(spt.name + ':' + spt.msg);
  456. // 拼接post json
  457. const prop = {
  458. code: this_code,
  459. status: this_status
  460. };
  461. const _self = $(this);
  462. postData('/tender/' + cur_tenderid + '/shenpi/save', prop, function (data) {
  463. if (this_status === sp_status.sqspr) {
  464. _self.parents('.form-group').siblings('.lc-show').html('');
  465. } else if (this_status === sp_status.gdspl) {
  466. const flow = sp_lc.find(x => { return x.code === this_code; });
  467. flow.auditGroupList = data.auditList;
  468. flow.groupList = data.groupList;
  469. let addhtml = auditUtils.getGroupHtml(flow, this_code);
  470. addhtml += '<ul class="list-unstyled">\n';
  471. addhtml += auditUtils.getgdsplHtml(flow, this_code);
  472. addhtml += '</ul>\n';
  473. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  474. } else if (this_status === sp_status.gdzs) {
  475. let addhtml = '<ul class="list-unstyled">\n' +
  476. ' <li class="d-flex justify-content-start mb-3">\n' +
  477. ' <span class="col-auto">授权审批人</span>\n' +
  478. ' <span class="col-7">\n' +
  479. ' <span class="d-inline-block"></span>\n' +
  480. ' </span>\n' +
  481. ' </li>\n';
  482. addhtml += data.auditList ? makeAudit(data.auditList) : makeSelectAudit(this_code);
  483. addhtml += '</ul>\n';
  484. _self.parents('.form-group').siblings('.lc-show').html(addhtml);
  485. }
  486. if(this_code === 'stage') {
  487. if(this_status === sp_status.gdspl) {
  488. $('#stage_cooperation').show();
  489. } else {
  490. $('#stage_cooperation').hide();
  491. }
  492. }
  493. });
  494. });
  495. // 选中审批人
  496. $('body').on('click', 'div[id$="_dropdownMenu"] dl dd', function () {
  497. const id = parseInt($(this).data('id'));
  498. if (!id) return;
  499. let this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  500. if (!this_code) this_code = $(this).parents('.dropdown').data('code');
  501. const user = _.find(accountList, function (item) {
  502. return item.id === id;
  503. });
  504. if (this_code === 'audit-ass') {
  505. auditAss.setAuditAssist(user);
  506. } else {
  507. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  508. if (this_status === sp_status.gdspl) {
  509. // 判断是否已存在审批人
  510. const aid_num = $(this).parents('ul').find('.remove-audit').length;
  511. for (let i = 0; i < aid_num; i++) {
  512. const aid = parseInt($(this).parents('ul').find('.remove-audit').eq(i).data('id'));
  513. if (aid === id) {
  514. toastr.warning('该审核人已存在,请勿重复添加');
  515. return;
  516. }
  517. }
  518. }
  519. const prop = {
  520. status: this_status,
  521. code: sp_type[this_code],
  522. audit_id: id,
  523. type: 'add',
  524. };
  525. if (this_status === sp_status.gdspl) {
  526. prop.audit_type = parseInt($(this).parents('li').find('select[class*="audit-type-key"]')[0].value);
  527. prop.audit_order = $(this).parents('li').index() + 1;
  528. }
  529. const _self = $(this);
  530. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  531. if (this_status === sp_status.gdspl) {
  532. const auditGroup = auditUtils.addAudit(this_code, data, prop.audit_order - 1);
  533. if (_self.parents('ul').find('.add-audit').length === 0) {
  534. const flow = sp_lc.find(x => { return x.code === this_code; });
  535. const addGroupHtml = (this_code === 'change'||this_code ==='stage') && (!flow.groupList || (flow.groupList && flow.groupList.length === 0)) ?
  536. `<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` : '';
  537. _self.parents('ul').append('<li>\n' +
  538. ' <span class="pl-3"><a href="javascript:void(0);" class="add-audit" ><i class="fa fa-plus"></i> 添加流程</a></span>\n' + addGroupHtml +
  539. ' </li>');
  540. }
  541. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, prop.audit_order));
  542. } else {
  543. _self.parents('.spr-span').html('<span class="d-inline-block"></span>\n' +
  544. '<span class="d-inline-block"><span class="badge badge-light">'+ user.name +' <span class="dropdown">\n' +
  545. ' <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' +
  546. ' <div class="dropdown-menu">\n' +
  547. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  548. ' <div class="dropdown-divider"></div>\n' +
  549. ' <div class="px-2 py-1 text-center">\n' +
  550. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + user.id + '">移除</button>\n' +
  551. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  552. ' </div>\n' +
  553. ' </div>\n' +
  554. ' </span> ' +
  555. ' </span></span></span>\n');
  556. }
  557. });
  558. }
  559. });
  560. // 移除审批人
  561. $('body').on('click', '.remove-audit', function () {
  562. const id = parseInt($(this).data('id'));
  563. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  564. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  565. const prop = {
  566. status: this_status,
  567. code: sp_type[this_code],
  568. audit_id: id,
  569. type: 'del',
  570. };
  571. const _self = $(this);
  572. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  573. if (this_status === sp_status.gdspl) {
  574. const index = _self.parents('li').index();
  575. const auditGroup = auditUtils.removeAudit(this_code, id, index);
  576. if (auditGroup) {
  577. _self.parents('li').html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, index + 1));
  578. } else {
  579. const _selflc = _self.parents('.lc-show');
  580. _self.parents('li').remove();
  581. const aid_num = parseInt(_selflc.children('ul').find('li.d-flex').length);
  582. if (aid_num === 0) {
  583. _selflc.children('ul').html(auditUtils.getAuditGroupHtml(this_code, [], 1));
  584. } else {
  585. for (let i = 0; i < aid_num; i++) {
  586. _selflc.find('li.d-flex').eq(i).find('.col-auto').text(transFormToChinese(i+1) + '审');
  587. }
  588. }
  589. }
  590. } else if (this_status === sp_status.gdzs) {
  591. let addhtml = '<ul class="list-unstyled">\n' +
  592. ' <li class="d-flex justify-content-start mb-3">\n' +
  593. ' <span class="col-auto">授权审批人</span>\n' +
  594. ' <span class="col-7">\n' +
  595. ' <span class="d-inline-block"></span>\n' +
  596. ' </span>\n' +
  597. ' </li>\n';
  598. addhtml += makeSelectAudit(this_code);
  599. addhtml += '</ul>\n';
  600. _self.parents('.lc-show').html(addhtml);
  601. }
  602. })
  603. });
  604. // 固定审批流-添加流程
  605. $('body').on('click', '.add-audit', function () {
  606. const num = $(this).parents('ul').children('li').length;
  607. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  608. //const addhtml = makeSelectAudit(this_code, transFormToChinese(num));
  609. const addhtml = auditUtils.getAuditGroupHtml(this_code, [], num);
  610. $(this).parents('ul').append(addhtml);
  611. $(this).parents('li').remove();
  612. });
  613. sortCategory2();
  614. initTenderTree2();
  615. $('body').on('click', '.set-otherTender', function () {
  616. const this_code = $(this).data('code');
  617. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  618. const lis = $(this).siblings('.lc-show').find('li');
  619. const auditList = [], aidList = [];
  620. const flow = sp_lc.find(x => { return x.code === this_code; });
  621. lis.each((i, li) => {
  622. const removes = $(li).find('.remove-audit');
  623. if (removes.length === 0) return;
  624. const select = $(li).find('select[class*="audit-type-key"]');
  625. const audit_type = select.length > 0 ? parseInt(select.val()) : 1;
  626. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == i+1; });
  627. for (const remove of removes) {
  628. const auditData = { audit_id: parseInt(remove.getAttribute('data-id')), audit_type, audit_order: i + 1 };
  629. const removeMultiData = multiData.find(x => { return x.audit_id === auditData.audit_id; });
  630. auditData.audit_group = removeMultiData ? removeMultiData.audit_group : '';
  631. auditData.audit_group_order = removeMultiData ? removeMultiData.audit_group_order : 0;
  632. auditData.audit_group_limit = removeMultiData ? removeMultiData.audit_group_limit : 0;
  633. auditList.push(auditData);
  634. aidList.push(parseInt(remove.getAttribute('data-id')));
  635. }
  636. });
  637. const html = getTenderTreeHtml2(this_code, this_status, aidList);
  638. $('#shenpi-name').text($(this).data('name'));
  639. $('#shenpi_code').val(this_code);
  640. $('#shenpi_status').val(this_status);
  641. $('#shenpi_auditors').val(JSON.stringify(auditList));
  642. $('#tender-list').html(html);
  643. $('#search-audit').val('');
  644. $('#search-result').text('0/0');
  645. $('#up-search').attr('disabled', true);
  646. $('#down-search').attr('disabled', true);
  647. setTimeout(function () { $("#tender-list [data-toggle='tooltip']").tooltip(); },800);
  648. });
  649. $('#save-other-tender').click(function () {
  650. $(this).attr('disabled', true);
  651. const num = $('#tender-list input:checked').length;
  652. if (num < 2) {
  653. toastr.warning('请选择需要设置审批同步的标段');
  654. $(this).removeAttr('disabled');
  655. return;
  656. }
  657. const data = {
  658. type: 'copy2ot',
  659. status: parseInt($('#shenpi_status').val()),
  660. code: $('#shenpi_code').val(),
  661. };
  662. if(data.status !== shenpi_status.gdspl) {
  663. data.auditList = JSON.parse($('#shenpi_auditors').val());
  664. }
  665. // 获取已选中的标段
  666. const tenderList = [];
  667. for (let i = 0; i < num; i++) {
  668. const tid = parseInt($('#tender-list input:checked').eq(i).data('tid'));
  669. if (tid !== cur_tenderid) {
  670. tenderList.push(tid);
  671. }
  672. }
  673. data.tidList = tenderList.join(',');
  674. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  675. toastr.success('设置成功');
  676. setTimeout(function () {
  677. window.location.reload();
  678. }, 1000)
  679. })
  680. });
  681. $('body').on('click', '.set-otherShenpi', function () {
  682. let canSetOther = true;
  683. const this_code = $(this).data('code');
  684. // if (['stage', 'change'].indexOf(this_code) !== -1) {
  685. // const select = $(this).siblings('.lc-show').find('select[class*="audit-type-key"]');
  686. // select.each((i, s) => {
  687. // if (s.value !== '1') canSetOther = false;
  688. // });
  689. // }
  690. // if (!canSetOther) {
  691. // toastr.warning('该流程含有会签或签,不可同步至其他流程');
  692. // $('#batch2').modal('hide');
  693. // return;
  694. // }
  695. const this_status = parseInt($(this).siblings('.lc-show').siblings('.form-group').find('input:checked').val());
  696. const copyFlow = [];
  697. const flow = $('li.d-flex', $(this).siblings('.lc-show'));
  698. for (const f of flow) {
  699. const audit_type = $('select', f).val() || 1;
  700. const auditors = $('.remove-audit', f);
  701. if (auditors.length === 0) continue;
  702. const aid = [];
  703. for (const a of auditors) {
  704. aid.push(a.getAttribute('data-id'));
  705. }
  706. copyFlow.push(`${audit_type}:${aid.join(',')}`);
  707. }
  708. const html = getShenpiHtml(this_code);
  709. $('#shenpi-name2').text($(this).data('name'));
  710. $('#shenpi_code2').val(this_code);
  711. $('#shenpi_status2').val(this_status);
  712. $('#shenpi_auditors2').val(copyFlow.join(';'));
  713. $('#shenpi-list').html(html);
  714. setTimeout(function () { $("#shenpi-list [data-toggle='tooltip']").tooltip(); },800);
  715. $('#batch2').modal('show');
  716. });
  717. $('#save-other-shenpi').click(function () {
  718. $(this).attr('disabled', true);
  719. const num = $('#shenpi-list input:checked').length;
  720. if (num < 1) {
  721. toastr.warning('请选择需要设置审批同步的流程');
  722. $(this).removeAttr('disabled');
  723. return;
  724. }
  725. const data = {
  726. type: 'copy2os',
  727. status: parseInt($('#shenpi_status2').val()),
  728. code: $('#shenpi_code2').val(),
  729. };
  730. if(data.status !== shenpi_status.gdspl) {
  731. data.flowList = $('#shenpi_auditors2').val();
  732. }
  733. // 获取已选中的标段
  734. const shenpiList = [];
  735. for (let i = 0; i < num; i++) {
  736. const code = $('#shenpi-list input:checked').eq(i).data('code');
  737. shenpiList.push(code);
  738. }
  739. data.shenpiList = shenpiList.join(',');
  740. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function () {
  741. toastr.success('设置成功');
  742. setTimeout(function () {
  743. window.location.reload();
  744. }, 1000)
  745. })
  746. });
  747. // 设置会签、或签
  748. $('body').on('change', 'select[class*="audit-type-key"]', function() {
  749. const removes = $(this).parents('.d-flex').find('.remove-audit');
  750. if (removes.length === 0) return;
  751. const this_status = parseInt($(this).parents('.lc-show').siblings('.form-group').find('input:checked').val());
  752. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  753. const ids = [];
  754. const liParent = $(this).parents('li');
  755. removes.each((i, r) => { ids.push(parseInt(r.getAttribute('data-id'))); });
  756. const prop = {
  757. status: this_status,
  758. code: sp_type[this_code],
  759. audit_id: ids,
  760. audit_type: parseInt(this.value),
  761. type: 'audit-type',
  762. };
  763. if (prop.audit_type === auditType.key.common && ids.length > 1) {
  764. toastr.warning('设置个人审批前请先删除多余的审批人');
  765. this.value = this.getAttribute('data-type');
  766. return;
  767. }
  768. const _self = this;
  769. postData('/tender/'+ cur_tenderid +'/shenpi/audit/save', prop, function () {
  770. _self.setAttribute('data-type', _self.value);
  771. const auditGroup = auditUtils.setAuditType(this_code, prop.audit_type, liParent.index());
  772. liParent.html(auditUtils.getAuditGroupInnerHtml(this_code, auditGroup, liParent.index() + 1));
  773. });
  774. });
  775. class AuditAss {
  776. constructor() {
  777. this.spread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);
  778. this.sheet = this.spread.getActiveSheet();
  779. this.tree = createNewPathTree('base', {
  780. id: 'ledger_id',
  781. pid: 'ledger_pid',
  782. order: 'order',
  783. level: 'level',
  784. rootId: -1,
  785. });
  786. this.spreadSetting = {
  787. cols: [
  788. {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree'},
  789. {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@'},
  790. {title: '协同人', colSpan: '1', rowSpan: '2', field: 'ass_name', hAlign: 1, width: 100, formatter: '@'},
  791. ],
  792. emptyRows: 0,
  793. headRows: 1,
  794. headRowHeight: [25, 25],
  795. defaultRowHeight: 21,
  796. headerFont: '12px 微软雅黑',
  797. font: '12px 微软雅黑',
  798. readOnly: true,
  799. localCache: {
  800. key: 'ledger-cooperation',
  801. colWidth: true,
  802. }
  803. };
  804. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  805. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  806. const self = this;
  807. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  808. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  809. this.spread.bind(spreadNS.Events.SelectionChanged, function() {
  810. self.refreshOperate();
  811. });
  812. $('#stage_audits').change(function () {
  813. self.uid = $(this).val();
  814. });
  815. // 多人协同
  816. $('#cooperation').on('shown.bs.modal', function () {
  817. // 执行一些动作...
  818. // 更新新的多人协同表格信息
  819. const newUidList = [];
  820. $('.stage_div ul li').each(function (k, v) {
  821. const audit_type = parseInt($(v).find('select').val());
  822. if (audit_type !== auditType.key.common) return;
  823. const uid = $(v).find('button').eq(0).data('id');
  824. if(uid) newUidList.push({ order: k + 1, audit_id: uid });
  825. });
  826. const yb = _.find(accountList, { 'id': cur_uid });
  827. let newhtml = '<option value="' + yb.id + '">' + yb.name + '(原报)</option>';
  828. if(newUidList.length > 0) {
  829. for (const id of newUidList) {
  830. const audit = _.find(accountList, { 'id': id.audit_id });
  831. newhtml += '<option value="' + audit.id + '">' + audit.name + '(' + transFormToChinese(id.order) + '审)</option>';
  832. }
  833. }
  834. $('#stage_audits').html(newhtml);
  835. self.uid = cur_uid;
  836. self.initLedgerTree(cur_uid);
  837. });
  838. $('#del-audit-ass').click(function () {
  839. self.setAuditAssist();
  840. });
  841. $('body').on('click', 'button[asid]', function () {
  842. self.removeAuditAss(parseInt(this.getAttribute('asid')));
  843. });
  844. }
  845. set uid(id) {
  846. this._uid = parseInt(id);
  847. this._refreshAss();
  848. }
  849. get uid() {
  850. return this._uid;
  851. }
  852. _refreshAssTable(){
  853. $('#stage_audit').text($("#stage_audits option:selected").text());
  854. const html = [];
  855. for (const sa of this.showAssList) {
  856. const lid = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  857. 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>`);
  858. }
  859. $('#coo_table').html(html.join(''));
  860. }
  861. _refreshAssTree() {
  862. const ledgerAss = {};
  863. for (const sa of this.showAssList) {
  864. const ledger = sa.ass_ledger_id ? sa.ass_ledger_id.split(',') : [];
  865. ledger.forEach(l => { ledgerAss[l] = sa; });
  866. }
  867. for (const n of this.tree.nodes) {
  868. const la = ledgerAss[n.ledger_id];
  869. n.ass_audit_id = la ? la.ass_user_id : null;
  870. n.ass_name = la ? la.name : '';
  871. }
  872. SpreadJsObj.reloadColData(this.sheet, 2);
  873. }
  874. _refreshAss() {
  875. this.showAssList = _.filter(this.assList, { 'user_id': parseInt(this.uid) });
  876. this._refreshAssTable();
  877. this._refreshAssTree();
  878. }
  879. initLedgerTree(uid) {
  880. if (this.loaded && this.tid && this.tid === cur_tenderid) return;
  881. this.spread.refresh();
  882. const self = this;
  883. postData('/tender/' + cur_tenderid + '/shenpi/ass/load', {}, function (data) {
  884. self.loaded = true;
  885. self.tid = cur_tenderid;
  886. self.assList = data.auditAssList;
  887. self.tree.loadDatas(data.ledgerList);
  888. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  889. self.uid = uid;
  890. self.refreshOperate();
  891. }, null, true);
  892. }
  893. loadPostData(data) {
  894. if (data.add) {
  895. this.assList.push(data.add);
  896. }
  897. if (data.del) {
  898. this.assList.splice(this.assList.findIndex(x => { return x.id === data.del.id }), 1);
  899. }
  900. if (data.update) {
  901. for (const d of data.update) {
  902. const od = this.assList.find(x => { return x.id === d.id });
  903. if (!od) continue;
  904. od.ass_ledger_id = d.ass_ledger_id;
  905. }
  906. }
  907. this._refreshAss();
  908. }
  909. setAuditAssist(assist){
  910. const node = SpreadJsObj.getSelectObject(this.sheet);
  911. if (assist && node.ass_audit_id === assist.id) return;
  912. if (assist && assist.id === this.uid) {
  913. toastr.warning('请勿添加本人');
  914. return;
  915. }
  916. const self = this;
  917. const data = { type: 'audit-ass'};
  918. if (assist) {
  919. const newAss = this.showAssList.find(x => { return x.ass_user_id === assist.id; });
  920. if (!newAss) {
  921. 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 + '' };
  922. } else {
  923. data.update = [{ id: newAss.id, ass_ledger_id: newAss.ass_ledger_id + ',' + node.ledger_id}];
  924. }
  925. }
  926. if (node.ass_audit_id) {
  927. const orgAss = this.showAssList.find(x => { return x.ass_user_id === node.ass_audit_id; });
  928. const rela_lid = orgAss.ass_ledger_id ? orgAss.ass_ledger_id.split(',') : [];
  929. rela_lid.splice(rela_lid.indexOf(node.ledger_id + ''), 1);
  930. if (rela_lid.length === 0) {
  931. data.del = { id: orgAss.id };
  932. } else {
  933. if (!data.update) data.update = [];
  934. data.update.push({ id: orgAss.id, ass_ledger_id: rela_lid.join(',')});
  935. }
  936. }
  937. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', data, function (result) {
  938. self.loadPostData(result);
  939. self.refreshOperate();
  940. });
  941. }
  942. removeAuditAss(assistId) {
  943. const self = this;
  944. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', { type: 'audit-ass', del: { id: assistId } }, function (result) {
  945. self.loadPostData(result);
  946. self.refreshOperate();
  947. });
  948. }
  949. refreshOperate() {
  950. const node = SpreadJsObj.getSelectObject(this.sheet);
  951. if (node && node.ass_audit_id) {
  952. $('#del-audit-ass').show();
  953. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '替换协同人';
  954. } else {
  955. $('#del-audit-ass').hide();
  956. $('#audit-ass_dropdownMenuButton')[0].innerHTML = '添加协同人';
  957. }
  958. }
  959. }
  960. const auditAss = new AuditAss();
  961. class AuditUnion {
  962. constructor() {
  963. this.spread = SpreadJsObj.createNewSpread($('#union-spread')[0]);
  964. this.sheet = this.spread.getActiveSheet();
  965. this.tree = createNewPathTree('base', {
  966. id: 'ledger_id',
  967. pid: 'ledger_pid',
  968. order: 'order',
  969. level: 'level',
  970. rootId: -1,
  971. });
  972. this.selectUnion = [{ value: 0, text: '' }];
  973. this.spreadSetting = {
  974. cols: [
  975. {title: '编号', colSpan: '1', rowSpan: '1', field: 'code', hAlign: 0, width: 165, formatter: '@', cellType: 'tree', readOnly: true },
  976. {title: '名称', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true },
  977. {title: '协同人', colSpan: '1', rowSpan: '1', field: 'audit_id', hAlign: 1, width: 100, cellType: 'customizeCombo', comboItems: this.selectUnion },
  978. ],
  979. emptyRows: 0,
  980. headRows: 1,
  981. headRowHeight: [32],
  982. defaultRowHeight: 21,
  983. headerFont: '12px 微软雅黑',
  984. font: '12px 微软雅黑',
  985. };
  986. sjsSettingObj.setFxTreeStyle(this.spreadSetting, sjsSettingObj.FxTreeStyle.jz);
  987. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  988. const self = this;
  989. SpreadJsObj.addDeleteBind(this.spread, function() { return; });
  990. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  991. this.spread.bind(spreadNS.Events.EditEnded, function(e, info) {
  992. const node = SpreadJsObj.getSelectObject(info.sheet);
  993. if (!node) return;
  994. const refreshAuditId = [];
  995. if (node.audit_id) refreshAuditId.push(node.audit_id);
  996. const col = info.sheet.zh_setting.cols[info.col];
  997. node[col.field] = info.editingText;
  998. if (node.audit_id) refreshAuditId.push(node.audit_id);
  999. self.refreshUnionCount(refreshAuditId);
  1000. });
  1001. $('#union').on('shown.bs.modal', function() {
  1002. self.spread.refresh();
  1003. });
  1004. $('#union-ok').click(function() {
  1005. const data = self.getUnionAuditLedgerData();
  1006. postData(`/tender/${cur_tenderid}/shenpi/union/save`, data, function(result) {
  1007. $('#union').modal('hide');
  1008. });
  1009. });
  1010. $('body').on('click', '[name=clear-union]', function() {
  1011. const aid = parseInt(this.getAttribute('aid'));
  1012. for (const node of self.tree.nodes) {
  1013. if (node.audit_id === aid) node.audit_id = 0;
  1014. }
  1015. SpreadJsObj.reloadColData(self.sheet, 2);
  1016. self.refreshUnionCount(aid);
  1017. });
  1018. }
  1019. _refreshUnionTree() {
  1020. const ledgerAss = {};
  1021. for (const a of this.auditors) {
  1022. a.lid.forEach(l => { ledgerAss[l] = a; });
  1023. }
  1024. for (const n of this.tree.nodes) {
  1025. const la = ledgerAss[n.ledger_id];
  1026. n.audit_id = la ? la.audit_id : 0;
  1027. n.audit_name = la ? la.name : '';
  1028. }
  1029. SpreadJsObj.reloadColData(this.sheet, 2);
  1030. }
  1031. setUnionAuditors(auditors) {
  1032. this.auditors = auditors;
  1033. this.selectUnion.length = 1;
  1034. const html = [];
  1035. for (const auditor of auditors) {
  1036. auditor.lid = auditor.audit_ledger_id ? auditor.audit_ledger_id.split(',') : [];
  1037. 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>`);
  1038. this.selectUnion.push({ value: auditor.audit_id, text: auditor.name });
  1039. }
  1040. $('#union_table').html(html.join(''));
  1041. this._refreshUnionTree();
  1042. }
  1043. refreshUnionCount(auditId) {
  1044. const auditIds = auditId instanceof Array ? auditId : [auditId];
  1045. for (const aid of auditIds) {
  1046. const unionNodes = this.tree.nodes.filter(x => { return x.audit_id === aid; });
  1047. $(`span[aid=${aid}]`).html(unionNodes.length);
  1048. }
  1049. }
  1050. loadUnionData(sp_type, audit_order) {
  1051. const data = { sp_type, audit_order };
  1052. if (!this.loaded) data.ledger = 1;
  1053. const self = this;
  1054. postData(`/tender/${cur_tenderid}/shenpi/union/load`, data, function(result) {
  1055. self.loaded = true;
  1056. if (result.ledgerList) {
  1057. self.tree.loadDatas(result.ledgerList);
  1058. SpreadJsObj.loadSheetData(self.sheet, SpreadJsObj.DataType.Tree, self.tree);
  1059. }
  1060. self.setUnionAuditors(result.unionAuditors);
  1061. if (self.auditors.length > 0) {
  1062. $('#union').modal('show');
  1063. } else {
  1064. toastr.warning(`${audit_order}审未添加任何协同人,请先添加协同人再分配协同台账`);
  1065. }
  1066. });
  1067. }
  1068. getUnionAuditLedgerData() {
  1069. this.auditors.forEach(a => { a.lid = []; });
  1070. for (const node of this.tree.nodes) {
  1071. if (node.audit_id > 0) {
  1072. const relaAudit = this.auditors.find(x => { return x.audit_id === node.audit_id; });
  1073. if (relaAudit) relaAudit.lid.push(node.ledger_id);
  1074. }
  1075. }
  1076. return this.auditors.map(a => {
  1077. return { id: a.id, audit_ledger_id: a.lid.join(',') };
  1078. });
  1079. }
  1080. }
  1081. const auditUnion = new AuditUnion();
  1082. $('body').on('click', '[name=union-set]', function() {
  1083. auditUnion.loadUnionData(this.getAttribute('sp_type'), this.getAttribute('audit_order'));
  1084. });
  1085. class AuditMulti {
  1086. constructor() {
  1087. this.spread = SpreadJsObj.createNewSpread($('#multi-spread')[0]);
  1088. this.sheet = this.spread.getActiveSheet();
  1089. this.spreadSetting = {
  1090. cols: [
  1091. {title: '审批人', colSpan: '1', rowSpan: '1', field: 'name', hAlign: 1, width: 80, formatter: '@', readOnly: true },
  1092. {title: '分组/部门', colSpan: '1', rowSpan: '1', field: 'audit_group', hAlign: 0, width: 100, formatter: '@' },
  1093. {title: '顺序', colSpan: '1', rowSpan: '1', field: 'audit_group_order', hAlign: 1, width: 80 },
  1094. {title: '受限', colSpan: '1', rowSpan: '1', field: 'audit_group_limit', hAlign: 1, width: 60, cellType: 'checkbox' },
  1095. {title: '允许退回', colSpan: '1', rowSpan: '1', field: 'audit_checkno_valid', hAlign: 1, width: 60, cellType: 'checkbox' },
  1096. {title: '最少审批', colSpan: '1', rowSpan: '1', field: 'audit_group_need', hAlign: 1, width: 80 },
  1097. ],
  1098. emptyRows: 0,
  1099. headRows: 1,
  1100. headRowHeight: [32],
  1101. defaultRowHeight: 21,
  1102. headerFont: '12px 微软雅黑',
  1103. font: '12px 微软雅黑',
  1104. };
  1105. SpreadJsObj.initSheet(this.sheet, this.spreadSetting);
  1106. const self = this;
  1107. SpreadJsObj.selChangedRefreshBackColor(this.sheet);
  1108. $('#multi').on('shown.bs.modal', function() {
  1109. self.spread.refresh();
  1110. });
  1111. $('#multi-ok').click(function() {
  1112. const data = self.getAuditData();
  1113. if (self.audit_type === auditType.key.and) {
  1114. const exist = !data[0].audit_group_order ? data.find(x => { return !!x.audit_group_order; }) : data.find(x => { return !x.audit_group_order; });
  1115. if (exist) {
  1116. toastr.error('如需设置顺序,所有审批人均应配置顺序');
  1117. return;
  1118. }
  1119. } else if (self.audit_type === auditType.key.multi) {
  1120. const exist = data.find(x => { return !x.audit_group || !x.audit_group_order; });
  1121. if (exist) {
  1122. toastr.error('分组审批时,分组/部门、顺序均不可为空');
  1123. return;
  1124. }
  1125. } else if (self.audit_type === auditType.key.or) {
  1126. for (const d of data) {
  1127. if (!d.audit_group_need) {
  1128. toastr.error('或签必须设置最少审批人数');
  1129. return;
  1130. }
  1131. if (d.audit_group_need < 1 || d.audit_group_need >= data.length) {
  1132. toastr.error('最少审批人数必须大于0,小于审批人数');
  1133. return;
  1134. }
  1135. }
  1136. }
  1137. postData(`/tender/${cur_tenderid}/shenpi/multi/save`, data, function(result) {
  1138. const flow = sp_lc.find(x => { return x.code === self.sp_type; });
  1139. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == self.audit_order});
  1140. for (const d of result) {
  1141. const md = multiData.find(x => { return x.id === d.id; });
  1142. if (!md) continue;
  1143. for (const prop in d) {
  1144. md[prop] = d[prop];
  1145. }
  1146. }
  1147. multiData.sort((a, b) => {
  1148. if (a.audit_group === b.audit_group) {
  1149. return a.audit_group_order - b.audit_group_order;
  1150. } else {
  1151. return a.audit_group === b.audit_group ? 0 : (a.audit_group < b.audit_group ? -1 : 1)
  1152. }
  1153. });
  1154. $('#multi').modal('hide');
  1155. $(self.multiBtn).parent().parent().html(auditUtils.getAuditGroupInnerHtml(self.sp_type, multiData, self.audit_order));
  1156. });
  1157. });
  1158. }
  1159. loadData(audit_type, sp_type, audit_order, multiBtn) {
  1160. this.audit_type = audit_type;
  1161. if (this.audit_type === auditType.key.multi) {
  1162. $('#multi-title').html('分组审批');
  1163. } else if (this.audit_type === auditType.key.and) {
  1164. $('#multi-title').html('会签设置');
  1165. } else if (this.audit_type === auditType.key.or) {
  1166. $('#multi-title').html('或签设置');
  1167. }
  1168. $('[name=set-hint]').hide();
  1169. $(`[name=set-hint][htype=${audit_type}]`).show();
  1170. this.multiBtn = multiBtn;
  1171. this.sp_type = sp_type;
  1172. this.audit_order = audit_order;
  1173. const flow = sp_lc.find(x => { return x.code === sp_type; });
  1174. const multiData = flow.auditGroupList.find(x => { return x[0].audit_order == audit_order});
  1175. this.data = JSON.parse(JSON.stringify(multiData));
  1176. const typeNeedCol = [
  1177. { key: auditType.key.multi, cols: ['name', 'audit_group', 'audit_group_limit', 'audit_group_order', 'audit_checkno_valid'] },
  1178. { key: auditType.key.and, cols: ['name', 'audit_group_order', 'audit_checkno_valid'] },
  1179. { key: auditType.key.or, cols: ['name', 'audit_group_need'] },
  1180. ];
  1181. const needCol = typeNeedCol.find(x => { return x.key === this.audit_type; });
  1182. this.sheet.zh_setting.cols.forEach(c => {
  1183. c.visible = needCol.cols.indexOf(c.field) >= 0;
  1184. });
  1185. SpreadJsObj.refreshColumnVisible(this.sheet);
  1186. SpreadJsObj.loadSheetData(this.sheet, SpreadJsObj.DataType.Data, this.data);
  1187. $('#multi').modal('show');
  1188. }
  1189. getAuditData() {
  1190. const sheet = this.sheet;
  1191. const col = { group: 1, order: 2, limit: 3, checkno: 4, need: 5, };
  1192. const updateData = this.data.map((x, i) => {
  1193. const data = { id: x.id };
  1194. data.audit_group = this.audit_type === auditType.key.multi ? sheet.getText(i, col.group) : '';
  1195. const order = sheet.getText(i, col.order);
  1196. data.audit_group_order = order ? _.parseInt(order) || 0 : 0;
  1197. data.audit_group_limit = this.audit_type === auditType.key.multi ? (sheet.getValue(i, col.limit) ? 1 : 0) : 0;
  1198. data.audit_checkno_valid = sheet.getValue(i, col.checkno) ? 1 : 0;
  1199. const need = sheet.getText(i, col.need);
  1200. data.audit_group_need = this.audit_type === auditType.key.or ? (need ? _.parseInt(need) || 1 : 1) : 1;
  1201. return data;
  1202. });
  1203. return updateData;
  1204. }
  1205. }
  1206. const auditMulti = new AuditMulti();
  1207. $('body').on('click', '[name=multi-set]', function() {
  1208. auditMulti.loadData(auditType.key.multi, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1209. });
  1210. $('body').on('click', '[name=and-set]', function() {
  1211. auditMulti.loadData(auditType.key.and, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1212. });
  1213. $('body').on('click', '[name=or-set]', function() {
  1214. auditMulti.loadData(auditType.key.or, this.getAttribute('sp_type'), this.getAttribute('audit_order'), this);
  1215. });
  1216. $.subMenu({
  1217. menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',
  1218. toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',
  1219. key: 'menu.1.0.0',
  1220. miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',
  1221. callback: function (info) {
  1222. if (info.mini) {
  1223. $('.panel-title').addClass('fluid');
  1224. $('#sub-menu').removeClass('panel-sidebar');
  1225. } else {
  1226. $('.panel-title').removeClass('fluid');
  1227. $('#sub-menu').addClass('panel-sidebar');
  1228. }
  1229. autoFlashHeight();
  1230. }
  1231. });
  1232. let timer2 = null;
  1233. let oldSearchVal2 = null;
  1234. $('body').on('input propertychange', '#batch input[name="audit-name"]', function(e) {
  1235. oldSearchVal2 = e.target.value;
  1236. timer2 && clearTimeout(timer2);
  1237. timer2 = setTimeout(() => {
  1238. const newVal = $(this).val();
  1239. const resultLength = $('#tender-list').find('.result').length;
  1240. if (resultLength > 0) {
  1241. let content = $('#tender-list').html();
  1242. const replaceStr = $('#tender-list').find('.result').eq(0).html();
  1243. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  1244. content = content.replace(regExp2, replaceStr);
  1245. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  1246. content = content.replace(regExp3, replaceStr);
  1247. $('#tender-list').html(content);
  1248. }
  1249. $('#search-result').text('0/0');
  1250. $('#up-search').attr('disabled', true);
  1251. $('#down-search').attr('disabled', true);
  1252. if (newVal && newVal === oldSearchVal2) {
  1253. const regExp = new RegExp(newVal, 'g');
  1254. for (let i = 0; i < $('#tender-list tr').length; i++) {
  1255. if (_.includes($('#tender-list tr').eq(i).children('td').eq(2).html(), newVal)) {
  1256. $('#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>'))
  1257. }
  1258. }
  1259. const resultLength2 = $('#tender-list').find('.result').length;
  1260. if (resultLength2 > 0) {
  1261. $('#tender-list').find('.result').eq(0).css('background', 'orange');
  1262. $('#search-result').text('1/' + resultLength2);
  1263. $('#up-search').attr('disabled', false);
  1264. $('#down-search').attr('disabled', false);
  1265. }
  1266. }
  1267. if($('#tender-list').find('.result').length > 0) {
  1268. const X = $('#tender-list').find('.result').eq(0).offset().top;
  1269. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1270. }
  1271. }, 400);
  1272. });
  1273. $('#up-search').on('click', function () {
  1274. const cur = parseInt($('#search-result').text().split('/')[0]);
  1275. const total = parseInt($('#search-result').text().split('/')[1]);
  1276. const now = cur - 1 !== 0 ? cur - 1: total;
  1277. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1278. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1279. // $('#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;">'))
  1280. // $('#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;">'))
  1281. $('#search-result').text(now + '/' + total);
  1282. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1283. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() - 30);
  1284. });
  1285. $('#down-search').on('click', function () {
  1286. const cur = parseInt($('#search-result').text().split('/')[0]);
  1287. const total = parseInt($('#search-result').text().split('/')[1]);
  1288. const now = cur + 1 > total ? 1: cur + 1;
  1289. $('#tender-list').find('.result').eq(cur-1).css('background', 'yellow');
  1290. $('#tender-list').find('.result').eq(now-1).css('background', 'orange');
  1291. // $('#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;">'))
  1292. // $('#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;">'))
  1293. $('#search-result').text(now + '/' + total);
  1294. const X = $('#tender-list').find('.result').eq(now-1).offset().top;
  1295. $('#tender-list').scrollTop(X - $('#tender-list').offset().top + $('#tender-list').scrollTop() -30);
  1296. });
  1297. // 审批组
  1298. $('body').on('click', '.show-spzsave', function () {
  1299. const this_code = $(this).attr('data-code');
  1300. const groupId = $(this).attr('data-group') || null;
  1301. const flow = sp_lc.find(x => { return x.code === this_code; });
  1302. $('#save-code').val(this_code);
  1303. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1304. if (group) {
  1305. $('#save-group-id').val(group.id);
  1306. $('#spzsave input[name="group_name"]').val(group.name);
  1307. $('#show-delete-group-btn').show();
  1308. } else {
  1309. $('#save-group-id').val('');
  1310. $('#spzsave input[name="group_name"]').val('');
  1311. $('#show-delete-group-btn').hide();
  1312. }
  1313. if (this_code === 'change') {
  1314. if (group) {
  1315. $('#show-change-type input').each(function () {
  1316. if (group.change_type[$(this).data('type')]) {
  1317. $(this).prop('checked', true);
  1318. } else {
  1319. $(this).prop('checked', false);
  1320. }
  1321. });
  1322. } else {
  1323. $('#show-change-type input').each(function () {
  1324. $(this).prop('checked', false);
  1325. });
  1326. $('#show-change-type input[data-type="change"]').prop('checked', true);
  1327. }
  1328. $('#show-change-type input').removeAttr('disabled');
  1329. $('#show-change-type').show();
  1330. } else {
  1331. $('#show-change-type input').attr('disabled', true);
  1332. $('#show-change-type').hide();
  1333. }
  1334. $('#spzsave').modal('show');
  1335. });
  1336. $('#save-group-btn').click(function () {
  1337. const name = _.trim($('#spzsave input[name="group_name"]').val());
  1338. if (!name) {
  1339. toastr.error('审批组名称不能为空');
  1340. return false;
  1341. }
  1342. if (name.length > 50) {
  1343. toastr.error('审批组名称不能超过50个字符');
  1344. return false;
  1345. }
  1346. const code = $('#save-code').val();
  1347. const prop = {
  1348. type: 'save-group',
  1349. name,
  1350. code,
  1351. }
  1352. const groupId = $('#save-group-id').val();
  1353. const flow = sp_lc.find(x => { return x.code === code; });
  1354. if (flow.groupList && flow.groupList.length >= 0 && _.findIndex(flow.groupList, function (item) {
  1355. return item.name === name && item.id !== parseInt(groupId);
  1356. }) !== -1) {
  1357. toastr.error('审批组名称已存在, 请更改名称');
  1358. return false;
  1359. }
  1360. if (groupId) {
  1361. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1362. if (!group) {
  1363. toastr.error('审批组不存在');
  1364. return false;
  1365. }
  1366. prop.groupId = group.id;
  1367. }
  1368. if (code === 'change') {
  1369. const change_type = {};
  1370. let change_flag = false;
  1371. $('#show-change-type input').each(function () {
  1372. change_type[$(this).data('type')] = $(this).prop('checked');
  1373. if ($(this).prop('checked')) {
  1374. change_flag = true;
  1375. }
  1376. });
  1377. if (!change_flag) {
  1378. toastr.error('请至少选择一种变更显示模块');
  1379. return false;
  1380. }
  1381. prop.change_type = change_type;
  1382. }
  1383. console.log(prop);
  1384. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1385. flow.auditGroupList = data.group.auditGroupList || [];
  1386. if (groupId) {
  1387. const index = flow.groupList.findIndex(x => { return x.id === parseInt(groupId); });
  1388. flow.groupList[index] = data.group;
  1389. } else {
  1390. if (!flow.groupList) flow.groupList = [];
  1391. for (const g of flow.groupList) {
  1392. g.is_select = 0;
  1393. }
  1394. flow.groupList.push(data.group);
  1395. }
  1396. // 配置页面
  1397. let addhtml = auditUtils.getGroupHtml(flow, code);
  1398. addhtml += '<ul class="list-unstyled">\n';
  1399. addhtml += auditUtils.getgdsplHtml(flow, code);
  1400. addhtml += '</ul>\n';
  1401. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1402. $('#spzsave').modal('hide');
  1403. });
  1404. });
  1405. // 切换审批组
  1406. $('body').on('change', '.group-list', function () {
  1407. const this_code = $(this).parents('.lc-show').siblings('.form-group').find('input:checked').data('code');
  1408. const flow = sp_lc.find(x => { return x.code === this_code; });
  1409. const groupId = parseInt($(this).val());
  1410. const _self = $(this);
  1411. const prop = {
  1412. type: 'change-group',
  1413. groupId,
  1414. }
  1415. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1416. flow.groupList.forEach(function (item) {
  1417. item.is_select = 0;
  1418. });
  1419. const group = flow.groupList.find(x => { return x.id === groupId; });
  1420. group.is_select = 1;
  1421. flow.auditGroupList = group.auditGroupList;
  1422. const addhtml = auditUtils.getgdsplHtml(flow, this_code);
  1423. _self.parents('.lc-show').children('ul').html(addhtml);
  1424. _self.parents('.lc-show').find('.edit-spzsave').attr('data-group', groupId);
  1425. });
  1426. });
  1427. $('#show-delete-group-btn').click(function () {
  1428. const code = $('#save-code').val();
  1429. const groupId = $('#save-group-id').val();
  1430. const flow = sp_lc.find(x => { return x.code === code; });
  1431. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1432. if (!group) {
  1433. toastr.error('该审批组不存在');
  1434. return false;
  1435. }
  1436. $('#delete-group-name').text(group.name);
  1437. $('#delete-group-id').val(group.id);
  1438. $('#delete-code').val(code);
  1439. $('#spzsave').modal('hide');
  1440. $('#spzdelete').modal('show');
  1441. });
  1442. $('#delete-group-btn').click(function () {
  1443. const code = $('#delete-code').val();
  1444. const groupId = $('#delete-group-id').val();
  1445. const flow = sp_lc.find(x => { return x.code === code; });
  1446. const group = groupId ? flow.groupList.find(x => { return x.id === parseInt(groupId); }) : null;
  1447. if (!group) {
  1448. toastr.error('该审批组不存在');
  1449. return false;
  1450. }
  1451. const prop = {
  1452. type: 'delete-group',
  1453. groupId: group.id,
  1454. }
  1455. console.log(prop);
  1456. postData('/tender/' + cur_tenderid + '/shenpi/audit/save', prop, function (data) {
  1457. // const flow = findSplc(code);
  1458. const index = flow.groupList.findIndex(x => { return x.id === group.id; });
  1459. flow.groupList.splice(index, 1);
  1460. flow.auditGroupList = flow.groupList.length > 0 ? flow.groupList[0].auditGroupList : [];
  1461. if (flow.groupList.length > 0) flow.groupList[0].is_select = 1;
  1462. // 配置页面
  1463. let addhtml = auditUtils.getGroupHtml(flow, code);
  1464. addhtml += '<ul class="list-unstyled">\n';
  1465. addhtml += auditUtils.getgdsplHtml(flow, code);
  1466. addhtml += '</ul>\n';
  1467. $('.' + code + '_div').children('.lc-show').html(addhtml);
  1468. $('#spzdelete').modal('hide');
  1469. });
  1470. });
  1471. });
  1472. // 审批流程-审批人html 生成
  1473. function makeAudit(audit, i = '终') {
  1474. return '<li class="d-flex justify-content-start mb-3">\n' +
  1475. ' <span class="col-auto">'+ i +'审</span>\n' +
  1476. ' <span class="col-7 spr-span">\n' +
  1477. ' <span class="d-inline-block"></span>\n' +
  1478. ' <span class="d-inline-block"><span class="badge badge-light">'+ audit.name +' <span class="dropdown">\n' +
  1479. ' <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' +
  1480. ' <div class="dropdown-menu">\n' +
  1481. ' <a class="dropdown-item" href="javascript:void(0);">确认移除审批人?</a>\n' +
  1482. ' <div class="dropdown-divider"></div>\n' +
  1483. ' <div class="px-2 py-1 text-center">\n' +
  1484. ' <button class="remove-audit btn btn-sm btn-danger" data-id="' + audit.audit_id + '">移除</button>\n' +
  1485. ' <button class="btn btn-sm btn-secondary">取消</button>\n' +
  1486. ' </div>\n' +
  1487. ' </div>\n' +
  1488. ' </span> ' +
  1489. // '<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' +
  1490. ' </span></span></span>\n' +
  1491. ' </li>';
  1492. }
  1493. // 审批流程-选择审批人html 生成
  1494. function makeSelectAudit(code, i = '终') {
  1495. let divhtml = '';
  1496. accountGroup.forEach((group, idx) => {
  1497. let didivhtml = '';
  1498. if(group) {
  1499. group.groupList.forEach(item => {
  1500. 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' +
  1501. '<p class="mb-0 d-flex"><span class="text-primary">' + item.name + '</span><span\n' +
  1502. ' class="ml-auto">' + item.mobile + '</span></p>\n' +
  1503. ' <span class="text-muted">' + item.role + '</span>\n' +
  1504. ' </dd>\n' : '';
  1505. });
  1506. 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' +
  1507. ' <div class="dd-content" data-toggleid="' + idx + '">\n' + didivhtml +
  1508. ' </div>\n';
  1509. }
  1510. });
  1511. let html = '<li class="d-flex justify-content-start mb-3">\n' +
  1512. ' <span class="col-auto">' + i + '审</span>\n' +
  1513. ' <span class="col-7 spr-span">\n' +
  1514. ' <span class="d-inline-block">\n' +
  1515. ' <div class="dropdown text-right">\n' +
  1516. ' <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' +
  1517. ' 选择审批人\n' +
  1518. ' </button>\n' +
  1519. ' <div class="dropdown-menu dropdown-menu-right" id="' + code + '_dropdownMenu" aria-labelledby="' + code + '_dropdownMenuButton" style="width:220px">\n' +
  1520. ' <div class="mb-2 p-2"><input class="form-control form-control-sm gr-search"\n' +
  1521. ' placeholder="姓名/手机 检索" autocomplete="off" data-code="' + code + '"></div>\n' +
  1522. ' <dl class="list-unstyled book-list">\n' + divhtml +
  1523. ' </dl>\n' +
  1524. ' </div>\n' +
  1525. ' </div>\n' +
  1526. ' </span>\n' +
  1527. ' </span>\n' +
  1528. ' </li>';
  1529. return html;
  1530. }