rpt_signature.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /**
  2. * Created by Tony on 2019/9/25.
  3. */
  4. 'use strict'
  5. let rptSignatureHelper = {
  6. currentSelectedESignAccDom: null,
  7. currentSelectedESignAccName: null,
  8. originalRoleRelList: [],
  9. buildSelectableAccount: function () {
  10. //PRJ_ACCOUNT_LIST
  11. //1. 清理所有选择项
  12. // $("#project_account_select_div").empty();
  13. let accDiv = $('#project_account_select_div');
  14. let accSelect = $('#project_account_select_dom'); //绑定成员
  15. accDiv.empty();
  16. accSelect.empty();
  17. //2. 一个个加可选用户项
  18. const prj_accounts = [];
  19. const prj_sel_option_accounts = [];
  20. const acc_role_keys = [];
  21. for (let accIdx = 0; accIdx < PRJ_ACCOUNT_LIST.length; accIdx++) {
  22. const prjAccount = PRJ_ACCOUNT_LIST[accIdx];
  23. let companyKey = prjAccount.company;
  24. let roleKey = prjAccount.role;
  25. if (companyKey === '') {
  26. companyKey = '其他单位';
  27. }
  28. if (roleKey === '') {
  29. roleKey = '工程师';
  30. }
  31. let keyIdx = acc_role_keys.indexOf(companyKey);
  32. if (keyIdx < 0) {
  33. acc_role_keys.push(companyKey);
  34. prj_accounts.push([]);
  35. prj_sel_option_accounts.push([]);
  36. keyIdx = prj_accounts.length - 1;
  37. //这里先push一些 html prefix,在后面统一在push html suffix
  38. prj_accounts[keyIdx].push('<ul class="list-group">');
  39. prj_accounts[keyIdx].push('<li class="px-2 text-muted"><i class="fa fa-caret-down"></i> ' + companyKey + '</li>');
  40. prj_sel_option_accounts[keyIdx].push('<optgroup label=" ' + companyKey + '">');
  41. }
  42. //push item
  43. 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>' +
  44. prjAccount.name + '-<small class="text-muted">' + roleKey + '</small></li>');
  45. prj_sel_option_accounts[keyIdx].push('<option value="' + accIdx + '">' + prjAccount.name + '-' + roleKey + '</option>');
  46. }
  47. for (const prjAccList of prj_accounts) {
  48. prjAccList.push('</ul>');
  49. }
  50. for (const prjAccList of prj_sel_option_accounts) {
  51. prjAccList.push('</optgroup>');
  52. }
  53. for (let idx = 0; idx < prj_accounts.length; idx++) {
  54. prj_accounts[idx] = prj_accounts[idx].join('');
  55. prj_sel_option_accounts[idx] = prj_sel_option_accounts[idx].join('');
  56. }
  57. accDiv.append(prj_accounts.join(''));
  58. accSelect.append(prj_sel_option_accounts.join(''));
  59. },
  60. createEsignatureByAccIdx: function (accIdx) {
  61. rptSignatureHelper.createPreSelectedSignature(PRJ_ACCOUNT_LIST[accIdx], null);
  62. },
  63. createEsignatureByRoleIdx: function (roleIdx) {
  64. rptSignatureHelper.createPreSelectedSignature(null, ROLE_LIST[roleIdx]);
  65. },
  66. createPreSelectedSignature: function (directAcc, roleAcc) {
  67. let dftSignSrc = '/public/images/user-sign.PNG';
  68. let userAcc = directAcc;
  69. if (roleAcc) {
  70. userAcc = rptSignatureHelper.getUserAccount(roleAcc.bind_acc_id);
  71. }
  72. if (userAcc.sign_path !== '') {
  73. dftSignSrc = '/public/images/' + userAcc.sign_path;
  74. }
  75. if (rptSignatureHelper.currentSelectedESignAccName !== null) {
  76. for (const page of zTreeOprObj.currentRptPageRst.items) {
  77. if (page.signature_cells) {
  78. for (const sCell of page.signature_cells) {
  79. if (sCell.signature_name === rptSignatureHelper.currentSelectedESignAccName) {
  80. sCell.pre_path = dftSignSrc;
  81. }
  82. }
  83. }
  84. }
  85. // 1. 删除不需要的child dom
  86. $(rptSignatureHelper.currentSelectedESignAccDom).empty();
  87. // 2. 创建已选择签名相关 dom
  88. rptSignatureHelper.cleanOldSignature(rptSignatureHelper.currentSelectedESignAccName);
  89. // 2.1 dom element
  90. const elementsStrArr = [];
  91. if (directAcc) {
  92. rptSignatureHelper.pushDomElementByUser(elementsStrArr, userAcc.name, userAcc.role);
  93. // 还有ROLE_REL_LIST
  94. let roleRelObj = {};
  95. roleRelObj.signature_name = rptSignatureHelper.currentSelectedESignAccName;
  96. roleRelObj.sign_path = dftSignSrc;
  97. roleRelObj.sign_date = '';
  98. roleRelObj.sign_date_format = 'yyyy年M月d日';
  99. roleRelObj.user_name = userAcc.name;
  100. roleRelObj.acc_id = userAcc.id;
  101. roleRelObj.type = '用户';
  102. roleRelObj.role = (userAcc.role === '')?"工程师":userAcc.role;
  103. ROLE_REL_LIST.push(roleRelObj);
  104. } else if (roleAcc) {
  105. // 创建相关dom元素
  106. rptSignatureHelper.pushDomElementByRole(elementsStrArr, roleAcc.name, userAcc.name);
  107. // 还有ROLE_REL_LIST
  108. let roleRelObj = {};
  109. roleRelObj.signature_name = rptSignatureHelper.currentSelectedESignAccName;
  110. roleRelObj.sign_path = dftSignSrc;
  111. roleRelObj.sign_date = '';
  112. roleRelObj.sign_date_format = 'yyyy年M月d日';
  113. roleRelObj.user_name = userAcc.name;
  114. roleRelObj.acc_id = userAcc.id;
  115. roleRelObj.type = '角色';
  116. roleRelObj.role = (userAcc.role === '')?"工程师":userAcc.role;
  117. roleRelObj.role_name = roleAcc.name;
  118. ROLE_REL_LIST.push(roleRelObj);
  119. }
  120. // elementsStrArr.push('');
  121. $(rptSignatureHelper.currentSelectedESignAccDom).append(elementsStrArr.join(' '));
  122. //.appendChild(pNode);
  123. //*/
  124. // 2.2 date-picker
  125. }
  126. },
  127. cleanOldSignature: function (signature_name) {
  128. // 清掉ROLE_REL_LIST原有的签名
  129. for (let idx = ROLE_REL_LIST.length - 1; idx >= 0 ; idx--) {
  130. if (ROLE_REL_LIST[idx].signature_name === signature_name) {
  131. ROLE_REL_LIST.splice(idx, 1);
  132. }
  133. }
  134. },
  135. resetESignature: function (pageRst) {
  136. let body = $('#eSignatureBodyDiv');
  137. body.empty();
  138. const signature_cells = [];
  139. const singatureNameArr = [];
  140. for (const page of pageRst.items) {
  141. if (page.signature_cells) {
  142. for (const sCell of page.signature_cells) {
  143. if (singatureNameArr.indexOf(sCell.signature_name) < 0) {
  144. signature_cells.push(sCell);
  145. singatureNameArr.push(sCell.signature_name);
  146. }
  147. }
  148. }
  149. }
  150. if (signature_cells.length > 0) {
  151. const elementsStrArr = [];
  152. const elementsDateStrArr = [];
  153. for (let scIdx = 0; scIdx < signature_cells.length; scIdx++) {
  154. const sCell = signature_cells[scIdx];
  155. elementsStrArr.push('<div class="form-group row">');
  156. elementsStrArr.push('<label for="staticEmail" class="col-sm-3 col-form-label pr-0">' + sCell.signature_name + '</label>');
  157. elementsStrArr.push('<div class="col-sm-9">');
  158. elementsStrArr.push('<ul class="list-group">');
  159. elementsStrArr.push('<li class="list-group-item">');
  160. if (sCell.path || sCell.pic) {
  161. let hasPic = false;
  162. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  163. const role_rel = ROLE_REL_LIST[idx];
  164. if (role_rel.signature_name === sCell.signature_name) {
  165. if (role_rel.type === '用户') {
  166. rptSignatureHelper.pushDomElementByUser(elementsStrArr, role_rel.user_name, role_rel.role);
  167. } else {
  168. //角色
  169. rptSignatureHelper.pushDomElementByRole(elementsStrArr, role_rel.role_name, role_rel.user_name);
  170. }
  171. const idSuffixStr = 'dtp_' + idx;
  172. /*
  173. elementsStrArr.push('<div class="dropdown">');
  174. if (role_rel.sign_date !== '') {
  175. //elementsStrArr.push('<a href="" data-toggle="dropdown">' + (new Date(role_rel.sign_date)).Format('yyyy-M-d') + '</a>');
  176. elementsStrArr.push('<a href="" data-toggle="dropdown"><i class="fa fa-calendar" title="添加签名日期"></i></a>');
  177. } else {
  178. elementsStrArr.push('<a href="" data-toggle="dropdown"><i class="fa fa-calendar" title="添加签名日期"></i></a>');
  179. }
  180. elementsStrArr.push('<form class="dropdown-menu p-2">');
  181. elementsStrArr.push('<div class="form-group">');
  182. elementsStrArr.push('<label for="exampleDropdownFormEmail2">签名日期</label>');
  183. if (role_rel.sign_date !== '') {
  184. //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') + '">');
  185. elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text">');
  186. } else {
  187. elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text">');
  188. }
  189. elementsStrArr.push('</div>');
  190. if (role_rel.sign_date !== '') {
  191. //elementsStrArr.push('<button type="submit" class="btn btn-sm btn-outline-danger">移除日期</button> <button type="submit" class="btn btn-sm btn-primary">确认</button>');
  192. elementsStrArr.push('<button type="submit" class="btn btn-sm btn-primary">确认</button>');
  193. } else {
  194. elementsStrArr.push('<button type="submit" class="btn btn-sm btn-primary">确认</button>');
  195. }
  196. elementsStrArr.push('</form>');
  197. elementsStrArr.push('</div>');
  198. /*/
  199. elementsStrArr.push('<div class="">');
  200. if (role_rel.sign_date !== '') {
  201. const dt = new Date(role_rel.sign_date);
  202. const dtVal = dt.Format('yyyy-M-dd');
  203. //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') + '">');
  204. 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 + '"');
  205. } else {
  206. elementsStrArr.push('<input id="' + idSuffixStr + '" class="datepicker-here form-control form-control-sm mt-0" placeholder="选择签名日期" data-language="zh" type="text" readonly="true"');
  207. }
  208. elementsStrArr.push('</div>');
  209. //*/
  210. hasPic = true;
  211. break;
  212. }
  213. if (!hasPic) {
  214. // 在交互操作中,有可能实际上是没有
  215. // 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>');
  216. }
  217. }
  218. } else {
  219. 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>');
  220. }
  221. elementsStrArr.push('</li>');
  222. elementsStrArr.push('</ul>');
  223. elementsStrArr.push('</div>');
  224. elementsStrArr.push('</div>');
  225. //还有签名日期(用不用得上不管,先放上去再说)
  226. }
  227. body.append(elementsStrArr.join(' '));
  228. }
  229. },
  230. pushDomElementByUser: function (elementsStrArr, userName, userRole) {
  231. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><span>' + userName +
  232. '-<small class="text-muted">' + ((userRole === '')?"工程师":userRole) +
  233. '</small></span><a onclick="rptSignatureHelper.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>')
  234. },
  235. pushDomElementByRole: function (elementsStrArr, roleName, userName) {
  236. elementsStrArr.push('<p class=" d-flex justify-content-between m-0"><span><i class="fa fa-user" title="角色"> ' + roleName +
  237. '</i>-<small class="text-muted">' + userName +
  238. '</small></span><a onclick="rptSignatureHelper.removeSignature(this)" class="text-danger"><i class="fa fa-remove" title="移除签名"></i></a></p>')
  239. },
  240. removeSignature: function (dom) {
  241. let accTxtName = $(dom.parentNode.parentNode.parentNode.parentNode.parentNode).find('label')[0].innerText;
  242. let jDom = $(dom.parentNode.parentNode);
  243. jDom.empty();
  244. jDom.append('<a href="#add-sign" onclick="rptSignatureHelper.currentSelectedESignAccDom = this.parentNode; rptSignatureHelper.currentSelectedESignAccName = \'' +
  245. accTxtName + '\'" data-toggle="modal" data-target="#add-sign"><i class="fa fa-plus"></i> 添加签名</a>');
  246. // 要记得清空相关pre_path属性
  247. for (const page of zTreeOprObj.currentRptPageRst.items) {
  248. if (page.signature_cells) {
  249. for (const sCell of page.signature_cells) {
  250. if (sCell.signature_name === accTxtName) {
  251. sCell.pre_path = '';
  252. }
  253. }
  254. }
  255. }
  256. // 还有ROLE_REL_LIST
  257. rptSignatureHelper.cleanOldSignature(accTxtName);
  258. },
  259. removeSelectSignature: function () {
  260. for (const page of zTreeOprObj.currentRptPageRst.items) {
  261. if (page.signature_cells) {
  262. for (const sCell of page.signature_cells) {
  263. if (sCell.hasOwnProperty('pre_path')) {
  264. delete sCell.pre_path;
  265. }
  266. }
  267. }
  268. }
  269. ROLE_REL_LIST = [];
  270. ROLE_REL_LIST = ROLE_REL_LIST.concat(rptSignatureHelper.originalRoleRelList);
  271. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  272. },
  273. resetSignDate: function() {
  274. for (let idx = 0; idx < ROLE_REL_LIST.length; idx++) {
  275. const role_rel = ROLE_REL_LIST[idx];
  276. const idSuffixStr = 'dtp_' + idx;
  277. let dtDom = $('#' + idSuffixStr);
  278. if (dtDom.length === 1) {
  279. const dtStr = dtDom[0].value;
  280. if (dtStr && dtStr !== '' && dtStr.length === 10) {
  281. const year = parseInt(dtStr.slice(0, 4));
  282. const month = parseInt(dtStr.slice(5, 7)) - 1;
  283. const dt = parseInt(dtStr.slice(8, 10));
  284. role_rel.sign_date = new Date(year, month, dt);
  285. } else {
  286. role_rel.sign_date = '';
  287. }
  288. // 要处理相关签名Cell属性(默认跟普通cell一样,就多了个signature_name)
  289. for (const page of zTreeOprObj.currentRptPageRst.items) {
  290. if (page.signature_date_cells) {
  291. for (const sCell of page.signature_date_cells) {
  292. if (sCell.signature_name === role_rel.signature_name + '_签字日期') {
  293. if (role_rel.sign_date !== '') {
  294. sCell.Value = role_rel.sign_date.Format(role_rel.sign_date_format);
  295. } else {
  296. sCell.Value = '';
  297. }
  298. }
  299. }
  300. }
  301. }
  302. }
  303. }
  304. // 还有ROLE_REL_LIST
  305. // rptSignatureHelper.cleanOldSignature(accTxtName);
  306. },
  307. setupAfterSelectSignature: function () {
  308. //0. 签名日期
  309. rptSignatureHelper.resetSignDate();
  310. //1. 重刷page
  311. for (const page of zTreeOprObj.currentRptPageRst.items) {
  312. if (page.signature_cells) {
  313. for (const sCell of page.signature_cells) {
  314. if (sCell.hasOwnProperty('pre_path')) {
  315. sCell.path = sCell.pre_path;
  316. delete sCell.pre_path;
  317. }
  318. }
  319. }
  320. }
  321. zTreeOprObj.showPage(zTreeOprObj.currentPage, zTreeOprObj.canvas);
  322. //2. 更新数据
  323. const params = {};
  324. params.id = CURRENT_ROLE_REL_ID;
  325. params.tender_id = TENDER_ID;
  326. params.rpt_id = zTreeOprObj.currentNode.refId;
  327. params.rel_content = ROLE_REL_LIST;
  328. rptSignatureHelper.originalRoleRelList = [];
  329. rptSignatureHelper.originalRoleRelList = rptSignatureHelper.originalRoleRelList.concat(ROLE_REL_LIST);
  330. CommonAjax.postXsrfEx("/tender/report_api/updateRoleRelationship", params, 10000, true, getCookie('csrfToken'),
  331. function(result){
  332. console.log(result);
  333. if (result.data && result.data.insertId >= 0) {
  334. CURRENT_ROLE_REL_ID = result.data.insertId;
  335. }
  336. }, function(err){
  337. // hintBox.unWaitBox();
  338. }, function(ex){
  339. // hintBox.unWaitBox();
  340. }
  341. );
  342. },
  343. switchAddRoleDiv: function (dom) {
  344. if (dom.nextElementSibling.children[0].style.display === 'none') {
  345. dom.nextElementSibling.children[0].style.display = '';
  346. } else {
  347. dom.nextElementSibling.children[0].style.display = 'none';
  348. }
  349. },
  350. createNewRole: function (dom) {
  351. if ($('#acc_role_name')[0].value !== '') {
  352. const params = {};
  353. params.name = $('#acc_role_name')[0].value;
  354. const selectedAcc = PRJ_ACCOUNT_LIST[$('#project_account_select_dom')[0].selectedOptions[0].value];
  355. const roleName = (selectedAcc.role === '')?'工程师':selectedAcc.role;
  356. params.bind_acc_id = selectedAcc.id;
  357. params.prj_id = PROJECT_ID;
  358. params.tender_id = TENDER_ID;
  359. CommonAjax.postXsrfEx("/tender/report_api/createSignatureRole", params, 10000, true, getCookie('csrfToken'),
  360. function(result){
  361. console.log(result);
  362. const newRole = {};
  363. newRole.name = params.name;
  364. newRole.bind_acc_id = selectedAcc.id;
  365. newRole.prj_id = PROJECT_ID;
  366. newRole.tender_id = TENDER_ID;
  367. ROLE_LIST.push(newRole);
  368. const domArr = [];
  369. domArr.push('<li class="add-sign-list-item">');
  370. //1. apply签名
  371. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + (ROLE_LIST.length - 1) +')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  372. domArr.push('<i class="fa fa-plus"></i>');
  373. domArr.push('</a>');
  374. //2. 编辑角色(暂缓处理click事件)
  375. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  376. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  377. domArr.push('</a>');
  378. //3. 显示名称
  379. domArr.push('<i class="fa fa-user"></i> ' + $('#acc_role_name')[0].value + '<p>' + selectedAcc.name + '-<small class="text-muted">' + roleName + '</small></p>');
  380. $('#existed_roles_ul').append(domArr.join(' '));
  381. }, function(err){
  382. // hintBox.unWaitBox();
  383. }, function(ex){
  384. // hintBox.unWaitBox();
  385. }
  386. );
  387. } else {
  388. alert('请输入合适的名称!');
  389. }
  390. },
  391. buildRoleDom: function (roleList) {
  392. const ulDom = $('#existed_roles_ul');
  393. ulDom.empty();
  394. for (let domIdx = 0; domIdx < roleList.length; domIdx++) {
  395. const role = roleList[domIdx];
  396. const domArr = [];
  397. domArr.push('<li class="add-sign-list-item">');
  398. //1. apply签名
  399. domArr.push('<a href="javascript:void(0)" onclick="rptSignatureHelper.createEsignatureByRoleIdx(' + domIdx + ')" class="btn-link pull-right" title="添加" data-dismiss="modal">');
  400. domArr.push('<i class="fa fa-plus"></i>');
  401. domArr.push('</a>');
  402. //2. 编辑角色(暂缓)
  403. domArr.push('<a href="javascript:void(0)" onclick="" class="btn-link pull-right mr-1" title="编辑">');
  404. domArr.push('<i class="fa fa-pencil-square-o"></i>');
  405. domArr.push('</a>');
  406. //3. 显示名称
  407. let acc = rptSignatureHelper.getUserAccount(role.bind_acc_id);
  408. domArr.push('<i class="fa fa-user"></i> ' + role.name + '<p>' + acc.name + '-<small class="text-muted">' + ((acc.role === '')?"工程师":acc.role) + '</small></p>');
  409. ulDom.append(domArr.join(' '));
  410. }
  411. },
  412. getUserAccount: function (accId) {
  413. let rst = null;
  414. for (const acc of PRJ_ACCOUNT_LIST) {
  415. if (acc.id === accId) {
  416. rst = acc;
  417. break;
  418. }
  419. }
  420. return rst;
  421. },
  422. mergeSignDate: function () {
  423. if (ROLE_REL_LIST && ROLE_REL_LIST.length > 0 && STAGE_AUDIT && STAGE_AUDIT.length > 0) {
  424. for (const role_rel of ROLE_REL_LIST) {
  425. if (role_rel.sign_date === undefined || role_rel.sign_date === null || role_rel.sign_date === '') {
  426. for (const stg_audit of STAGE_AUDIT) {
  427. if (role_rel.acc_id === stg_audit.aid) {
  428. role_rel.sign_date = stg_audit.end_time;
  429. break;
  430. }
  431. }
  432. }
  433. }
  434. }
  435. }
  436. }