rpt_signature.js 34 KB

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