rpt_signature.js 34 KB

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