PersonEcontarct.js 51 KB

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