EcontarctEx.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. shr.defineClass("shr.ats.Econtarct", shr.framework.List, {
  2. protocolData: {},
  3. signerCount: 1,
  4. contractName: "",
  5. selectedRowsData: {},
  6. initalizeDOM: function () {
  7. shr.ats.Econtarct.superClass.initalizeDOM.call(this);
  8. this.changeEntrys();
  9. },
  10. sendSignAction: function () {
  11. var _this = this;
  12. var l = $("#grid").jqGrid("getSelectedRowsData");
  13. if (l.length !== 1) {
  14. shr.showWarning({
  15. 'message': "请选择一条元数据!!注意:只能选择一条数据!"
  16. });
  17. return
  18. }
  19. var id = l[0]["person.id"];
  20. var number = l[0]["eSignMapping.number"];
  21. _this.contractName = l[0]["eSignMapping.name"]
  22. if (number) {
  23. shr.callHandler({
  24. action: "getTableData",
  25. param: { "number": number, "id": id },
  26. type: "POST",
  27. success: function (res) {
  28. _this.protocolData = _this.sortFieldsBySeq(res.data);
  29. _this.renderAllTablesByColumns();
  30. var eSignTemplateId;
  31. for (var key in _this.protocolData) {
  32. _this.protocolData[key];
  33. if (_this.protocolData[key]) {
  34. eSignTemplateId = _this.protocolData[key].eSignTemplateNum
  35. break;
  36. }
  37. }
  38. _this.resetSigners(eSignTemplateId);
  39. $('#popup-overlay').css('display', 'flex');
  40. }
  41. });
  42. } else {
  43. shr.showWarning({
  44. 'message': "未获取到e签宝映射!!"
  45. });
  46. return
  47. }
  48. },
  49. changeEntrys: function () {
  50. var _this = this;
  51. // 绑定签署方类型切换事件(使用事件委托)
  52. $(document).on('change', '.type-select', function () {
  53. _this.changeSignerType(this);
  54. });
  55. // 绑定签署顺序验证事件(使用事件委托)
  56. $(document).on('input', '.order-input', function () {
  57. _this.validateOrder(this);
  58. });
  59. // 弹窗控制
  60. $('#open-popup').click(function () {
  61. $('#popup-overlay').css('display', 'flex');
  62. });
  63. $('#close-popup').click(function () {
  64. $('#popup-overlay').hide();
  65. });
  66. // $('#popup-overlay').click(function (e) {
  67. // if (e.target === this) {
  68. // $(this).hide();
  69. // }
  70. // });
  71. let lastCheckedRadio = null;
  72. $(document).on('click', '[name="signer-radio-orgname"]', function (a, e) {
  73. const $this = $(this);
  74. // 判断当前点击的元素是否是上一次选中的元素
  75. if ($this[0] === lastCheckedRadio) {
  76. // 取消选中
  77. $this.prop('checked', false);
  78. lastCheckedRadio = null; // 清空记录
  79. } else {
  80. // 原生已自动选中当前元素,只需更新记录(同组其他项已被原生取消)
  81. lastCheckedRadio = $this[0];
  82. }
  83. if ($('[name="signer-radio-orgname"').size() > 1) {
  84. $('[name="signer-radio-orgname"').prop('checked', false)
  85. lastCheckedRadio = null;
  86. shr.showWarning({
  87. 'message': "多个公司签署不允许使用电子签"
  88. });
  89. }
  90. });
  91. $('#addSigner').click(function () {
  92. _this.signerCount++;
  93. // 创建新签署方卡片
  94. var newSigner = '<div class="signer-card" data-id="' + _this.signerCount + '">' +
  95. '<div class="card-header">' +
  96. '<div class="card-info">' +
  97. '<select class="type-select type-personal" id="signer-' + _this.signerCount + '-type" name="signer-' + _this.signerCount + '-type" disabled>' +
  98. '<option value="personal" >个人</option>' +
  99. '<option value="company">企业</option>' +
  100. '<option value="copy" selected>抄送</option>' +
  101. '</select>' +
  102. '<span class="signer-name" id="signername_index' + _this.signerCount + '" ">签署方' + _this.signerCount + '</span>' +
  103. '<span class="signer-role">签署</span>' +
  104. '<input type="number" min="1" max="255" value="' + _this.signerCount + '" class="order-input" id="signer-' + _this.signerCount + '-order" name="signer-' + _this.signerCount + '-order">' +
  105. '</div>' +
  106. '<div class="card-actions">' +
  107. '<span class="action-link delete-signer"><span class="icon"></span>删除</span>' +
  108. '</div>' +
  109. '</div>' +
  110. '<div class="form-grid signer-fields">' +
  111. '<div class="form-group">' +
  112. '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name">' +
  113. '<span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>' +
  114. '<input type="hidden" id="signer-' + _this.signerCount + '-person-f7" name="signer-' + _this.signerCount + '-person-f7">' +
  115. '</div>' +
  116. '<div class="form-group">' +
  117. '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account">' +
  118. '</div>' +
  119. '</div>' +
  120. '</div>';
  121. // 添加到容器
  122. $('#signersContainer').append(newSigner);
  123. // 初始化F7选择器
  124. _this.initPersonF7(_this.signerCount);
  125. $('#signer-' + _this.signerCount + '-type').val('copy').trigger('change');
  126. });
  127. // 删除签署方
  128. $(document).on('click', '.delete-signer', function () {
  129. var card = $(this).closest('.signer-card');
  130. card.addClass('fade-out');
  131. setTimeout(function () {
  132. card.remove();
  133. // 更新序号
  134. _this.updateSignerNumbers();
  135. }, 300);
  136. });
  137. $('#getData').click(function () {
  138. var data = _this.getSignerData();
  139. console.log(data);
  140. });
  141. // 确认按钮事件
  142. $('#global-confirm').click(function () {
  143. $.block.show({
  144. text: '正在发送合同,请稍等...'
  145. });
  146. var data = _this.collectAllTableData();
  147. var data1 = _this.getSignerData();
  148. var signFlowTitle = $("#popup_title").attr("value");
  149. var sourceId = $("#grid").jqGrid("getSelectedRowsData")[0] ? $("#grid").jqGrid("getSelectedRowsData")[0].id : '';
  150. var personId = $("#grid").jqGrid("getSelectedRowsData")[0]['person.id'];
  151. var d = {};
  152. d.signInfo = data1;
  153. d.templateInfo = data;
  154. d.signFlowTitle = signFlowTitle;
  155. d.sourceId = "通用电子签署申请单" + "_" + sourceId;
  156. d.personId = personId
  157. console.log(d);
  158. var param = {}
  159. param.data = d;
  160. //param.mack="preview";
  161. // 调用服务获取字段数据
  162. window.setTimeout(function () {
  163. shr.callService({
  164. serviceName: 'create_by_fileOSF',
  165. param: param,
  166. success: function (data) {
  167. console.log("========调用合同返回参数=========")
  168. console.log(data)
  169. if (data.code === 0) {
  170. $('#popup-overlay').hide();
  171. shr.showInfo({
  172. 'message': "发送成功!!!"
  173. });
  174. } else {
  175. shr.showError({
  176. 'message': data.message
  177. });
  178. }
  179. $.block.hide();
  180. },
  181. error: function (e) {
  182. shr.showError({
  183. 'message': e
  184. });
  185. $.block.hide();
  186. }
  187. });
  188. }, 300)
  189. });
  190. },
  191. /**
  192. * 处理字段排序:按seq升序排列(从小到大)
  193. * @param {Object} data - 原始文档数据
  194. * @returns {Object} 排序后的文档数据
  195. */
  196. sortFieldsBySeq: function (data) {
  197. const sortedData = {};
  198. // 遍历每个文档
  199. Object.entries(data).forEach(([docId, docInfo]) => {
  200. // 深拷贝文档信息,避免修改原对象
  201. const newDocInfo = JSON.parse(JSON.stringify(docInfo));
  202. // 提取fields的键值对数组,并按seq升序排序
  203. const fieldsArr = Object.entries(newDocInfo.fields);
  204. const sortedFieldsArr = fieldsArr.sort((a, b) => {
  205. // a[1] 和 b[1] 是字段对象,取seq属性比较
  206. return a[1].seq - b[1].seq; // 升序(从小到大);降序则改为 b[1].seq - a[1].seq
  207. });
  208. // 将排序后的数组转回对象(ES6+ 保留顺序)
  209. newDocInfo.fields = Object.fromEntries(sortedFieldsArr);
  210. // 存入排序后的数据对象
  211. sortedData[docId] = newDocInfo;
  212. });
  213. return sortedData;
  214. },
  215. renderAllTablesByColumns: function () {
  216. var _this = this;
  217. if (_this.contractName !== "") {
  218. $("#popup_title").attr("value", _this.contractName);
  219. }
  220. var wrapper = $('#tables-wrapper');
  221. wrapper.empty();
  222. $.each(_this.protocolData, function (protocolKey, protocolInfo) {
  223. var tableContainer = $('<div>').addClass('table-container');
  224. // 表格标题和预览按钮
  225. var tableTitle = $('<div>').addClass('table-title');
  226. tableTitle.append($('<span>').text(protocolInfo.name || '未命名模板'));
  227. var previewBtn = $('<button>').addClass('preview-btn').text('预览');
  228. previewBtn.click(function () {
  229. _this.previewTableData(protocolKey);
  230. });
  231. tableTitle.append(previewBtn);
  232. var table = $('<table>').addClass('data-table').attr('id', 'table-' + protocolKey);
  233. var fieldNames = [];
  234. var fieldValues = [];
  235. $.each(protocolInfo.fields || {}, function (fieldKey, fieldInfo) {
  236. if (fieldInfo.dataType !== "签署区" && fieldInfo.dataType !== "骑缝签署区" && fieldInfo.dataType !== "签署日期") {
  237. fieldNames.push(fieldInfo.name || '未命名字段');
  238. fieldValues.push({
  239. fieldKey: fieldKey,
  240. value: fieldInfo.value === null ? '' : fieldInfo.value,
  241. dataType: fieldInfo.dataType || '单行文本',
  242. dataFormat: fieldInfo.dataFormat,
  243. isRequired: fieldInfo.isRequired
  244. });
  245. }
  246. });
  247. // 表头渲染
  248. var thead = $('<thead>');
  249. var headerTr = $('<tr>');
  250. $.each(fieldNames, function (index, name) {
  251. headerTr.append($('<th>').text(name));
  252. });
  253. thead.append(headerTr);
  254. table.append(thead);
  255. // 内容渲染
  256. var tbody = $('<tbody>');
  257. var dataTr = $('<tr>');
  258. $.each(fieldValues, function (index, fieldData) {
  259. var inputHtml;
  260. // 处理日期类型
  261. if (fieldData.dataType === "日期") {
  262. var inputType = _this.getInputType(fieldData.dataFormat);
  263. var formattedValue = _this.formatDateForInput(fieldData.value, fieldData.dataFormat);
  264. if (fieldData.isRequired) {
  265. inputHtml = '<input style="background-color: #D9EDF7;" type="' + inputType + '" value="' + formattedValue + '" placeholder="请输入值">';
  266. } else {
  267. inputHtml = '<input type="' + inputType + '" value="' + formattedValue + '" placeholder="请输入值">';
  268. }
  269. } else if(fieldData.dataType === "勾选框"){
  270. if(fieldData.value==1||fieldData.value=="1"){
  271. inputHtml = '<input type="Checkbox" checked>';
  272. }else {
  273. inputHtml = '<input type="Checkbox">';
  274. }
  275. }else {
  276. // 非日期类型使用普通文本输入
  277. if (fieldData.isRequired) {
  278. inputHtml = '<input style="background-color: #D9EDF7;" type="text" value="' + fieldData.value + '" placeholder="请输入值">';
  279. } else {
  280. inputHtml = '<input type="text" value="' + fieldData.value + '" placeholder="请输入值">';
  281. }
  282. }
  283. if (fieldData.dataType !== "签署区" && fieldData.dataType !== "骑缝签署区" && fieldData.dataType !== "签署日期") {
  284. dataTr.append($(
  285. '<td data-field-key="' + fieldData.fieldKey + '" ' +
  286. 'data-data-type="' + fieldData.dataType + '"' +
  287. 'data-data-format="' + fieldData.dataFormat + '">' +
  288. inputHtml +
  289. '</td>'
  290. ));
  291. }
  292. });
  293. tbody.append(dataTr);
  294. table.append(tbody);
  295. tableContainer.append(tableTitle).append(table);
  296. wrapper.append(tableContainer);
  297. });
  298. },
  299. formatDateForInput: function (value, dataFormat) {
  300. if (!value) return '';
  301. // 补零工具函数:保证数字为两位(兼容ES5及以上)
  302. function padZero(num) {
  303. return num < 10 ? '0' + num : num;
  304. }
  305. // 尝试解析各种可能的日期格式
  306. var date;
  307. if (value instanceof Date) {
  308. date = value;
  309. } else {
  310. // 替换常见分隔符(包括中文年、月、日),统一为 '-' 和 'T'(兼容ISO格式)
  311. var normalizedValue = value
  312. .replace(/[./年]/g, '-') // 将 . / 年 替换为 -
  313. .replace(/月/g, '-') // 将 月 替换为 -
  314. .replace(/日/g, '') // 移除 日
  315. .replace(/\s+/, 'T') // 空格替换为T(衔接时分秒)
  316. .replace(/:/g, ':'); // 保留冒号(时分秒分隔符)
  317. date = new Date(normalizedValue);
  318. // 如果解析失败,尝试其他格式
  319. if (isNaN(date.getTime())) {
  320. // 处理类似 "2025-11" 这样的年月格式
  321. if (value.match(/^\d{4}-\d{2}$/)) {
  322. date = new Date(value + '-01');
  323. } else {
  324. console.warn('无法解析日期: ' + value);
  325. return value; // 解析失败时返回原始值
  326. }
  327. }
  328. }
  329. // 根据dataFormat返回对应格式
  330. if (dataFormat.indexOf('yyyy-MM-dd HH:mm:ss') !== -1) {
  331. return date.toISOString().slice(0, 19).replace('T', ' '); // 注意:原代码slice(0,19)是"2025-11-12T13:45:30",这里替换T为空格更符合常规
  332. } else if (dataFormat.indexOf('yyyy-MM-dd HH:mm') !== -1) {
  333. return date.toISOString().slice(0, 16).replace('T', ' ');
  334. } else if (dataFormat.indexOf('yyyy-MM-dd') !== -1) {
  335. return date.toISOString().slice(0, 10);
  336. } else if (dataFormat.indexOf('yyyy年MM月dd日') !== -1) {
  337. // 基础中文日期格式:yyyy年MM月dd日
  338. const year = date.getFullYear();
  339. const month = padZero(date.getMonth() + 1); // 月份是0-based(0-11),需+1
  340. const day = padZero(date.getDate());
  341. let result = `${year}年${month}月${day}日`;
  342. // 扩展:处理时分秒
  343. if (dataFormat.indexOf('HH:mm:ss') !== -1) {
  344. const hour = padZero(date.getHours());
  345. const minute = padZero(date.getMinutes());
  346. const second = padZero(date.getSeconds());
  347. result += ` ${hour}:${minute}:${second}`;
  348. } else if (dataFormat.indexOf('HH:mm') !== -1) {
  349. const hour = padZero(date.getHours());
  350. const minute = padZero(date.getMinutes());
  351. result += ` ${hour}:${minute}`;
  352. }
  353. return result;
  354. }
  355. // 未知格式,返回原始值
  356. return value;
  357. },
  358. getInputType: function (dataFormat) {
  359. // 添加对dataFormat的检查,无值时默认使用"yyyy-MM-dd"
  360. if (!dataFormat) {
  361. dataFormat = "yyyy-MM-dd";
  362. }
  363. // 处理中文日期格式:yyyy年MM月dd日(包括扩展格式)
  364. if (dataFormat.indexOf('yyyy年MM月dd日') !== -1) {
  365. return 'text';
  366. }
  367. // 简化原有逻辑:合并HH:mm:ss和HH:mm的判断
  368. if (dataFormat.indexOf('HH:mm') !== -1) { // 同时匹配HH:mm和HH:mm:ss
  369. return 'datetime-local';
  370. } else if (dataFormat.indexOf('yyyy-MM-dd') !== -1) {
  371. return 'date';
  372. }
  373. // 未知格式返回text
  374. return 'text';
  375. },
  376. // 预览单个表格数据
  377. previewTableData: function (protocolKey) {
  378. var _this = this;
  379. var protocolInfo = _this.protocolData[protocolKey] || {};
  380. var tableData = {};
  381. tableData[protocolKey] = {
  382. "name": protocolInfo.name || protocolKey,
  383. "id": protocolInfo.id || protocolKey,
  384. "fields": {}
  385. };
  386. $('#table-' + protocolKey + ' tbody tr td').each(function (index) {
  387. var fieldKey = $(this).data('field-key');
  388. var fieldName = $('#table-' + protocolKey + ' thead th:eq(' + index + ')').text() || '字段' + (index + 1);
  389. var value = $(this).find('input').val() || null;
  390. var dataType = "单行文本";
  391. if (protocolInfo.fields && protocolInfo.fields[fieldKey]) {
  392. dataType = protocolInfo.fields[fieldKey].dataType || "单行文本";
  393. }
  394. if(dataType==="勾选框"){
  395. value = ""+$(this).find('input').is(':checked')+""
  396. }
  397. tableData[protocolKey].fields[fieldKey] = {
  398. name: fieldName,
  399. dataType: dataType,
  400. value: value
  401. };
  402. });
  403. var param = {}
  404. param.data = tableData;
  405. param.mack = "preview";
  406. $.block.show({
  407. text: '正在获取预览地址,请稍等...'
  408. });
  409. window.setTimeout(function () {
  410. // 调用服务获取字段数据
  411. shr.callService({
  412. serviceName: 'create_by_fileOSF',
  413. param: param,
  414. success: function (data) {
  415. console.log("========调用合同返回参数=========")
  416. console.log(data)
  417. if (data.code !== 0) {
  418. shr.showError({
  419. 'message': data.message
  420. });
  421. } else {
  422. window.open(data.data.fileDownloadUrl, '_blank');
  423. }
  424. $.block.hide();
  425. },
  426. error: function (e) {
  427. shr.showError({
  428. 'message': e
  429. });
  430. $.block.hide();
  431. }
  432. });
  433. }, 300)
  434. },
  435. // 收集所有表格数据
  436. collectAllTableData: function () {
  437. var allData = {};
  438. var _this = this;
  439. $.each(_this.protocolData, function (protocolKey, protocolInfo) {
  440. // var tableData = {
  441. // tableName: protocolInfo.name,
  442. // tableId: protocolInfo.id,
  443. // fields: protocolInfo.fields
  444. // };
  445. var tableData = protocolInfo
  446. $('#table-' + protocolKey + ' tbody tr td').each(function (index) {
  447. var fieldKey = $(this).data('field-key');
  448. var fieldName = $('#table-' + protocolKey + ' thead th:eq(' + index + ')').text();
  449. var dataType = $(this).data('data-type');
  450. var dataFormat = $(this).data('data-format');
  451. tableData.fields[fieldKey].name = fieldName;
  452. tableData.fields[fieldKey].dataType = dataType;
  453. tableData.fields[fieldKey].dataFormat = dataFormat;
  454. var value=""
  455. if(dataType=="勾选框"){
  456. value = ""+$(this).find('input').is(':checked')+""
  457. }else {
  458. value = $(this).find('input').val() || null;
  459. }
  460. tableData.fields[fieldKey].value = value;
  461. // tableData.fields[fieldKey] = {
  462. // name: fieldName,
  463. // dataType: dataType,
  464. // dataFormat: dataFormat,
  465. // value: value
  466. // };
  467. });
  468. allData[protocolKey] = tableData;
  469. });
  470. console.log('===== 所有表格数据 =====');
  471. console.log(JSON.stringify(allData, null, 2));
  472. return allData;
  473. },
  474. // 验证签署顺序输入值
  475. validateOrder: function (input) {
  476. var value = parseInt(input.value);
  477. if (isNaN(value) || value < 1) {
  478. input.value = 1;
  479. } else if (value > 255) {
  480. input.value = 255;
  481. }
  482. },
  483. // 切换签署方类型
  484. changeSignerType: function (selectElement) {
  485. var type = selectElement.value;
  486. var card = $(selectElement).closest('.signer-card');
  487. var cardId = card.attr('data-id');
  488. var fieldsContainer = card.find('.signer-fields');
  489. var orderInput = card.find('.order-input');
  490. var roleElement = card.find('.signer-role');
  491. var nameElement = card.find('.signer-name');
  492. // 更新选择框样式和颜色
  493. if (type === 'personal') {
  494. $(selectElement).removeClass('type-company type-copy').addClass('type-personal');
  495. // 显示个人字段和签署顺序
  496. fieldsContainer.html(
  497. '<div class="form-group">' +
  498. '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + cardId + '-name" name="signer-' + cardId + '-name">' +
  499. '<span class="input-marker" id="name-tip-' + cardId + '">ⓘ</span>' +
  500. '<input type="hidden" id="signer-' + cardId + '-person-f7" name="signer-' + cardId + '-person-f7">' +
  501. '</div>' +
  502. '<div class="form-group">' +
  503. '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + cardId + '-account" name="signer-' + cardId + '-account">' +
  504. '</div>'
  505. );
  506. nameElement.text('签署方' + cardId)
  507. roleElement.text('签署');
  508. $('#span-' + cardId + '').remove();
  509. orderInput.show();
  510. // 初始化F7选择器
  511. this.initPersonF7(cardId);
  512. } else if (type === 'company') {
  513. $(selectElement).removeClass('type-personal type-copy').addClass('type-company');
  514. $('#signer-' + cardId + '-order').after('<span id="span-' + cardId + '" style="display: none;"> 自动签 <input type="radio" placeholder="" class="" id="signer-' + cardId + '-radio" name="signer-radio-orgname"></span>');
  515. // 显示企业字段和签署顺序
  516. fieldsContainer.html(
  517. '<div class="form-group">' +
  518. '<input type="text" placeholder="请输入企业完整名称" class="input-field" id="signer-' + cardId + '-orgname" name="signer-' + cardId + '-orgname">' +
  519. '</div>' +
  520. '<div class="form-group">' +
  521. '<input readonly type="text" placeholder="企业章" class="input-field" id="signer-' + cardId + '-orgnId" name="signer-' + cardId + '-orgnId">' +
  522. '<span class="input-marker" id="name-orgId-' + cardId + '">ⓘ</span>' +
  523. '<input type="hidden" id="signer-' + cardId + '-orgnId-f7" name="signer-' + cardId + '-orgnId-f7">' +
  524. '</div>' +
  525. '<div class="form-group">' +
  526. '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + cardId + '-name" name="signer-' + cardId + '-name">' +
  527. '<span class="input-marker" id="name-tip-' + cardId + '">ⓘ</span>' +
  528. '<input type="hidden" id="signer-' + cardId + '-person-f7" name="signer-' + cardId + '-person-f7">' +
  529. '</div>' +
  530. '<div class="form-group">' +
  531. '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + cardId + '-account" name="signer-' + cardId + '-account">' +
  532. '</div>'
  533. );
  534. nameElement.text('签署方' + cardId)
  535. roleElement.text('签署');
  536. orderInput.show();
  537. // 初始化F7选择器
  538. this.initPersonF7(cardId);
  539. } else if (type === 'copy') {
  540. // 处理抄送类型
  541. $(selectElement).removeClass('type-personal type-company').addClass('type-copy');
  542. $('#span-' + cardId + '').remove();
  543. // 显示抄送字段,隐藏签署顺序
  544. fieldsContainer.html(
  545. '<div class="form-group">' +
  546. '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + cardId + '-name" name="signer-' + cardId + '-name">' +
  547. '<span class="input-marker" id="name-tip-' + cardId + '">ⓘ</span>' +
  548. '<input type="hidden" id="signer-' + cardId + '-person-f7" name="signer-' + cardId + '-person-f7">' +
  549. '</div>' +
  550. '<div class="form-group">' +
  551. '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + cardId + '-account" name="signer-' + cardId + '-account">' +
  552. '</div>'
  553. );
  554. nameElement.text('抄送方' + cardId)
  555. roleElement.text('抄送');
  556. orderInput.hide(); // 隐藏签署顺序
  557. // 初始化F7选择器
  558. this.initPersonF7(cardId);
  559. }
  560. },
  561. // 初始化人员选择F7
  562. initPersonF7: function (cardId) {
  563. var grid_f7_json = {
  564. id: 'signer-' + cardId + '-person-f7',
  565. name: 'signer-' + cardId + '-person-f7'
  566. };
  567. grid_f7_json.subWidgetName = 'shrPromptGrid';
  568. grid_f7_json.subWidgetOptions = {
  569. title: "员工",
  570. uipk: "com.kingdee.eas.custom.entryconfig.app.person.F7",
  571. query: "",
  572. filter: "",
  573. domain: "",
  574. multiselect: false,
  575. treeFilterConfig: '',
  576. permItemId: "",
  577. isHasMultileDialog: false,
  578. isTree: false,
  579. treeUrl: "",
  580. isContainLowerOrg: false,
  581. isAdminOrg: false,
  582. pgSizes: true,
  583. f7SearchConfig: { "displayField": [], "filterFields": "" },
  584. dataShowMode: "layout"
  585. };
  586. grid_f7_json.readonly = '';
  587. grid_f7_json.validate = '{required:false}';
  588. grid_f7_json.value = { 'id': "", 'name': "" };
  589. grid_f7_json.isHROrg = "false";
  590. grid_f7_json.isAdminOrg = "false";
  591. grid_f7_json.searchLikePattern = "any";
  592. // 初始化F7选择器
  593. $('#signer-' + cardId + '-person-f7').shrPromptBox(grid_f7_json);
  594. // 绑定选择事件,将选择的姓名回填到真实姓名输入框
  595. $('#signer-' + cardId + '-person-f7').shrPromptBox('option', {
  596. afterOnSelectRowHandler: function (a, data) {
  597. $('#signer-' + cardId + '-name').val(data.value.name);
  598. $('#signer-' + cardId + '-account').val(data.value.cell);
  599. console.log(data);
  600. }
  601. });
  602. $('#name-tip-' + cardId).click(function () {
  603. $('#signer-' + cardId + '-person-f7').shrPromptBox("open");
  604. });
  605. $('#signer-' + cardId + '-person-f7').parent().parent().parent().hide();
  606. id = "signer-' + cardId + '-orgnId-f7"
  607. var grid_f7_json = {
  608. id: 'signer-' + cardId + '-orgnId-f7',
  609. name: 'signer-' + cardId + '-orgnId-f7'
  610. };
  611. grid_f7_json.subWidgetName = 'shrPromptGrid';
  612. grid_f7_json.subWidgetOptions = {
  613. title: "印章",
  614. uipk: "com.kingdee.eas.custom.esign.app.Seal.list",
  615. query: "",
  616. filter: "",
  617. domain: "",
  618. multiselect: false,
  619. treeFilterConfig: '',
  620. permItemId: "",
  621. isHasMultileDialog: false,
  622. isTree: false,
  623. treeUrl: "",
  624. isContainLowerOrg: false,
  625. isAdminOrg: false,
  626. pgSizes: true,
  627. f7SearchConfig: { "displayField": [], "filterFields": "" },
  628. dataShowMode: "layout"
  629. };
  630. grid_f7_json.readonly = '';
  631. grid_f7_json.validate = '{required:false}';
  632. grid_f7_json.value = { 'id': "", 'name': "" };
  633. grid_f7_json.isHROrg = "false";
  634. grid_f7_json.isAdminOrg = "false";
  635. grid_f7_json.searchLikePattern = "any";
  636. // 初始化F7选择器
  637. $('#signer-' + cardId + '-orgnId-f7').shrPromptBox(grid_f7_json);
  638. $('#signer-' + cardId + '-orgnId-f7').shrPromptBox('option', {
  639. afterOnSelectRowHandler: function (a, data) {
  640. $('#signer-' + cardId + '-orgnId').val(data.value.sealId);
  641. console.log(data);
  642. }
  643. });
  644. $('#name-orgId-' + cardId).click(function () {
  645. $('#signer-' + cardId + '-orgnId-f7').shrPromptBox("open");
  646. });
  647. $('#signer-' + cardId + '-orgnId-f7').parent().parent().parent().hide();
  648. },
  649. // 更新签署方序号
  650. updateSignerNumbers: function () {
  651. var _this = this;
  652. $('.signer-card').each(function (index, element) {
  653. var newNumber = index + 1;
  654. var oldId = $(element).attr('data-id');
  655. // 更新卡片ID
  656. $(element).attr('data-id', newNumber);
  657. // 更新显示名称
  658. $(element).find('.signer-name').text('签署方' + newNumber);
  659. // 更新所有相关元素的ID和name属性
  660. $(element).find('[id^="signer-' + oldId + '-"]').each(function () {
  661. var field = $(this).attr('id').split('-').pop();
  662. $(this).attr('id', 'signer-' + newNumber + '-' + field);
  663. var name = $(this).attr('name');
  664. if (name !== "signer-radio-orgname") {
  665. $(this).attr('name', 'signer-' + newNumber + '-' + field);
  666. }
  667. });
  668. // 重新初始化F7组件(因为ID发生了变化)
  669. _this.initPersonF7(newNumber);
  670. // 如果没有设置过顺序值,自动填充序号(只对非抄送类型生效)
  671. var orderInput = $(element).find('.order-input');
  672. var typeSelect = $(element).find('.type-select');
  673. if (typeSelect.val() !== 'copy' && (!orderInput.val() || orderInput.val() < 1)) {
  674. orderInput.val(newNumber);
  675. }
  676. });
  677. _this.signerCount = $('.signer-card').length;
  678. },
  679. // 获取数据方法
  680. getSignerData: function () {
  681. var result = {
  682. signers: [],
  683. copiers: []
  684. };
  685. // 遍历所有签署方卡片
  686. $('.signer-card').each(function () {
  687. var cardId = $(this).attr('data-id');
  688. var type = $(this).find('#signer-' + cardId + '-type').val();
  689. // 获取F7选择的完整数据
  690. var f7Data = $('#signer-' + cardId + '-person-f7').shrPromptBox('getValue') || {};
  691. if (type === 'personal') {
  692. // 个人签署方
  693. result.signers.push({
  694. psnSignerInfo: {
  695. psnAccount: $(this).find('#signer-' + cardId + '-account').val() || '',
  696. psnName: $(this).find('#signer-' + cardId + '-name').val() || '',
  697. signOrder: $(this).find('#signer-' + cardId + '-order').val() || '1',
  698. f7Data: f7Data, // 包含F7选择的完整数据
  699. signName: $(this).find('#signername_index' + cardId).text() || '',
  700. }
  701. });
  702. } else if (type === 'company') {
  703. // 企业签署方
  704. result.signers.push({
  705. orgSignerInfo: {
  706. orgName: $(this).find('#signer-' + cardId + '-orgname').val() || '',
  707. psnName: $(this).find('#signer-' + cardId + '-name').val() || '',
  708. psnAccount: $(this).find('#signer-' + cardId + '-account').val() || '',
  709. signOrder: $(this).find('#signer-' + cardId + '-order').val() || '1',
  710. f7Data: f7Data, // 包含F7选择的完整数据
  711. sealId: $(this).find('#signer-' + cardId + '-orgnId').val() || '',
  712. isRadio: $('#signer-' + cardId + '-radio').is(":checked"),
  713. signName: $(this).find('#signername_index' + cardId).text() || '',
  714. }
  715. });
  716. } else if (type === 'copy') {
  717. // 抄送方
  718. result.copiers.push({
  719. psnAccount: $(this).find('#signer-' + cardId + '-account').val() || '',
  720. psnName: $(this).find('#signer-' + cardId + '-name').val() || '',
  721. f7Data: f7Data, // 包含F7选择的完整数据
  722. signName: $(this).find('#signername_index' + cardId).text() || '',
  723. });
  724. }
  725. });
  726. return result;
  727. },
  728. // 重置参与方设置
  729. resetSigners: function (eSignTemplateId) {
  730. var _this = this;
  731. // 清空现有签署方卡片
  732. $('#signersContainer').empty();
  733. // 重置签署方计数
  734. this.signerCount = 1;
  735. // 隐藏结果区域
  736. $('#resultArea').hide();
  737. var param = {}
  738. param.mack = "getTemplate";
  739. param.eSignTemplateNum = eSignTemplateId
  740. shr.callService({
  741. serviceName: 'create_by_fileOSF',
  742. param: param,
  743. success: function (data) {
  744. console.log("========签署信息=========")
  745. console.log(data)
  746. if (data.data.length <= 0) {
  747. shr.showWarning({
  748. 'message': "未获取到设置签署信息请自行设置签署人!注:需要和e签宝保持一致。"
  749. });
  750. }
  751. var d = data.data
  752. for (let i = 0; i < d.length; i++) {
  753. var entry = d[i];
  754. //签署类型 1 公司签署 2 个人签署 3 抄送人
  755. var type = entry.participantType;
  756. var defaultSigner = "";
  757. if (type == 1 || type == "1") {
  758. var participantFlag = entry.participantFlag;
  759. var orgParticipant = entry.orgParticipant
  760. var participantSetMode = entry.participantSetMode
  761. if (participantSetMode == 2 ) {
  762. continue;
  763. }
  764. defaultSigner = '<div class="signer-card" data-id="' + _this.signerCount + '">' +
  765. '<div class="card-header">' +
  766. '<div class="card-info"><select class="type-select type-company" id="signer-' + _this.signerCount + '-type" name="signer-' + _this.signerCount + '-type" disabled>' +
  767. '<option value="personal" >个人</option>' +
  768. '<option value="company" selected >企业</option>' +
  769. '<option value="copy">抄送</option>' +
  770. '</select>' +
  771. '<span class="signer-name" id="signername_index' + _this.signerCount + '">' + participantFlag + '</span><span class="signer-role">签署</span>' +
  772. '<input type="number" min="1" max="255" value="' + _this.signerCount + '" class="order-input"id="signer-' + _this.signerCount + '-order" name="signer-' + _this.signerCount + '-order" style="">' +
  773. '<span id="span-' + _this.signerCount + '" style="display: none;"> 自动签 <input type="radio"placeholder="" class="" id="signer-' + _this.signerCount + '-radio" name="signer-radio-orgname"></span>' +
  774. '</div>' +
  775. '<!--div class="card-actions"><span class="action-link delete-signer"><span class="icon"></span>删除</span></div-->' +
  776. '</div>' +
  777. '<div class="form-grid signer-fields">'
  778. if (orgParticipant != null) {
  779. var orgName = orgParticipant.orgName;
  780. //disabled
  781. if (orgName != null && orgName != undefined && orgName != "") {
  782. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入企业完整名称" value="' + orgParticipant.orgName + '" class="input-field" id="signer-' + _this.signerCount + '-orgname"name="signer-' + _this.signerCount + '-orgname"></div>'
  783. } else {
  784. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入企业完整名称" value="' + orgParticipant.orgName + '" class="input-field" id="signer-' + _this.signerCount + '-orgname"name="signer-' + _this.signerCount + '-orgname" disabled ></div>'
  785. }
  786. } else {
  787. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入企业完整名称" value="" class="input-field" id="signer-' + _this.signerCount + '-orgname"name="signer-' + _this.signerCount + '-orgname"></div>'
  788. }
  789. defaultSigner += '<div class="form-group"><input readonly="" type="text" placeholder="企业章" class="input-field"id="signer-' + _this.signerCount + '-orgnId" name="signer-' + _this.signerCount + '-orgnId"><span class="input-marker" id="name-orgId-' + _this.signerCount + '">ⓘ</span>' +
  790. '<div class="ui-promptBox-frame" style="display: none;">' +
  791. '<div class="ui-promptBox-layout">' +
  792. '<div class="ui-promptBox-inputframe"><input type="hidden" id="signer-' + _this.signerCount + '-orgnId-f7_el" name="hidd_name_signer-' + _this.signerCount + '-orgnId-f7" value=""><input type="hidden" id="signer-' + _this.signerCount + '-orgnId-f7"name="signer-' + _this.signerCount + '-orgnId-f7" ctrlrole="promptBox" autocomplete="off" value="" title=""></div>' +
  793. '<div class="ui-promptBox-icon"><img style="cursor:pointer;" src="/shr/styles/images/seniorf7.png">' +
  794. '</div>' +
  795. '</div>' +
  796. '</div>' +
  797. '</div>';
  798. if (orgParticipant != null) {
  799. var transactor = orgParticipant.transactor;
  800. if (transactor != null && transactor != undefined) {
  801. defaultSigner += '<div class="form-group"><input type="text" placeholder="真实姓名" value="' + transactor.transactorName + '" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name"><span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>'
  802. } else {
  803. defaultSigner += '<div class="form-group"><input type="text" placeholder="真实姓名" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name"><span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>'
  804. }
  805. } else {
  806. defaultSigner += '<div class="form-group"><input type="text" placeholder="真实姓名" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name"><span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>'
  807. }
  808. defaultSigner += '<div class="ui-promptBox-frame" style="display: none;">' +
  809. '<div class="ui-promptBox-layout">' +
  810. '<div class="ui-promptBox-inputframe"><input type="hidden" id="signer-' + _this.signerCount + '-person-f7_el" name="hidd_name_signer-' + _this.signerCount + '-person-f7" value=""><input type="hidden" id="signer-' + _this.signerCount + '-person-f7"' +
  811. ' name="signer-' + _this.signerCount + '-person-f7" ctrlrole="promptBox" autocomplete="off" value="" title=""></div>' +
  812. '<div class="ui-promptBox-icon"><img style="cursor:pointer;" src="/shr/styles/images/seniorf7.png">' +
  813. '</div>' +
  814. '</div>' +
  815. '</div>' +
  816. '</div>';
  817. if (orgParticipant != null) {
  818. var transactor = orgParticipant.transactor;
  819. if (transactor != null && transactor != undefined) {
  820. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入手机号/邮箱" value="' + transactor.transactorPsnAccount + '" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account"></div>';
  821. } else {
  822. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account"></div>';
  823. }
  824. } else {
  825. defaultSigner += '<div class="form-group"><input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account"></div>';
  826. }
  827. defaultSigner += '</div>' +
  828. '</div>';
  829. } else if (type == 2 || type == "2") {
  830. var participantFlag = entry.participantFlag;
  831. var psnParticipant = entry.psnParticipant
  832. var participantSetMode = entry.participantSetMode
  833. if (participantSetMode == 2 ) {
  834. continue;
  835. }
  836. // 添加默认的第一个签署方卡片 默认个人
  837. defaultSigner = '<div class="signer-card" data-id="' + _this.signerCount + '">' +
  838. '<div class="card-header">' +
  839. '<div class="card-info">' +
  840. '<select class="type-select type-personal" id="signer-' + _this.signerCount + '-type" name="signer-' + _this.signerCount + '-type" disabled>' +
  841. '<option value="personal" selected >个人</option>' +
  842. '<option value="company" >企业</option>' +
  843. '<option value="copy">抄送</option>' +
  844. '</select>' +
  845. '<span class="signer-name" id = "signername_index' + _this.signerCount + '">' + participantFlag + '</span>' +
  846. '<span class="signer-role">签署</span>' +
  847. '<input type="number" min="1" max="255" value="' + _this.signerCount + '" class="order-input" id="signer-' + _this.signerCount + '-order" name="signer-' + _this.signerCount + '-order">' +
  848. '</div>' +
  849. '<!--div class="card-actions">' +
  850. '<span class="action-link delete-signer"><span class="icon"></span>删除</span>' +
  851. '</div-->' +
  852. '</div>' +
  853. '<div class="form-grid signer-fields">' +
  854. '<div class="form-group">';
  855. if (psnParticipant != null && psnParticipant != undefined) {
  856. defaultSigner += '<input type="text" placeholder="真实姓名" value="' + psnParticipant.psnName + '" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name">';
  857. } else {
  858. defaultSigner += '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name">';
  859. }
  860. defaultSigner += '<span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>' +
  861. '<input type="hidden" id="signer-' + _this.signerCount + '-person-f7" name="signer-' + _this.signerCount + '-person-f7">' +
  862. '</div>' +
  863. '<div class="form-group">';
  864. if (psnParticipant != null && psnParticipant != undefined) {
  865. defaultSigner += '<input type="text" placeholder="请输入手机号/邮箱" value="' + psnParticipant.psnAccount + '" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account">';
  866. } else {
  867. defaultSigner += '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account">';
  868. }
  869. defaultSigner += '</div>' +
  870. '</div>' +
  871. '</div>';
  872. } else if (type == 3 || type == "3") {
  873. var copierPsnInfo = entry.copierPsnInfo;
  874. defaultSigner = '<div class="signer-card" data-id="' + _this.signerCount + '">' +
  875. '<div class="card-header">' +
  876. '<div class="card-info"><select class="type-select type-copy" id="signer-' + _this.signerCount + '-type" name="signer-' + _this.signerCount + '-type" disabled>' +
  877. '<option value="personal">个人</option>' +
  878. '<option value="company">企业</option>' +
  879. '<option value="copy" selected >抄送</option>' +
  880. '</select>' +
  881. '<span class="signer-name" id="signername_index' + _this.signerCount + '" > 抄送方' + _this.signerCount + '</span><span class="signer-role">抄送</span>' +
  882. '<input type="number" min="1" max="255" value="' + _this.signerCount + '" class="order-input" id="signer-' + _this.signerCount + '-order" name="signer-' + _this.signerCount + '-order" style="display: none;"></div>' +
  883. '<!--div class="card-actions"><span class="action-link delete-signer"><span class="icon"></span>删除</span></div-->' +
  884. '</div>' +
  885. '<div class="form-grid signer-fields">' +
  886. '<div class="form-group">';
  887. if (copierPsnInfo != null && copierPsnInfo != undefined) {
  888. defaultSigner += '<input type="text" placeholder="真实姓名" value="' + copierPsnInfo.psnName + '" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name">';
  889. } else {
  890. defaultSigner += '<input type="text" placeholder="真实姓名" class="input-field" id="signer-' + _this.signerCount + '-name" name="signer-' + _this.signerCount + '-name">';
  891. }
  892. defaultSigner += '<span class="input-marker" id="name-tip-' + _this.signerCount + '">ⓘ</span>' +
  893. '<div class="ui-promptBox-frame" style="display: none;">' +
  894. '<div class="ui-promptBox-layout">' +
  895. '<div class="ui-promptBox-inputframe">' +
  896. '<input type="hidden" id="signer-' + _this.signerCount + '-person-f7_el" name="hidd_name_signer-' + _this.signerCount + '-person-f7" value="">' +
  897. '<input type="hidden" id="signer-' + _this.signerCount + '-person-f7" name="signer-' + _this.signerCount + '-person-f7" ctrlrole="promptBox" autocomplete="off" value="" title="">' +
  898. '</div>' +
  899. '<div class="ui-promptBox-icon"><img style="cursor:pointer;" src="/shr/styles/images/seniorf7.png">' +
  900. '</div>' +
  901. '</div>' +
  902. '</div>' +
  903. '</div>' +
  904. '<div class="form-group">';
  905. if (copierPsnInfo != null && copierPsnInfo != undefined) {
  906. defaultSigner += '<input type="text" placeholder="请输入手机号/邮箱" value="' + copierPsnInfo.psnAccount + '" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account">';
  907. } else {
  908. defaultSigner += '<input type="text" placeholder="请输入手机号/邮箱" class="input-field" id="signer-' + _this.signerCount + '-account" name="signer-' + _this.signerCount + '-account">';
  909. }
  910. defaultSigner += '</div>' +
  911. '</div>' +
  912. '</div>';
  913. } else {
  914. shr.showWarning({
  915. 'message': "获取到设置签署信息失败!请自行设置签署人!注:需要和e签宝保持一致。"
  916. });
  917. }
  918. $('#signersContainer').append(defaultSigner);
  919. _this.initPersonF7(_this.signerCount);
  920. _this.signerCount++
  921. }
  922. },
  923. error: function (e) {
  924. shr.showError({
  925. 'message': e
  926. });
  927. }
  928. });
  929. }
  930. });