rpt_signature.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  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) {
  186. let body = $('#eSignatureBodyDiv');
  187. body.empty();
  188. const signature_cells = [];
  189. const singatureNameArr = [];
  190. for (const page of pageRst.items) {
  191. if (page.signature_cells) {
  192. for (const sCell of page.signature_cells) {
  193. if (sCell.signature_name !== null && sCell.signature_name !== undefined && sCell.signature_name !== 'dummy_pic') {
  194. if (singatureNameArr.indexOf(sCell.signature_name) < 0) {
  195. signature_cells.push(sCell);
  196. singatureNameArr.push(sCell.signature_name);
  197. }
  198. }
  199. }
  200. }
  201. }
  202. if (signature_cells.length > 0) {
  203. const elementsStrArr = [];
  204. const elementsDateStrArr = [];
  205. for (let scIdx = 0; scIdx < signature_cells.length; scIdx++) {
  206. const sCell = signature_cells[scIdx];
  207. elementsStrArr.push('<div class="form-group row">');
  208. elementsStrArr.push('<label for="staticEmail" class="col-sm-3 col-form-label pr-0">' + sCell.signature_name + '</label>');
  209. elementsStrArr.push('<div class="col-sm-9">');
  210. elementsStrArr.push('<ul class="list-group">');
  211. elementsStrArr.push('<li class="list-group-item">');
  212. let hasPic = false;
  213. //新需求中,即使没有审核,也可以设置签名
  214. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  215. const role_rel = ROLE_REL_LIST[idx];
  216. if (role_rel.signature_name === sCell.signature_name) {
  217. if (role_rel.type === '用户') {
  218. rptSignatureHelper.pushDomElementByUser(elementsStrArr, role_rel.user_name, role_rel.role);
  219. } else {
  220. //角色
  221. rptSignatureHelper.pushDomElementByRole(elementsStrArr, role_rel.role_name, role_rel.user_name);
  222. }
  223. const idSuffixStr = 'dtp_' + role_rel.signature_name;
  224. elementsStrArr.push('<div class="">');
  225. if (role_rel.sign_date !== '') {
  226. const dt = new Date(role_rel.sign_date);
  227. const dtVal = dt.Format('yyyy-MM-dd');
  228. //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') + '">');
  229. // 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 + '"');
  230. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date" value="' + dtVal + '"');
  231. } else {
  232. // elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text" readonly="true"');
  233. elementsStrArr.push('<input id="' + idSuffixStr + '" class="form-control form-control-sm mt-0" placeholder="选择签名日期" type="date"');
  234. }
  235. elementsStrArr.push('</div>');
  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. resetSignDate: function() {
  365. for (const page of zTreeOprObj.currentRptPageRst.items) {
  366. if (page.signature_date_cells) {
  367. for (const sCell of page.signature_date_cells) {
  368. sCell.Value = _getSignDateDftName();
  369. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  370. const role_rel = ROLE_REL_LIST[idx];
  371. const idSuffixStr = 'dtp_' + role_rel.signature_name;
  372. let dtDom = $('#' + idSuffixStr);
  373. if (dtDom.length === 1) {
  374. const dtStr = dtDom[0].value;
  375. if (dtStr && dtStr !== '' && dtStr.length >= 8 && dtStr.length <= 10) {
  376. // const tmpDt = new Date(dtStr);
  377. // const year = parseInt(tmpDt.getFullYear());
  378. // const month = parseInt(tmpDt.getMonth());
  379. // const dt = parseInt(tmpDt.getDate());
  380. // role_rel.sign_date = new Date(year, month, dt);
  381. role_rel.sign_date = new Date(dtStr);
  382. } else {
  383. role_rel.sign_date = '';
  384. }
  385. // 要处理相关签名Cell属性(默认跟普通cell一样,就多了个signature_name)
  386. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  387. if (role_rel.sign_date !== '') {
  388. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  389. }
  390. }
  391. }
  392. }
  393. }
  394. }
  395. }
  396. },
  397. resetSignAudit: function () {
  398. for (const page of zTreeOprObj.currentRptPageRst.items) {
  399. if (page.signature_audit_cells) {
  400. for (const sCell of page.signature_audit_cells) {
  401. sCell.Value = '';
  402. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  403. const role_rel = ROLE_REL_LIST[idx];
  404. const idSuffixStr = 'dtp_' + role_rel.signature_name;
  405. let dtDom = $('#' + idSuffixStr);
  406. if (dtDom.length === 1) {
  407. const dtStr = dtDom[0].value;
  408. // 要处理相关签名Cell属性(默认跟普通cell一样,就多了个signature_name)
  409. if (sCell.signature_name === role_rel.signature_name + '_审核意见') {
  410. if (role_rel.sign_date !== '') {
  411. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  412. }
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. },
  420. setupAfterSelectSignature: function () {
  421. //0. 签名日期
  422. rptSignatureHelper.resetSignDate();
  423. rptSignatureHelper.resetSignAudit();
  424. if (current_stage_status === 3) {
  425. //1. 重刷page
  426. for (const page of zTreeOprObj.currentRptPageRst.items) {
  427. if (page.signature_cells) {
  428. for (const sCell of page.signature_cells) {
  429. if (sCell.hasOwnProperty('pre_path')) {
  430. sCell.path = sCell.pre_path;
  431. delete sCell.pre_path;
  432. }
  433. }
  434. }
  435. }
  436. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  437. }
  438. //2. 更新数据
  439. const params = {};
  440. params.id = CURRENT_ROLE_REL_ID;
  441. params.tender_id = TENDER_ID;
  442. params.stage_id = getStageId();
  443. params.rpt_id = zTreeOprObj.currentNode.refId;
  444. params.rel_content = ROLE_REL_LIST;
  445. // rptSignatureHelper.originalRoleRelList = [];
  446. // rptSignatureHelper.originalRoleRelList = rptSignatureHelper.originalRoleRelList.concat(ROLE_REL_LIST);
  447. rptSignatureHelper.originalRoleRelList = JSON.parse(JSON.stringify(ROLE_REL_LIST));
  448. CommonAjax.postXsrfEx("/tender/report_api/updateRoleRelationship", params, 10000, true, getCookie('csrfToken'),
  449. function(result){
  450. console.log(result);
  451. if (result.data && result.data.insertId > 0) {
  452. CURRENT_ROLE_REL_ID = result.data.insertId;
  453. }
  454. }, function(err){
  455. // hintBox.unWaitBox();
  456. }, function(ex){
  457. // hintBox.unWaitBox();
  458. }
  459. );
  460. },
  461. switchAddRoleDiv: function (dom) {
  462. if (dom.nextElementSibling.children[0].style.display === 'none') {
  463. dom.nextElementSibling.children[0].style.display = '';
  464. } else {
  465. dom.nextElementSibling.children[0].style.display = 'none';
  466. }
  467. },
  468. createNewRole: function (dom) {
  469. if ($('#acc_role_name')[0].value !== '') {
  470. const params = {};
  471. params.name = $('#acc_role_name')[0].value;
  472. const selectedAcc = PRJ_ACCOUNT_LIST[$('#project_account_select_dom')[0].selectedOptions[0].value];
  473. const roleName = (selectedAcc.role === '')?DFT_ROLE_NAME:selectedAcc.role;
  474. params.bind_acc_id = selectedAcc.id;
  475. params.prj_id = PROJECT_ID;
  476. params.tender_id = TENDER_ID;
  477. CommonAjax.postXsrfEx("/tender/report_api/createSignatureRole", params, 10000, true, getCookie('csrfToken'),
  478. function(result){
  479. console.log(result);
  480. const newRole = {};
  481. newRole.name = params.name;
  482. newRole.bind_acc_id = selectedAcc.id;
  483. newRole.prj_id = PROJECT_ID;
  484. newRole.tender_id = TENDER_ID;
  485. ROLE_LIST.push(newRole);
  486. const domArr = [];
  487. domArr.push('<li class="add-sign-list-item">');
  488. //1. apply签名
  489. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + (ROLE_LIST.length - 1) +')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  490. domArr.push('<i class="fa fa-plus"></i>');
  491. domArr.push('</a>');
  492. //2. 编辑角色(暂缓处理click事件)
  493. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  494. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  495. domArr.push('</a>');
  496. //3. 显示名称
  497. domArr.push('<i class="fa fa-user"></i> ' + $('#acc_role_name')[0].value + '<p>' + selectedAcc.name + '-<small class="text-muted">' + roleName + '</small></p>');
  498. $('#existed_roles_ul').append(domArr.join(' '));
  499. }, function(err){
  500. // hintBox.unWaitBox();
  501. }, function(ex){
  502. // hintBox.unWaitBox();
  503. }
  504. );
  505. } else {
  506. alert('请输入合适的名称!');
  507. }
  508. },
  509. buildRoleDom: function (roleList) {
  510. const ulDom = $('#existed_roles_ul');
  511. ulDom.empty();
  512. for (let domIdx = 0; domIdx < roleList.length; domIdx++) {
  513. const role = roleList[domIdx];
  514. const domArr = [];
  515. domArr.push('<li class="add-sign-list-item">');
  516. //1. apply签名
  517. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + domIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  518. domArr.push('<i class="fa fa-plus"></i>');
  519. domArr.push('</a>');
  520. //2. 编辑角色(暂缓)
  521. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  522. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  523. domArr.push('</a>');
  524. //3. 显示名称
  525. let acc = rptSignatureHelper.getUserAccount(role.bind_acc_id);
  526. 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>');
  527. ulDom.append(domArr.join(' '));
  528. }
  529. },
  530. getUserAccount: function (accId) {
  531. let rst = null;
  532. for (const acc of PRJ_ACCOUNT_LIST) {
  533. if (acc.id === accId) {
  534. rst = acc;
  535. break;
  536. }
  537. }
  538. return rst;
  539. },
  540. mergeSignature: function (pageData, currRoleRelList) {
  541. for (const page of pageData.items) {
  542. if (page.signature_cells) {
  543. for (const sCell of page.signature_cells) {
  544. for (const role_rel of currRoleRelList) {
  545. if (role_rel.signature_name === sCell.signature_name) {
  546. sCell.path = role_rel.sign_path;
  547. sCell.pre_path = role_rel.sign_path;
  548. }
  549. }
  550. }
  551. }
  552. }
  553. },
  554. mergeSignDate: function (pageData, currRoleRelList) {
  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. rptSignatureHelper.originalRoleRelList[rridx].sign_date = dftDate;
  563. /*/
  564. let hasAudit = false;
  565. for (const stg_audit of STAGE_AUDIT) {
  566. if (role_rel.acc_id === stg_audit.aid) {
  567. hasAudit = true;
  568. if (stg_audit.status === 3) {
  569. role_rel.sign_date = stg_audit.end_time;
  570. rptSignatureHelper.originalRoleRelList[rridx].sign_date = stg_audit.end_time;
  571. } else {
  572. role_rel.sign_date = '';
  573. rptSignatureHelper.originalRoleRelList[rridx].sign_date = '';
  574. }
  575. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  576. }
  577. }
  578. let isOrgRpt = false;
  579. for (const stg of STAGE_LIST) {
  580. if (stg.id === current_stage_id) {
  581. if (stg.user_id === role_rel.acc_id) {
  582. isOrgRpt = true;
  583. }
  584. break;
  585. }
  586. }
  587. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  588. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  589. role_rel.sign_date = STAGE_AUDIT_ORG[0].begin_time;
  590. rptSignatureHelper.originalRoleRelList[rridx].sign_date = STAGE_AUDIT_ORG[0].begin_time;
  591. }
  592. }
  593. if (!isOrgRpt && !hasAudit) {
  594. //非审批流程人员以及非原报,则显示期截至时间
  595. for (const stg of STAGE_LIST) {
  596. if (stg.id === current_stage_id && stg.period) {
  597. const period = stg.period.split(' ~ ');
  598. if (period.length === 2) {
  599. role_rel.sign_date = period[1];
  600. rptSignatureHelper.originalRoleRelList[rridx].sign_date = period[1];
  601. }
  602. }
  603. }
  604. }
  605. //*/
  606. }
  607. }
  608. }
  609. for (const page of pageData.items) {
  610. if (page.signature_date_cells) {
  611. for (const sCell of page.signature_date_cells) {
  612. sCell.Value = _getSignDateDftName();
  613. for (const role_rel of currRoleRelList) {
  614. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  615. if (role_rel.sign_date !== '') {
  616. if (typeof role_rel.sign_date === 'string') {
  617. role_rel.sign_date = new Date(role_rel.sign_date);
  618. }
  619. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  620. }
  621. break;
  622. }
  623. }
  624. }
  625. }
  626. }
  627. }
  628. }
  629. function _getSignDateByAllScenarios(userAccId) {
  630. let rst = '';
  631. let hasAudit = false;
  632. for (const stg_audit of STAGE_AUDIT) {
  633. if (stg_audit.aid === userAccId) {
  634. hasAudit = true;
  635. if (stg_audit.status === 3) {
  636. rst = stg_audit.end_time;
  637. } else {
  638. rst = '';
  639. }
  640. // break; //因为实际业务中会有反复,所以就不break了,一直判断,以最后一个为准
  641. }
  642. }
  643. let isOrgRpt = false;
  644. for (const stg of STAGE_LIST) {
  645. if (stg.id === current_stage_id) {
  646. if (stg.user_id === userAccId) {
  647. isOrgRpt = true;
  648. }
  649. break;
  650. }
  651. }
  652. if (isOrgRpt && !hasAudit && STAGE_AUDIT_ORG && STAGE_AUDIT_ORG.length > 0) {
  653. if (STAGE_AUDIT_ORG[0].begin_time && STAGE_AUDIT_ORG[0].begin_time !== '' && STAGE_AUDIT_ORG[0].begin_time.length > 20) {
  654. rst = STAGE_AUDIT_ORG[0].begin_time;
  655. }
  656. }
  657. if (!isOrgRpt && !hasAudit) {
  658. //非审批流程人员以及非原报,则显示期截至时间
  659. for (const stg of STAGE_LIST) {
  660. if (stg.id === current_stage_id && stg.period) {
  661. const period = stg.period.split(' ~ ');
  662. if (period.length === 2) {
  663. rst = period[1];
  664. }
  665. }
  666. }
  667. }
  668. return rst;
  669. }
  670. function _getSignDateDftName() {
  671. return ' 年 月 日';
  672. }