setting_manage.js 68 KB

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