spbld.js 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216
  1. ///全称spbuilder
  2. var spbld = window.NameSpace || {};
  3. ////遍历日期控件data-type='date',根据其data-formate属性然后为其调用不同的laydate.js的方法
  4. ///样例:<input type="text" data-type="date" id="PrjTable_0_0_0_projectdate" class="laydate-logo" data-format="yyyy-MM-dd" placeholder="请选择时间">
  5. //根据元素 data-formate 属性然后为其调用不同的laydate.js的方法
  6. spbld.laydateRender = function (obj) {
  7. var getid = $(obj).attr("id");
  8. var getformat = $(obj).attr("data-format");
  9. if (getformat == "yyyy-MM-dd" || getformat == "MM-dd" || getformat == "dd") {
  10. laydate.render({ elem: '#' + getid + '', type: 'date', format: '' + getformat + '', theme: '#009f95' });
  11. } else if (getformat == "yyyy-MM") {
  12. laydate.render({ elem: '#' + getid + '', type: 'month', format: 'yyyy-MM', theme: '#009f95' });
  13. } else if (getformat == "yyyy-MM-dd HH:mm:ss" || getformat == "yyyy-MM-dd HH:mm") {
  14. laydate.render({ elem: '#' + getid + '', type: 'datetime', format: '' + getformat + '', theme: '#009f95' });
  15. } else if (getformat == "MM") {
  16. laydate.render({ elem: '#' + getid + '', type: 'month', format: 'MM', theme: '#009f95' });
  17. } else if (getformat == "yyyy") {
  18. laydate.render({ elem: '#' + getid + '', type: 'year', format: 'yyyy', theme: '#009f95' });
  19. } else if (getformat == "HH:mm:ss" || getformat == "HH:mm") {
  20. laydate.render({ elem: '#' + getid + '', type: 'time', format: '' + getformat + '', theme: '#009f95' });
  21. } else { return; }
  22. }
  23. spbld.laydate = function () {
  24. if ($("body").find("input[data-type='date']").length > 0) {
  25. $("body").find("input[data-type='date']").each(function () {
  26. spbld.laydateRender(this);
  27. });
  28. };
  29. };
  30. ////子表按钮操作
  31. spbld.subtable = function () {
  32. //初始化 禁用子表中所有表单
  33. var $subTable = $('.fb-subtable-control');
  34. if ($subTable.length > 0) {
  35. $subTable.find('input').attr('disabled', 'disabled');
  36. $subTable.find('select').attr('disabled', 'disabled');
  37. $subTable.find('textarea').attr('disabled', 'disabled');
  38. } else {
  39. return;
  40. }
  41. //添加按钮
  42. $('.fb-add-data').click(function (e) {
  43. // 点击一次添加后 隐藏 添加按钮
  44. $(this).attr('disabled', 'disabled');
  45. // 向上查找到当前点击的table
  46. var $currentTable = $(e.target).closest('table');
  47. // 当前表的最后一行
  48. var $currentTableLastTr = $currentTable.find('tr:last');
  49. if ($currentTableLastTr.find('td:first').attr('data-index') == '0') {
  50. //解除禁用
  51. $currentTableLastTr.find('input').removeAttr('disabled');
  52. $currentTableLastTr.find('select').removeAttr('disabled');
  53. $currentTableLastTr.find('textarea').removeAttr('disabled');
  54. $currentTableLastTr.find('.fb-edit-data').removeAttr('disabled');
  55. $currentTableLastTr.find('.fb-delete-data').removeAttr('disabled');
  56. $currentTableLastTr.find('.fb-submit-data').removeAttr('disabled');
  57. // 禁用其他行按钮
  58. $currentTableLastTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled');
  59. $currentTableLastTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled');
  60. $currentTableLastTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled');
  61. $currentTableLastTr.find('.fb-edit-data').hide();
  62. $currentTableLastTr.find('.fb-submit-data').show();
  63. $currentTableLastTr.find('input[type=text]:eq(0)').focus();
  64. } else {
  65. // 克隆tbody中最后一行数据
  66. var cloneTr = $currentTable.find('tbody>tr:last').clone(true);
  67. // 获取第一个td中的数字并+1
  68. var index = +cloneTr.find('td:first').html() + 1;
  69. // 将新的序号填入克隆的当前行,新建所以其data-index均置为0
  70. cloneTr.find('td:first').attr('data-index', 0).html(index);
  71. // 清空内容
  72. cloneTr.find('input[type=text]').val('');
  73. cloneTr.find('input[type=number]').val('');
  74. cloneTr.find('select').val('');
  75. cloneTr.find('textarea').val('');
  76. if (cloneTr.find(".fb-checkboxpart").length>0) {
  77. ////多选框组件清空
  78. cloneTr.find(".fb-checkboxpart").find("input[type='checkbox']").removeAttr("checked");
  79. var get_style = cloneTr.find(".fb-checkboxpart").attr("data-style");
  80. if (get_style == "sp-checkbox-none") {
  81. cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-none-checked");
  82. } else if (get_style == "sp-checkbox-gray") {
  83. cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-gray-checked");
  84. } else if (get_style == "sp-checkbox-blue") {
  85. cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-blue-checked");
  86. } else if (get_style == "sp-checkbox-orange") {
  87. cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-orange-checked");
  88. } else { return;}
  89. }
  90. if (cloneTr.find(".sp-upload").length > 0) {
  91. ////上传组件清空
  92. cloneTr.find(".sp-upload").find(".sp-upload-img").attr("src", "");
  93. cloneTr.find(".sp-upload").find(".sp-upload-tip").hide();
  94. cloneTr.find(".sp-upload").find(".sp-upload-tip-lh").remove();
  95. }
  96. // 再执行laydareRender
  97. if (cloneTr.find('input[data-type=date]')) {
  98. var cloneLayDateInput = cloneTr.find('input[data-type=date]');
  99. cloneLayDateInput.each(function () {
  100. // 生产随机数 用于id
  101. var randNum = Math.floor(Math.random() * 90000) + 10000;
  102. $(this).attr('id', $(this).attr('id') + randNum).removeAttr('lay-key');
  103. })
  104. }
  105. //插入到dom中
  106. $currentTable.find('tbody').append(cloneTr);
  107. // 再执行laydareRender
  108. if (cloneTr.find('input[data-type=date]')) {
  109. var cloneLayDateInput = cloneTr.find('input[data-type=date]');
  110. cloneLayDateInput.each(function () {
  111. spbld.laydateRender(this);
  112. })
  113. }
  114. // 禁用其他行按钮
  115. cloneTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled');
  116. cloneTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled');
  117. cloneTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled');
  118. cloneTr.find('input').removeAttr('disabled');
  119. cloneTr.find('select').removeAttr('disabled');
  120. cloneTr.find('textarea').removeAttr('disabled');
  121. cloneTr.find('.fb-edit-data').removeAttr('disabled');
  122. cloneTr.find('.fb-delete-data').removeAttr('disabled');
  123. cloneTr.find('.fb-submit-data').removeAttr('disabled');
  124. cloneTr.find('.fb-edit-data').hide();
  125. cloneTr.find('.fb-submit-data').show();
  126. cloneTr.find('input[type=text]:eq(0)').focus();
  127. }
  128. })
  129. //编辑按钮 解除表里表单的禁用
  130. $('.fb-edit-data').click(function (e) {
  131. //获取点击按钮的所在行
  132. var $currentTr = $(e.target).closest('tr');
  133. // 点击一次编辑后 隐藏 添加按钮
  134. $(e.target).closest('table').find('.fb-add-data').attr('disabled', 'disabled');
  135. //隐藏当前按钮
  136. $(this).hide();
  137. //显示提交( √ )按钮
  138. $currentTr.find('.fb-submit-data').show().removeAttr('disabled');
  139. //解除禁用
  140. $currentTr.find('input').removeAttr('disabled');
  141. $currentTr.find('select').removeAttr('disabled');
  142. $currentTr.find('textarea').removeAttr('disabled');
  143. $currentTr.find('input[type=text]:eq(0)').focus();
  144. // 禁用其他行按钮
  145. $currentTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled');
  146. $currentTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled');
  147. $currentTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled');
  148. })
  149. };
  150. ///给自定义表单的table赋值,AssignValueToTable
  151. ///jsonStr字符串
  152. var spbld_userid = ""; var spbld_routeinfoid = ""; var spbld_routeid = ""; var spbld_postAccessToken = "";
  153. spbld.fbAssignValueToTable = function (jsonStr, userid, routeinfoid, routeid, postAccessToken) {
  154. spbld_userid = userid;
  155. spbld_routeinfoid = routeinfoid;
  156. spbld_routeid = routeid;
  157. spbld_postAccessToken = postAccessToken;
  158. var res = JSON.parse(jsonStr);
  159. //console.log(jsonStr);
  160. ///1.对主表的字段进行遍历
  161. var get_mainTableName = res.TableName;
  162. if (sp.isval(res.TableCols)) {
  163. $.each(res.TableCols, function (index, item) {
  164. var controlIndex = $("#" + get_mainTableName + "_0_0_0_" + item.CODE); ////控件id
  165. if (item.EKIND == "edit" || item.EKIND == "number" || item.EKIND == "decimal") {
  166. ///此时用的都是单行文本框
  167. if ($("body").find(controlIndex).length > 0) {
  168. controlIndex.val(item.VALUE);
  169. }
  170. } else if (item.EKIND == "datetime") {///日期格式时,需要先为其格式化
  171. if ($("body").find(controlIndex).length > 0) {
  172. var get_format = controlIndex.attr("data-format");
  173. var formateDate = sp.datefmt(get_format, item.VALUE);
  174. controlIndex.val(formateDate);
  175. }
  176. } else if (item.EKIND == "text") {///多行文本时
  177. if ($("body").find(controlIndex).length > 0) {
  178. controlIndex.val(item.VALUE);
  179. }
  180. } else if (item.EKIND == "select") {///下拉选择框
  181. if ($("body").find(controlIndex).length > 0) {
  182. //controlIndex.val(item.VALUE);
  183. if (sp.isval(item.TCHILD_DATA)) {
  184. controlIndex.html(""); ///清空里面组件,重新赋值
  185. var set_control = "";
  186. $.each(item.TCHILD_DATA, function (index2, item2) {
  187. if (item2.CODE == item.VALUE) {
  188. item2.CHECKED = true;
  189. set_control += "<option value='" + item2.CODE + "' selected = 'selected' >" + item2.CNAME + "</option>";
  190. } else {
  191. set_control += "<option value='" + item2.CODE + "'>" + item2.CNAME + "</option>";
  192. }
  193. });
  194. controlIndex.html(set_control);
  195. } else {
  196. ///不请空还是原来默认2项数据
  197. return;
  198. }
  199. }
  200. } else if (item.EKIND == "radiobox") {///单选按钮
  201. if ($("body").find(controlIndex).length > 0) {
  202. var get_radioStyle = controlIndex.attr("data-style");
  203. if (sp.isval(item.TCHILD_DATA)) {
  204. controlIndex.html(""); ///清空里面组件,重新赋值
  205. var set_control = "";
  206. $.each(item.TCHILD_DATA, function (index2, item2) {
  207. if (item2.checked) {
  208. var set_label_class = "";
  209. if (get_radioStyle == "sp-radio-default") {
  210. set_label_class = "rd-default-checked";
  211. } else if (get_radioStyle == "sp-radio-blue") {
  212. set_label_class = "rd-blue-checked";
  213. } else if (get_radioStyle == "sp-radio-orange") {
  214. set_label_class = "rd-orange-checked";
  215. } else if (get_radioStyle == "sp-radio-none") {
  216. set_label_class = "rd-none-checked";
  217. } else { return; }
  218. set_control += "<label class='" + set_label_class + "'><input type='radio' value='" + item2.ccode + "' checked='checked' />" + item2.cname + "</label>";
  219. } else {
  220. set_control += "<label><input type='radio' value='" + item2.ccode + "' />" + item2.cname + "</label>";
  221. }
  222. });
  223. controlIndex.html(set_control);
  224. } else {
  225. ///不请空还是原来默认2项数据
  226. return;
  227. }
  228. }
  229. } else if (item.EKIND == "popradiobox") {
  230. ///单向选择器
  231. if ($("body").find(controlIndex).length > 0) {
  232. if (sp.isval(item.TCHILD_DATA)) {
  233. controlIndex.val(""); ///控件清空val值
  234. controlIndex.attr("data-ccode", "");///控件清空ccode值
  235. var set_control = "", set_control_val = "", set_control_ccode = "";
  236. $.each(item.TCHILD_DATA, function (index2, item2) {
  237. if (item2.checked) {
  238. set_control += "<label class='rd-blue-checked'><input type='radio' value='" + item2.ccode + "' checked='checked' />" + item2.cname + "</label>";
  239. set_control_val += item2.cname + ",";
  240. set_control_ccode += item2.ccode + ",";
  241. } else {
  242. set_control += "<label><input type='radio' value='" + item2.ccode + "' />" + item2.cname + "</label>";
  243. }
  244. });
  245. if (sp.isval(set_control_val) && sp.isval(set_control_ccode)) {
  246. controlIndex.val(sp.cutlast(set_control_val));///控件显示val值
  247. controlIndex.attr("data-ccode", sp.cutlast(set_control_ccode));///控件赋值ccode值
  248. }
  249. $("#layer_popradiobox_" + item.CODE).find(".fb-radiopart").html(set_control);
  250. } else {
  251. ///不请空还是原来默认2项数据
  252. return;
  253. }
  254. }
  255. } else if (item.EKIND == "checkbox") {///多选按钮
  256. if ($("body").find(controlIndex).length > 0) {
  257. var get_checkboxStyle = controlIndex.attr("data-style");
  258. if (sp.isval(item.TCHILD_DATA)) {
  259. controlIndex.html(""); ///清空里面组件,重新赋值
  260. var set_control = "";
  261. $.each(item.TCHILD_DATA, function (index2, item2) {
  262. if (item2.checked) {
  263. var set_label_class = "";
  264. if (get_checkboxStyle == "sp-checkbox-gray") {
  265. set_label_class = "chb-gray-checked";
  266. } else if (get_checkboxStyle == "sp-checkbox-blue") {
  267. set_label_class = "chb-blue-checked";
  268. } else if (get_checkboxStyle == "sp-checkbox-orange") {
  269. set_label_class = "chb-orange-checked";
  270. } else if (get_checkboxStyle == "sp-checkbox-none") {
  271. set_label_class = "chb-none-checked";
  272. } else { return; }
  273. set_control += "<label class='" + set_label_class + "'><input type='checkbox' value='" + item2.ccode + "' checked='checked' />" + item2.cname + "</label>"
  274. } else {
  275. set_control += "<label><input type='checkbox' value='" + item2.ccode + "' />" + item2.cname + "</label>";
  276. }
  277. });
  278. controlIndex.html(set_control);
  279. } else {
  280. ///不请空还是原来默认2项数据
  281. return;
  282. }
  283. }
  284. } else if (item.EKIND == "popcheckbox") {
  285. ///多向选择器
  286. if ($("body").find(controlIndex).length > 0) {
  287. if (sp.isval(item.TCHILD_DATA)) {
  288. controlIndex.val(""); ///控件清空val值
  289. controlIndex.attr("data-ccode", "");///控件清空ccode值
  290. var set_control = "", set_control_val = "", set_control_ccode = "";
  291. $.each(item.TCHILD_DATA, function (index2, item2) {
  292. if (item2.checked) {
  293. set_control += "<label class='chb-blue-checked'><input type='checkbox' value='" + item2.ccode + "' checked='checked' />" + item2.cname + "</label>";
  294. set_control_val += item2.cname + ",";
  295. set_control_ccode += item2.ccode + ",";
  296. } else {
  297. set_control += "<label><input type='checkbox' value='" + item2.ccode + "' />" + item2.cname + "</label>";
  298. }
  299. });
  300. if (sp.isval(set_control_val) && sp.isval(set_control_ccode)) {
  301. controlIndex.val(sp.cutlast(set_control_val));///控件显示val值
  302. controlIndex.attr("data-ccode", sp.cutlast(set_control_ccode));///控件赋值ccode值
  303. }
  304. $("#layer_popcheckbox_" + item.CODE).find(".fb-checkboxpart").html(set_control);
  305. } else {
  306. ///不请空还是原来默认2项数据
  307. return;
  308. }
  309. }
  310. } else if (item.EKIND == "optionbox") {
  311. ////签写意见
  312. if ($("body").find(controlIndex).length > 0) {
  313. spbld.getOptionboxData(controlIndex, get_mainTableName, item.CODE, userid, routeinfoid, routeid, postAccessToken);
  314. }
  315. } else if (item.EKIND == "imgupload") {
  316. ///图片上传
  317. if ($("body").find(controlIndex).length > 0) {
  318. controlIndex.find(".sp-upload-img").attr("src", item.VALUE);
  319. }
  320. } else if (item.EKIND == "fileupload") {///附件上传
  321. if ($("body").find(controlIndex).length > 0) {
  322. $.each(item.VALUE, function (index2, item2) {
  323. var fileSize = 0;
  324. if (item2.size > 1024 * 1024) {
  325. fileSize = (Math.round(item2.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
  326. }
  327. else {
  328. fileSize = (Math.round(item2.size * 100 / 1024) / 100).toString() + 'KB';
  329. }
  330. var settiplh = "<div class='sp-upload-tip-lh' data-url='" + item2.url + "' data-name='" + item2.name + "' data-size='" + item2.size + "'><div class='sp-upload-tip-info' style='display:block'><a href='" + item2.url + "'>" + item2.name + "(" + fileSize + ")</a><i class='fa fa-close sp-upload-tip-close'> 删除</i></div></div>";
  331. controlIndex.find(".sp-upload-tip").show().append(settiplh);
  332. });
  333. }
  334. } else { return; }
  335. });
  336. }
  337. ////************************************************************************************************************
  338. ////2.对子表字段进行遍历subTable,会有多子表结构
  339. if (sp.isval(res.subTable)) {
  340. $.each(res.subTable, function (index, item) {
  341. if ($("body").find($("#subTable_0_0_0_" + item.subTableName)).length > 0) {
  342. var cloneTr = $("#subTable_0_0_0_" + item.subTableName + " tbody>tr:first").clone(true);
  343. for (var j = 1; j < item.subTableColumns.length; j++) {
  344. cloneTr.find('td:first').attr('data-index', j + 1).html(j + 1);
  345. if (cloneTr.find('input[data-type=date]')) {
  346. var cloneLayDateInput = cloneTr.find('input[data-type=date]');
  347. cloneLayDateInput.each(function () {
  348. var randNum = Math.floor(Math.random() * 90000) + 10000;
  349. $(this).attr('id', $(this).attr('id') + randNum);
  350. })
  351. }
  352. $("#subTable_0_0_0_" + item.subTableName + " tbody").append(cloneTr);
  353. }
  354. for (var i = 0; i < item.subTableColumns.length; i++) {
  355. $.each(item.subTableColumns[i], function (index2, item2) {
  356. var tbodyTRindex = $("#subTable_0_0_0_" + item.subTableName + " tbody tr:eq(" + i + ")"); ///第几行
  357. if (item2.showcode == "ID") {
  358. tbodyTRindex.find('td:first').attr("data-index", item2.showvalue);
  359. }
  360. if (item2.showtype == "edit" || item2.showtype == "number" || item2.showtype == "decimal") {
  361. //console.log($("#subTable_0_0_0_" + item.subTableName + " tbody tr:eq(" + i + ")").length);
  362. ///判断子表中,每行中是否存在与json字段对应的input,如果存在给其赋值
  363. if (tbodyTRindex.find("input[data-code='" + item2.showcode + "']").length > 0) {
  364. tbodyTRindex.find("input[data-code='" + item2.showcode + "']").val(item2.showvalue);
  365. };
  366. } else if (item2.showtype == "datetime") {///日期格式时,需要先为其格式化
  367. if (tbodyTRindex.find("input[data-code='" + item2.showcode + "']").length > 0) {
  368. var get_format = tbodyTRindex.find("input[data-code='" + item2.showcode + "']").attr("data-format");
  369. var formateDate = sp.datefmt(get_format, item2.showvalue);
  370. tbodyTRindex.find("input[data-code='" + item2.showcode + "']").val(formateDate);
  371. };
  372. } else if (item2.showtype == "text") {
  373. if (tbodyTRindex.find("textarea[data-code='" + item2.showcode + "']").length > 0) {
  374. tbodyTRindex.find("textarea[data-code='" + item2.showcode + "']").val(item2.showvalue);
  375. };
  376. } else if (item2.showtype == "select") {
  377. if (tbodyTRindex.find("select[data-code='" + item2.showcode + "']").length > 0) {
  378. tbodyTRindex.find("select[data-code='" + item2.showcode + "']").val(item2.showvalue);
  379. };
  380. } else if (item2.showtype == "radio") {
  381. //console.log($("div[data-code='sex']").length)
  382. if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) {
  383. var get_radioStyle = tbodyTRindex.find("div[data-code='" + item2.showcode + "']").attr("data-style");
  384. tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find("input[type='radio']").each(function () {
  385. if ($(this).val() == item2.showvalue) {
  386. ///此处radio选中,其他的radio去掉选中
  387. $(this).attr("checked", "checked");
  388. $(this).parent("label").siblings().children("input[type='radio']").removeAttr("checked");
  389. ///此处radio的label加上选中样式,其他的label去掉选中样式
  390. if (get_radioStyle == "sp-radio-default") {
  391. $(this).parent("label").addClass("rd-default-checked");
  392. $(this).parent("label").siblings().removeClass("rd-default-checked");
  393. } else if (get_radioStyle == "sp-radio-blue") {
  394. $(this).parent("label").addClass("rd-blue-checked");
  395. $(this).parent("label").siblings().removeClass("rd-blue-checked");
  396. } else if (get_radioStyle == "sp-radio-orange") {
  397. $(this).parent("label").addClass("rd-orange-checked");
  398. $(this).parent("label").siblings().removeClass("rd-orange-checked");
  399. } else if (get_radioStyle == "sp-radio-none") {
  400. $(this).parent("label").addClass("rd-none-checked");
  401. $(this).parent("label").siblings().removeClass("rd-none-checked");
  402. } else { return; }
  403. }
  404. });
  405. };
  406. } else if (item2.showtype == "checkbox") {
  407. if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) {
  408. var get_checkboxStyle = tbodyTRindex.find("div[data-code='" + item2.showcode + "']").attr("data-style");
  409. var get_checkboxvalue = item2.showvalue.split(",");
  410. for (var kk = 0; kk < get_checkboxvalue.length; kk++) {
  411. tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find("input[type='checkbox']").each(function () {
  412. if ($(this).val() == get_checkboxvalue[kk]) {
  413. ///此处checkbox选中
  414. $(this).attr("checked", "checked");
  415. ///此处checkbox的label加上选中样式
  416. if (get_checkboxStyle == "sp-checkbox-gray") {
  417. $(this).parent("label").addClass("chb-gray-checked");
  418. } else if (get_checkboxStyle == "sp-checkbox-blue") {
  419. $(this).parent("label").addClass("chb-blue-checked");
  420. } else if (get_checkboxStyle == "sp-checkbox-orange") {
  421. $(this).parent("label").addClass("chb-orange-checked");
  422. } else if (get_checkboxStyle == "sp-checkbox-none") {
  423. $(this).parent("label").addClass("chb-none-checked");
  424. } else { return; }
  425. }
  426. });
  427. };
  428. };
  429. } else if (item2.showtype == "img") {
  430. if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) {
  431. tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find(".sp-upload-img").attr("src", item2.showvalue);
  432. };
  433. } else if (item2.showtype == "file") {
  434. if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) {
  435. $.each(item2.showvalue, function (index3, item3) {
  436. var fileSize = 0;
  437. if (item3.size > 1024 * 1024) {
  438. fileSize = (Math.round(item3.size * 100 / (1024 * 1024)) / 100).toString() + 'MB';
  439. }
  440. else {
  441. fileSize = (Math.round(item3.size * 100 / 1024) / 100).toString() + 'KB';
  442. }
  443. var settiplh = "<div class='sp-upload-tip-lh' data-url='" + item3.url + "' data-name='" + item3.name + "' data-size='" + item3.size + "'><div class='sp-upload-tip-info' style='display:block'><a href='" + item3.url + "'>" + item3.name + "(" + fileSize + ")</a><i class='fa fa-close sp-upload-tip-close'> 删除</i></div></div>";
  444. tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find(".sp-upload-tip").show().append(settiplh);
  445. });
  446. };
  447. } else { return; }
  448. });
  449. };
  450. };
  451. });
  452. }
  453. };
  454. ///格式化自定义表单的table组成json字符串,
  455. ///partID是指定的表单table外层div的id
  456. spbld.fbFrtTableJson = function (partID, TableName) {
  457. var mainTableColumns = [];///声明主表列的数组
  458. var fb_json_str = "";
  459. ///遍历主表中的控件组成json
  460. if ($(partID).children(".sp-fb-grid").length > 0) {
  461. if ($(partID + " .sp-fb-grid>tbody>tr>td>input[type='text']").length > 0) {
  462. $(partID + " .sp-fb-grid>tbody>tr>td>input[type='text']").each(function () {
  463. //console.log($(this).attr("data-code"));
  464. if ($(this).attr("data-type") == "text") {
  465. var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ",";
  466. fb_json_str += set_str;
  467. } else if ($(this).attr("data-type") == "date") {
  468. var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ",";
  469. fb_json_str += set_str;
  470. } else { return; }
  471. });
  472. }
  473. if ($(partID + " .sp-fb-grid>tbody>tr>td>input[type='number']").length > 0) {
  474. $(partID + " .sp-fb-grid>tbody>tr>td>input[type='number']").each(function () {
  475. var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ",";
  476. fb_json_str += set_str;
  477. });
  478. }
  479. if ($(partID + " .sp-fb-grid>tbody>tr>td>textarea").length > 0) {
  480. $(partID + " .sp-fb-grid>tbody>tr>td>textarea").each(function () {
  481. var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ",";
  482. fb_json_str += set_str;
  483. });
  484. }
  485. if ($(partID + " .sp-fb-grid>tbody>tr>td>select").length > 0) {
  486. $(partID + " .sp-fb-grid>tbody>tr>td>select").each(function () {
  487. var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ",";
  488. fb_json_str += set_str;
  489. });
  490. }
  491. if ($(partID + " .sp-fb-grid>tbody>tr>td>.fb-radiopart").length > 0) {
  492. $(partID + " .sp-fb-grid>tbody>tr>td>.fb-radiopart").each(function () {
  493. var getchecked = $(this).find("input[type='radio']:checked").val();
  494. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"radio\", \"showvalue\":\"" + getchecked + "\"}";
  495. mainTableColumns.push(JSON.parse(setjson));
  496. });
  497. }
  498. if ($(partID + " .sp-fb-grid>tbody>tr>td>.fb-checkboxpart").length > 0) {
  499. $(partID + " .sp-fb-grid>tbody>tr>td>.fb-checkboxpart").each(function () {
  500. var getchecked = "";
  501. $(this).find("input[type='checkbox']").each(function () {
  502. if ($(this).is(":checked")) {
  503. getchecked += $(this).val() + ",";
  504. }
  505. });
  506. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"checkbox\", \"showvalue\":\"" + sp.cutlast(getchecked) + "\"}";
  507. mainTableColumns.push(JSON.parse(setjson));
  508. });
  509. }
  510. if ($(partID + " .sp-fb-grid>tbody>tr>td>.sp-upload").length > 0) {
  511. $(partID + " .sp-fb-grid>tbody>tr>td>.sp-upload").each(function () {
  512. var get_showtype = "";
  513. var get_showvalue = "";
  514. if ($(this).children(".sp-upload-img").length > 0) {
  515. get_showtype = "img";
  516. get_showvalue = $(".sp-upload-img", this).attr("src");
  517. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":\"" + get_showvalue + "\"}";
  518. mainTableColumns.push(JSON.parse(setjson));
  519. } else if ($(this).children(".sp-upload-file-single").length > 0) {
  520. get_showtype = "file";
  521. $(".sp-upload-tip-lh", this).each(function () {
  522. get_showvalue += "{\"name\":\"" + $(this).attr("data-name") + "\", \"url\":\"" + $(this).attr("data-url") + "\", \"size\":" + $(this).attr("data-size") + "},";
  523. });
  524. //console.log(sp.cutlast(get_showvalue));
  525. var loc = "[" + sp.cutlast(get_showvalue) + "]";
  526. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":" + loc + "}";
  527. mainTableColumns.push(JSON.parse(setjson));
  528. }
  529. });
  530. }
  531. //console.log(JSON.stringify(mainTableColumns));
  532. };
  533. ////***********************************
  534. ///遍历子表
  535. var subTableAllArray = [];///声明子表数组集合变量
  536. if ($(partID).find(".sp-subgrid-job").length > 0) {
  537. $(partID + " .sp-subgrid-job").each(function (index, item) {
  538. var subTableColumnsArray = [];
  539. $("tbody tr", this).each(function (index2, item2) {
  540. ////加上判断该行是不是都为空
  541. var hasval = 0;///声明行中控件都为空的标志hasval =0
  542. if ($(this).find("input[type='text']").length > 0) {
  543. $(this).find("input[type='text']").each(function () {
  544. if ($(this).val() != "" && $(this).val() != null) {
  545. hasval = 1;
  546. }
  547. });
  548. }
  549. if ($(this).find("input[type='number']").length > 0) {
  550. $(this).find("input[type='number']").each(function () {
  551. if ($(this).val() != "" && $(this).val() != null) {
  552. hasval = 1;
  553. }
  554. });
  555. }
  556. if ($(this).find("textarea").length > 0) {
  557. $(this).find("textarea").each(function () {
  558. if ($(this).val() != "" && $(this).val() != null) {
  559. hasval = 1;
  560. }
  561. });
  562. }
  563. if ($(this).find(".fb-checkboxpart").length > 0) {
  564. $(this).find(".fb-checkboxpart").each(function () {
  565. $(this).find("input[type='checkbox']").each(function () {
  566. if ($(this).is(":checked")) {
  567. hasval = 1;
  568. }
  569. });
  570. });
  571. }
  572. if ($(this).find(".sp-upload").length > 0) {
  573. $(this).find(".sp-upload").each(function () {
  574. if ($(this).children(".sp-upload-img").length > 0) {
  575. var get_showvalue = $(".sp-upload-img", this).attr("src");
  576. if (get_showvalue != "" && get_showvalue != null) {
  577. hasval = 1;
  578. }
  579. } else if ($(this).children(".sp-upload-file-single").length > 0) {
  580. if ($(this).find(".sp-upload-tip-lh").length > 0) {
  581. hasval = 1;
  582. }
  583. }
  584. });
  585. }
  586. ///*************************************************************************************
  587. ///此处是得到该行控件不都为空,则将其遍历组成json
  588. if (hasval == 1) {
  589. var subTableColumnsSub = [];
  590. var getID = $(this).find('td:first').attr("data-index");
  591. var setjsonID = "{\"showcode\":\"ID\", \"showtype\":\"number\", \"showvalue\":\"" + getID + "\"}";
  592. subTableColumnsSub.push(JSON.parse(setjsonID));
  593. if ($(this).find("input[type='text']").length > 0) {
  594. $(this).find("input[type='text']").each(function () {
  595. if ($(this).attr("data-type") == "text") {
  596. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"edit\", \"showvalue\":\"" + $(this).val() + "\"}";
  597. subTableColumnsSub.push(JSON.parse(setjson));
  598. } else if ($(this).attr("data-type") == "date") {
  599. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"datetime\", \"showvalue\":\"" + $(this).val() + "\"}";
  600. subTableColumnsSub.push(JSON.parse(setjson));
  601. } else { return; }
  602. });
  603. }
  604. if ($(this).find("input[type='number']").length > 0) {
  605. $(this).find("input[type='number']").each(function () {
  606. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"number\", \"showvalue\":\"" + $(this).val() + "\"}";
  607. subTableColumnsSub.push(JSON.parse(setjson));
  608. });
  609. }
  610. if ($(this).find("textarea").length > 0) {
  611. $(this).find("textarea").each(function () {
  612. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"text\", \"showvalue\":\"" + $(this).val() + "\"}";
  613. subTableColumnsSub.push(JSON.parse(setjson));
  614. });
  615. }
  616. if ($(this).find("select").length > 0) {
  617. $(this).find("select").each(function () {
  618. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"select\", \"showvalue\":\"" + $(this).val() + "\"}";
  619. subTableColumnsSub.push(JSON.parse(setjson));
  620. });
  621. }
  622. if ($(this).find(".fb-radiopart").length > 0) {
  623. $(this).find(".fb-radiopart").each(function () {
  624. var getchecked = $(this).find("input[type='radio']:checked").val();
  625. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"radio\", \"showvalue\":\"" + getchecked + "\"}";
  626. subTableColumnsSub.push(JSON.parse(setjson));
  627. });
  628. }
  629. if ($(this).find(".fb-checkboxpart").length > 0) {
  630. $(this).find(".fb-checkboxpart").each(function () {
  631. var getchecked = "";
  632. $(this).find("input[type='checkbox']").each(function () {
  633. if ($(this).is(":checked")) {
  634. getchecked += $(this).val() + ",";
  635. }
  636. });
  637. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"checkbox\", \"showvalue\":\"" + sp.cutlast(getchecked) + "\"}";
  638. subTableColumnsSub.push(JSON.parse(setjson));
  639. });
  640. }
  641. if ($(this).find(".sp-upload").length > 0) {
  642. $(this).find(".sp-upload").each(function () {
  643. var get_showtype = "";
  644. var get_showvalue = "";
  645. if ($(this).children(".sp-upload-img").length > 0) {
  646. get_showtype = "img";
  647. get_showvalue = $(".sp-upload-img", this).attr("src");
  648. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":\"" + get_showvalue + "\"}";
  649. subTableColumnsSub.push(JSON.parse(setjson));
  650. } else if ($(this).children(".sp-upload-file-single").length > 0) {
  651. get_showtype = "file";
  652. $(".sp-upload-tip-lh", this).each(function () {
  653. get_showvalue += "{\"name\":\"" + $(this).attr("data-name") + "\", \"url\":\"" + $(this).attr("data-url") + "\", \"size\":" + $(this).attr("data-size") + "},";
  654. });
  655. //console.log(sp.cutlast(get_showvalue));
  656. var loc = "[" + sp.cutlast(get_showvalue) + "]";
  657. var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":" + loc + "}";
  658. subTableColumnsSub.push(JSON.parse(setjson));
  659. }
  660. });
  661. }
  662. subTableColumnsArray.push(subTableColumnsSub);
  663. }
  664. });
  665. //console.log(JSON.stringify(subTableColumnsArray));
  666. var subTableArray = "{\"subTableName\":\"" + $(this).attr("data-subtablename") + "\", \"subTableColumns\":" + JSON.stringify(subTableColumnsArray) + "}";
  667. //console.log(subTableArray);
  668. subTableAllArray.push(JSON.parse(subTableArray));
  669. });
  670. };
  671. //console.log(JSON.stringify(subTableAllArray));
  672. //var frtJson = "";///整体json串
  673. //if ($(partID).children(".sp-fb-grid").length > 0 && $(partID).find(".sp-subgrid-job").length > 0) {
  674. // //主表和子表都有
  675. // frtJson = "{\"TableName\":\"" + TableName + "\", \"mainTableColumns\":" + JSON.stringify(mainTableColumns) + ", \"subTable\":" + JSON.stringify(subTableAllArray) + "}";
  676. //} else if ($(partID).children(".sp-fb-grid").length > 0 && $(partID).find(".sp-subgrid-job").length == 0) {
  677. // //只有主表没有子表
  678. // frtJson = "{\"TableName\":\"" + TableName + "\", \"mainTableColumns\":" + JSON.stringify(mainTableColumns) + "}";
  679. //} else { return; }
  680. ////console.log(frtJson);
  681. //return frtJson;
  682. if (sp.isval(fb_json_str)) {
  683. var set_json = "{" + sp.cutlast(fb_json_str) + "}";
  684. //console.log(set_json);
  685. return set_json;
  686. } else {
  687. return fb_json_str;
  688. }
  689. };
  690. ////单选选择器--打开事件
  691. spbld.layer_popradiobox_open = function (layerid) {
  692. sp.layer("#" + layerid);
  693. }
  694. ////单选选择器---确定事件
  695. spbld.layer_popradiobox_true = function (layerid,controlid,showcode) {
  696. var get_inputRadioChecked=$("#" + layerid).find(".fb-radiopart").find("input[type='radio']:checked");
  697. $("#" + controlid).val(get_inputRadioChecked.parent().text());
  698. $("#" + controlid).attr("data-ccode", get_inputRadioChecked.val());
  699. sp.layerhide();
  700. }
  701. ///多项选择器
  702. spbld.layer_popcheckbox_open = function (layerid) {
  703. sp.layer("#" + layerid);
  704. }
  705. ////多项选择器---确定事件
  706. spbld.layer_popcheckbox_true = function (layerid, controlid, showcode) {
  707. var get_inputChecboxChecked = $("#" + layerid).find(".fb-checkboxpart").find("input[type='checkbox']:checked");
  708. var set_control_val = "", set_control_ccode = "";
  709. get_inputChecboxChecked.each(function (item2,index2) {
  710. set_control_val += $(this).parent().text()+ ",";
  711. set_control_ccode += $(this).val() + ",";
  712. })
  713. $("#" + controlid).val(sp.cutlast(set_control_val));
  714. $("#" + controlid).attr("data-ccode", sp.cutlast(set_control_ccode));
  715. sp.layerhide();
  716. }
  717. ////**签写意见业务操作--start********************************************************************************
  718. spbld.getOptionboxData = function (controlIndex, get_mainTableName, colname, userid, routeinfoid, routeid, postAccessToken) {
  719. ////加载数据
  720. var postData = {
  721. "cmanid": userid,///签字人ID
  722. "routeinfoid": routeinfoid,///流程实例ID
  723. "routeid": routeid,//流程流转ID
  724. "tableid": get_mainTableName,//表单名称
  725. "colid": colname//列名称
  726. }
  727. var postData_2 = {
  728. data: s4.encryptData_CBC(JSON.stringify(postData))
  729. }
  730. //var yijianJson = "";
  731. //if (colname == "yijiancontrol") {
  732. // yijianJson = 'json.page/optionbox/optionbox_1.txt?v=' + new Date();
  733. //} else {
  734. // yijianJson = 'json.page/optionbox/optionbox_2.txt?v=' + new Date();
  735. //}
  736. $.ajax({
  737. //////g2app/abase/queryDataOpinion
  738. //url: yijianJson,
  739. //type:'get',
  740. url: apiurljs.login + "g2app/abase/queryDataOpinion",
  741. type: 'post',
  742. data: JSON.stringify(postData_2),
  743. dataType: "json",
  744. contentType: "application/json",
  745. headers: { Authorization: "Bearer " + postAccessToken }, ////请求头headers
  746. success: function (obj) {
  747. var res = strToJson(s4.decryptData_CBC(obj.data));
  748. //console.log(JSON.stringify(res));
  749. controlIndex.html("");
  750. if (sp.isval(res.data)) {
  751. $.each(res.data, function (index2, item2) {
  752. var set_text_or_img = "";
  753. if (sp.isval(item2.OPINION)) {
  754. set_text_or_img = "<div class='sp-lh-20'>" + item2.OPINION + "</div>";
  755. } else if (sp.isval(item2.OPINIONIMAGE)) {
  756. set_text_or_img = "<img class='sp-pull-left' src='" + item2.OPINIONIMAGE + "' style='max-width: 50%;max-height: 85px;' />"
  757. } else { set_text_or_img = ""; }
  758. var set_btn_html = "";
  759. if (routeid == item2.ROUTEID) {
  760. set_btn_html = "<div class='sp-page sp-mt-5'><span class='sp-btn-red-outline sp-btn-radius' onclick=\"spbld.layer_optionbox_delete(this,'" + get_mainTableName + "_0_0_0_" + colname + "','" + get_mainTableName + "','" + colname + "','" + item2.USERID + "','" + item2.ROUTEINFOID + "','" + item2.ROUTEID + "')\">删除</span></div>" +
  761. "<div class='sp-page sp-mt-10'><span class='sp-btn-blue-outline sp-btn-radius' onclick=\"spbld.layer_optionbox_edit('" + get_mainTableName + "_0_0_0_" + colname + "','" + get_mainTableName + "','" + colname + "','" + item2.OPINION + "','" + item2.OPINIONIMAGE + "','" + item2.USERID + "','" + item2.ROUTEINFOID + "','" + item2.ROUTEID + "')\">修改</span></div>"
  762. }
  763. var setHtml = "<div class='sp-page-mgn sp-border-bottom sp-pb-20 sp-color-black'>" +
  764. "<div class='sp-page-col' style='width: calc(100% - 220px);'>" +
  765. set_text_or_img +
  766. "</div>" +
  767. "<div class='sp-page-col sp-text-right' style='width:120px;'>" +
  768. "<div class='sp-page sp-mt-20'>" + item2.CMANNAME + "</div>" +
  769. "<div class='sp-page'>" + sp.format(item2.CDATE) + "</div>" +
  770. "</div>" +
  771. "<div class='sp-page-col sp-text-center' style='width:100px;'>"
  772. + set_btn_html +
  773. "</div>" +
  774. "</div>";
  775. controlIndex.append(setHtml);
  776. //console.log(controlIndex.next());
  777. //console.log(routeid + "、" + item2.ROUTEID);
  778. if (routeid == item2.ROUTEID) {
  779. ///已有数据且流程流转ID相同时,签写意见按钮隐藏;
  780. controlIndex.next().hide();
  781. } else {
  782. controlIndex.next().show();
  783. }
  784. });
  785. controlIndex.children(".sp-page-mgn:last-child").removeClass("sp-border-bottom").removeClass("sp-pb-20");
  786. } else {
  787. controlIndex.next().show();
  788. }
  789. },
  790. error: function (returndata) {
  791. console.log(JSON.stringify(returndata));
  792. }
  793. });
  794. }
  795. ///打开签写意见弹出层
  796. spbld.layer_optionbox_open = function (idstr, mainTableName, showcode) {
  797. ////为tabs选项框赋值点击切换事件
  798. sp.layer("#layer_optionbox");
  799. $("#layer_optionbox_textarea").val("");
  800. $("#layer_optionbox_true_btn").attr("data-mainTableName", mainTableName).attr("data-colname", showcode).attr("data-userid", spbld_userid).attr("data-routeinfoid", spbld_routeinfoid).attr("data-routeid", spbld_routeid);///往确定按钮中赋值属性
  801. spbld.layer_optionbox_tabs(0);///传0默认打开第一层
  802. ///常用语检索数据--2023-zyg
  803. spbld.layer_optionbox_queryDataPatterns(mainTableName, showcode, spbld_userid);
  804. }
  805. ///签写意见--tabs切换
  806. spbld.layer_optionbox_tabs = function (indexSet) {
  807. indexSet = indexSet || 0;
  808. ///初始设置
  809. $("#layer_optionbox_tabs .sp-tab-menu li").removeClass("sp-tab-current");
  810. $("#layer_optionbox_tabs .sp-tab-menu li:eq(" + indexSet + ")").addClass("sp-tab-current");
  811. $("#layer_optionbox_tabs .sp-tab-box").children('div').addClass("sp-tab-hide");
  812. $("#layer_optionbox_tabs .sp-tab-box").children('div:eq(' + indexSet + ')').removeClass("sp-tab-hide");
  813. if (indexSet == 1) {
  814. setTimeout(function () {
  815. ///延时1秒加载canvas划线,js否则得不到canvas外层的宽度高度
  816. spbld.lineCanvas();
  817. }, 10)
  818. }
  819. ////点击事件设置
  820. $("#layer_optionbox_tabs .sp-tab-menu li").click(function () {
  821. $(this).addClass("sp-tab-current").siblings().removeClass("sp-tab-current");
  822. var get_index = $(this).attr("data-index");
  823. $("#layer_optionbox_tabs .sp-tab-box").children('div').addClass("sp-tab-hide");
  824. $("#layer_optionbox_tabs .sp-tab-box").children('div:eq(' + get_index + ')').removeClass("sp-tab-hide");
  825. if (get_index == 1) {
  826. setTimeout(function () {
  827. ///延时1秒加载canvas划线,js否则得不到canvas外层的宽度高度
  828. spbld.lineCanvas();
  829. }, 10)
  830. }
  831. })
  832. };
  833. ///清空canvas
  834. spbld.layer_optionbox_cnavas_clear = function () {
  835. let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域
  836. var cxt = canvas.getContext("2d");
  837. cxt.clearRect(0, 0, canvas.width, canvas.height);
  838. };
  839. //canvas画布签字
  840. spbld.lineCanvas = function () {
  841. let canvasBody = document.getElementById('layer_optionbox_canvas_outpart');///canvas的外层区域
  842. //console.log(canvasBody);
  843. //console.log("clientWidth:"+canvasBody.clientWidth);
  844. //console.log("clientHeight:" + canvasBody.clientHeight);
  845. let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域
  846. canvas.width = canvasBody.clientWidth;
  847. canvas.height = canvasBody.clientHeight;
  848. let ctx = canvas.getContext('2d');
  849. ctx.lineWidth = 4;
  850. ctx.strokeStyle = '#333';
  851. ctx.lineCap = 'round';
  852. ctx.lineJoin = 'round';
  853. let isDrawing = false;
  854. let dataURL = '';
  855. let initX;
  856. let initY;
  857. // 事件监听--开始绘制
  858. canvas.addEventListener("mousedown", function (e) {
  859. isDrawing = true;
  860. initX = e.offsetX;
  861. initY = e.offsetY
  862. });
  863. canvas.addEventListener('mousemove', draw);
  864. canvas.addEventListener("mouseup", function () {
  865. isDrawing = false
  866. });
  867. canvas.addEventListener("mouseout", function () {
  868. isDrawing = false
  869. });
  870. // 绘制中...
  871. function draw(e) {
  872. if (!isDrawing) return
  873. ctx.beginPath();
  874. // 起点
  875. ctx.moveTo(initX, initY);
  876. // 终点
  877. ctx.lineTo(e.offsetX, e.offsetY);
  878. ctx.stroke();
  879. initX = e.offsetX;
  880. initY = e.offsetY;
  881. }
  882. };
  883. ///删除意见
  884. spbld.layer_optionbox_delete = function (obj, controlIndex, maintable, colname, userid, routeinfoid, routeid) {
  885. if (confirm("您确定要删除吗?")) {
  886. var postData = {
  887. cmanid: userid,
  888. routeid: routeid,
  889. tableid: maintable,
  890. colid: colname
  891. }
  892. var postData_2 = {
  893. data: s4.encryptData_CBC(JSON.stringify(postData))
  894. }
  895. /////g2app/abase/deleteDataOpinion
  896. $.ajax({
  897. //url: 'json.page/optionbox/optionbox_delete.txt?v='+ new Date(),
  898. //type: 'get',
  899. url: apiurljs.login + "g2app/abase/deleteDataOpinion",
  900. type: 'post',
  901. data: JSON.stringify(postData_2),
  902. dataType: "json",
  903. contentType: "application/json",
  904. headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers
  905. success: function (obj) {
  906. var res = strToJson(s4.decryptData_CBC(obj.data));
  907. if (res.success) {
  908. //alert(obj);
  909. spbld.getOptionboxData($("#" + controlIndex), maintable, colname, userid, routeinfoid, routeid, spbld_postAccessToken);
  910. }
  911. },
  912. error: function (returndata) {
  913. sp.dialog("意见删除失败!")
  914. }
  915. });
  916. }
  917. }
  918. ////修改意见
  919. spbld.layer_optionbox_edit = function (idstr, maintable, colname, OPINION, OPINIONIMAGE, userid, routeinfoid, routeid) {
  920. $("#layer_optionbox_true_btn").attr("data-mainTableName", maintable).attr("data-colname", colname).attr("data-userid", userid).attr("data-routeinfoid", routeinfoid).attr("data-routeid", routeid);///往确定按钮中赋值属性
  921. if (sp.isval(OPINION)) {
  922. sp.layer("#layer_optionbox");
  923. spbld.layer_optionbox_tabs(0);
  924. ///常用语检索数据--2023-zyg
  925. spbld.layer_optionbox_queryDataPatterns(maintable, colname, userid);
  926. setTimeout(function () {
  927. $("#layer_optionbox_textarea").val(OPINION);
  928. }, 10);
  929. } else {
  930. sp.layer("#layer_optionbox");
  931. spbld.layer_optionbox_tabs(1);
  932. setTimeout(function () {
  933. ///把base64格式图片画到canvas画布上
  934. let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域
  935. var cxt = canvas.getContext("2d");
  936. let img = new Image();
  937. img.src = OPINIONIMAGE;
  938. img.onload = function () {
  939. cxt.drawImage(this, 0, 0, canvas.width, canvas.height);
  940. }
  941. }, 20);
  942. }
  943. }
  944. ///签写意见------确认按钮保存事件
  945. spbld.layer_optionbox_true = function () {
  946. var get_tabsIndex = $("#layer_optionbox_tabs").find(".sp-tab-current").attr("data-index");
  947. if (get_tabsIndex == 0) {
  948. ///为文字
  949. var get_txtval = $("#layer_optionbox_textarea").val();
  950. if (sp.isval(get_txtval)) {
  951. spbld.layer_optionbox_true_submitData(get_tabsIndex, get_txtval);
  952. } else {
  953. alert("文字内容不能为空");
  954. }
  955. } else {
  956. ///1时为手签
  957. //PNG 算法,判断canvas内容是否为空
  958. let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域
  959. var blank = document.createElement('canvas');
  960. blank.width = canvas.width;
  961. blank.height = canvas.height;
  962. if (canvas.toDataURL() == blank.toDataURL()) {
  963. alert("手签内容不能为空");
  964. } else {
  965. //console.log(canvas.toDataURL());
  966. spbld.layer_optionbox_true_submitData(get_tabsIndex, canvas.toDataURL());
  967. }
  968. }
  969. };
  970. spbld.layer_optionbox_true_submitData = function (get_tabsIndex,cval) {
  971. var get_mainTabmeName = $("#layer_optionbox_true_btn").attr("data-maintablename");
  972. var get_colName = $("#layer_optionbox_true_btn").attr("data-colname");
  973. var get_userid = $("#layer_optionbox_true_btn").attr("data-userid");
  974. var get_routeinfoid = $("#layer_optionbox_true_btn").attr("data-routeinfoid");
  975. var get_routeid = $("#layer_optionbox_true_btn").attr("data-routeid");
  976. var set_opinion = "";
  977. var set_opinionimage = "";
  978. if (get_tabsIndex == 0) {
  979. set_opinion = cval;
  980. set_opinionimage = "";
  981. } else {
  982. set_opinion = "";
  983. set_opinionimage = cval;
  984. }
  985. var postData = {
  986. "cmanid": get_userid,//签字人ID
  987. "routeinfoid": get_routeinfoid,//流程实例ID
  988. "routeid": get_routeid,//流程流转ID
  989. "tableid": get_mainTabmeName,//表单名称
  990. "colid": get_colName,//列名称
  991. "opiniontype": get_tabsIndex,//签字类别 0-正常文字 1-语音转文字(配话筒) 2-手写签字(配手写板)
  992. "cresult": "",//意见判定 可以为空,也可以设为同意、不同意、通过、不通过等
  993. "opinion": set_opinion,//签字意见
  994. "opinionimage": set_opinionimage//签字图片 存图片的BASE64字符串
  995. }
  996. //console.log(postData);
  997. var postData_2 = {
  998. data: s4.encryptData_CBC(JSON.stringify(postData))
  999. }
  1000. /////g2app/abase/saveDataOpinion
  1001. $.ajax({
  1002. //url: 'json.page/optionbox/optionbox_save.txt?v=' + new Date(),
  1003. //type: 'get',
  1004. url: apiurljs.login + "g2app/abase/saveDataOpinion",
  1005. type: 'post',
  1006. data: JSON.stringify(postData_2),
  1007. dataType: "json",
  1008. contentType: "application/json",
  1009. headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers
  1010. success: function (obj) {
  1011. var res = strToJson(s4.decryptData_CBC(obj.data));
  1012. if (res.success) {
  1013. sp.layerhide();
  1014. setTimeout(function () {
  1015. spbld.getOptionboxData($("#" + get_mainTabmeName + "_0_0_0_" + get_colName), get_mainTabmeName, get_colName, get_userid, get_routeinfoid, get_routeid, spbld_postAccessToken);
  1016. }, 200);
  1017. }
  1018. },
  1019. error: function (returndata) {
  1020. }
  1021. });
  1022. };
  1023. ///常用语操作---检索数据--2023-zyg
  1024. spbld.layer_optionbox_queryDataPatterns = function (get_mainTabmeName, get_colName, userid) {
  1025. var postData = {
  1026. "cmanid": userid,//签字人ID
  1027. "tableid": get_mainTabmeName,//表单名称
  1028. "colid": get_colName//列名称
  1029. }
  1030. var postData_2 = {
  1031. data: s4.encryptData_CBC(JSON.stringify(postData))
  1032. }
  1033. //////g2app/abase/queryDataPatterns 检索指定列的意见列表
  1034. $.ajax({
  1035. //url: 'json.page/optionbox/queryDataPatterns.txt?v=' + new Date(),
  1036. //type: 'get',
  1037. url: apiurljs.login + "g2app/abase/queryDataPatterns",
  1038. type: 'post',
  1039. data: JSON.stringify(postData_2),
  1040. dataType: "json",
  1041. contentType: "application/json",
  1042. headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers
  1043. success: function (obj) {
  1044. var res = strToJson(s4.decryptData_CBC(obj.data));
  1045. console.log(JSON.stringify(res));
  1046. ////{"code":0,"data":[{"TABLEID":"FW_ZSWPXXW","ID":"1110264415638523904","COLID":"WLDQFL","CONTENTS":"办理"},{"TABLEID":"FW_ZBWWHQ","ID":"1090645648408920065","COLID":"GPJZSC","CONTENTS":"可以"},{"TABLEID":"FW_DJGZDT","ID":"1090236997412823040","COLID":"HQBMFZRSH","CONTENTS":"同意"}],"message":"数据检索成功。","success":true}
  1047. if (sp.isval(res.data)) {
  1048. $("#layer_optionbox_patterns").html("");
  1049. $.each(res.data, function (index2, item2) {
  1050. var setHtml = "<span class='sp-lh-20'><span class='sp-page-col' style='width: calc(100% - 60px);'>" + item2.CONTENTS + "</span><span class='sp-page-col sp-text-center' style='width:60px;'><span onclick=\"spbld.layer_optionbox_queryDataPatterns_add('" + item2.CONTENTS + "')\" class='sp-logo-add' title='选中'></span><span class='sp-logo-delete' title='删除' onclick=\"spbld.layer_optionbox_queryDataPatterns_delete('" + get_mainTabmeName + "','" + get_colName + "','" + item2.ID + "')\" style='margin-left:10px;'></span></span></span>";
  1051. $("#layer_optionbox_patterns").append(setHtml);
  1052. });
  1053. }
  1054. },
  1055. error: function (returndata) {
  1056. }
  1057. });
  1058. };
  1059. spbld.layer_optionbox_queryDataPatterns_add = function (cval) {
  1060. //常用语操作---添加到左侧意见textarea中
  1061. $("#layer_optionbox_textarea").val(cval);
  1062. };
  1063. spbld.layer_optionbox_queryDataPatterns_delete = function (get_mainTabmeName, get_colName, idnum) {
  1064. if (confirm("您确定要删除吗?")) {
  1065. //常用语操作---删除
  1066. var postData = {
  1067. "id": idnum//常用语id
  1068. }
  1069. var postData_2 = {
  1070. data: s4.encryptData_CBC(JSON.stringify(postData))
  1071. }
  1072. //////g2app/abase/deleteDataOpinion 删除指定列的意见
  1073. $.ajax({
  1074. //url: 'json.page/optionbox/deleteDataOpinion.txt?v=' + new Date(),
  1075. //type: 'get',
  1076. url: apiurljs.login + "g2app/abase/deleteDataPatterns",
  1077. type: 'post',
  1078. data: JSON.stringify(postData_2),
  1079. dataType: "json",
  1080. contentType: "application/json",
  1081. headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers
  1082. success: function (obj) {
  1083. var res = strToJson(s4.decryptData_CBC(obj.data));
  1084. //console.log(JSON.stringify(res));
  1085. if (res.success) {
  1086. //console.log(spbld_userid)
  1087. spbld.layer_optionbox_queryDataPatterns(get_mainTabmeName, get_colName, spbld_userid);///重新检索常用语
  1088. }
  1089. },
  1090. error: function (returndata) {
  1091. }
  1092. });
  1093. }
  1094. };
  1095. spbld.layer_optionbox_patterns_add = function () {
  1096. /////常用语操作---新增
  1097. var get_phraseText = $("#layer_optionbox_patterns_input").val();
  1098. if (sp.isval(get_phraseText)) {
  1099. var get_mainTabmeName = $("#layer_optionbox_true_btn").attr("data-maintablename");
  1100. var get_colName = $("#layer_optionbox_true_btn").attr("data-colname");
  1101. var postData = {
  1102. cmanid: spbld_userid,
  1103. tableid: get_mainTabmeName,
  1104. colid: get_colName,
  1105. contents: get_phraseText
  1106. }
  1107. //console.log(postData);
  1108. var postData_2 = {
  1109. data: s4.encryptData_CBC(JSON.stringify(postData))
  1110. }
  1111. //////g2app/abase/insertDataPatterns 添加常用语到常用语库
  1112. $.ajax({
  1113. url: apiurljs.login + "g2app/abase/insertDataPatterns",
  1114. type: 'post',
  1115. data: JSON.stringify(postData_2),
  1116. dataType: "json",
  1117. contentType: "application/json",
  1118. headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers
  1119. success: function (obj) {
  1120. var res = strToJson(s4.decryptData_CBC(obj.data));
  1121. //console.log(JSON.stringify(res));
  1122. if (res.success) {
  1123. //console.log(spbld_userid)
  1124. spbld.layer_optionbox_queryDataPatterns(get_mainTabmeName, get_colName, spbld_userid);///重新检索常用语
  1125. }
  1126. },
  1127. error: function (returndata) {
  1128. }
  1129. });
  1130. } else {
  1131. alert("常用语不能为空!");
  1132. }
  1133. };
  1134. ////**签写意见业务操作--end********************************************************************************