setting_manage.js 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. // 游客及投资管理用户添加到其他标段
  2. const tenderTree4User = [];
  3. let parentId4User = 0;
  4. // 分类数据排序
  5. function sortCategory4User() {
  6. category.sort(function (a, b) {
  7. return a.level ? (b.level ? a.level - b.level : -1) : a.id - b.id;
  8. });
  9. }
  10. // 初始化TenderTree数据
  11. function initTenderTree4User () {
  12. const levelCategory = category.filter(function (c) {
  13. return c.level && c.level > 0;
  14. });
  15. function findCategoryNode4User(cid, value, array) {
  16. for (const a of array) {
  17. if (a.cid === cid && a.vid === value) {
  18. return a;
  19. }
  20. }
  21. }
  22. function getCategoryNode4User(category, value, parent, i = null) {
  23. const array = parent ? parent.children : tenderTree4User;
  24. let cate = findCategoryNode4User(category.id, value, array);
  25. if (!cate) {
  26. const cateValue = findNode2('id', value, category.value);
  27. if (!cateValue) return null;
  28. cate = {
  29. cid: category.id,
  30. vid: value,
  31. name: cateValue.value,
  32. children: [],
  33. level: i ? i : category.level,
  34. sort_id: ++parentId4User,
  35. sort: cateValue.sort,
  36. };
  37. array.push(cate);
  38. }
  39. return cate;
  40. }
  41. function loadTenderCategory4User (tender) {
  42. let tenderCategory = null;
  43. for (const [index,lc] of levelCategory.entries()) {
  44. const tenderCate = findNode2('cid', lc.id, tender.category);
  45. if (tenderCate) {
  46. tenderCategory = getCategoryNode4User(lc, tenderCate.value, tenderCategory);
  47. } else {
  48. if (index === 0 && tender.category) {
  49. for (const [i,c] of tender.category.entries()) {
  50. const cate = findNode2('id', c.cid, category);
  51. if (cate) tenderCategory = getCategoryNode4User(cate, c.value, tenderCategory, i+1);
  52. }
  53. }
  54. return tenderCategory;
  55. }
  56. }
  57. return tenderCategory;
  58. }
  59. tenderTree4User.splice(0, tenderTree4User.length);
  60. for (const t of tenders) {
  61. t.valid = true;
  62. delete t.level;
  63. if (t.category && levelCategory.length > 0) {
  64. const parent = loadTenderCategory4User(t);
  65. if (parent) {
  66. t.level = parent.level + 1;
  67. parent.children.push(t);
  68. } else {
  69. tenderTree4User.push(t);
  70. }
  71. } else {
  72. tenderTree4User.push(t);
  73. }
  74. }
  75. sortTenderTree(tenderTree4User);
  76. }
  77. function recursiveGetTenderNodeHtml4User (node, arr, pid) {
  78. const html = [];
  79. html.push('<tr pid="' + pid + '">');
  80. // 名称
  81. html.push('<td class="in-' + node.level + '">');
  82. if (node.cid) {
  83. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  84. } else {
  85. html.push('<span class="text-muted mr-2">');
  86. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  87. html.push('</span>');
  88. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  89. html.push('<a href="javascript: void(0)" id="' + node.id + '">', node.name, '</a>');
  90. }
  91. html.push('</td>');
  92. html.push('<td>');
  93. if (!node.cid) {
  94. html.push('<input data-tid="'+ node.id +'" type="checkbox"'+ (cur_tenderid === node.id ? ' checked disabled' : '') +'>');
  95. }
  96. html.push('</td>');
  97. html.push('</tr>');
  98. if (node.children) {
  99. for (const c of node.children) {
  100. html.push(recursiveGetTenderNodeHtml4User(c, node.children, node.sort_id));
  101. }
  102. }
  103. return html.join('');
  104. }
  105. // 根据TenderTree数据获取Html代码
  106. function getTenderTreeHtml4User () {
  107. if (tenderTree4User.length > 0) {
  108. const html = [];
  109. html.push('<table class="table table-hover table-bordered">');
  110. html.push('<thead>', '<tr>');
  111. html.push('<th>名称</th>');
  112. html.push('<th width="40">选择</th>');
  113. html.push('</tr>', '</thead>');
  114. parentId4User = 0;
  115. for (const t of tenderTree4User) {
  116. html.push(recursiveGetTenderNodeHtml4User(t, tenderTree4User, ''));
  117. }
  118. html.push('</table>');
  119. return html.join('');
  120. } else {
  121. return EmptyTenderHtml.join('');
  122. }
  123. }
  124. function recursiveGetFilterTenderNodeHtml (node, arr) {
  125. const html = [];
  126. html.push(`<tr ${node.id ? 'tid="'+ node.id +'"' : ''}>`);
  127. // 名称
  128. html.push('<td class="in-' + node.level + '">');
  129. if (node.cid) {
  130. html.push('<i class="fa fa-folder-o"></i> ', node.name);
  131. } else {
  132. html.push('<span class="text-muted mr-2">');
  133. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  134. html.push('</span>', node.name);
  135. }
  136. html.push('</td>');
  137. html.push('<td class="text-center">');
  138. if (!node.cid) {
  139. html.push(`<input data-tid="${node.id}" data-type="filter_budget" type="checkbox" ${node.filter_budget ? 'checked' : ''}>`);
  140. }
  141. html.push('</td>');
  142. html.push('<td class="text-center">');
  143. if (!node.cid) {
  144. html.push(`<input data-tid="${node.id}" data-type="filter_fund" type="checkbox" ${node.filter_fund ? 'checked' : ''}>`);
  145. }
  146. html.push('</td>');
  147. html.push('</tr>');
  148. if (node.children) {
  149. for (const c of node.children) {
  150. html.push(recursiveGetFilterTenderNodeHtml(c, node.children));
  151. }
  152. }
  153. return html.join('');
  154. }
  155. function getFilterTenderTreeHtml() {
  156. const html = [];
  157. for (const t of tenderTree4User) {
  158. html.push(recursiveGetFilterTenderNodeHtml(t, tenderTree4User));
  159. }
  160. $('#filter-tender-list').html(html.join(''));
  161. }
  162. $(document).ready(() => {
  163. autoFlashHeight();
  164. function getObjHeight(select) {
  165. return select.length > 0 ? select.height() : 0;
  166. }
  167. const cHeader = getObjHeight($(".c-header"));
  168. $('.tab-content').height($(window).height()-cHeader-90+53-46);
  169. if (typeof approvalOnly !== 'undefined' && approvalOnly) {
  170. initTenderApprovalPage();
  171. return;
  172. }
  173. const tabTypes = {
  174. tourist: '游客',
  175. schedule: '标段进度',
  176. contract: '合同管理',
  177. construction: '施工日志',
  178. quality: '质量管理',
  179. safe: '安全管理',
  180. };
  181. const tabTypeKeys = ['tourist', 'schedule', 'contract', 'construction', 'quality', 'safe'];
  182. // 单个tenderPermission字段用这个
  183. const tenderPermissionKeys = ['schedule'];
  184. // 多个tenderPermission字段融合处理用这个
  185. const tPsKeys = {
  186. quality: ['quality', 'inspection'],
  187. safe: ['safe_inspection', 'safe_payment'],
  188. };
  189. const $filterTenderDone = $('body #filter-tender-done')
  190. if (window.location.search && window.location.search.split('done=')[1]) {
  191. $filterTenderDone.prop('checked', window.location.search.split('done=')[1] === '1' ? true : false);
  192. } else {
  193. $filterTenderDone.prop('checked', true);
  194. }
  195. $filterTenderDone.on('change', function() {
  196. const isChecked = $(this).is(':checked');
  197. if (isChecked) {
  198. window.location.href = `/sp/${spid}/setting/manage?done=1`;
  199. } else {
  200. window.location.href = `/sp/${spid}/setting/manage?done=0`;
  201. }
  202. });
  203. $('body').on('click', '.c-body .tender-info', function () {
  204. $('.c-body .tender-info').removeClass('table-warning');
  205. $(this).addClass('table-warning');
  206. const tid = parseInt($(this).attr('data-id'));
  207. if (!tid) {
  208. toastr.warning('不存在标段无法设置');
  209. return;
  210. }
  211. // 请求获取右侧列表信息
  212. postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'msg', tid: parseInt($(this).attr('data-id'))}, function (result) {
  213. sp_lc = result.shenpi.sp_lc;
  214. sp_type = result.shenpi.sp_type;
  215. sp_status = result.shenpi.sp_status;
  216. sp_status_list = result.shenpi.sp_status_list;
  217. cur_tenderid = result.tender.id;
  218. cur_uid = result.tender.user_id;
  219. setShenpiHtml(result.shenpi, result.tender, result.revising);
  220. setTouristHtml(result.tourists);
  221. // setScheduleHtml(result.scheduleAuditList);
  222. setContractHtml(result.contractAuditList);
  223. setConstructionHtml(result.constructionAuditList);
  224. for (const tpkey of tenderPermissionKeys) {
  225. setTenderPermissionHtml(result[tpkey + 'AuditList'], tpkey);
  226. }
  227. for (const tpk in tPsKeys) {
  228. setTenderPermissionsHtml(result[tpk + 'AuditList'], tpk, tPsKeys[tpk]);
  229. }
  230. resetAddUserHtml();
  231. });
  232. });
  233. setTimeout(function () {
  234. $('.c-body .tender-info').eq(0).click();// 需要延时加载
  235. }, 500);
  236. $('body').on('click', '.nav .nav-link', function () {
  237. $('#contract-tip').hide();
  238. if ($(this).attr('href') === '#splc') {
  239. $('#user-set').hide();
  240. } else {
  241. $('#user-set').show();
  242. const href = $(this).attr('href');
  243. if (href === '#guest') {
  244. $('#add_user_dropdownMenuButton').attr('data-type', 'tourist');
  245. // } else if (href === '#tzpro') {
  246. // $('#add_user_dropdownMenuButton').attr('data-type', 'schedule');
  247. } else if (href === '#htgl') {
  248. $('#add_user_dropdownMenuButton').attr('data-type', 'contract');
  249. $('#contract-tip').show();
  250. } else if (href === '#sgrz') {
  251. $('#add_user_dropdownMenuButton').attr('data-type', 'construction');
  252. } else if (_.includes(tenderPermissionKeys, $(this).attr('href').substring(1))) {
  253. $('#add_user_dropdownMenuButton').attr('data-type', $(this).attr('href').substring(1));
  254. } else if (_.includes(Object.keys(tPsKeys), $(this).attr('href').substring(1))) {
  255. $('#add_user_dropdownMenuButton').attr('data-type', $(this).attr('href').substring(1));
  256. }
  257. let currentNavType = null;
  258. if (href === '#guest') currentNavType = 'tourist';
  259. else if (href === '#tzpro') currentNavType = 'schedule';
  260. else if (href === '#htgl') currentNavType = 'contract';
  261. else if (href === '#sgrz') currentNavType = 'construction';
  262. else if (href === '#quality') currentNavType = 'quality';
  263. else if (href === '#safe') currentNavType = 'safe';
  264. if(currentNavType) {
  265. setTimeout(() => updateSelectedMarks(), 0);
  266. }
  267. }
  268. });
  269. $('body').on('click', '.c-body a', function (e) {
  270. e.stopPropagation();
  271. });
  272. // 权限设置
  273. $('body').on('click', '#tourist-users .set-tourist-permission', function () {
  274. const id = parseInt($(this).data('id'));
  275. const permission = {
  276. file: ($(this).attr('name') === 'file' ? $(this).is(':checked') : $('#' + id + '_file').is(':checked')) ? 1 : 0,
  277. tag: ($(this).attr('name') === 'tag' ? $(this).is(':checked') : $('#' + id + '_tag').is(':checked')) ? 1 : 0,
  278. }
  279. const prop = {
  280. id,
  281. type: 'permission',
  282. permission,
  283. }
  284. console.log(prop);
  285. postData('/tender/' + cur_tenderid + '/tourist/audit/save', prop, function (data) {
  286. });
  287. });
  288. // 权限更改
  289. // $('body').on('click', '#schedule-users input[type="checkbox"]', function () {
  290. // let permission = scPermission.no;
  291. // const value = parseInt($(this).data('zhi'));
  292. // if ($(this).is(':checked')) {
  293. // if (value === scPermission.edit) {
  294. // permission = scPermission.edit;
  295. // $(this).parents('td').siblings().find('input').prop('checked', true);
  296. // } else if (value === scPermission.show) {
  297. // permission = scPermission.show;
  298. // }
  299. // } else {
  300. // if (value === scPermission.edit) {
  301. // permission = scPermission.show;
  302. // } else if (value === scPermission.show) {
  303. // permission = scPermission.no;
  304. // $(this).parents('td').siblings().find('input').prop('checked', false);
  305. // }
  306. // }
  307. // const id = parseInt($(this).data('id'));
  308. // const prop = {
  309. // id,
  310. // permission,
  311. // type: 'edit',
  312. // };
  313. // const _self = $(this);
  314. // postData('/tender/' + cur_tenderid + '/schedule/audit/save', prop, function (data) {
  315. // });
  316. // });
  317. // 权限更改
  318. $('body').on('click', '#contract-users input[type="checkbox"]', function () {
  319. const type = $(this).attr('data-type');
  320. const value = $(this).is(':checked') ? 1 : 0;
  321. const id = parseInt($(this).val());
  322. const updateInfo = { uid: id };
  323. updateInfo[type] = value;
  324. postData(`/sp/${spid}/contract/tender/${cur_tenderid}/audit/save`, { type: 'save-permission', updateData: updateInfo }, function (result) {
  325. })
  326. });
  327. // 权限更改
  328. $('body').on('click', '#construction-users input[type="checkbox"]', function () {
  329. const id = parseInt($(this).data('id'));
  330. const prop = {
  331. type: 'save-report',
  332. updateData: {
  333. id,
  334. is_report: $(this).is(':checked') ? 1 : 0,
  335. }
  336. };
  337. const _self = $(this);
  338. postData('/sp/' + spid + '/construction/' + cur_tenderid + '/audit/save', prop, function (data) {
  339. });
  340. });
  341. for (const tpKey of tenderPermissionKeys) {
  342. $('body').on('click', `#${tpKey}-users input[type="checkbox"]`, function () {
  343. const uid = parseInt($(this).parents('tr').data('uid'));
  344. const member = {
  345. uid,
  346. };
  347. member[tpKey] = [1];
  348. $(this).parents('tr').find('input[type="checkbox"]').each(function () {
  349. if ($(this).is(':checked')) {
  350. member[tpKey].push($(this).data('value'));
  351. }
  352. });
  353. const prop = {
  354. type: 'save-permission',
  355. uid,
  356. members: [member],
  357. key: tpKey,
  358. };
  359. const _self = $(this);
  360. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', prop, function (data) {
  361. });
  362. });
  363. }
  364. for (const tPsKey in tPsKeys) {
  365. $('body').on('click', `#${tPsKey}-users input[type="checkbox"]`, function () {
  366. const uid = parseInt($(this).parents('tr').data('uid'));
  367. const member = {
  368. uid,
  369. };
  370. const key = $(this).data('key');
  371. member[key] = [];
  372. if ($(this).data('block') === 'view' && !$(this).is(':checked')) {
  373. $(this).parents('tr').find(`input[data-key="${key}"]`).prop('checked', false);
  374. } else {
  375. let viewFlag = false;
  376. $(this).parents('tr').find(`input[data-key="${key}"]`).each(function () {
  377. if ($(this).is(':checked')) {
  378. if ($(this).data('block') !== 'view') {
  379. member[key].push(1);
  380. $(this).parents('tr').find(`input[data-key="${key}"][data-block="view"]`).prop('checked', true);
  381. viewFlag = true;
  382. }
  383. member[key].push($(this).data('value'));
  384. }
  385. });
  386. }
  387. const prop = {
  388. type: 'save-permission',
  389. uid,
  390. members: [member],
  391. key,
  392. };
  393. const _self = $(this);
  394. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', prop, function (data) {
  395. });
  396. });
  397. }
  398. for (const key of tabTypeKeys) {
  399. $('body').on('click', `#${key}-users .remove-${key}-user`, function () {
  400. $('#remove_user_type').val(key);
  401. $('#remove_user_id').val($(this).data('id'));
  402. $('#show_id').val($(this).data('show-id'));
  403. });
  404. }
  405. // 移除用户确定
  406. $('#remove_user_btn').click(function () {
  407. const type = $('#remove_user_type').val();
  408. if (tabTypeKeys.indexOf(type) === -1) {
  409. toastr.error('参数有误');
  410. return;
  411. }
  412. const id = parseInt($('#remove_user_id').val());
  413. const showId = parseInt($('#show_id').val());
  414. if (type === 'contract') {
  415. postData('/sp/' + spid + '/contract/tender/' + cur_tenderid + '/audit/save', { type: 'del-audit', id }, function (data) {
  416. $('#'+ type + '-users').find('tr[data-uid="'+ id +'"]').remove();
  417. $('#remove-user').modal('hide');
  418. selectedUserIdsByType[type] = selectedUserIdsByType[type].filter(function(userId) {
  419. return userId !== showId;
  420. });
  421. updateSelectedMarks();
  422. });
  423. } else if (type === 'construction') {
  424. postData('/sp/' + spid + '/' + type + '/' + cur_tenderid + '/audit/save', { type: 'del-audit', id }, function (data) {
  425. $('#'+ type + '-users').find('tr[data-id="'+ id +'"]').remove();
  426. $('#remove-user').modal('hide');
  427. selectedUserIdsByType[type] = selectedUserIdsByType[type].filter(function(userId) {
  428. return userId !== showId;
  429. });
  430. updateSelectedMarks();
  431. });
  432. } else if (_.includes(tenderPermissionKeys, type)) {
  433. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', { type: 'del-audit', id, key: type }, function (data) {
  434. $('#'+ type + '-users').find('tr[data-uid="'+ id +'"]').remove();
  435. $('#remove-user').modal('hide');
  436. selectedUserIdsByType[type] = selectedUserIdsByType[type].filter(function(userId) {
  437. return userId !== showId;
  438. });
  439. updateSelectedMarks();
  440. });
  441. } else if (_.includes(Object.keys(tPsKeys), type)) {
  442. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', { type: 'del-audit', id, key: type, together: 1 }, function (data) {
  443. $('#'+ type + '-users').find('tr[data-uid="'+ id +'"]').remove();
  444. $('#remove-user').modal('hide');
  445. selectedUserIdsByType[type] = selectedUserIdsByType[type].filter(function(userId) {
  446. return userId !== showId;
  447. });
  448. updateSelectedMarks();
  449. });
  450. } else {
  451. const prop = {
  452. id: id,
  453. type: 'del',
  454. };
  455. postData('/tender/' + cur_tenderid + '/' + type + '/audit/save', prop, function (data) {
  456. $('#'+ type + '-users').find('tr[data-id="'+ id +'"]').remove();
  457. $('#remove-user').modal('hide');
  458. selectedUserIdsByType[type] = selectedUserIdsByType[type].filter(function(userId) {
  459. return userId !== showId;
  460. });
  461. updateSelectedMarks();
  462. });
  463. }
  464. });
  465. // 投资进度
  466. let timerAddUser = null;
  467. let oldSearchValAddUser = null;
  468. $('body').on('input propertychange', '#add_user_dropdownMenu2 .gr-search', function (e) {
  469. const currentDropdownType = $('#add_user_dropdownMenuButton').attr('data-type');
  470. let currentSelectedIdsForType = [];
  471. if (currentDropdownType && selectedUserIdsByType.hasOwnProperty(currentDropdownType)) {
  472. currentSelectedIdsForType = selectedUserIdsByType[currentDropdownType]; // 获取对应类型的ID数组
  473. }
  474. oldSearchValAddUser = e.target.value;
  475. timerAddUser && clearTimeout(timerAddUser);
  476. timerAddUser = setTimeout(() => {
  477. const newVal = $(this).val();
  478. if (newVal && newVal === oldSearchValAddUser) {
  479. let html = '';
  480. accountList.filter(item => item && item.id !== cur_uid && (item.name.indexOf(newVal) !== -1 || (item.mobile && item.mobile.indexOf(newVal) !== -1))).forEach(item => {
  481. const itemIdInt = parseInt(item.id, 10);
  482. const isSelected = currentSelectedIdsForType.includes(itemIdInt);
  483. const selectedMarkStyle = isSelected ? '' : ' style="display:none;"';
  484. html += `<dd class="border-bottom p-2 mb-0 user-item" data-id="${item.id}" >
  485. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  486. class="ml-auto">${item.mobile || ''}</span>
  487. <span class="selected-mark text-success ml-2"${selectedMarkStyle}><i class="fa fa-check"></i></span>
  488. </p>
  489. <span class="text-muted">${item.role || ''}</span>
  490. </dd>`
  491. });
  492. $('#add_user_dropdownMenu2 .book-list').empty();
  493. $('#add_user_dropdownMenu2 .book-list').append(html);
  494. } else {
  495. if (!$('#add_user_dropdownMenu2 .acc-btn').length) {
  496. resetAddUserHtml();
  497. }
  498. }
  499. }, 400);
  500. });
  501. function resetAddUserHtml() {
  502. const currentDropdownType = $('#add_user_dropdownMenuButton').attr('data-type');
  503. let currentSelectedIdsForType = [];
  504. if (currentDropdownType && selectedUserIdsByType.hasOwnProperty(currentDropdownType)) {
  505. currentSelectedIdsForType = selectedUserIdsByType[currentDropdownType];
  506. }
  507. let html = '';
  508. accountGroup.forEach((group, idx) => {
  509. if (!group) return;
  510. html += `<dt><a href="javascript: void(0);" class="acc-btn" data-groupid="${idx}" data-type="hide"><i class="fa fa-plus-square"></i>
  511. </a> ${group.groupName}</dt>
  512. <div class="dd-content" data-toggleid="${idx}">`;
  513. group.groupList.forEach(item => {
  514. if (item.id !== cur_uid) {
  515. const itemIdInt = parseInt(item.id, 10);
  516. const isSelected = currentSelectedIdsForType.includes(itemIdInt);
  517. const selectedMarkStyle = isSelected ? '' : ' style="display:none;"';
  518. html += `<dd class="border-bottom p-2 mb-0 user-item" data-id="${item.id}" >
  519. <p class="mb-0 d-flex"><span class="text-primary">${item.name}</span><span
  520. class="ml-auto">${item.mobile || ''}</span>
  521. <span class="selected-mark text-success ml-2"${selectedMarkStyle}><i class="fa fa-check"></i></span>
  522. </p>
  523. <span class="text-muted">${item.role || ''}</span>
  524. </dd>`;
  525. }
  526. });
  527. html += '</div>';
  528. });
  529. $('#add_user_dropdownMenu2 .book-list').empty();
  530. $('#add_user_dropdownMenu2 .book-list').append(html);
  531. }
  532. // 添加审批流程按钮逻辑
  533. $('body').on('click', '#add_user_dropdownMenu2 .book-list dt', function () {
  534. const idx = $(this).find('.acc-btn').attr('data-groupid');
  535. const type = $(this).find('.acc-btn').attr('data-type');
  536. if (type === 'hide') {
  537. $(this).parent().find(`div[data-toggleid="${idx}"]`).show(() => {
  538. $(this).children().find('i').removeClass('fa-plus-square').addClass('fa-minus-square-o');
  539. $(this).find('.acc-btn').attr('data-type', 'show');
  540. })
  541. } else {
  542. $(this).parent().find(`div[data-toggleid="${idx}"]`).hide(() => {
  543. $(this).children().find('i').removeClass('fa-minus-square-o').addClass('fa-plus-square');
  544. $(this).find('.acc-btn').attr('data-type', 'hide');
  545. })
  546. }
  547. return false;
  548. });
  549. // 选中用户
  550. $('body').on('click', '#add_user_dropdownMenu2 dl dd', function (e) {
  551. const id = parseInt($(this).data('id'));
  552. if (id) {
  553. const user = _.find(accountList, function (item) {
  554. return item.id === id;
  555. });
  556. const type = $('#add_user_dropdownMenuButton').attr('data-type');
  557. if (type === 'tourist') {
  558. const saIdList = [];
  559. for (let i = 0; i < $('#tourist-users tr').length; i++) {
  560. saIdList.push(parseInt($('#tourist-users tr').eq(i).data('uid')));
  561. }
  562. if (_.includes(saIdList, id)) {
  563. toastr.error('该用户已存在列表中,无需重复添加');
  564. e.stopPropagation();
  565. return;
  566. }
  567. const prop = {
  568. user_id: id,
  569. type: 'add',
  570. };
  571. postData('/tender/' + cur_tenderid + '/tourist/audit/save', prop, function (data) {
  572. selectedUserIdsByType.tourist.push(id);
  573. const html = `<tr data-uid="${user.id}" data-id="${data.id}">
  574. <td>${user.name}</td>
  575. <td>${user.role}</td>
  576. <td class="text-center">
  577. <div class="custom-control custom-checkbox mb-2">
  578. <input type="checkbox" id="${data.id}_file" data-id="${data.id}" name="file" class="custom-control-input set-tourist-permission">
  579. <label class="custom-control-label" for="${data.id}_file"></label>
  580. </div>
  581. </td>
  582. <td class="text-center">
  583. <div class="custom-control custom-checkbox mb-2">
  584. <input type="checkbox" id="${data.id}_tag" data-id="${data.id}" name="tag" class="custom-control-input set-tourist-permission">
  585. <label class="custom-control-label" for="${data.id}_tag"></label>
  586. </div>
  587. </td>
  588. <td class="text-center">
  589. <a href="#remove-user1" data-id="${data.id}" data-show-id="${user.id}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-tourist-user">移除</a>
  590. </td>
  591. </tr>`;
  592. $('#tourist-users').append(html);
  593. updateSelectedMarks();
  594. });
  595. // } else if (type === 'schedule') {
  596. // const user = _.find(accountList, function (item) {
  597. // return item.id === id;
  598. // });
  599. // const saIdList = [];
  600. // for (let i = 0; i < $('#schedule-users tr').length; i++) {
  601. // saIdList.push(parseInt($('#schedule-users tr').eq(i).data('uid')));
  602. // }
  603. // if (_.includes(saIdList, id)) {
  604. // toastr.error('该用户已存在列表中,无需重复添加');
  605. // e.stopPropagation();
  606. // return;
  607. // }
  608. //
  609. // const prop = {
  610. // audit_id: id,
  611. // type: 'add',
  612. // };
  613. // postData('/tender/' + cur_tenderid + '/schedule/audit/save', prop, function (data) {
  614. // selectedUserIdsByType.schedule.push(user.id);
  615. // const html = `<tr data-uid="${user.id}" data-id="${data.id}">
  616. // <td>${user.name}</td>
  617. // <td>${user.role}</td>
  618. // <td class="text-center">
  619. // <div class="custom-control custom-checkbox mb-2">
  620. // <input type="checkbox" data-zhi="${scPermission.show}" data-id="${data.id}" id="${data.id}_customRadio41" name="customCheckbox" class="custom-control-input" checked>
  621. // <label class="custom-control-label" for="${data.id}_customRadio41"></label>
  622. // </div>
  623. // </td>
  624. // <td class="text-center">
  625. // <div class="custom-control custom-checkbox mb-2">
  626. // <input type="checkbox" data-zhi="${scPermission.edit}" data-id="${data.id}" id="${data.id}_customRadio42" name="customCheckbox" class="custom-control-input">
  627. // <label class="custom-control-label" for="${data.id}_customRadio42"></label>
  628. // </div>
  629. // </td>
  630. // <td class="text-center">
  631. // <a href="#remove-user1" data-id="${data.id}" data-show-id="${user.id}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-schedule-user">移除</a>
  632. // </td>
  633. // </tr>`;
  634. // $('#schedule-users').append(html);
  635. // updateSelectedMarks();
  636. // });
  637. } else if (type === 'contract') {
  638. const user = _.find(accountList, function (item) {
  639. return item.id === id;
  640. });
  641. const saIdList = [];
  642. for (let i = 0; i < $('#contract-users tr').length; i++) {
  643. saIdList.push(parseInt($('#contract-users tr').eq(i).data('uid')));
  644. }
  645. if (_.includes(saIdList, id)) {
  646. toastr.error('该用户已存在列表中,无需重复添加');
  647. e.stopPropagation();
  648. return;
  649. }
  650. const prop = {
  651. id: id,
  652. type: 'add-audit',
  653. };
  654. postData('/sp/' + spid + '/contract/tender/' + cur_tenderid + '/audit/save', prop, function (datas) {
  655. setContractHtml(datas);
  656. updateSelectedMarks();
  657. });
  658. } else if (type === 'construction') {
  659. const user = _.find(accountList, function (item) {
  660. return item.id === id;
  661. });
  662. const saIdList = [];
  663. for (let i = 0; i < $('#construction-users tr').length; i++) {
  664. saIdList.push(parseInt($('#construction-users tr').eq(i).data('uid')));
  665. }
  666. if (_.includes(saIdList, id)) {
  667. toastr.error('该用户已存在列表中,无需重复添加');
  668. e.stopPropagation();
  669. return;
  670. }
  671. const prop = {
  672. id: id,
  673. type: 'add-audit',
  674. };
  675. postData('/sp/' + spid + '/construction/' + cur_tenderid + '/audit/save', prop, function (datas) {
  676. setConstructionHtml(datas);
  677. });
  678. } else if (_.includes(tenderPermissionKeys, type)) {
  679. const user = _.find(accountList, function (item) {
  680. return item.id === id;
  681. });
  682. const saIdList = [];
  683. for (let i = 0; i < $('#' + type + '-users tr').length; i++) {
  684. saIdList.push(parseInt($('#' + type + '-users tr').eq(i).data('uid')));
  685. }
  686. if (_.includes(saIdList, id)) {
  687. toastr.error('该用户已存在列表中,无需重复添加');
  688. e.stopPropagation();
  689. return;
  690. }
  691. const prop = {
  692. id: id,
  693. type: 'add-audit',
  694. key: type,
  695. };
  696. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', prop, function (datas) {
  697. setTenderPermissionHtml(datas, type);
  698. });
  699. } else if (_.includes(Object.keys(tPsKeys), type)) {
  700. const saIdList = [];
  701. for (let i = 0; i < $('#' + type + '-users tr').length; i++) {
  702. saIdList.push(parseInt($('#' + type + '-users tr').eq(i).data('uid')));
  703. }
  704. if (_.includes(saIdList, id)) {
  705. toastr.error('该用户已存在列表中,无需重复添加');
  706. e.stopPropagation();
  707. return;
  708. }
  709. const prop = {
  710. id: id,
  711. type: 'add-audit',
  712. key: type,
  713. together: 1,
  714. };
  715. postData('/sp/' + spid + '/quality/' + cur_tenderid + '/audit/save', prop, function (datas) {
  716. setTenderPermissionsHtml(datas, type, tPsKeys[type]);
  717. });
  718. }
  719. }
  720. e.stopPropagation();
  721. });
  722. sortCategory4User();
  723. initTenderTree4User();
  724. getFilterTenderTreeHtml();
  725. $('#set-other-tender-user-a').click(function () {
  726. if(!cur_tenderid) {
  727. toastr.warning('未选中标段无法设置');
  728. return;
  729. }
  730. const userType = $('#add_user_dropdownMenuButton').attr('data-type');
  731. const saIdList = [];
  732. for (let i = 0; i < $('#'+ userType +'-users tr').length; i++) {
  733. saIdList.push(parseInt($('#'+ userType +'-users tr').eq(i).data('uid')));
  734. }
  735. if (saIdList.length > 0) {
  736. $('#bdcopy').modal('show');
  737. } else {
  738. toastr.warning('未存在'+ tabTypes[userType] +'用户账号,无法应用至其他标段');
  739. return;
  740. }
  741. });
  742. $('#bdcopy').on('show.bs.modal', function () {
  743. const html = getTenderTreeHtml4User();
  744. $('#tender-list-4user').html(html);
  745. $('#search-tender').val('');
  746. $('#search-tender-result').text('0/0');
  747. $('#up-tender-search').attr('disabled', true);
  748. $('#down-tender-search').attr('disabled', true);
  749. setTimeout(function () { $('#tender-list-4user').scrollTop(0); },500);
  750. });
  751. let timer4SearchTender = null;
  752. let oldSearchVal4SearchTender = null;
  753. $('body').on('input propertychange', '#bdcopy input[name="tender-name"]', function(e) {
  754. oldSearchVal4SearchTender = e.target.value;
  755. timer4SearchTender && clearTimeout(timer4SearchTender);
  756. timer4SearchTender = setTimeout(() => {
  757. const newVal = $(this).val();
  758. const resultLength = $('#tender-list-4user').find('.result').length;
  759. if (resultLength > 0) {
  760. let content = $('#tender-list-4user').html();
  761. const replaceStr = $('#tender-list-4user').find('.result').eq(0).html();
  762. const regExp2 = new RegExp('<span class="result" style="background: yellow;">' + replaceStr + '</span>', 'g');
  763. content = content.replace(regExp2, replaceStr);
  764. const regExp3 = new RegExp('<span class="result" style="background: orange;">' + replaceStr + '</span>', 'g');
  765. content = content.replace(regExp3, replaceStr);
  766. $('#tender-list-4user').html(content);
  767. }
  768. $('#search-tender-result').text('0/0');
  769. $('#up-tender-search').attr('disabled', true);
  770. $('#down-tender-search').attr('disabled', true);
  771. if (newVal && newVal === oldSearchVal4SearchTender) {
  772. const regExp = new RegExp(newVal, 'g');
  773. for (let i = 0; i < $('#tender-list-4user tr').length; i++) {
  774. if (_.includes($('#tender-list-4user tr').eq(i).children('td').eq(0).children('a').html(), newVal)) {
  775. $('#tender-list-4user tr').eq(i).children('td').eq(0).children('a').html($('#tender-list-4user tr').eq(i).children('td').eq(0).children('a').html().replace(regExp, '<span class="result" style="background: yellow;">' + newVal + '</span>'))
  776. }
  777. }
  778. const resultLength2 = $('#tender-list-4user').find('.result').length;
  779. if (resultLength2 > 0) {
  780. $('#tender-list-4user').find('.result').eq(0).css('background', 'orange');
  781. $('#search-tender-result').text('1/' + resultLength2);
  782. $('#up-tender-search').attr('disabled', false);
  783. $('#down-tender-search').attr('disabled', false);
  784. }
  785. }
  786. if($('#tender-list-4user').find('.result').length > 0) {
  787. const X = $('#tender-list-4user').find('.result').eq(0).offset().top;
  788. $('#tender-list-4user').scrollTop(X - $('#tender-list-4user').offset().top + $('#tender-list-4user').scrollTop() - 30);
  789. }
  790. }, 400);
  791. });
  792. $('#up-tender-search').on('click', function () {
  793. const cur = parseInt($('#search-tender-result').text().split('/')[0]);
  794. const total = parseInt($('#search-tender-result').text().split('/')[1]);
  795. const now = cur - 1 !== 0 ? cur - 1: total;
  796. $('#tender-list-4user').find('.result').eq(cur-1).css('background', 'yellow');
  797. $('#tender-list-4user').find('.result').eq(now-1).css('background', 'orange');
  798. // $('#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;">'))
  799. // $('#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;">'))
  800. $('#search-tender-result').text(now + '/' + total);
  801. const X = $('#tender-list-4user').find('.result').eq(now-1).offset().top;
  802. $('#tender-list-4user').scrollTop(X - $('#tender-list-4user').offset().top + $('#tender-list-4user').scrollTop() - 30);
  803. });
  804. $('#down-tender-search').on('click', function () {
  805. const cur = parseInt($('#search-tender-result').text().split('/')[0]);
  806. const total = parseInt($('#search-tender-result').text().split('/')[1]);
  807. const now = cur + 1 > total ? 1: cur + 1;
  808. $('#tender-list-4user').find('.result').eq(cur-1).css('background', 'yellow');
  809. $('#tender-list-4user').find('.result').eq(now-1).css('background', 'orange');
  810. // $('#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;">'))
  811. // $('#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;">'))
  812. $('#search-tender-result').text(now + '/' + total);
  813. const X = $('#tender-list-4user').find('.result').eq(now-1).offset().top;
  814. $('#tender-list-4user').scrollTop(X - $('#tender-list-4user').offset().top + $('#tender-list-4user').scrollTop() -30);
  815. });
  816. $('#save-other-tender-user').click(function () {
  817. $(this).attr('disabled', true);
  818. const num = $('#tender-list-4user input:checked').length;
  819. if (num < 2) {
  820. toastr.warning('请选择需要应用同步的标段');
  821. $(this).attr('disabled', false);
  822. return;
  823. }
  824. const userType = $('#add_user_dropdownMenuButton').attr('data-type');
  825. const data = {
  826. type: 'copy2otu',
  827. tid: cur_tenderid,
  828. userType,
  829. };
  830. const saIdList = [];
  831. for (let i = 0; i < $('#'+ userType +'-users tr').length; i++) {
  832. const userData = {
  833. uid: parseInt($('#'+ userType +'-users tr').eq(i).data('uid')),
  834. }
  835. if (userType === 'tourist') {
  836. userData.permission = {
  837. file: $('#tourist-users tr').eq(i).find('input[type="checkbox"]').eq(0).is(':checked') ? 1 : 0,
  838. tag: $('#tourist-users tr').eq(i).find('input[type="checkbox"]').eq(1).is(':checked') ? 1 : 0,
  839. };
  840. // } else if (userType === 'schedule') {
  841. // let permission = scPermission.no;
  842. // const _this = $('#schedule-users tr').eq(i).find('input[type="checkbox"]').eq(0);
  843. // const _other = $('#schedule-users tr').eq(i).find('input[type="checkbox"]').eq(1);
  844. // if (_this.is(':checked') && _other.is(':checked')) {
  845. // permission = scPermission.edit;
  846. // } else if (_this.is(':checked') && !_other.is(':checked')) {
  847. // permission = scPermission.show;
  848. // }
  849. // userData.permission = permission;
  850. } else if (userType === 'contract') {
  851. userData.permission = {
  852. add: $('#contract-users tr').eq(i).find('input[data-type="permission_add"]').eq(0).is(':checked') ? 1 : 0,
  853. edit: $('#contract-users tr').eq(i).find('input[data-type="permission_edit"]').eq(0).is(':checked') ? 1 : 0,
  854. edit_contract: $('#contract-users tr').eq(i).find('input[data-type="permission_edit_contract"]').eq(0).is(':checked') ? 1 : 0,
  855. add_pay: $('#contract-users tr').eq(i).find('input[data-type="permission_add_pay"]').eq(0).is(':checked') ? 1 : 0,
  856. showUnit: $('#contract-users tr').eq(i).find('input[data-type="permission_show_unit"]').eq(0).is(':checked') ? 1 : 0,
  857. showNode: $('#contract-users tr').eq(i).find('input[data-type="permission_show_node"]').eq(0).is(':checked') ? 1 : 0,
  858. }
  859. } else if (userType === 'construction') {
  860. userData.is_report = $('#construction-users tr').eq(i).find('input[type="checkbox"]').eq(0).is(':checked') ? 1 : 0;
  861. } else if (_.includes(tenderPermissionKeys, userType)) {
  862. userData.member = {};
  863. userData.member[userType] = [1];
  864. $('#'+ userType +'-users tr').eq(i).find('input[type="checkbox"]').each(function () {
  865. if ($(this).is(':checked')) {
  866. userData.member[userType].push(parseInt($(this).attr('data-value')));
  867. }
  868. });
  869. } else if (_.includes(Object.keys(tPsKeys), userType)) {
  870. userData.member = {};
  871. for (const key of tPsKeys[userType]) {
  872. userData.member[key] = [];
  873. $('#'+ userType +'-users tr').eq(i).find('input[data-key="' + key + '"]').each(function () {
  874. if ($(this).is(':checked')) {
  875. userData.member[key].push(parseInt($(this).attr('data-value')));
  876. }
  877. });
  878. }
  879. }
  880. saIdList.push(userData);
  881. }
  882. data.auditList = saIdList;
  883. // 获取已选中的标段
  884. const tenderList = [];
  885. for (let i = 0; i < num; i++) {
  886. const tid = parseInt($('#tender-list-4user input:checked').eq(i).data('tid'));
  887. if (tid !== cur_tenderid) {
  888. tenderList.push(tid);
  889. }
  890. }
  891. data.tidList = tenderList.join(',');
  892. // 请求获取右侧列表信息
  893. const _self = $(this);
  894. postData(`/sp/${spid}/setting/manage/tender/save`, data, function (result) {
  895. toastr.success('应用至其他标段成功');
  896. _self.attr('disabled', false);
  897. $('#bdcopy').modal('hide');
  898. }, function () {
  899. _self.attr('disabled', false);
  900. });
  901. });
  902. // 关联标段
  903. $('#select-tender').on('show.bs.modal', function () {
  904. $('#select-all-tender').prop('checked', false);
  905. postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'noSp-tenders' }, function (result) {
  906. const html = [];
  907. for (const t of result) {
  908. html.push('<tr>');
  909. html.push('<td><a target="_blank" href="/tender/', t.id, '">', t.name, '</a></td>');
  910. html.push('<td>', t.user_name, '</td>');
  911. html.push('<td>', moment(t.create_time).format('YYYY-MM-DD'), '</td>');
  912. html.push('<td class="text-center">', '<input type="checkbox" data-tid="' + t.id + '">', '</td>');
  913. html.push('</tr>');
  914. }
  915. $('#no-project-tenders').html(html.join(''));
  916. });
  917. });
  918. $('#bind-sp-btn').click(function () {
  919. const num = $('#no-project-tenders input:checked').length;
  920. if (num < 1) {
  921. toastr.warning('请选择需要关联的标段');
  922. return;
  923. }
  924. const tidList = [];
  925. for (let i = 0; i < num; i++) {
  926. tidList.push($('#no-project-tenders input:checked').eq(i).data('tid'));
  927. }
  928. postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'bind-sp', spid, tidList: tidList.join(',') }, function (result) {
  929. toastr.success('关联标段成功');
  930. $('#select-tender').modal('hide');
  931. setTimeout(function () {
  932. window.location.reload();
  933. }, 500);
  934. });
  935. });
  936. $('#select-all-tender').click(function () {
  937. const checked = $(this).is(':checked');
  938. $('#no-project-tenders input').prop('checked', checked);
  939. });
  940. // $('#change-sp').change(function () {
  941. // const spid = $(this).val();
  942. // console.log(spid);
  943. // postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'get-category', spid }, function (result) {
  944. // $('#cate-list', '#edit-bd').html(getCategoryHtml(result));
  945. // const tender = _.find(tenders, { id: cur_tenderid });
  946. // if (tender && tender.spid === spid) {
  947. // for (const c of tender.category) {
  948. // // $('input[value=' + c.value + ']', '#edit-bd').prop('checked', 'checked');
  949. // $('option[value=' + c.value + ']', '#edit-bd').prop('selected', true);
  950. // }
  951. // }
  952. // });
  953. // })
  954. $('#filter-tender-ok').click(function() {
  955. const updateData = [];
  956. const tr = $('tr[tid]', '#filter-tender');
  957. for (const t of tr) {
  958. const data = { id: t.getAttribute('tid')};
  959. const checkes = $('input', t);
  960. for (const c of checkes) {
  961. data[c.getAttribute('data-type')] = c.checked ? 1 : 0;
  962. }
  963. updateData.push(data);
  964. }
  965. postData(`/sp/${spid}/list/batchUpdate`, updateData, function() {
  966. window.location.reload();
  967. });
  968. });
  969. $('#edit-bd').on('show.bs.modal', function () {
  970. const tree = new TreeSelect({
  971. element: '#tree-container',
  972. data: subProjects,
  973. selected: spid,
  974. onSelect: (id, label) => {
  975. const newSpid = id;
  976. console.log(newSpid);
  977. $('#change-sp').val(newSpid);
  978. postData(`/sp/${newSpid}/setting/manage/tender/save`, { type: 'get-category', spid: newSpid }, function (result) {
  979. $('#cate-list', '#edit-bd').html(getCategoryHtml(result));
  980. const tender = _.find(tenders, { id: cur_tenderid });
  981. if (tender && tender.spid === newSpid) {
  982. for (const c of tender.category) {
  983. // $('input[value=' + c.value + ']', '#edit-bd').prop('checked', 'checked');
  984. $('option[value=' + c.value + ']', '#edit-bd').prop('selected', true);
  985. }
  986. }
  987. });
  988. // console.log('选中了:', id, label);
  989. }
  990. });
  991. });
  992. });
  993. const tenderListSpec = (function(){
  994. function getTenderTreeHeaderHtml() {
  995. const html = [];
  996. html.push('<table class="table table-hover table-bordered">');
  997. html.push('<thead style="position: sticky;left:176px;top: 0;">', '<tr>');
  998. html.push('<th class="text-center" style="width: 80%">', '标段名称', '</th>');
  999. html.push('<th class="text-center" style="width: 20%">', '创建人', '</th>');
  1000. html.push('</tr>', '</thead>');
  1001. return html.join('');
  1002. }
  1003. function getTenderNodeHtml(node, arr, pid) {
  1004. const html = [];
  1005. html.push('<tr pid="' + pid + '"', (node.cid ? '' : 'class="tender-info" data-id="'+ node.id +'"'), '>');
  1006. // 名称
  1007. html.push('<td style="width: 80%" class="in-' + node.level + '"' + (node.cid ? '' : 'tid="' + node.id + '"') + '>');
  1008. if (node.cid) {
  1009. html.push('<span onselectstart="return false" style="{-moz-user-select:none}" class="fold-switch mr-1" title="收起" cid="'+ node.sort_id +'"><i class="fa fa-minus-square-o"></i></span> <i class="fa fa-folder-o"></i> ');
  1010. html.push((node.level === 1 ? '<b>' : ''), node.name, (node.level === 1 ? '</b>' : ''));
  1011. } else {
  1012. html.push('<div class="d-flex justify-content-between align-items-center">');
  1013. html.push('<div>');
  1014. html.push('<span class="text-muted mr-2">');
  1015. html.push(arr.indexOf(node) === arr.length - 1 ? '└' : '├');
  1016. html.push('</span>');
  1017. //html.push('<a href="/tender/' + node.id + '">', node[c.field], '</a>');
  1018. const onlyApproval = typeof approvalOnly !== 'undefined' && approvalOnly;
  1019. html.push('<a href="javascript: void(0)" id="' + node.id + '"' + (onlyApproval ? '' : ' name="name"') + '>', node.name, '</a>');
  1020. html.push('</div>');
  1021. if (!onlyApproval) {
  1022. html.push('<div class="btn-group-table" tid="' + node.id + '">');
  1023. html.push('<a href="javascript:void(0);" name="edit" class="mr-1"><i class="fa fa-pencil fa-fw"></i></a>');
  1024. const hasStage = node.progress ? (node.stage_count > 0 ? true : node.stage_status !== 0) : !!node.lastStage;
  1025. if (!hasStage) {
  1026. html.push('<a href="javascript:void(0);" name="del" class="mr-1"><i class="fa fa-trash-o fa-fw text-danger"></i></a>');
  1027. } else {
  1028. html.push('<a href="javascript:void(0);" data-toggle="tooltip" title="请先删除所有期" class="mr-1"><i class="fa fa-trash-o fa-fw text-secondary"></i></a>');
  1029. }
  1030. html.push('</div>');
  1031. }
  1032. html.push('</div>');
  1033. }
  1034. html.push('</td>');
  1035. // 创建人
  1036. html.push('<td style="width: 20%" class="text-center">', node.user_name ? node.user_name : '', '</td>');
  1037. html.push('</tr>');
  1038. return html.join('');
  1039. }
  1040. return { getTenderNodeHtml, getTenderTreeHeaderHtml }
  1041. })();
  1042. function updateSelectedMarks(forcedType = null) {
  1043. let currentUserListSelector = '';
  1044. let selectedIdsArray = [];
  1045. let currentType = forcedType;
  1046. if (!currentType) {
  1047. const $activeTabPane = $('.tab-pane.active');
  1048. const activeTabId = $activeTabPane.attr('id');
  1049. switch(activeTabId) {
  1050. case 'guest': currentType = 'tourist'; break;
  1051. case 'tzpro': currentType = 'schedule'; break;
  1052. case 'htgl': currentType = 'contract'; break;
  1053. case 'sgrz': currentType = 'construction'; break;
  1054. case 'quality': currentType = 'quality'; break;
  1055. case 'safe': currentType = 'safe'; break;
  1056. default: currentType = null;
  1057. }
  1058. }
  1059. if (currentType && selectedUserIdsByType.hasOwnProperty(currentType)) {
  1060. switch(currentType) {
  1061. case 'tourist': currentUserListSelector = '#tourist-users'; break;
  1062. case 'schedule': currentUserListSelector = '#schedule-users'; break;
  1063. case 'contract': currentUserListSelector = '#contract-users'; break;
  1064. case 'construction': currentUserListSelector = '#construction-users'; break;
  1065. case 'quality': currentUserListSelector = '#quality-users'; break;
  1066. case 'inspection': currentUserListSelector = '#inspection-users'; break;
  1067. case 'safe': currentUserListSelector = '#safe-users'; break;
  1068. }
  1069. selectedIdsArray = selectedUserIdsByType[currentType];
  1070. } else {
  1071. $('.user-item').find('.selected-mark').hide();
  1072. $('.user-item').removeClass('bg-light');
  1073. return;
  1074. }
  1075. if ($('#add_user_dropdownMenu2 .book-list').length > 0) {
  1076. $('.user-item').each(function() {
  1077. const userIdStr = $(this).data('id');
  1078. const userId = parseInt(userIdStr, 10);
  1079. const $mark = $(this).find('.selected-mark');
  1080. if (!isNaN(userId) && selectedIdsArray.includes(userId)) {
  1081. $mark.show();
  1082. $(this).addClass('bg-light');
  1083. } else {
  1084. $mark.hide();
  1085. $(this).removeClass('bg-light');
  1086. }
  1087. });
  1088. }
  1089. }
  1090. function setShenpiHtml(shenpi, tender, revising) {
  1091. renderTenderApproval(shenpi, tender, revising);
  1092. }
  1093. let selectedUserIdsByType = {
  1094. tourist: [],
  1095. schedule: [],
  1096. contract: [],
  1097. construction: [],
  1098. quality: [],
  1099. inspection: [],
  1100. safe: []
  1101. };
  1102. function setTouristHtml(tourists) {
  1103. let html = '';
  1104. if (tourists.length > 0) {
  1105. for (const t of tourists) {
  1106. html += `<tr data-uid="${t.user_id}" data-id="${t.id}">
  1107. <td>${t.user_name}</td>
  1108. <td>${t.user_role}</td>
  1109. <td class="text-center">
  1110. <div class="custom-control custom-checkbox mb-2">
  1111. <input type="checkbox" id="${t.id}_file" data-id="${t.id}" name="file" class="custom-control-input set-tourist-permission" ${t.permission.file ? 'checked' : ''}>
  1112. <label class="custom-control-label" for="${t.id}_file"></label>
  1113. </div>
  1114. </td>
  1115. <td class="text-center">
  1116. <div class="custom-control custom-checkbox mb-2">
  1117. <input type="checkbox" id="${t.id}_tag" data-id="${t.id}" name="tag" class="custom-control-input set-tourist-permission" ${t.permission.tag ? 'checked' : ''}>
  1118. <label class="custom-control-label" for="${t.id}_tag"></label>
  1119. </div>
  1120. </td>
  1121. <td class="text-center">
  1122. <a href="#remove-user1" data-id="${t.id}" data-show-id="${t.user_id}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-tourist-user">移除</a>
  1123. </td>
  1124. </tr>`;
  1125. }
  1126. selectedUserIdsByType.tourist = [];
  1127. if (Array.isArray(tourists)) {
  1128. tourists.forEach(function(tourist) {
  1129. if (tourist.user_id !== undefined && tourist.user_id !== null) {
  1130. selectedUserIdsByType.tourist.push(parseInt(tourist.user_id, 10));
  1131. }
  1132. });
  1133. }
  1134. }
  1135. $('#tourist-users').html(html);
  1136. updateSelectedMarks();
  1137. }
  1138. function setScheduleHtml(scheduleAuditList) {
  1139. let html = '';
  1140. if (scheduleAuditList.length > 0) {
  1141. for (const sa of scheduleAuditList) {
  1142. const audit = _.find(accountList, { id: sa.audit_id });
  1143. html += `<tr data-uid="${sa.audit_id}" data-id="${sa.id}">
  1144. <td>${audit ? audit.name : ''}</td>
  1145. <td>${audit ? audit.role : ''}</td>
  1146. <td class="text-center">
  1147. <div class="custom-control custom-checkbox mb-2">
  1148. <input type="checkbox" data-zhi="${scPermission.show}" data-id="${sa.id}" id="${sa.id}_customRadio41" name="customCheckbox" class="custom-control-input" ${sa.permission !== scPermission.no ? 'checked' : ''}>
  1149. <label class="custom-control-label" for="${sa.id}_customRadio41"></label>
  1150. </div>
  1151. </td>
  1152. <td class="text-center">
  1153. <div class="custom-control custom-checkbox mb-2">
  1154. <input type="checkbox" data-zhi="${scPermission.edit}" data-id="${sa.id}" id="${sa.id}_customRadio42" name="customCheckbox" class="custom-control-input" ${sa.permission === scPermission.edit ? 'checked' : ''}>
  1155. <label class="custom-control-label" for="${sa.id}_customRadio42"></label>
  1156. </div>
  1157. </td>
  1158. <td class="text-center">
  1159. <a href="#remove-user1" data-id="${sa.id}" data-show-id="${sa.user_id}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-schedule-user">移除</a>
  1160. </td>
  1161. </tr>`;
  1162. }
  1163. if (Array.isArray(scheduleAuditList)) {
  1164. scheduleAuditList.forEach(function(sa) {
  1165. if (sa.audit_id !== undefined && sa.audit_id !== null) {
  1166. selectedUserIdsByType.schedule.push(parseInt(sa.audit_id, 10));
  1167. }
  1168. });
  1169. }
  1170. }
  1171. $('#schedule-users').html(html);
  1172. updateSelectedMarks();
  1173. }
  1174. function setContractHtml(datas) {
  1175. let list = '';
  1176. for (const ca of datas) {
  1177. list += `<tr data-uid="${ca.uid}" data-id="${ca.id}">
  1178. <td>${ca.name}</td>
  1179. <td>${ca.role}</td>
  1180. <td class="text-center">
  1181. <input type="checkbox" class="permission-checkbox" data-type="permission_edit" value="${ca.uid}" ${ca.permission_edit ? 'checked' : ''}>
  1182. </td>
  1183. <td class="text-center">
  1184. <input type="checkbox" class="permission-checkbox" data-type="permission_add" value="${ca.uid}" ${ca.permission_add ? 'checked' : ''}>
  1185. </td>
  1186. <td class="text-center">
  1187. <input type="checkbox" class="permission-checkbox" data-type="permission_edit_contract" value="${ca.uid}" ${ca.permission_edit_contract ? 'checked' : ''}>
  1188. </td>
  1189. <td class="text-center">
  1190. <input type="checkbox" class="permission-checkbox" data-type="permission_add_pay" value="${ca.uid}" ${ca.permission_add_pay ? 'checked' : ''}>
  1191. </td>
  1192. <td class="text-center">
  1193. <input type="checkbox" class="permission-checkbox" data-type="permission_show_unit" value="${ca.uid}" ${ca.permission_show_unit ? 'checked' : ''}>
  1194. </td>
  1195. <td class="text-center">
  1196. <input type="checkbox" class="permission-checkbox" data-type="permission_show_node" value="${ca.uid}" ${ca.permission_show_node ? 'checked' : ''}>
  1197. </td>
  1198. <td class="text-center">
  1199. <a href="#remove-user1" data-show-id="${ca.uid}" data-toggle="modal" data-target="#remove-user" class="btn btn-outline-danger btn-sm ml-1 remove-contract-user" data-id="${ca.uid}">移除</a>
  1200. </td>
  1201. </tr>`;
  1202. }
  1203. if (Array.isArray(datas)) {
  1204. datas.forEach(function(ca) {
  1205. if (ca.uid !== undefined && ca.uid !== null) {
  1206. selectedUserIdsByType.contract.push(parseInt(ca.uid, 10));
  1207. }
  1208. });
  1209. }
  1210. $('#contract-users').html(list);
  1211. updateSelectedMarks();
  1212. }
  1213. function setConstructionHtml(constructionAuditList) {
  1214. let html = '';
  1215. if (constructionAuditList.length > 0) {
  1216. for (const sa of constructionAuditList) {
  1217. html += `<tr data-uid="${sa.uid}" data-id="${sa.id}">
  1218. <td>${sa.name}</td>
  1219. <td>${sa.role}</td>
  1220. <td class="text-center">
  1221. <div class="custom-control custom-checkbox mb-2">
  1222. <input type="checkbox" data-id="${sa.id}" id="${sa.id}_construction" name="customCheckbox" class="custom-control-input" ${sa.is_report ? 'checked' : ''}>
  1223. <label class="custom-control-label" for="${sa.id}_construction"></label>
  1224. </div>
  1225. </td>
  1226. <td class="text-center">
  1227. <a href="#remove-user1" data-show-id="${sa.uid}" data-id="${sa.id}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-construction-user">移除</a>
  1228. </td>
  1229. </tr>`;
  1230. }
  1231. if (Array.isArray(constructionAuditList)) {
  1232. constructionAuditList.forEach(function(sa) {
  1233. if (sa.uid !== undefined && sa.uid !== null) {
  1234. selectedUserIdsByType.construction.push(parseInt(sa.uid, 10));
  1235. }
  1236. });
  1237. }
  1238. }
  1239. $('#construction-users').html(html);
  1240. updateSelectedMarks();
  1241. }
  1242. function setTenderPermissionsHtml(auditList, key, keys) {
  1243. const html = [];
  1244. for (const m of auditList) {
  1245. html.push(getUserPermissionsHtml(m, key, keys));
  1246. }
  1247. if (Array.isArray(auditList)) {
  1248. auditList.forEach(function(sa) {
  1249. if (sa.uid !== undefined && sa.uid !== null) {
  1250. selectedUserIdsByType[key].push(parseInt(sa.uid, 10));
  1251. }
  1252. });
  1253. }
  1254. $('#' + key + '-users').html(html.join(''));
  1255. updateSelectedMarks();
  1256. }
  1257. const getUserPermissionsHtml = function(user, key, keys) {
  1258. const html = [];
  1259. html.push(`<tr data-uid="${user.uid}" data-id="${user.id}">`);
  1260. html.push(`<td>${user.name}</td>`, `<td>${user.role}</td>`);
  1261. const block = _.find(permissionBlock, { key: key });
  1262. for (const block of permissionBlock) {
  1263. if (keys.indexOf(block.key) < 0) continue;
  1264. for (const p of block.permission) {
  1265. const checked = user[block.key] ? (user[block.key].indexOf(p.value) >= 0 ? 'checked' : '') : '';
  1266. html.push(`<td class="text-center"><input type="checkbox" data-key="${block.key}" data-block="${p.key}" data-value="${p.value}" ${checked}></td>`);
  1267. }
  1268. }
  1269. html.push(`<td class="text-center"><a href="#remove-user1" data-id="${user.uid}" data-show-id="${user.uid}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-${key}-user">移除</a></td>`);
  1270. html.push('</tr>');
  1271. return html.join('');
  1272. };
  1273. function setTenderPermissionHtml(auditList, key) {
  1274. const html = [];
  1275. for (const m of auditList) {
  1276. html.push(getUserPermissionHtml(m, key));
  1277. }
  1278. if (Array.isArray(auditList)) {
  1279. auditList.forEach(function(sa) {
  1280. if (sa.uid !== undefined && sa.uid !== null) {
  1281. selectedUserIdsByType[key].push(parseInt(sa.uid, 10));
  1282. }
  1283. });
  1284. }
  1285. $('#' + key + '-users').html(html.join(''));
  1286. updateSelectedMarks();
  1287. }
  1288. const getUserPermissionHtml = function(user, key) {
  1289. const html = [];
  1290. html.push(`<tr data-uid="${user.uid}" data-id="${user.id}">`);
  1291. html.push(`<td>${user.name}</td>`, `<td>${user.role}</td>`);
  1292. const block = _.find(permissionBlock, { key: key });
  1293. for (const p of block.permission) {
  1294. if (p.isDefault) continue;
  1295. const checked = user[block.key] ? (user[block.key].indexOf(p.value) >= 0 ? 'checked' : '') : '';
  1296. html.push(`<td class="text-center"><input type="checkbox" data-block="${p.key}" data-value="${p.value}" ${checked}></td>`);
  1297. }
  1298. html.push(`<td class="text-center"><a href="#remove-user1" data-show-id="${user.uid}" data-id="${user.uid}" data-toggle="modal" data-target="#remove-user" class="btn btn-sm btn-outline-danger remove-${key}-user">移除</a></td>`);
  1299. html.push('</tr>');
  1300. return html.join('');
  1301. };
  1302. let tenderApprovalLoadId = 0;
  1303. function initTenderApprovalPage() {
  1304. tenderApprovalEditor.init();
  1305. $('body').on('click', '.setting-approval-page .tender-info', function (event) {
  1306. event.preventDefault();
  1307. loadTenderApproval(Number($(this).attr('data-id')));
  1308. });
  1309. $('body').on('click', '.setting-approval-page .approval-retry', function () {
  1310. loadTenderApproval(Number($(this).attr('data-id')));
  1311. });
  1312. const firstTender = $('.setting-approval-page .tender-info').eq(0);
  1313. if (firstTender.length) loadTenderApproval(Number(firstTender.attr('data-id')));
  1314. }
  1315. function loadTenderApproval(tid) {
  1316. if (!Number.isSafeInteger(tid) || tid <= 0) return;
  1317. const loadId = ++tenderApprovalLoadId;
  1318. const rows = $('.setting-approval-page .tender-info');
  1319. rows.removeClass('table-warning');
  1320. rows.filter('[data-id="' + tid + '"]').addClass('table-warning');
  1321. // Loading or failed requests must not leave the previous tender editable.
  1322. cur_tenderid = 0;
  1323. cur_uid = null;
  1324. sp_lc = [];
  1325. $('#splc').html('<div class="text-muted p-3">正在加载审批流程…</div>');
  1326. postData(`/sp/${spid}/setting/manage/tender/save`, { type: 'approval-msg', tid }, function (result) {
  1327. if (loadId !== tenderApprovalLoadId) return;
  1328. sp_lc = result.shenpi.sp_lc;
  1329. sp_type = result.shenpi.sp_type;
  1330. sp_status = result.shenpi.sp_status;
  1331. sp_status_list = result.shenpi.sp_status_list;
  1332. cur_tenderid = result.tender.id;
  1333. cur_uid = result.tender.user_id;
  1334. tenderApprovalEditor.setData(result);
  1335. }, function () {
  1336. if (loadId !== tenderApprovalLoadId) return;
  1337. $('#splc').html('<div class="alert alert-warning">审批流程加载失败,请重试。' +
  1338. '<button type="button" class="btn btn-sm btn-outline-primary ml-2 approval-retry" data-id="' + tid + '">重新加载</button></div>');
  1339. });
  1340. }