///全称spbuilder var spbld = window.NameSpace || {}; ////遍历日期控件data-type='date',根据其data-formate属性然后为其调用不同的laydate.js的方法 ///样例: //根据元素 data-formate 属性然后为其调用不同的laydate.js的方法 spbld.laydateRender = function (obj) { var getid = $(obj).attr("id"); var getformat = $(obj).attr("data-format"); if (getformat == "yyyy-MM-dd" || getformat == "MM-dd" || getformat == "dd") { laydate.render({ elem: '#' + getid + '', type: 'date', format: '' + getformat + '', theme: '#009f95' }); } else if (getformat == "yyyy-MM") { laydate.render({ elem: '#' + getid + '', type: 'month', format: 'yyyy-MM', theme: '#009f95' }); } else if (getformat == "yyyy-MM-dd HH:mm:ss" || getformat == "yyyy-MM-dd HH:mm") { laydate.render({ elem: '#' + getid + '', type: 'datetime', format: '' + getformat + '', theme: '#009f95' }); } else if (getformat == "MM") { laydate.render({ elem: '#' + getid + '', type: 'month', format: 'MM', theme: '#009f95' }); } else if (getformat == "yyyy") { laydate.render({ elem: '#' + getid + '', type: 'year', format: 'yyyy', theme: '#009f95' }); } else if (getformat == "HH:mm:ss" || getformat == "HH:mm") { laydate.render({ elem: '#' + getid + '', type: 'time', format: '' + getformat + '', theme: '#009f95' }); } else { return; } } spbld.laydate = function () { if ($("body").find("input[data-type='date']").length > 0) { $("body").find("input[data-type='date']").each(function () { spbld.laydateRender(this); }); }; }; ////子表按钮操作 spbld.subtable = function () { //初始化 禁用子表中所有表单 var $subTable = $('.fb-subtable-control'); if ($subTable.length > 0) { $subTable.find('input').attr('disabled', 'disabled'); $subTable.find('select').attr('disabled', 'disabled'); $subTable.find('textarea').attr('disabled', 'disabled'); } else { return; } //添加按钮 $('.fb-add-data').click(function (e) { // 点击一次添加后 隐藏 添加按钮 $(this).attr('disabled', 'disabled'); // 向上查找到当前点击的table var $currentTable = $(e.target).closest('table'); // 当前表的最后一行 var $currentTableLastTr = $currentTable.find('tr:last'); if ($currentTableLastTr.find('td:first').attr('data-index') == '0') { //解除禁用 $currentTableLastTr.find('input').removeAttr('disabled'); $currentTableLastTr.find('select').removeAttr('disabled'); $currentTableLastTr.find('textarea').removeAttr('disabled'); $currentTableLastTr.find('.fb-edit-data').removeAttr('disabled'); $currentTableLastTr.find('.fb-delete-data').removeAttr('disabled'); $currentTableLastTr.find('.fb-submit-data').removeAttr('disabled'); // 禁用其他行按钮 $currentTableLastTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled'); $currentTableLastTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled'); $currentTableLastTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled'); $currentTableLastTr.find('.fb-edit-data').hide(); $currentTableLastTr.find('.fb-submit-data').show(); $currentTableLastTr.find('input[type=text]:eq(0)').focus(); } else { // 克隆tbody中最后一行数据 var cloneTr = $currentTable.find('tbody>tr:last').clone(true); // 获取第一个td中的数字并+1 var index = +cloneTr.find('td:first').html() + 1; // 将新的序号填入克隆的当前行,新建所以其data-index均置为0 cloneTr.find('td:first').attr('data-index', 0).html(index); // 清空内容 cloneTr.find('input[type=text]').val(''); cloneTr.find('input[type=number]').val(''); cloneTr.find('select').val(''); cloneTr.find('textarea').val(''); if (cloneTr.find(".fb-checkboxpart").length>0) { ////多选框组件清空 cloneTr.find(".fb-checkboxpart").find("input[type='checkbox']").removeAttr("checked"); var get_style = cloneTr.find(".fb-checkboxpart").attr("data-style"); if (get_style == "sp-checkbox-none") { cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-none-checked"); } else if (get_style == "sp-checkbox-gray") { cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-gray-checked"); } else if (get_style == "sp-checkbox-blue") { cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-blue-checked"); } else if (get_style == "sp-checkbox-orange") { cloneTr.find(".fb-checkboxpart").find("label").removeClass("chb-orange-checked"); } else { return;} } if (cloneTr.find(".sp-upload").length > 0) { ////上传组件清空 cloneTr.find(".sp-upload").find(".sp-upload-img").attr("src", ""); cloneTr.find(".sp-upload").find(".sp-upload-tip").hide(); cloneTr.find(".sp-upload").find(".sp-upload-tip-lh").remove(); } // 再执行laydareRender if (cloneTr.find('input[data-type=date]')) { var cloneLayDateInput = cloneTr.find('input[data-type=date]'); cloneLayDateInput.each(function () { // 生产随机数 用于id var randNum = Math.floor(Math.random() * 90000) + 10000; $(this).attr('id', $(this).attr('id') + randNum).removeAttr('lay-key'); }) } //插入到dom中 $currentTable.find('tbody').append(cloneTr); // 再执行laydareRender if (cloneTr.find('input[data-type=date]')) { var cloneLayDateInput = cloneTr.find('input[data-type=date]'); cloneLayDateInput.each(function () { spbld.laydateRender(this); }) } // 禁用其他行按钮 cloneTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled'); cloneTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled'); cloneTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled'); cloneTr.find('input').removeAttr('disabled'); cloneTr.find('select').removeAttr('disabled'); cloneTr.find('textarea').removeAttr('disabled'); cloneTr.find('.fb-edit-data').removeAttr('disabled'); cloneTr.find('.fb-delete-data').removeAttr('disabled'); cloneTr.find('.fb-submit-data').removeAttr('disabled'); cloneTr.find('.fb-edit-data').hide(); cloneTr.find('.fb-submit-data').show(); cloneTr.find('input[type=text]:eq(0)').focus(); } }) //编辑按钮 解除表里表单的禁用 $('.fb-edit-data').click(function (e) { //获取点击按钮的所在行 var $currentTr = $(e.target).closest('tr'); // 点击一次编辑后 隐藏 添加按钮 $(e.target).closest('table').find('.fb-add-data').attr('disabled', 'disabled'); //隐藏当前按钮 $(this).hide(); //显示提交( √ )按钮 $currentTr.find('.fb-submit-data').show().removeAttr('disabled'); //解除禁用 $currentTr.find('input').removeAttr('disabled'); $currentTr.find('select').removeAttr('disabled'); $currentTr.find('textarea').removeAttr('disabled'); $currentTr.find('input[type=text]:eq(0)').focus(); // 禁用其他行按钮 $currentTr.siblings().find('.fb-submit-data').attr('disabled', 'disabled'); $currentTr.siblings().find('.fb-delete-data').attr('disabled', 'disabled'); $currentTr.siblings().find('.fb-edit-data').attr('disabled', 'disabled'); }) }; ///给自定义表单的table赋值,AssignValueToTable ///jsonStr字符串 var spbld_userid = ""; var spbld_routeinfoid = ""; var spbld_routeid = ""; var spbld_postAccessToken = ""; spbld.fbAssignValueToTable = function (jsonStr, userid, routeinfoid, routeid, postAccessToken) { spbld_userid = userid; spbld_routeinfoid = routeinfoid; spbld_routeid = routeid; spbld_postAccessToken = postAccessToken; var res = JSON.parse(jsonStr); //console.log(jsonStr); ///1.对主表的字段进行遍历 var get_mainTableName = res.TableName; if (sp.isval(res.TableCols)) { $.each(res.TableCols, function (index, item) { var controlIndex = $("#" + get_mainTableName + "_0_0_0_" + item.CODE); ////控件id if (item.EKIND == "edit" || item.EKIND == "number" || item.EKIND == "decimal") { ///此时用的都是单行文本框 if ($("body").find(controlIndex).length > 0) { controlIndex.val(item.VALUE); } } else if (item.EKIND == "datetime") {///日期格式时,需要先为其格式化 if ($("body").find(controlIndex).length > 0) { var get_format = controlIndex.attr("data-format"); var formateDate = sp.datefmt(get_format, item.VALUE); controlIndex.val(formateDate); } } else if (item.EKIND == "text") {///多行文本时 if ($("body").find(controlIndex).length > 0) { controlIndex.val(item.VALUE); } } else if (item.EKIND == "select") {///下拉选择框 if ($("body").find(controlIndex).length > 0) { //controlIndex.val(item.VALUE); if (sp.isval(item.TCHILD_DATA)) { controlIndex.html(""); ///清空里面组件,重新赋值 var set_control = ""; $.each(item.TCHILD_DATA, function (index2, item2) { if (item2.CODE == item.VALUE) { item2.CHECKED = true; set_control += ""; } else { set_control += ""; } }); controlIndex.html(set_control); } else { ///不请空还是原来默认2项数据 return; } } } else if (item.EKIND == "radiobox") {///单选按钮 if ($("body").find(controlIndex).length > 0) { var get_radioStyle = controlIndex.attr("data-style"); if (sp.isval(item.TCHILD_DATA)) { controlIndex.html(""); ///清空里面组件,重新赋值 var set_control = ""; $.each(item.TCHILD_DATA, function (index2, item2) { if (item2.checked) { var set_label_class = ""; if (get_radioStyle == "sp-radio-default") { set_label_class = "rd-default-checked"; } else if (get_radioStyle == "sp-radio-blue") { set_label_class = "rd-blue-checked"; } else if (get_radioStyle == "sp-radio-orange") { set_label_class = "rd-orange-checked"; } else if (get_radioStyle == "sp-radio-none") { set_label_class = "rd-none-checked"; } else { return; } set_control += ""; } else { set_control += ""; } }); controlIndex.html(set_control); } else { ///不请空还是原来默认2项数据 return; } } } else if (item.EKIND == "popradiobox") { ///单向选择器 if ($("body").find(controlIndex).length > 0) { if (sp.isval(item.TCHILD_DATA)) { controlIndex.val(""); ///控件清空val值 controlIndex.attr("data-ccode", "");///控件清空ccode值 var set_control = "", set_control_val = "", set_control_ccode = ""; $.each(item.TCHILD_DATA, function (index2, item2) { if (item2.checked) { set_control += ""; set_control_val += item2.cname + ","; set_control_ccode += item2.ccode + ","; } else { set_control += ""; } }); if (sp.isval(set_control_val) && sp.isval(set_control_ccode)) { controlIndex.val(sp.cutlast(set_control_val));///控件显示val值 controlIndex.attr("data-ccode", sp.cutlast(set_control_ccode));///控件赋值ccode值 } $("#layer_popradiobox_" + item.CODE).find(".fb-radiopart").html(set_control); } else { ///不请空还是原来默认2项数据 return; } } } else if (item.EKIND == "checkbox") {///多选按钮 if ($("body").find(controlIndex).length > 0) { var get_checkboxStyle = controlIndex.attr("data-style"); if (sp.isval(item.TCHILD_DATA)) { controlIndex.html(""); ///清空里面组件,重新赋值 var set_control = ""; $.each(item.TCHILD_DATA, function (index2, item2) { if (item2.checked) { var set_label_class = ""; if (get_checkboxStyle == "sp-checkbox-gray") { set_label_class = "chb-gray-checked"; } else if (get_checkboxStyle == "sp-checkbox-blue") { set_label_class = "chb-blue-checked"; } else if (get_checkboxStyle == "sp-checkbox-orange") { set_label_class = "chb-orange-checked"; } else if (get_checkboxStyle == "sp-checkbox-none") { set_label_class = "chb-none-checked"; } else { return; } set_control += "" } else { set_control += ""; } }); controlIndex.html(set_control); } else { ///不请空还是原来默认2项数据 return; } } } else if (item.EKIND == "popcheckbox") { ///多向选择器 if ($("body").find(controlIndex).length > 0) { if (sp.isval(item.TCHILD_DATA)) { controlIndex.val(""); ///控件清空val值 controlIndex.attr("data-ccode", "");///控件清空ccode值 var set_control = "", set_control_val = "", set_control_ccode = ""; $.each(item.TCHILD_DATA, function (index2, item2) { if (item2.checked) { set_control += ""; set_control_val += item2.cname + ","; set_control_ccode += item2.ccode + ","; } else { set_control += ""; } }); if (sp.isval(set_control_val) && sp.isval(set_control_ccode)) { controlIndex.val(sp.cutlast(set_control_val));///控件显示val值 controlIndex.attr("data-ccode", sp.cutlast(set_control_ccode));///控件赋值ccode值 } $("#layer_popcheckbox_" + item.CODE).find(".fb-checkboxpart").html(set_control); } else { ///不请空还是原来默认2项数据 return; } } } else if (item.EKIND == "optionbox") { ////签写意见 if ($("body").find(controlIndex).length > 0) { spbld.getOptionboxData(controlIndex, get_mainTableName, item.CODE, userid, routeinfoid, routeid, postAccessToken); } } else if (item.EKIND == "imgupload") { ///图片上传 if ($("body").find(controlIndex).length > 0) { controlIndex.find(".sp-upload-img").attr("src", item.VALUE); } } else if (item.EKIND == "fileupload") {///附件上传 if ($("body").find(controlIndex).length > 0) { $.each(item.VALUE, function (index2, item2) { var fileSize = 0; if (item2.size > 1024 * 1024) { fileSize = (Math.round(item2.size * 100 / (1024 * 1024)) / 100).toString() + 'MB'; } else { fileSize = (Math.round(item2.size * 100 / 1024) / 100).toString() + 'KB'; } var settiplh = "
" + item2.name + "(" + fileSize + ") 删除
"; controlIndex.find(".sp-upload-tip").show().append(settiplh); }); } } else { return; } }); } ////************************************************************************************************************ ////2.对子表字段进行遍历subTable,会有多子表结构 if (sp.isval(res.subTable)) { $.each(res.subTable, function (index, item) { if ($("body").find($("#subTable_0_0_0_" + item.subTableName)).length > 0) { var cloneTr = $("#subTable_0_0_0_" + item.subTableName + " tbody>tr:first").clone(true); for (var j = 1; j < item.subTableColumns.length; j++) { cloneTr.find('td:first').attr('data-index', j + 1).html(j + 1); if (cloneTr.find('input[data-type=date]')) { var cloneLayDateInput = cloneTr.find('input[data-type=date]'); cloneLayDateInput.each(function () { var randNum = Math.floor(Math.random() * 90000) + 10000; $(this).attr('id', $(this).attr('id') + randNum); }) } $("#subTable_0_0_0_" + item.subTableName + " tbody").append(cloneTr); } for (var i = 0; i < item.subTableColumns.length; i++) { $.each(item.subTableColumns[i], function (index2, item2) { var tbodyTRindex = $("#subTable_0_0_0_" + item.subTableName + " tbody tr:eq(" + i + ")"); ///第几行 if (item2.showcode == "ID") { tbodyTRindex.find('td:first').attr("data-index", item2.showvalue); } if (item2.showtype == "edit" || item2.showtype == "number" || item2.showtype == "decimal") { //console.log($("#subTable_0_0_0_" + item.subTableName + " tbody tr:eq(" + i + ")").length); ///判断子表中,每行中是否存在与json字段对应的input,如果存在给其赋值 if (tbodyTRindex.find("input[data-code='" + item2.showcode + "']").length > 0) { tbodyTRindex.find("input[data-code='" + item2.showcode + "']").val(item2.showvalue); }; } else if (item2.showtype == "datetime") {///日期格式时,需要先为其格式化 if (tbodyTRindex.find("input[data-code='" + item2.showcode + "']").length > 0) { var get_format = tbodyTRindex.find("input[data-code='" + item2.showcode + "']").attr("data-format"); var formateDate = sp.datefmt(get_format, item2.showvalue); tbodyTRindex.find("input[data-code='" + item2.showcode + "']").val(formateDate); }; } else if (item2.showtype == "text") { if (tbodyTRindex.find("textarea[data-code='" + item2.showcode + "']").length > 0) { tbodyTRindex.find("textarea[data-code='" + item2.showcode + "']").val(item2.showvalue); }; } else if (item2.showtype == "select") { if (tbodyTRindex.find("select[data-code='" + item2.showcode + "']").length > 0) { tbodyTRindex.find("select[data-code='" + item2.showcode + "']").val(item2.showvalue); }; } else if (item2.showtype == "radio") { //console.log($("div[data-code='sex']").length) if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) { var get_radioStyle = tbodyTRindex.find("div[data-code='" + item2.showcode + "']").attr("data-style"); tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find("input[type='radio']").each(function () { if ($(this).val() == item2.showvalue) { ///此处radio选中,其他的radio去掉选中 $(this).attr("checked", "checked"); $(this).parent("label").siblings().children("input[type='radio']").removeAttr("checked"); ///此处radio的label加上选中样式,其他的label去掉选中样式 if (get_radioStyle == "sp-radio-default") { $(this).parent("label").addClass("rd-default-checked"); $(this).parent("label").siblings().removeClass("rd-default-checked"); } else if (get_radioStyle == "sp-radio-blue") { $(this).parent("label").addClass("rd-blue-checked"); $(this).parent("label").siblings().removeClass("rd-blue-checked"); } else if (get_radioStyle == "sp-radio-orange") { $(this).parent("label").addClass("rd-orange-checked"); $(this).parent("label").siblings().removeClass("rd-orange-checked"); } else if (get_radioStyle == "sp-radio-none") { $(this).parent("label").addClass("rd-none-checked"); $(this).parent("label").siblings().removeClass("rd-none-checked"); } else { return; } } }); }; } else if (item2.showtype == "checkbox") { if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) { var get_checkboxStyle = tbodyTRindex.find("div[data-code='" + item2.showcode + "']").attr("data-style"); var get_checkboxvalue = item2.showvalue.split(","); for (var kk = 0; kk < get_checkboxvalue.length; kk++) { tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find("input[type='checkbox']").each(function () { if ($(this).val() == get_checkboxvalue[kk]) { ///此处checkbox选中 $(this).attr("checked", "checked"); ///此处checkbox的label加上选中样式 if (get_checkboxStyle == "sp-checkbox-gray") { $(this).parent("label").addClass("chb-gray-checked"); } else if (get_checkboxStyle == "sp-checkbox-blue") { $(this).parent("label").addClass("chb-blue-checked"); } else if (get_checkboxStyle == "sp-checkbox-orange") { $(this).parent("label").addClass("chb-orange-checked"); } else if (get_checkboxStyle == "sp-checkbox-none") { $(this).parent("label").addClass("chb-none-checked"); } else { return; } } }); }; }; } else if (item2.showtype == "img") { if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) { tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find(".sp-upload-img").attr("src", item2.showvalue); }; } else if (item2.showtype == "file") { if (tbodyTRindex.find("div[data-code='" + item2.showcode + "']").length > 0) { $.each(item2.showvalue, function (index3, item3) { var fileSize = 0; if (item3.size > 1024 * 1024) { fileSize = (Math.round(item3.size * 100 / (1024 * 1024)) / 100).toString() + 'MB'; } else { fileSize = (Math.round(item3.size * 100 / 1024) / 100).toString() + 'KB'; } var settiplh = "
" + item3.name + "(" + fileSize + ") 删除
"; tbodyTRindex.find("div[data-code='" + item2.showcode + "']").find(".sp-upload-tip").show().append(settiplh); }); }; } else { return; } }); }; }; }); } }; ///格式化自定义表单的table组成json字符串, ///partID是指定的表单table外层div的id spbld.fbFrtTableJson = function (partID, TableName) { var mainTableColumns = [];///声明主表列的数组 var fb_json_str = ""; ///遍历主表中的控件组成json if ($(partID).children(".sp-fb-grid").length > 0) { if ($(partID + " .sp-fb-grid>tbody>tr>td>input[type='text']").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>input[type='text']").each(function () { //console.log($(this).attr("data-code")); if ($(this).attr("data-type") == "text") { var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ","; fb_json_str += set_str; } else if ($(this).attr("data-type") == "date") { var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ","; fb_json_str += set_str; } else { return; } }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>input[type='number']").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>input[type='number']").each(function () { var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ","; fb_json_str += set_str; }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>textarea").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>textarea").each(function () { var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ","; fb_json_str += set_str; }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>select").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>select").each(function () { var set_str = "\"" + $(this).attr("data-code") + "\":\"" + $(this).val() + "\"" + ","; fb_json_str += set_str; }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>.fb-radiopart").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>.fb-radiopart").each(function () { var getchecked = $(this).find("input[type='radio']:checked").val(); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"radio\", \"showvalue\":\"" + getchecked + "\"}"; mainTableColumns.push(JSON.parse(setjson)); }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>.fb-checkboxpart").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>.fb-checkboxpart").each(function () { var getchecked = ""; $(this).find("input[type='checkbox']").each(function () { if ($(this).is(":checked")) { getchecked += $(this).val() + ","; } }); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"checkbox\", \"showvalue\":\"" + sp.cutlast(getchecked) + "\"}"; mainTableColumns.push(JSON.parse(setjson)); }); } if ($(partID + " .sp-fb-grid>tbody>tr>td>.sp-upload").length > 0) { $(partID + " .sp-fb-grid>tbody>tr>td>.sp-upload").each(function () { var get_showtype = ""; var get_showvalue = ""; if ($(this).children(".sp-upload-img").length > 0) { get_showtype = "img"; get_showvalue = $(".sp-upload-img", this).attr("src"); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":\"" + get_showvalue + "\"}"; mainTableColumns.push(JSON.parse(setjson)); } else if ($(this).children(".sp-upload-file-single").length > 0) { get_showtype = "file"; $(".sp-upload-tip-lh", this).each(function () { get_showvalue += "{\"name\":\"" + $(this).attr("data-name") + "\", \"url\":\"" + $(this).attr("data-url") + "\", \"size\":" + $(this).attr("data-size") + "},"; }); //console.log(sp.cutlast(get_showvalue)); var loc = "[" + sp.cutlast(get_showvalue) + "]"; var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":" + loc + "}"; mainTableColumns.push(JSON.parse(setjson)); } }); } //console.log(JSON.stringify(mainTableColumns)); }; ////*********************************** ///遍历子表 var subTableAllArray = [];///声明子表数组集合变量 if ($(partID).find(".sp-subgrid-job").length > 0) { $(partID + " .sp-subgrid-job").each(function (index, item) { var subTableColumnsArray = []; $("tbody tr", this).each(function (index2, item2) { ////加上判断该行是不是都为空 var hasval = 0;///声明行中控件都为空的标志hasval =0 if ($(this).find("input[type='text']").length > 0) { $(this).find("input[type='text']").each(function () { if ($(this).val() != "" && $(this).val() != null) { hasval = 1; } }); } if ($(this).find("input[type='number']").length > 0) { $(this).find("input[type='number']").each(function () { if ($(this).val() != "" && $(this).val() != null) { hasval = 1; } }); } if ($(this).find("textarea").length > 0) { $(this).find("textarea").each(function () { if ($(this).val() != "" && $(this).val() != null) { hasval = 1; } }); } if ($(this).find(".fb-checkboxpart").length > 0) { $(this).find(".fb-checkboxpart").each(function () { $(this).find("input[type='checkbox']").each(function () { if ($(this).is(":checked")) { hasval = 1; } }); }); } if ($(this).find(".sp-upload").length > 0) { $(this).find(".sp-upload").each(function () { if ($(this).children(".sp-upload-img").length > 0) { var get_showvalue = $(".sp-upload-img", this).attr("src"); if (get_showvalue != "" && get_showvalue != null) { hasval = 1; } } else if ($(this).children(".sp-upload-file-single").length > 0) { if ($(this).find(".sp-upload-tip-lh").length > 0) { hasval = 1; } } }); } ///************************************************************************************* ///此处是得到该行控件不都为空,则将其遍历组成json if (hasval == 1) { var subTableColumnsSub = []; var getID = $(this).find('td:first').attr("data-index"); var setjsonID = "{\"showcode\":\"ID\", \"showtype\":\"number\", \"showvalue\":\"" + getID + "\"}"; subTableColumnsSub.push(JSON.parse(setjsonID)); if ($(this).find("input[type='text']").length > 0) { $(this).find("input[type='text']").each(function () { if ($(this).attr("data-type") == "text") { var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"edit\", \"showvalue\":\"" + $(this).val() + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); } else if ($(this).attr("data-type") == "date") { var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"datetime\", \"showvalue\":\"" + $(this).val() + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); } else { return; } }); } if ($(this).find("input[type='number']").length > 0) { $(this).find("input[type='number']").each(function () { var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"number\", \"showvalue\":\"" + $(this).val() + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); }); } if ($(this).find("textarea").length > 0) { $(this).find("textarea").each(function () { var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"text\", \"showvalue\":\"" + $(this).val() + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); }); } if ($(this).find("select").length > 0) { $(this).find("select").each(function () { var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"select\", \"showvalue\":\"" + $(this).val() + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); }); } if ($(this).find(".fb-radiopart").length > 0) { $(this).find(".fb-radiopart").each(function () { var getchecked = $(this).find("input[type='radio']:checked").val(); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"radio\", \"showvalue\":\"" + getchecked + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); }); } if ($(this).find(".fb-checkboxpart").length > 0) { $(this).find(".fb-checkboxpart").each(function () { var getchecked = ""; $(this).find("input[type='checkbox']").each(function () { if ($(this).is(":checked")) { getchecked += $(this).val() + ","; } }); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"checkbox\", \"showvalue\":\"" + sp.cutlast(getchecked) + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); }); } if ($(this).find(".sp-upload").length > 0) { $(this).find(".sp-upload").each(function () { var get_showtype = ""; var get_showvalue = ""; if ($(this).children(".sp-upload-img").length > 0) { get_showtype = "img"; get_showvalue = $(".sp-upload-img", this).attr("src"); var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":\"" + get_showvalue + "\"}"; subTableColumnsSub.push(JSON.parse(setjson)); } else if ($(this).children(".sp-upload-file-single").length > 0) { get_showtype = "file"; $(".sp-upload-tip-lh", this).each(function () { get_showvalue += "{\"name\":\"" + $(this).attr("data-name") + "\", \"url\":\"" + $(this).attr("data-url") + "\", \"size\":" + $(this).attr("data-size") + "},"; }); //console.log(sp.cutlast(get_showvalue)); var loc = "[" + sp.cutlast(get_showvalue) + "]"; var setjson = "{\"showcode\":\"" + $(this).attr("data-code") + "\", \"showtype\":\"" + get_showtype + "\", \"showvalue\":" + loc + "}"; subTableColumnsSub.push(JSON.parse(setjson)); } }); } subTableColumnsArray.push(subTableColumnsSub); } }); //console.log(JSON.stringify(subTableColumnsArray)); var subTableArray = "{\"subTableName\":\"" + $(this).attr("data-subtablename") + "\", \"subTableColumns\":" + JSON.stringify(subTableColumnsArray) + "}"; //console.log(subTableArray); subTableAllArray.push(JSON.parse(subTableArray)); }); }; //console.log(JSON.stringify(subTableAllArray)); //var frtJson = "";///整体json串 //if ($(partID).children(".sp-fb-grid").length > 0 && $(partID).find(".sp-subgrid-job").length > 0) { // //主表和子表都有 // frtJson = "{\"TableName\":\"" + TableName + "\", \"mainTableColumns\":" + JSON.stringify(mainTableColumns) + ", \"subTable\":" + JSON.stringify(subTableAllArray) + "}"; //} else if ($(partID).children(".sp-fb-grid").length > 0 && $(partID).find(".sp-subgrid-job").length == 0) { // //只有主表没有子表 // frtJson = "{\"TableName\":\"" + TableName + "\", \"mainTableColumns\":" + JSON.stringify(mainTableColumns) + "}"; //} else { return; } ////console.log(frtJson); //return frtJson; if (sp.isval(fb_json_str)) { var set_json = "{" + sp.cutlast(fb_json_str) + "}"; //console.log(set_json); return set_json; } else { return fb_json_str; } }; ////单选选择器--打开事件 spbld.layer_popradiobox_open = function (layerid) { sp.layer("#" + layerid); } ////单选选择器---确定事件 spbld.layer_popradiobox_true = function (layerid,controlid,showcode) { var get_inputRadioChecked=$("#" + layerid).find(".fb-radiopart").find("input[type='radio']:checked"); $("#" + controlid).val(get_inputRadioChecked.parent().text()); $("#" + controlid).attr("data-ccode", get_inputRadioChecked.val()); sp.layerhide(); } ///多项选择器 spbld.layer_popcheckbox_open = function (layerid) { sp.layer("#" + layerid); } ////多项选择器---确定事件 spbld.layer_popcheckbox_true = function (layerid, controlid, showcode) { var get_inputChecboxChecked = $("#" + layerid).find(".fb-checkboxpart").find("input[type='checkbox']:checked"); var set_control_val = "", set_control_ccode = ""; get_inputChecboxChecked.each(function (item2,index2) { set_control_val += $(this).parent().text()+ ","; set_control_ccode += $(this).val() + ","; }) $("#" + controlid).val(sp.cutlast(set_control_val)); $("#" + controlid).attr("data-ccode", sp.cutlast(set_control_ccode)); sp.layerhide(); } ////**签写意见业务操作--start******************************************************************************** spbld.getOptionboxData = function (controlIndex, get_mainTableName, colname, userid, routeinfoid, routeid, postAccessToken) { ////加载数据 var postData = { "cmanid": userid,///签字人ID "routeinfoid": routeinfoid,///流程实例ID "routeid": routeid,//流程流转ID "tableid": get_mainTableName,//表单名称 "colid": colname//列名称 } var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } //var yijianJson = ""; //if (colname == "yijiancontrol") { // yijianJson = 'json.page/optionbox/optionbox_1.txt?v=' + new Date(); //} else { // yijianJson = 'json.page/optionbox/optionbox_2.txt?v=' + new Date(); //} $.ajax({ //////g2app/abase/queryDataOpinion //url: yijianJson, //type:'get', url: apiurljs.login + "g2app/abase/queryDataOpinion", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //console.log(JSON.stringify(res)); controlIndex.html(""); if (sp.isval(res.data)) { $.each(res.data, function (index2, item2) { var set_text_or_img = ""; if (sp.isval(item2.OPINION)) { set_text_or_img = "
" + item2.OPINION + "
"; } else if (sp.isval(item2.OPINIONIMAGE)) { set_text_or_img = "" } else { set_text_or_img = ""; } var set_btn_html = ""; if (routeid == item2.ROUTEID) { set_btn_html = "
删除
" + "
修改
" } var setHtml = "
" + "
" + set_text_or_img + "
" + "
" + "
" + item2.CMANNAME + "
" + "
" + sp.format(item2.CDATE) + "
" + "
" + "
" + set_btn_html + "
" + "
"; controlIndex.append(setHtml); //console.log(controlIndex.next()); //console.log(routeid + "、" + item2.ROUTEID); if (routeid == item2.ROUTEID) { ///已有数据且流程流转ID相同时,签写意见按钮隐藏; controlIndex.next().hide(); } else { controlIndex.next().show(); } }); controlIndex.children(".sp-page-mgn:last-child").removeClass("sp-border-bottom").removeClass("sp-pb-20"); } else { controlIndex.next().show(); } }, error: function (returndata) { console.log(JSON.stringify(returndata)); } }); } ///打开签写意见弹出层 spbld.layer_optionbox_open = function (idstr, mainTableName, showcode) { ////为tabs选项框赋值点击切换事件 sp.layer("#layer_optionbox"); $("#layer_optionbox_textarea").val(""); $("#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);///往确定按钮中赋值属性 spbld.layer_optionbox_tabs(0);///传0默认打开第一层 ///常用语检索数据--2023-zyg spbld.layer_optionbox_queryDataPatterns(mainTableName, showcode, spbld_userid); } ///签写意见--tabs切换 spbld.layer_optionbox_tabs = function (indexSet) { indexSet = indexSet || 0; ///初始设置 $("#layer_optionbox_tabs .sp-tab-menu li").removeClass("sp-tab-current"); $("#layer_optionbox_tabs .sp-tab-menu li:eq(" + indexSet + ")").addClass("sp-tab-current"); $("#layer_optionbox_tabs .sp-tab-box").children('div').addClass("sp-tab-hide"); $("#layer_optionbox_tabs .sp-tab-box").children('div:eq(' + indexSet + ')').removeClass("sp-tab-hide"); if (indexSet == 1) { setTimeout(function () { ///延时1秒加载canvas划线,js否则得不到canvas外层的宽度高度 spbld.lineCanvas(); }, 10) } ////点击事件设置 $("#layer_optionbox_tabs .sp-tab-menu li").click(function () { $(this).addClass("sp-tab-current").siblings().removeClass("sp-tab-current"); var get_index = $(this).attr("data-index"); $("#layer_optionbox_tabs .sp-tab-box").children('div').addClass("sp-tab-hide"); $("#layer_optionbox_tabs .sp-tab-box").children('div:eq(' + get_index + ')').removeClass("sp-tab-hide"); if (get_index == 1) { setTimeout(function () { ///延时1秒加载canvas划线,js否则得不到canvas外层的宽度高度 spbld.lineCanvas(); }, 10) } }) }; ///清空canvas spbld.layer_optionbox_cnavas_clear = function () { let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域 var cxt = canvas.getContext("2d"); cxt.clearRect(0, 0, canvas.width, canvas.height); }; //canvas画布签字 spbld.lineCanvas = function () { let canvasBody = document.getElementById('layer_optionbox_canvas_outpart');///canvas的外层区域 //console.log(canvasBody); //console.log("clientWidth:"+canvasBody.clientWidth); //console.log("clientHeight:" + canvasBody.clientHeight); let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域 canvas.width = canvasBody.clientWidth; canvas.height = canvasBody.clientHeight; let ctx = canvas.getContext('2d'); ctx.lineWidth = 4; ctx.strokeStyle = '#333'; ctx.lineCap = 'round'; ctx.lineJoin = 'round'; let isDrawing = false; let dataURL = ''; let initX; let initY; // 事件监听--开始绘制 canvas.addEventListener("mousedown", function (e) { isDrawing = true; initX = e.offsetX; initY = e.offsetY }); canvas.addEventListener('mousemove', draw); canvas.addEventListener("mouseup", function () { isDrawing = false }); canvas.addEventListener("mouseout", function () { isDrawing = false }); // 绘制中... function draw(e) { if (!isDrawing) return ctx.beginPath(); // 起点 ctx.moveTo(initX, initY); // 终点 ctx.lineTo(e.offsetX, e.offsetY); ctx.stroke(); initX = e.offsetX; initY = e.offsetY; } }; ///删除意见 spbld.layer_optionbox_delete = function (obj, controlIndex, maintable, colname, userid, routeinfoid, routeid) { if (confirm("您确定要删除吗?")) { var postData = { cmanid: userid, routeid: routeid, tableid: maintable, colid: colname } var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } /////g2app/abase/deleteDataOpinion $.ajax({ //url: 'json.page/optionbox/optionbox_delete.txt?v='+ new Date(), //type: 'get', url: apiurljs.login + "g2app/abase/deleteDataOpinion", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { //alert(obj); spbld.getOptionboxData($("#" + controlIndex), maintable, colname, userid, routeinfoid, routeid, spbld_postAccessToken); } }, error: function (returndata) { sp.dialog("意见删除失败!") } }); } } ////修改意见 spbld.layer_optionbox_edit = function (idstr, maintable, colname, OPINION, OPINIONIMAGE, userid, routeinfoid, routeid) { $("#layer_optionbox_true_btn").attr("data-mainTableName", maintable).attr("data-colname", colname).attr("data-userid", userid).attr("data-routeinfoid", routeinfoid).attr("data-routeid", routeid);///往确定按钮中赋值属性 if (sp.isval(OPINION)) { sp.layer("#layer_optionbox"); spbld.layer_optionbox_tabs(0); ///常用语检索数据--2023-zyg spbld.layer_optionbox_queryDataPatterns(maintable, colname, userid); setTimeout(function () { $("#layer_optionbox_textarea").val(OPINION); }, 10); } else { sp.layer("#layer_optionbox"); spbld.layer_optionbox_tabs(1); setTimeout(function () { ///把base64格式图片画到canvas画布上 let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域 var cxt = canvas.getContext("2d"); let img = new Image(); img.src = OPINIONIMAGE; img.onload = function () { cxt.drawImage(this, 0, 0, canvas.width, canvas.height); } }, 20); } } ///签写意见------确认按钮保存事件 spbld.layer_optionbox_true = function () { var get_tabsIndex = $("#layer_optionbox_tabs").find(".sp-tab-current").attr("data-index"); if (get_tabsIndex == 0) { ///为文字 var get_txtval = $("#layer_optionbox_textarea").val(); if (sp.isval(get_txtval)) { spbld.layer_optionbox_true_submitData(get_tabsIndex, get_txtval); } else { alert("文字内容不能为空"); } } else { ///1时为手签 //PNG 算法,判断canvas内容是否为空 let canvas = document.getElementById('layer_optionbox_canvas');///canvas签字区域 var blank = document.createElement('canvas'); blank.width = canvas.width; blank.height = canvas.height; if (canvas.toDataURL() == blank.toDataURL()) { alert("手签内容不能为空"); } else { //console.log(canvas.toDataURL()); spbld.layer_optionbox_true_submitData(get_tabsIndex, canvas.toDataURL()); } } }; spbld.layer_optionbox_true_submitData = function (get_tabsIndex,cval) { var get_mainTabmeName = $("#layer_optionbox_true_btn").attr("data-maintablename"); var get_colName = $("#layer_optionbox_true_btn").attr("data-colname"); var get_userid = $("#layer_optionbox_true_btn").attr("data-userid"); var get_routeinfoid = $("#layer_optionbox_true_btn").attr("data-routeinfoid"); var get_routeid = $("#layer_optionbox_true_btn").attr("data-routeid"); var set_opinion = ""; var set_opinionimage = ""; if (get_tabsIndex == 0) { set_opinion = cval; set_opinionimage = ""; } else { set_opinion = ""; set_opinionimage = cval; } var postData = { "cmanid": get_userid,//签字人ID "routeinfoid": get_routeinfoid,//流程实例ID "routeid": get_routeid,//流程流转ID "tableid": get_mainTabmeName,//表单名称 "colid": get_colName,//列名称 "opiniontype": get_tabsIndex,//签字类别 0-正常文字 1-语音转文字(配话筒) 2-手写签字(配手写板) "cresult": "",//意见判定 可以为空,也可以设为同意、不同意、通过、不通过等 "opinion": set_opinion,//签字意见 "opinionimage": set_opinionimage//签字图片 存图片的BASE64字符串 } //console.log(postData); var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } /////g2app/abase/saveDataOpinion $.ajax({ //url: 'json.page/optionbox/optionbox_save.txt?v=' + new Date(), //type: 'get', url: apiurljs.login + "g2app/abase/saveDataOpinion", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); if (res.success) { sp.layerhide(); setTimeout(function () { spbld.getOptionboxData($("#" + get_mainTabmeName + "_0_0_0_" + get_colName), get_mainTabmeName, get_colName, get_userid, get_routeinfoid, get_routeid, spbld_postAccessToken); }, 200); } }, error: function (returndata) { } }); }; ///常用语操作---检索数据--2023-zyg spbld.layer_optionbox_queryDataPatterns = function (get_mainTabmeName, get_colName, userid) { var postData = { "cmanid": userid,//签字人ID "tableid": get_mainTabmeName,//表单名称 "colid": get_colName//列名称 } var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } //////g2app/abase/queryDataPatterns 检索指定列的意见列表 $.ajax({ //url: 'json.page/optionbox/queryDataPatterns.txt?v=' + new Date(), //type: 'get', url: apiurljs.login + "g2app/abase/queryDataPatterns", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); console.log(JSON.stringify(res)); ////{"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} if (sp.isval(res.data)) { $("#layer_optionbox_patterns").html(""); $.each(res.data, function (index2, item2) { var setHtml = "" + item2.CONTENTS + ""; $("#layer_optionbox_patterns").append(setHtml); }); } }, error: function (returndata) { } }); }; spbld.layer_optionbox_queryDataPatterns_add = function (cval) { //常用语操作---添加到左侧意见textarea中 $("#layer_optionbox_textarea").val(cval); }; spbld.layer_optionbox_queryDataPatterns_delete = function (get_mainTabmeName, get_colName, idnum) { if (confirm("您确定要删除吗?")) { //常用语操作---删除 var postData = { "id": idnum//常用语id } var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } //////g2app/abase/deleteDataOpinion 删除指定列的意见 $.ajax({ //url: 'json.page/optionbox/deleteDataOpinion.txt?v=' + new Date(), //type: 'get', url: apiurljs.login + "g2app/abase/deleteDataPatterns", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //console.log(JSON.stringify(res)); if (res.success) { //console.log(spbld_userid) spbld.layer_optionbox_queryDataPatterns(get_mainTabmeName, get_colName, spbld_userid);///重新检索常用语 } }, error: function (returndata) { } }); } }; spbld.layer_optionbox_patterns_add = function () { /////常用语操作---新增 var get_phraseText = $("#layer_optionbox_patterns_input").val(); if (sp.isval(get_phraseText)) { var get_mainTabmeName = $("#layer_optionbox_true_btn").attr("data-maintablename"); var get_colName = $("#layer_optionbox_true_btn").attr("data-colname"); var postData = { cmanid: spbld_userid, tableid: get_mainTabmeName, colid: get_colName, contents: get_phraseText } //console.log(postData); var postData_2 = { data: s4.encryptData_CBC(JSON.stringify(postData)) } //////g2app/abase/insertDataPatterns 添加常用语到常用语库 $.ajax({ url: apiurljs.login + "g2app/abase/insertDataPatterns", type: 'post', data: JSON.stringify(postData_2), dataType: "json", contentType: "application/json", headers: { Authorization: "Bearer " + spbld_postAccessToken }, ////请求头headers success: function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); //console.log(JSON.stringify(res)); if (res.success) { //console.log(spbld_userid) spbld.layer_optionbox_queryDataPatterns(get_mainTabmeName, get_colName, spbld_userid);///重新检索常用语 } }, error: function (returndata) { } }); } else { alert("常用语不能为空!"); } }; ////**签写意见业务操作--end********************************************************************************