rpt_signature.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. /**
  2. * Created by Tony on 2019/9/25.
  3. */
  4. 'use strict'
  5. const DFT_ROLE_NAME = '';
  6. let rptSignatureHelper = {
  7. currentSelectedESignAccDom: null,
  8. currentSelectedESignAccIdx: -1,
  9. currentSelectedESignAccName: null,
  10. currentSelectedESignParentDivId: '',
  11. originalRoleRelList: [],
  12. buildSelectableAccount: function () {
  13. //PRJ_ACCOUNT_LIST
  14. //1. 清理所有选择项
  15. // $("#project_account_select_div").empty();
  16. let accDiv = $('#project_account_select_div');
  17. let accSelect = $('#project_account_select_dom'); //绑定成员
  18. let searchInput = $('#search_account').val();
  19. accDiv.empty();
  20. accSelect.empty();
  21. //2. 一个个加可选用户项
  22. const prj_accounts = [];
  23. const prj_sel_option_accounts = [];
  24. const acc_role_keys = [];
  25. for (let accIdx = 0; accIdx < PRJ_ACCOUNT_LIST.length; accIdx++) {
  26. const prjAccount = PRJ_ACCOUNT_LIST[accIdx];
  27. if (searchInput === '' || (searchInput !== '' && prjAccount.name.indexOf(searchInput) !== -1)) {
  28. let companyKey = prjAccount.account_group;
  29. let roleKey = prjAccount.role;
  30. if (companyKey === '') {
  31. companyKey = '其他单位';
  32. }
  33. if (roleKey === '') {
  34. roleKey = DFT_ROLE_NAME;
  35. }
  36. let keyIdx = acc_role_keys.indexOf(companyKey);
  37. if (keyIdx < 0) {
  38. acc_role_keys.push(companyKey);
  39. prj_accounts.push([]);
  40. prj_sel_option_accounts.push([]);
  41. keyIdx = prj_accounts.length - 1;
  42. //这里先push一些 html prefix,在后面统一在push html suffix
  43. prj_accounts[keyIdx].push('<ul class="list-group">');
  44. prj_accounts[keyIdx].push('<li class="px-2 text-muted"><i class="fa fa-caret-down"></i> ' + companyKey + '</li>');
  45. prj_sel_option_accounts[keyIdx].push('<optgroup label=" ' + companyKey + '">');
  46. }
  47. //push item
  48. prj_accounts[keyIdx].push('<li class="add-sign-list-item"><a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByAccIdx(' + accIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal"><i class="fa fa-plus"></i></a>' +
  49. prjAccount.name + '-<small class="text-muted">' + roleKey + '</small></li>');
  50. prj_sel_option_accounts[keyIdx].push('<option value="' + accIdx + '">' + prjAccount.name + '-' + roleKey + '</option>');
  51. }
  52. }
  53. for (const prjAccList of prj_accounts) {
  54. prjAccList.push('</ul>');
  55. }
  56. for (const prjAccList of prj_sel_option_accounts) {
  57. prjAccList.push('</optgroup>');
  58. }
  59. for (let idx = 0; idx < prj_accounts.length; idx++) {
  60. prj_accounts[idx] = prj_accounts[idx].join('');
  61. prj_sel_option_accounts[idx] = prj_sel_option_accounts[idx].join('');
  62. }
  63. accDiv.append(prj_accounts.join(''));
  64. accSelect.append(prj_sel_option_accounts.join(''));
  65. },
  66. buildSelectableAccountUsed: function () {
  67. //PRJ_ACCOUNT_LIST
  68. //1. 清理所有选择项
  69. // $("#project_account_select_div").empty();
  70. let accDiv = $('#account_used_select_div');
  71. accDiv.empty();
  72. //2. 一个个加可选用户项
  73. const prj_accounts = [];
  74. for (let uidx = 0; uidx < USED_LIST.length; uidx++) {
  75. const accIdx = PRJ_ACCOUNT_LIST.findIndex(function(item) {
  76. return item.id === USED_LIST[uidx].uid;
  77. });
  78. if (accIdx === -1 || accIdx === undefined) {
  79. continue;
  80. }
  81. const prjAccount = PRJ_ACCOUNT_LIST[accIdx];
  82. let roleKey = prjAccount.role;
  83. if (roleKey === '') {
  84. roleKey = DFT_ROLE_NAME;
  85. }
  86. //push item
  87. prj_accounts.push('<li class="add-sign-list-item"><a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByAccIdx(' + accIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal"><i class="fa fa-plus"></i></a>' +
  88. prjAccount.name + '-<small class="text-muted">' + roleKey + '</small></li>');
  89. }
  90. accDiv.append(prj_accounts.join(''));
  91. },
  92. createEsignatureByAccIdx: function (accIdx) {
  93. rptSignatureHelper.createPreSelectedSignature(PRJ_ACCOUNT_LIST[accIdx], null);
  94. },
  95. createEsignatureByRoleIdx: function (roleIdx) {
  96. rptSignatureHelper.createPreSelectedSignature(null, ROLE_LIST[roleIdx]);
  97. },
  98. createPreSelectedSignature: function (directAcc, roleAcc) {
  99. let dftSignSrc = '/public/upload/sign/user-sign.PNG';
  100. let userAcc = directAcc;
  101. if (roleAcc) {
  102. userAcc = rptSignatureHelper.getUserAccount(roleAcc.bind_acc_id);
  103. }
  104. if (userAcc.sign_path !== '') {
  105. dftSignSrc = '/public/upload/sign/' + userAcc.sign_path;
  106. }
  107. if (rptSignatureHelper.currentSelectedESignAccName !== null) {
  108. for (const page of zTreeOprObj.currentRptPageRst.items) {
  109. if (page.signature_cells) {
  110. for (const sCell of page.signature_cells) {
  111. if (sCell.signature_name === rptSignatureHelper.currentSelectedESignAccName) {
  112. sCell.pre_path = dftSignSrc;
  113. }
  114. }
  115. }
  116. }
  117. // 1. 删除不需要的child dom
  118. $(rptSignatureHelper.currentSelectedESignAccDom).empty();
  119. // 2. 创建已选择签名相关 dom
  120. rptSignatureHelper.cleanOldSignature(rptSignatureHelper.currentSelectedESignAccName);
  121. // 2.1 dom element
  122. const elementsStrArr = [];
  123. let dftDate = _getSignDateByAllScenarios(userAcc.id);
  124. if (dftDate !== '' && dftDate.length > 20) {
  125. dftDate = (new Date(dftDate)).Format('yyyy-MM-dd');
  126. }
  127. if (directAcc) {
  128. rptSignatureHelper.pushDomElementByUser(elementsStrArr, userAcc.name, userAcc.role);
  129. // 还有ROLE_REL_LIST
  130. let roleRelObj = {};
  131. roleRelObj.signature_name = rptSignatureHelper.currentSelectedESignAccName;
  132. roleRelObj.sign_path = dftSignSrc;
  133. // roleRelObj.sign_date = '';
  134. roleRelObj.sign_date = dftDate;
  135. roleRelObj.sign_date_format = 'yyyy年M月d日';
  136. roleRelObj.user_name = userAcc.name;
  137. roleRelObj.acc_id = userAcc.id;
  138. roleRelObj.type = '用户';
  139. roleRelObj.role = (userAcc.role === '')?DFT_ROLE_NAME:userAcc.role;
  140. ROLE_REL_LIST.push(roleRelObj);
  141. } else if (roleAcc) {
  142. // 创建相关dom元素
  143. rptSignatureHelper.pushDomElementByRole(elementsStrArr, roleAcc.name, userAcc.name);
  144. // 还有ROLE_REL_LIST
  145. let roleRelObj = {};
  146. roleRelObj.signature_name = rptSignatureHelper.currentSelectedESignAccName;
  147. roleRelObj.sign_path = dftSignSrc;
  148. // roleRelObj.sign_date = '';
  149. roleRelObj.sign_date = dftDate;
  150. roleRelObj.sign_date_format = 'yyyy年M月d日';
  151. roleRelObj.user_name = userAcc.name;
  152. roleRelObj.acc_id = userAcc.id;
  153. roleRelObj.type = '角色';
  154. roleRelObj.role = (userAcc.role === '')?DFT_ROLE_NAME:userAcc.role;
  155. roleRelObj.role_name = roleAcc.name;
  156. ROLE_REL_LIST.push(roleRelObj);
  157. }
  158. // elementsStrArr.push('');
  159. rptSignatureHelper.pushDatePickerDom(elementsStrArr, userAcc.id);
  160. $(rptSignatureHelper.currentSelectedESignAccDom).append(elementsStrArr.join(' '));
  161. //.appendChild(pNode);
  162. //*/
  163. // 2.2 date-picker
  164. // 更新最近使用名单
  165. const params = {};
  166. params.uid = userAcc.id;
  167. params.prj_id = PROJECT_ID;
  168. params.tender_id = TENDER_ID;
  169. CommonAjax.postXsrfEx("/tender/report_api/updateSignatureUsed", params, 10000, true, getCookie('csrfToken_j'),
  170. function(result){
  171. console.log(result);
  172. USED_LIST = result.data;
  173. $('#search_account').val('');
  174. rptSignatureHelper.buildSelectableAccount();
  175. rptSignatureHelper.buildSelectableAccountUsed();
  176. }, function(err){
  177. // hintBox.unWaitBox();
  178. }, function(ex){
  179. // hintBox.unWaitBox();
  180. }
  181. );
  182. }
  183. },
  184. cleanOldSignature: function (signature_name) {
  185. // 清掉ROLE_REL_LIST原有的签名
  186. for (let idx = ROLE_REL_LIST.length - 1; idx >= 0 ; idx--) {
  187. if (ROLE_REL_LIST[idx].signature_name === signature_name) {
  188. ROLE_REL_LIST.splice(idx, 1);
  189. }
  190. }
  191. },
  192. resetESignature: function (pageRst, signatureDivId) {
  193. // let body = $('#eSignatureBodyDiv');
  194. if (pageRst !== null) {
  195. let body = $('#' + signatureDivId);
  196. rptSignatureHelper.currentSelectedESignParentDivId = signatureDivId;
  197. body.empty();
  198. const signature_cells = [];
  199. const singatureNameArr = [];
  200. for (const page of pageRst.items) {
  201. if (page.signature_cells) {
  202. for (const sCell of page.signature_cells) {
  203. if (sCell.signature_name !== null && sCell.signature_name !== undefined && sCell.signature_name !== 'dummy_pic') {
  204. if (singatureNameArr.indexOf(sCell.signature_name) < 0) {
  205. signature_cells.push(sCell);
  206. singatureNameArr.push(sCell.signature_name);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. if (signature_cells.length > 0) {
  213. const elementsStrArr = [];
  214. const elementsDateStrArr = [];
  215. for (let scIdx = 0; scIdx < signature_cells.length; scIdx++) {
  216. const sCell = signature_cells[scIdx];
  217. elementsStrArr.push('<div class="form-group row">');
  218. elementsStrArr.push('<label for="staticEmail" class="col-sm-3 col-form-label pr-0">' + sCell.signature_name + '</label>');
  219. elementsStrArr.push('<div class="col-sm-9">');
  220. elementsStrArr.push('<ul class="list-group">');
  221. elementsStrArr.push('<li class="list-group-item">');
  222. let hasPic = false;
  223. //新需求中,即使没有审核,也可以设置签名
  224. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  225. const role_rel = ROLE_REL_LIST[idx];
  226. if (role_rel.signature_name === sCell.signature_name) {
  227. if (role_rel.type === '用户') {
  228. rptSignatureHelper.pushDomElementByUser(elementsStrArr, role_rel.user_name, role_rel.role);
  229. } else {
  230. //角色
  231. rptSignatureHelper.pushDomElementByRole(elementsStrArr, role_rel.role_name, role_rel.user_name);
  232. }
  233. const idSuffixStr = 'dtp_' + role_rel.signature_name + '_' + signatureDivId;
  234. elementsStrArr.push('<div class="">');
  235. if (role_rel.sign_date !== '') {
  236. const dt = new Date(role_rel.sign_date);
  237. const dtVal = dt.Format('yyyy-MM-dd');
  238. //elementsStrArr.push('<input class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text" value="' + (new Date(role_rel.sign_date)).Format('yyyy-M-d') + '">');
  239. // elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text" readonly="true" value="' + dtVal + '"');
  240. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date" value="' + dtVal + '"');
  241. } else {
  242. // elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text" readonly="true"');
  243. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date"');
  244. }
  245. hasPic = true;
  246. break;
  247. }
  248. }
  249. if (!hasPic) {
  250. // 在交互操作中,有可能实际上是没有
  251. elementsStrArr.push('<a href="#add-sign" onclick="rptSignatureHelper.currentSelectedESignAccDom = this.parentNode; rptSignatureHelper.currentSelectedESignAccName = \'' + sCell.signature_name + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  252. }
  253. // if (sCell.path || sCell.pic) {
  254. // } else {
  255. // elementsStrArr.push('<a href="#add-sign" onclick="rptSignatureHelper.currentSelectedESignAccDom = this.parentNode; rptSignatureHelper.currentSelectedESignAccName = \'' + sCell.signature_name + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  256. // }
  257. elementsStrArr.push('</li>');
  258. elementsStrArr.push('</ul>');
  259. elementsStrArr.push('</div>');
  260. elementsStrArr.push('</div>');
  261. //还有签名日期(用不用得上不管,先放上去再说)
  262. }
  263. body.append(elementsStrArr.join(' '));
  264. }
  265. }
  266. },
  267. checkAndShowCrossTendersESignature: function () {
  268. let btnDom = $('#btn_cross_tender')[0];
  269. if (zTreeOprObj.currentNode) {
  270. btnDom.style.display = '';
  271. } else {
  272. btnDom.style.display = 'none';
  273. }
  274. },
  275. pushDomElementByUser: function (elementsStrArr, userName, userRole) {
  276. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><span>' + userName +
  277. '-<small class="text-muted">' + ((userRole === '')?DFT_ROLE_NAME:userRole) +
  278. '</small></span><a onclick="rptSignatureHelper.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>');
  279. // rptSignatureHelper.pushDatePickerDom(elementsStrArr);
  280. },
  281. pushDomElementByRole: function (elementsStrArr, roleName, userName) {
  282. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><span><i class="fa fa-user" title="角色"> ' + roleName +
  283. '</i>-<small class="text-muted">' + userName +
  284. '</small></span><a onclick="rptSignatureHelper.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>');
  285. // rptSignatureHelper.pushDatePickerDom(elementsStrArr);
  286. },
  287. pushDatePickerDom: function (elementsStrArr, userAccId) {
  288. let idSuffixStr = 'dtp_' + rptSignatureHelper.currentSelectedESignAccName + '_' + rptSignatureHelper.currentSelectedESignParentDivId;
  289. elementsStrArr.push('<div class="">');
  290. // 日期控件存在页面高度不过高无法选中bug,先不用
  291. // elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" data-position="right bottom" type="text" readonly="true"');
  292. //*
  293. let dftDate = _getSignDateByAllScenarios(userAccId);
  294. if (dftDate !== '' && dftDate.length > 20) {
  295. dftDate = (new Date(dftDate)).Format('yyyy-MM-dd');
  296. }
  297. /*/
  298. let dftDate = '';
  299. let hasAudit = false;
  300. if (STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  301. for (const stga of STAGE_AUDIT) {
  302. if (stga.aid === userAccId) {
  303. hasAudit = true;
  304. if (stga.status === 3 && stga.end_time && stga.end_time !== '' && stga.end_time.length > 20) {
  305. //只有在审批人通过后才获取审批时间
  306. // let dt = new Date(stga.end_time);
  307. dftDate = (new Date(stga.end_time)).Format('yyyy-MM-dd');
  308. } else {
  309. dftDate = '';
  310. }
  311. // break; // 实际情况:有可能会有多次审核,要取最后一次
  312. }
  313. }
  314. }
  315. let isOrgRpt = false;
  316. for (const stg of STAGE_LIST) {
  317. if (stg.id === current_stage_id) {
  318. if (stg.user_id === userAccId) {
  319. isOrgRpt = true;
  320. }
  321. break;
  322. }
  323. }
  324. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  325. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  326. dftDate = (new Date(STAGE_AUDIT_ORG[0].begin_time)).Format('yyyy-MM-dd');
  327. }
  328. }
  329. if (!isOrgRpt && !hasAudit) {
  330. //非审批流程人员以及非原报,则显示期截至时间
  331. for (const stg of STAGE_LIST) {
  332. if (stg.id === current_stage_id && stg.period) {
  333. const period = stg.period.split(' ~ ');
  334. if (period.length === 2) {
  335. dftDate = period[1];
  336. }
  337. }
  338. }
  339. }
  340. //*/
  341. if (dftDate !== '') {
  342. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date" value="' + dftDate + '"');
  343. } else {
  344. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date"');
  345. }
  346. elementsStrArr.push('</div>');
  347. },
  348. removeSignature: function (dom) {
  349. let accTxtName = $(dom.parentNode.parentNode.parentNode.parentNode.parentNode).find('label')[0].innerText;
  350. let jDom = $(dom.parentNode.parentNode);
  351. jDom.empty();
  352. jDom.append('<a href="#add-sign" onclick="rptSignatureHelper.currentSelectedESignAccDom = this.parentNode; rptSignatureHelper.currentSelectedESignAccName = \'' +
  353. accTxtName + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  354. // 要记得清空相关pre_path属性
  355. for (const page of zTreeOprObj.currentRptPageRst.items) {
  356. if (page.signature_cells) {
  357. for (const sCell of page.signature_cells) {
  358. if (sCell.signature_name === accTxtName) {
  359. sCell.pre_path = '';
  360. }
  361. }
  362. }
  363. }
  364. // 还有ROLE_REL_LIST
  365. rptSignatureHelper.cleanOldSignature(accTxtName);
  366. },
  367. removeSelectSignature: function () {
  368. for (const page of zTreeOprObj.currentRptPageRst.items) {
  369. if (page.signature_cells) {
  370. for (const sCell of page.signature_cells) {
  371. if (sCell.hasOwnProperty('pre_path')) {
  372. delete sCell.pre_path;
  373. }
  374. }
  375. }
  376. }
  377. // ROLE_REL_LIST = [];
  378. // ROLE_REL_LIST = ROLE_REL_LIST.concat(rptSignatureHelper.originalRoleRelList);
  379. ROLE_REL_LIST = JSON.parse(JSON.stringify(rptSignatureHelper.originalRoleRelList));
  380. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  381. },
  382. resetSignAudit: function () {
  383. rptSignatureHelper.mergeSignAudit(zTreeOprObj.currentRptPageRst, ROLE_REL_LIST, STAGE_AUDIT);
  384. },
  385. resetSignDate: function(signatureDivId) {
  386. for (const page of zTreeOprObj.currentRptPageRst.items) {
  387. if (page.signature_date_cells) {
  388. for (const sCell of page.signature_date_cells) {
  389. sCell.Value = _getSignDateDftName();
  390. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  391. const role_rel = ROLE_REL_LIST[idx];
  392. const idSuffixStr = 'dtp_' + role_rel.signature_name + '_' + signatureDivId;
  393. let dtDom = $('#' + idSuffixStr);
  394. if (dtDom.length === 1) {
  395. const dtStr = dtDom[0].value;
  396. if (dtStr && dtStr !== '' && dtStr.length >= 8 && dtStr.length <= 10) {
  397. role_rel.sign_date = new Date(dtStr);
  398. } else {
  399. role_rel.sign_date = '';
  400. }
  401. // 要处理相关签名Cell属性(默认跟普通cell一样,就多了个signature_name)
  402. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  403. if (role_rel.sign_date !== '') {
  404. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  405. }
  406. }
  407. }
  408. }
  409. }
  410. }
  411. }
  412. },
  413. setupAfterSelectMultiTenders: function (selectedTenders, signatureDivId) {
  414. //跨标段选择,有不少要注意的交互:
  415. //0. 签名日期
  416. rptSignatureHelper.resetSignDate(signatureDivId);
  417. rptSignatureHelper.resetSignAudit();
  418. //1. 重刷page
  419. if (current_stage_status === 3) {
  420. for (const page of zTreeOprObj.currentRptPageRst.items) {
  421. if (page.signature_cells) {
  422. for (const sCell of page.signature_cells) {
  423. if (sCell.hasOwnProperty('pre_path')) {
  424. sCell.path = sCell.pre_path;
  425. delete sCell.pre_path;
  426. }
  427. }
  428. }
  429. }
  430. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  431. }
  432. //2. 集中请求
  433. let params = {};
  434. params.id = CURRENT_ROLE_REL_ID;
  435. params.tender_id = TENDER_ID;
  436. params.stage_id = getStageId();
  437. params.rpt_id = zTreeOprObj.currentNode.refId;
  438. params.rel_content = ROLE_REL_LIST;
  439. params.selectedTenders = selectedTenders;
  440. rptSignatureHelper.originalRoleRelList = JSON.parse(JSON.stringify(ROLE_REL_LIST));
  441. CommonAjax.postXsrfEx("/tender/report_api/updateMultiRoleRelationship", params, 10000, true, getCookie('csrfToken_j'),
  442. function(result){
  443. console.log(result);
  444. if (result.data && result.data.insertId > 0) {
  445. CURRENT_ROLE_REL_ID = result.data.insertId;
  446. }
  447. }, function(err){
  448. // hintBox.unWaitBox();
  449. }, function(ex){
  450. // hintBox.unWaitBox();
  451. }
  452. );
  453. },
  454. setupAfterSelectSignature: function (signatureDivId) {
  455. //0. 签名日期
  456. rptSignatureHelper.resetSignDate(signatureDivId);
  457. rptSignatureHelper.resetSignAudit();
  458. if (current_stage_status === 3) {
  459. //1. 重刷page
  460. for (const page of zTreeOprObj.currentRptPageRst.items) {
  461. if (page.signature_cells) {
  462. for (const sCell of page.signature_cells) {
  463. if (sCell.hasOwnProperty('pre_path')) {
  464. sCell.path = sCell.pre_path;
  465. delete sCell.pre_path;
  466. }
  467. }
  468. }
  469. }
  470. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  471. }
  472. //2. 更新数据
  473. const params = {};
  474. params.id = CURRENT_ROLE_REL_ID;
  475. params.tender_id = TENDER_ID;
  476. params.stage_id = getStageId();
  477. params.rpt_id = zTreeOprObj.currentNode.refId;
  478. params.rel_content = ROLE_REL_LIST;
  479. // rptSignatureHelper.originalRoleRelList = [];
  480. // rptSignatureHelper.originalRoleRelList = rptSignatureHelper.originalRoleRelList.concat(ROLE_REL_LIST);
  481. rptSignatureHelper.originalRoleRelList = JSON.parse(JSON.stringify(ROLE_REL_LIST));
  482. CommonAjax.postXsrfEx("/tender/report_api/updateRoleRelationship", params, 10000, true, getCookie('csrfToken_j'),
  483. function(result){
  484. console.log(result);
  485. if (result.data && result.data.insertId > 0) {
  486. CURRENT_ROLE_REL_ID = result.data.insertId;
  487. }
  488. }, function(err){
  489. // hintBox.unWaitBox();
  490. }, function(ex){
  491. // hintBox.unWaitBox();
  492. }
  493. );
  494. },
  495. switchAddRoleDiv: function (dom) {
  496. if (dom.nextElementSibling.children[0].style.display === 'none') {
  497. dom.nextElementSibling.children[0].style.display = '';
  498. } else {
  499. dom.nextElementSibling.children[0].style.display = 'none';
  500. }
  501. },
  502. createNewRole: function (dom) {
  503. if ($('#acc_role_name')[0].value !== '') {
  504. const params = {};
  505. params.name = $('#acc_role_name')[0].value;
  506. const selectedAcc = PRJ_ACCOUNT_LIST[$('#project_account_select_dom')[0].selectedOptions[0].value];
  507. const roleName = (selectedAcc.role === '')?DFT_ROLE_NAME:selectedAcc.role;
  508. params.bind_acc_id = selectedAcc.id;
  509. params.prj_id = PROJECT_ID;
  510. params.tender_id = TENDER_ID;
  511. CommonAjax.postXsrfEx("/tender/report_api/createSignatureRole", params, 10000, true, getCookie('csrfToken_j'),
  512. function(result){
  513. console.log(result);
  514. const newRole = {};
  515. newRole.name = params.name;
  516. newRole.bind_acc_id = selectedAcc.id;
  517. newRole.prj_id = PROJECT_ID;
  518. newRole.tender_id = TENDER_ID;
  519. ROLE_LIST.push(newRole);
  520. const domArr = [];
  521. domArr.push('<li class="add-sign-list-item">');
  522. //1. apply签名
  523. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + (ROLE_LIST.length - 1) +')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  524. domArr.push('<i class="fa fa-plus"></i>');
  525. domArr.push('</a>');
  526. //2. 编辑角色(暂缓处理click事件)
  527. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  528. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  529. domArr.push('</a>');
  530. //3. 显示名称
  531. domArr.push('<i class="fa fa-user"></i> ' + $('#acc_role_name')[0].value + '<p>' + selectedAcc.name + '-<small class="text-muted">' + roleName + '</small></p>');
  532. $('#existed_roles_ul').append(domArr.join(' '));
  533. }, function(err){
  534. // hintBox.unWaitBox();
  535. }, function(ex){
  536. // hintBox.unWaitBox();
  537. }
  538. );
  539. } else {
  540. alert('请输入合适的名称!');
  541. }
  542. },
  543. buildRoleDom: function (roleList) {
  544. const ulDom = $('#existed_roles_ul');
  545. ulDom.empty();
  546. for (let domIdx = 0; domIdx < roleList.length; domIdx++) {
  547. const role = roleList[domIdx];
  548. const domArr = [];
  549. domArr.push('<li class="add-sign-list-item">');
  550. //1. apply签名
  551. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + domIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  552. domArr.push('<i class="fa fa-plus"></i>');
  553. domArr.push('</a>');
  554. //2. 编辑角色(暂缓)
  555. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  556. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  557. domArr.push('</a>');
  558. //3. 显示名称
  559. let acc = rptSignatureHelper.getUserAccount(role.bind_acc_id);
  560. domArr.push('<i class="fa fa-user"></i> ' + role.name + '<p>' + acc.name + '-<small class="text-muted">' + ((acc.role === '')?DFT_ROLE_NAME:acc.role) + '</small></p>');
  561. ulDom.append(domArr.join(' '));
  562. }
  563. },
  564. getUserAccount: function (accId) {
  565. let rst = null;
  566. for (const acc of PRJ_ACCOUNT_LIST) {
  567. if (acc.id === accId) {
  568. rst = acc;
  569. break;
  570. }
  571. }
  572. return rst;
  573. },
  574. mergeSignature: function (pageData, currRoleRelList) {
  575. for (const page of pageData.items) {
  576. if (page.signature_cells) {
  577. for (const sCell of page.signature_cells) {
  578. for (const role_rel of currRoleRelList) {
  579. if (role_rel.signature_name === sCell.signature_name) {
  580. sCell.path = role_rel.sign_path;
  581. sCell.pre_path = role_rel.sign_path;
  582. }
  583. }
  584. }
  585. }
  586. }
  587. },
  588. mergeSignAudit: function (pageData, currRoleRelList, currAuditList) {
  589. for (const page of pageData.items) {
  590. if (page.signature_audit_cells) {
  591. for (const sCell of page.signature_audit_cells) {
  592. sCell.Value = ''; // 这里要先清除原有信息
  593. for (const role_rel of currRoleRelList) {
  594. if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
  595. let preDate = '';
  596. sCell.Value = '同意'; // 只有选择了签名的,才需要初始化一个默认的意见(之前的逻辑在有多个签名,哪怕只选择了一个,其他的意见都会有默认意见)
  597. for (const audit_rel of currAuditList) {
  598. if (role_rel.acc_id === audit_rel.aid) {
  599. if (audit_rel.end_time > preDate && audit_rel.status === 3) {
  600. sCell.Value = audit_rel.opinion;
  601. preDate = audit_rel.end_time;
  602. }
  603. //不能break,实际会有多个审核意见,以最后一个为准
  604. }
  605. }
  606. break;
  607. }
  608. }
  609. }
  610. }
  611. }
  612. },
  613. mergeSignDate: function (pageData, currRoleRelList, isMergeOrgAlso) {
  614. if (currRoleRelList && currRoleRelList.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  615. for (let rridx = 0; rridx < currRoleRelList.length; rridx++) {
  616. const role_rel = currRoleRelList[rridx];
  617. if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
  618. //*
  619. let dftDate = _getSignDateByAllScenarios(role_rel.acc_id);
  620. role_rel.sign_date = dftDate;
  621. if (isMergeOrgAlso) {
  622. rptSignatureHelper.originalRoleRelList[rridx].sign_date = dftDate;
  623. //备注:在多选导出的情况下,originalRoleRelList不需要merge
  624. }
  625. /*/
  626. let hasAudit = false;
  627. for (const stg_audit of STAGE_AUDIT) {
  628. if (role_rel.acc_id === stg_audit.aid) {
  629. hasAudit = true;
  630. if (stg_audit.status === 3) {
  631. role_rel.sign_date = stg_audit.end_time;
  632. rptSignatureHelper.originalRoleRelList[rridx].sign_date = stg_audit.end_time;
  633. } else {
  634. role_rel.sign_date = '';
  635. rptSignatureHelper.originalRoleRelList[rridx].sign_date = '';
  636. }
  637. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  638. }
  639. }
  640. let isOrgRpt = false;
  641. for (const stg of STAGE_LIST) {
  642. if (stg.id === current_stage_id) {
  643. if (stg.user_id === role_rel.acc_id) {
  644. isOrgRpt = true;
  645. }
  646. break;
  647. }
  648. }
  649. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  650. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  651. role_rel.sign_date = STAGE_AUDIT_ORG[0].begin_time;
  652. rptSignatureHelper.originalRoleRelList[rridx].sign_date = STAGE_AUDIT_ORG[0].begin_time;
  653. }
  654. }
  655. if (!isOrgRpt && !hasAudit) {
  656. //非审批流程人员以及非原报,则显示期截至时间
  657. for (const stg of STAGE_LIST) {
  658. if (stg.id === current_stage_id && stg.period) {
  659. const period = stg.period.split(' ~ ');
  660. if (period.length === 2) {
  661. role_rel.sign_date = period[1];
  662. rptSignatureHelper.originalRoleRelList[rridx].sign_date = period[1];
  663. }
  664. }
  665. }
  666. }
  667. //*/
  668. }
  669. }
  670. }
  671. for (const page of pageData.items) {
  672. if (page.signature_date_cells) {
  673. for (const sCell of page.signature_date_cells) {
  674. if (sCell.Value === undefined || sCell.Value === null && sCell.Value === '') {
  675. sCell.Value = _getSignDateDftName();
  676. }
  677. for (const role_rel of currRoleRelList) {
  678. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  679. if (role_rel.sign_date !== '') {
  680. if (typeof role_rel.sign_date === 'string') {
  681. role_rel.sign_date = new Date(role_rel.sign_date);
  682. }
  683. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  684. }
  685. break;
  686. }
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. function _getSignDateByAllScenarios(userAccId) {
  694. let rst = '';
  695. let hasAudit = false;
  696. for (const stg_audit of STAGE_AUDIT) {
  697. if (stg_audit.aid === userAccId) {
  698. hasAudit = true;
  699. if (stg_audit.status === 3) {
  700. rst = stg_audit.end_time;
  701. } else {
  702. rst = '';
  703. }
  704. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  705. }
  706. }
  707. let isOrgRpt = false;
  708. for (const stg of STAGE_LIST) {
  709. if (stg.id === current_stage_id) {
  710. if (stg.user_id === userAccId) {
  711. isOrgRpt = true;
  712. }
  713. break;
  714. }
  715. }
  716. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  717. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  718. rst = STAGE_AUDIT_ORG[0].begin_time;
  719. }
  720. }
  721. if (!isOrgRpt && !hasAudit) {
  722. //非审批流程人员以及非原报,则显示期截至时间
  723. for (const stg of STAGE_LIST) {
  724. if (stg.id === current_stage_id && stg.period) {
  725. const period = stg.period.split(' ~ ');
  726. if (period.length === 2) {
  727. rst = period[1];
  728. }
  729. }
  730. }
  731. }
  732. return rst;
  733. }
  734. function _getSignDateDftName() {
  735. return ' 年 月 日';
  736. }