12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550 |
- //表单设计
- $.fn.frmDesign = function (options) {
- var $frmdesigh = $(this);
- if (!$frmdesigh.attr('id')) {
- return false;
- }
- var defaults = {
- controlDataJson: [],
- tablefiledJsonData: "",
- frmContent: "",
- Height: 572,
- url: "",
- param: "",
- isSystemTable: 0,//默认是不绑定数据表的
- getData: function (isTest) {
- var postData = [];
- var j = 0;
- var _controlfieldHistory = {};
- for (var i in options.controlDataJson) {
- var rowJson = options.controlDataJson[i];
- if (rowJson.control_field == "" && isTest != true) {
- dialogTop("请输入字段Id", "error");
- $("#app_layout_list").find('[data-value=' + i + ']').addClass('activeerror');
- return false;
- }
- if (rowJson.control_label == "" && isTest != true) {
- dialogTop("请输入字段名称", "error");
- $("#app_layout_list").find('[data-value=' + i + ']').addClass('activeerror');
- return false;
- }
- if (isTest != true)
- {
- if (_controlfieldHistory[rowJson.control_field] != undefined)
- {
- dialogTop("字段Id有重复", "error");
- return false;
- }
- _controlfieldHistory[rowJson.control_field] = "1";
- }
- if (rowJson.control_item != undefined) {
- var controlitem = [];
- for (var j in rowJson.control_item) {
- controlitem.push(rowJson.control_item[j]);
- }
- rowJson.control_item = controlitem;
- }
- j++;
- postData.push(rowJson);
- }
- if (j == 0 && isTest != true)
- {
- dialogTop("不能是空表单", "error");
- return false;
- }
- return postData;
- }
- };
- var options = $.extend(defaults, options);
- var divhtml = '<div class="app_body"><div id="move_item_list" class="app_field">';
- divhtml += '<div class="item_row"><i id="text" class="fa fa-italic"></i>文本框</div>';
- divhtml += '<div class="item_row"><i id="textarea" class="fa fa-align-justify"></i>文本区</div>';
- divhtml += '<div class="item_row"><i id="texteditor" class="fa fa-edit"></i>编辑器</div>';
- divhtml += '<div class="item_row"><i id="radio" class="fa fa-circle-thin"></i>单选框</div>';
- divhtml += '<div class="item_row"><i id="checkbox" class="fa fa-square-o"></i>多选框</div>';
- divhtml += '<div class="item_row"><i id="select" class="fa fa-caret-square-o-right"></i>下拉框</div>';
- divhtml += '<div class="item_row"><i id="datetime" class="fa fa-calendar"></i>日期框</div>';
- divhtml += '<div class="item_row"><i id="image" class="fa fa-photo"></i>图片</div>';
- divhtml += '<div class="item_row"><i id="upload" class="fa fa-paperclip"></i>附件</div>';
- // divhtml += '<div class="item_row"><i id="departmentlist" class="fa fa-sitemap"></i>单位组织</div>';
- // divhtml += '<div class="item_row"><i id="dataitemlist" class="fa fa-book"></i>数据字典</div>';
- divhtml += '</div>';
- divhtml += '<div class="app_layout">';
- divhtml += ' <div id="app_layout_list" class="item_table notclose connectedSortable">';
- divhtml += ' <div class="guideareas"></div>';
- divhtml += ' </div>';
- divhtml += '</div>';
- divhtml += ' <div id="app_layout_option" class="field_option notclose">';
- divhtml += ' </div>';
- divhtml += '</div>';
- $frmdesigh.html(divhtml);
-
-
- $frmdesigh.find(".app_body").height(options.Height);
- $frmdesigh.find(".field_option").height(options.Height - 14).css("right", -240);
- $frmdesigh.find(".guideareas").height(options.Height - 33);
- var item_field_value_width = $(window).width() - 558;
- //表单控件拖动
- function formdesigner_move() {
- $("#move_item_list .item_row").draggable({
- connectToSortable: "#app_layout_list",
- helper: "clone",
- revert: "invalid"
- });
- $("#app_layout_list").sortable({
- opacity: 0.4,
- delay: 300,
- cursor: 'move',
- placeholder: "ui-state-highlight",
- stop: function (event, ui) {
- var random_id = String(Math.random()).substr(2);
- var $item_control = null;
- var $this_place = $(ui.item[0]);
- var controltype = $this_place.find('i').attr('id');
- var controlrowJson = {};
- controlrowJson["control_type"] = controltype;
- if (!!controltype) {
- switch (controltype) {
- case "text":
- $item_control = $('<div class="item_field_label"><span>文本框</span></div><div class="item_field_value">文本框</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "文本框";
- controlrowJson["control_field"] = "";
- controlrowJson["control_verify"] = "";
- controlrowJson["control_default"] = "";
- controlrowJson["control_required"] = "0";
- //controlrowJson["control_only"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "textarea":
- $item_control = $('<div class="item_field_label"><span>文本区</span></div><div class="item_field_value">文本区</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "文本区";
- controlrowJson["control_field"] = "";
- controlrowJson["control_verify"] = "";
- controlrowJson["control_height"] = "100px";
- controlrowJson["control_default"] = "";
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "texteditor":
- $item_control = $('<div class="item_field_label"><span>编辑器</span></div><div class="item_field_value">编辑器</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "编辑器";
- controlrowJson["control_field"] = "";
- controlrowJson["control_verify"] = "";
- controlrowJson["control_height"] = "200px";
- controlrowJson["control_default"] = "";
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "radio":
- $item_control = $('<div class="item_field_label"><span>单选项</span></div><div class="item_field_value">单选项/未添加选项</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "单选项";
- controlrowJson["control_field"] = "";
- controlrowJson["control_item"] = [];
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "checkbox":
- $item_control = $('<div class="item_field_label"><span>多选项</span></div><div class="item_field_value">多选项/未添加选项</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "多选项";
- controlrowJson["control_field"] = "";
- controlrowJson["control_item"] = [];
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "select":
- $item_control = $('<div class="item_field_label"><span>下拉框</span></div><div class="item_field_value">下拉框/未添加选项</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "下拉框";
- controlrowJson["control_field"] = "";
- controlrowJson["control_item"] = [];
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "datetime":
- $item_control = $('<div class="item_field_label"><span>日期框</span></div><div class="item_field_value">年-月-日</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "日期框";
- controlrowJson["control_field"] = "";
- controlrowJson["control_dateformat"] = "date";
- controlrowJson["control_default"] = "";
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "image":
- $item_control = $('<div class="item_field_label"><span>上传图片</span></div><div class="item_field_value">上传图片/jpg,gif,png,bmp</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "上传图片";
- controlrowJson["control_field"] = "";
- controlrowJson["control_fileformat"] = "jpg,gif,png,bmp";
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "upload":
- $item_control = $('<div class="item_field_label"><span>上传文件</span></div><div class="item_field_value">上传文件/doc,xls,ppt,pdf</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div>');
- controlrowJson["control_label"] = "上传文件";
- controlrowJson["control_field"] = "";
- controlrowJson["control_fileformat"] = "doc,xls,ppt,pdf";
- controlrowJson["control_required"] = "0";
- options.controlDataJson[random_id] = controlrowJson;
- break;
- case "departmentlist":
- break;
- case "dataitemlist":
- break;
- default:
- break;
- }
- if ($item_control) {
- $this_place.html($item_control);
- $this_place.find('.item_field_value').width(item_field_value_width);
- $this_place.attr('data-value', random_id)
- item_rowclick();
- $this_place.trigger("click");
- }
- } else {
- $this_place.trigger("click");
- }
- },
- start: function (event, ui) {
- $(".guideareas").hide()
- $(".ui-state-highlight").html('拖放控件到这里');
- $(".field_option").hide();
- $("#app_layout_list .item_row").removeClass('active')
- },
- out: function (event, ui) {
- if (ui.helper != null) {
- var falg = true;
- for (item in options.controlDataJson) {
- falg = false;
- break;
- }
- if (falg) {
- $(".guideareas").show();
- }
- }
- }
- });
- item_rowclick();
- function item_rowclick() {
- $("#app_layout_list .item_row").find('.item_field_remove i').click(function () {
- var $item_row = $(this).parents('.item_row');
- delete options.controlDataJson[$item_row.attr('data-value')];
- $item_row.remove();
- $(".field_option").animate({ right: -240, speed: 2000 });
- var falg = true;
- for (item in options.controlDataJson) {
- falg = false;
- break;
- }
- if (falg) {
- $(".guideareas").show();
- }
- });//移除空件
- $("#app_layout_list .item_row").unbind('click');
- $("#app_layout_list .item_row").click(function () {
- var $this = $(this);
- var $field_option = $(".field_option");
- $("#app_layout_list .item_row").removeClass('active').removeClass('activeerror');
- $this.addClass('active');
- $('.field_option').animate({ right: 0, speed: 2000 }).show();
- initControlProperty($this);
- });
- document.onclick = function (event) {
- try
- {
- var _event = event ? event : window.event;
- var _target = _event.target ? _event.target : _event.srcElement;
- var className = "";
- while (className != "app_body") {
- className = _target.className;
- if (className == undefined || className.indexOf("notclose") > 0) {
- break;
- }
- _target = _target.parentNode;
- if (_target == null) {
- break;
- }
- }
- if (className != undefined && className.indexOf("notclose") < 0 && _target != null) {
- $(".field_option").animate({ right: -240, speed: 2000 });
- $("#app_layout_list .item_row").removeClass('active').removeClass('activeerror');
- }
- }
- catch(e)
- {
-
- }
- };
- }
- //初始化控件属性
- function initControlProperty(e) {
- var rowJson = options.controlDataJson[e.attr('data-value')];
- if (rowJson) {
- switch (rowJson.control_type) {
- case "text":
- textProperty(e);
- break;
- case "textarea":
- textareaProperty(e);
- break;
- case "texteditor":
- texteditorProperty(e);
- break;
- break;
- case "radio":
- radioProperty(e);
- break;
- case "checkbox":
- checkboxProperty(e);
- break;
- case "select":
- selectProperty(e);
- break;
- case "datetime":
- datetimeProperty(e);
- break;
- case "image":
- imageProperty(e);
- break;
- case "upload":
- uploadProperty(e);
- break;
- case "departmentlist":
- break;
- case "dataitemlist":
- break;
- default:
- break;
- }
- } else {
- //$(".field_option").html("");
- }
- }
- //获取表单
- if (options.frmContent != "" && options.frmContent != null)
- {
- frmToHtml(options.frmContent);
- }
- else if (options.url != "") {
- $.ajax({
- url: options.url,
- data: options.param,
- type: "GET",
- dataType: "json",
- async: false,
- success: function (data) {
- if (data.FrmContent != null)
- {
- frmToHtml(data.FrmContent);
- }
- },
- error: function (XMLHttpRequest, textStatus, errorThrown) {
- dialogMsg(errorThrown, -1);
- }
- });
- }
- //json=>html
- function frmToHtml(frmContent) {
- var frmContentJson = eval('(' + frmContent + ')');
- var num = 0;
- $app_layout_list = $('#app_layout_list');
- $.each(frmContentJson, function (id, item) {
- $(".guideareas").hide();
- var random_id = String(Math.random()).substr(2);
- options.controlDataJson[random_id] = item;
- var controlitemstr = "";
- if (item.control_item != undefined) {
- var controlitem = [];
- $.each(item.control_item, function (i, n) {
- controlitem[n.identify] = n;
- if (controlitemstr != "") {
- controlitemstr += "、";
- }
- controlitemstr += n.name;
- });
- options.controlDataJson[random_id].control_item = controlitem;
- }
- var controlrequired = item.control_required == '1' ? '<font face="宋体">*</font>' : '';
- var _item_field_value = "";
- switch (item.control_type) {
- case "text":
- _item_field_value = "文本框";
- break;
- case "textarea":
- _item_field_value = "文本区";
- break;
- case "texteditor":
- _item_field_value = "编辑器";
- break;
- case "radio":
- _item_field_value = "单选项/";
- break;
- case "checkbox":
- _item_field_value = "多选项/";
- break;
- case "select":
- _item_field_value = "下拉框/";
- break;
- case "datetime":
- _item_field_value = "年-月-日";
- break;
- case "image":
- _item_field_value = "上传图片/" + item.control_fileformat;
- break;
- case "upload":
- _item_field_value = "上传文件/"+ item.control_fileformat;
- break;
- case "departmentlist":
- break;
- case "dataitemlist":
- break;
- default:
- break;
- }
- var $item_control = $('<div class="item_row ui-draggable" ><div class="item_field_label"><span>' + item.control_label + '</span>' + controlrequired + '</div><div class="item_field_value">' + _item_field_value + controlitemstr + '</div><div class="item_field_remove"><i title="移除控件" class="del fa fa-close"></i></div></div>');
- if ($item_control) {
- $item_control.attr('data-value', random_id);
- $app_layout_list.append($item_control);
- item_rowclick();
- if (num == 0) {
- $item_control.trigger("click");
- }
- num++;
- }
- });
- $app_layout_list.find('.item_field_value').width(item_field_value_width);
- }
- }
- formdesigner_move();
-
- function textProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>无样式的单行文本框</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';//<input id="control_field" type="text" class="form-control" placeholder="必填项"/>
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"/></div>';
- _html += '<div class="field_title">字段验证</div>';
- _html += '<div class="field_control"><select id="control_verify" class="form-control"><option value="">==请选择==</option><option value="Num">数字</option><option value="Double">小数</option><option value="Phone">必须电话格式</option><option value="Mobile">手机格式</option><option value="Email">电子邮件格式</option><option value="IDCard">身份证格式</option></select></div>';
- _html += '<div class="field_title">默认值<i title="仅在添加数据时默认填入" class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><input id="control_default" type="text" class="form-control" placeholder="无则不填"/></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox" />必填</label></div></div>';//<label><input id="control_only" type="checkbox" />唯一<i title="字段中填入的值不可重复" class="help fa fa-question-circle"></i></label>
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_verify').val(rowJson.control_verify);
- $html.find('#control_default').val(rowJson.control_default);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_verify').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_default').keyup(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- //$html.find('#control_only').click(function (e) {
- // var value = 0;
- // if ($(this).attr("checked")) {
- // $(this).attr("checked", false);
- // value = 0;
- // } else {
- // $(this).attr("checked", true);
- // value = 1;
- // }
- // rowJson[$(this).attr('id')] = value;
- // controlDataJson[e_row.attr('data-value')] = rowJson;
- //});
- }
- function textareaProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>无样式的多行文本框</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">字段高度</div>';
- _html += '<div class="field_control"><input id="control_height" type="text" class="form-control" value="100px"></div>';
- _html += '<div class="field_title">默认值<i title="仅在添加数据时默认填入" class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><input id="control_default" type="text" class="form-control" placeholder="无则不填"></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_verify').val(rowJson.control_verify);
- $html.find('#control_height').val(rowJson.control_height);
- $html.find('#control_default').val(rowJson.control_default);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_verify').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_height').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_default').keyup(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- function texteditorProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>类似word,可设置丰富文字样式的多行文本编辑区</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">字段高度</div>';
- _html += '<div class="field_control"><input id="control_height" type="text" class="form-control" value="200px"></div>';
- _html += '<div class="field_title">默认值<i title="仅在添加数据时默认填入" class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><input id="control_default" type="text" class="form-control" placeholder="无则不填"></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_verify').val(rowJson.control_verify);
- $html.find('#control_height').val(rowJson.control_height);
- $html.find('#control_default').val(rowJson.control_default);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_verify').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_height').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_default').keyup(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- function radioProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>显示所有备选项,从中只可选择一项</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">备选项<div class="addclassify"><a><i class="fa fa-plus"></i>添加</a></div></div>';
- _html += '<div class="field_control"><ul class="classify"></ul></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var getRowJson = options.controlDataJson[e_row.attr('data-value')];
- if (getRowJson == null) {
- return false;
- }
- setControlField(getRowJson, e_row, $html);
- $html.find('#control_label').val(getRowJson.control_label);
- if (getRowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- //处理备选项
- var $classify = $(".field_control .classify");
- $classify.sortable({
- handle: '.dragitem',
- stop: function (event, ui) {
- var tempitemjson = controlItemListJson;
- controlItemListJson = {};
- $classify.find('li').each(function (i) {
- var id = $(this).attr('data-value');
- controlItemListJson[id] = tempitemjson[id];
- });
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('单选项/' + String(_name).replace(/,/g, '、'));
- }
- });
- //选项列表Json
- var controlItemListJson = options.controlDataJson[e_row.attr('data-value')]["control_item"];
- for (var i in controlItemListJson) {
- additem(i);
- var $thisObjectRow = $classify.find('[data-value=' + i + ']');
- $thisObjectRow.find('input[name=name]').val(controlItemListJson[i].name);
- $thisObjectRow.find('em').attr('class', controlItemListJson[i].color);
- $thisObjectRow.find('input[name=defaults]').attr("checked", controlItemListJson[i].defaults == 1 ? true : false);
- }
- //添加一项li
- $('.addclassify').find('a').click(function () {
- var random_id = String(Math.random()).substr(2);
- controlItemListJson[random_id] = {
- identify: random_id,
- color: "color_a",
- name: "",
- defaults: "0",
- }
- additem(random_id);
- })
- function additem(random_id) {
- var $li = $('<li><span><em title="色彩" class="color_a"></em><i title="移除" class="fa fa-close"></i></span><i class="dragitem fa fa-arrows"></i><input name="defaults" type="radio" title="设置默认值"><input name="name" type="text" placeholder="请填写备选项"></li>');
- $li.attr('data-value', random_id)
- $classify.append($li);
- //移除一项li
- $li.find('i.fa-close').click(function () {
- var id = $(this).parents('li').attr('data-value');
- delete controlItemListJson[id];
- $(this).parents('li').remove();
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('单选项/' + String(_name).replace(/,/g, '、'));
- });
- //点击切换色彩
- var clickindex = 1;
- $li.find('em').click(function () {
- var color = ['color_a', 'color_b', 'color_c', 'color_d', 'color_e', 'color_f', 'color_g', 'color_h', 'color_i'];
- $(this).attr('class', color[clickindex]);
- controlItemListJson[$(this).parents('li').attr('data-value')].color = color[clickindex];
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- clickindex++;
- if (clickindex == 9) {
- clickindex = 0
- }
- });
- //默认值事件
- $li.find('input[name=defaults]').click(function () {
- for (var i in controlItemListJson) {
- controlItemListJson[i].defaults = 0;
- }
- controlItemListJson[$(this).parents('li').attr('data-value')].defaults = 1;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- });
- //输入事件
- $li.find('input[name=name]').change(function () {
- var value = $(this).val();
- controlItemListJson[$(this).parents('li').attr('data-value')].name = value;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name);
- }
- }
- e_row.find('.item_field_value').html('单选项/' + String(_name).replace(/,/g, '、'));
- })
- }
- if ($classify.find('li').length == 0) {
- $('.addclassify').find('a').trigger("click");
- }
- }
- function checkboxProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>显示所有备选项,从中可以选择多项</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">备选项<div class="addclassify"><a><i class="fa fa-plus"></i>添加</a></div></div>';
- _html += '<div class="field_control"><ul class="classify"></ul></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var getRowJson = options.controlDataJson[e_row.attr('data-value')];
- if (getRowJson == null) {
- return false;
- }
- setControlField(getRowJson, e_row, $html);
- $html.find('#control_label').val(getRowJson.control_label);
- if (getRowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- //处理备选项
- var $classify = $(".field_control .classify");
- $classify.sortable({
- handle: '.dragitem',
- stop: function (event, ui) {
- var tempitemjson = controlItemListJson;
- controlItemListJson = {};
- $classify.find('li').each(function (i) {
- var id = $(this).attr('data-value');
- controlItemListJson[id] = tempitemjson[id];
- });
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('多选项/' + String(_name).replace(/,/g, '、'));
- }
- });
- //选项列表Json
- var controlItemListJson = options.controlDataJson[e_row.attr('data-value')]["control_item"];
- for (var i in controlItemListJson) {
- additem(i);
- var $thisObjectRow = $classify.find('[data-value=' + i + ']');
- $thisObjectRow.find('input[name=name]').val(controlItemListJson[i].name);
- $thisObjectRow.find('em').attr('class', controlItemListJson[i].color);
- $thisObjectRow.find('input[name=defaults]').attr("checked", controlItemListJson[i].defaults == 1 ? true : false);
- }
- //添加一项li
- $('.addclassify').find('a').click(function () {
- var random_id = String(Math.random()).substr(2);
- controlItemListJson[random_id] = {
- identify: random_id,
- color: "color_a",
- name: "",
- defaults: "0",
- }
- additem(random_id);
- })
- function additem(random_id) {
- var $li = $('<li><span><em title="色彩" class="color_a"></em><i title="移除" class="fa fa-close"></i></span><i class="dragitem fa fa-arrows"></i><input name="defaults" type="checkbox" title="设置默认值"><input name="name" type="text" placeholder="请填写备选项"></li>');
- $li.attr('data-value', random_id)
- $classify.append($li);
- //移除一项li
- $li.find('i.fa-close').click(function () {
- var id = $(this).parents('li').attr('data-value');
- delete controlItemListJson[id];
- $(this).parents('li').remove();
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('多选项/' + String(_name).replace(/,/g, '、'));
- });
- //点击切换色彩
- var clickindex = 1;
- $li.find('em').click(function () {
- var color = ['color_a', 'color_b', 'color_c', 'color_d', 'color_e', 'color_f', 'color_g', 'color_h', 'color_i'];
- $(this).attr('class', color[clickindex]);
- controlItemListJson[$(this).parents('li').attr('data-value')].color = color[clickindex];
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- clickindex++;
- if (clickindex == 9) {
- clickindex = 0
- }
- });
- //复选框事件
- $li.find('input[name=defaults]').click(function () {
- controlItemListJson[$(this).parents('li').attr('data-value')].defaults = 1;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- });
- //输入事件
- $li.find('input[name=name]').keyup(function () {
- var value = $(this).val();
- controlItemListJson[$(this).parents('li').attr('data-value')].name = value;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name);
- }
- }
- e_row.find('.item_field_value').html('多选项/' + String(_name).replace(/,/g, '、'));
- })
- }
- if ($classify.find('li').length == 0) {
- $('.addclassify').find('a').trigger("click");
- }
- }
- function selectProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>显示所有备选项,从中只可选择一项</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">备选项<div class="addclassify"><a><i class="fa fa-plus"></i>添加</a></div></div>';
- _html += '<div class="field_control"><ul class="classify"></ul></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var getRowJson = options.controlDataJson[e_row.attr('data-value')];
- if (getRowJson == null) {
- return false;
- }
- setControlField(getRowJson, e_row, $html);
- $html.find('#control_label').val(getRowJson.control_label);
- if (getRowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- getRowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = getRowJson;
- });
- //处理备选项
- var $classify = $(".field_control .classify");
- $classify.sortable({
- handle: '.dragitem',
- stop: function (event, ui) {
- var tempitemjson = controlItemListJson;
- controlItemListJson = {};
- $classify.find('li').each(function (i) {
- var id = $(this).attr('data-value');
- controlItemListJson[id] = tempitemjson[id];
- });
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('下拉框/' + String(_name).replace(/,/g, '、'));
- }
- });
- //选项列表Json
- var controlItemListJson = options.controlDataJson[e_row.attr('data-value')]["control_item"];
- for (var i in controlItemListJson) {
- additem(i);
- var $thisObjectRow = $classify.find('[data-value=' + i + ']');
- $thisObjectRow.find('input[name=name]').val(controlItemListJson[i].name);
- $thisObjectRow.find('em').attr('class', controlItemListJson[i].color);
- $thisObjectRow.find('input[name=defaults]').attr("checked", controlItemListJson[i].defaults == 1 ? true : false);
- }
- //添加一项li
- $('.addclassify').find('a').click(function () {
- var random_id = String(Math.random()).substr(2);
- controlItemListJson[random_id] = {
- identify: random_id,
- color: "color_a",
- name: "",
- defaults: "0",
- }
- additem(random_id);
- })
- function additem(random_id) {
- var $li = $('<li><span><em title="色彩" class="color_a"></em><i title="移除" class="fa fa-close"></i></span><i class="dragitem fa fa-arrows"></i><input name="defaults" type="radio" title="设置默认值"><input name="name" type="text" placeholder="请填写备选项"></li>');
- $li.attr('data-value', random_id)
- $classify.append($li);
- //移除一项li
- $li.find('i.fa-close').click(function () {
- var id = $(this).parents('li').attr('data-value');
- delete controlItemListJson[id];
- $(this).parents('li').remove();
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name)
- };
- }
- e_row.find('.item_field_value').html('下拉框/' + String(_name).replace(/,/g, '、'));
- });
- //点击切换色彩
- var clickindex = 1;
- $li.find('em').click(function () {
- var color = ['color_a', 'color_b', 'color_c', 'color_d', 'color_e', 'color_f', 'color_g', 'color_h', 'color_i'];
- $(this).attr('class', color[clickindex]);
- controlItemListJson[$(this).parents('li').attr('data-value')].color = color[clickindex];
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- clickindex++;
- if (clickindex == 9) {
- clickindex = 0
- }
- });
- //默认值事件
- $li.find('input[name=defaults]').click(function () {
- for (var i in controlItemListJson) {
- controlItemListJson[i].defaults = 0;
- }
- controlItemListJson[$(this).parents('li').attr('data-value')].defaults = 1;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- });
- //输入事件
- $li.find('input[name=name]').keyup(function () {
- var value = $(this).val();
- controlItemListJson[$(this).parents('li').attr('data-value')].name = value;
- options.controlDataJson[e_row.attr('data-value')]["control_item"] = controlItemListJson;
- var _name = [];
- for (var i in controlItemListJson) {
- if (controlItemListJson[i].name) {
- _name.push(controlItemListJson[i].name);
- }
- }
- e_row.find('.item_field_value').html('下拉框/' + String(_name).replace(/,/g, '、'));
- })
- }
- if ($classify.find('li').length == 0) {
- $('.addclassify').find('a').trigger("click");
- }
- }
- function datetimeProperty(e_row) {
- var _html = '';
- _html += '<div class="field_tips"><i class="fa fa-info-circle"></i><span>选择日期、时间控件</span></div>';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">日期格式</div>';
- _html += '<div class="field_control"><select id="control_dateformat" class="form-control"><option value="date">仅日期</option><option value="datetime">日期和时间</option></select></div>';
- _html += '<div class="field_title">默认值<i title="仅在添加数据时默认填入" class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><select id="control_default" class="form-control"><option value="">请选择</option><option value="Yesterday">昨天</option><option value="Today">今天</option><option value="Tomorrow">明天</option></select></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_dateformat').val(rowJson.control_dateformat);
- $html.find('#control_default').val(rowJson.control_default);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_dateformat').change(function (e) {
- var value = $(this).val();
- if (value == 'date') {
- e_row.find('.item_field_value').html('年-月-日');
- } else if (value == 'datetime') {
- e_row.find('.item_field_value').html('年-月-日 时:分');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_default').change(function (e) {
- var value = $(this).val();
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- function imageProperty(e_row) {
- var _html = '';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">图片格式<i title=".jpg .gif .png .bmp" class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><input id="control_fileformat" type="text" class="form-control" placeholder="如:jpg,gif,png,bmp"></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_fileformat').val(rowJson.control_fileformat);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_fileformat').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_value').html('上传图片/' + value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- function uploadProperty(e_row) {
- var _html = '';
- _html += '<div class="field_title">字段标识</div>';
- _html += '<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>';
- _html += '<div class="field_title">字段说明</div>';
- _html += '<div class="field_control"><input id="control_label" type="text" class="form-control" placeholder="必填项"></div>';
- _html += '<div class="field_title">文件格式<i title=".doc .xls .ppt .pdf " class="help fa fa-question-circle"></i></div>';
- _html += '<div class="field_control"><input id="control_fileformat" type="text" class="form-control" placeholder="如:doc,xls,ppt,pdf"></div>';
- _html += '<div class="field_title">设置</div>';
- _html += '<div class="field_control"><div class="checkbox notclose" style="padding-left: 3px;"><label><input id="control_required" type="checkbox">必填</label></div></div>';
- var $html = $(_html);
- $(".field_option").html($html);
- var rowJson = options.controlDataJson[e_row.attr('data-value')];
- if (rowJson == null) {
- return false;
- }
- setControlField(rowJson, e_row, $html);
- $html.find('#control_label').val(rowJson.control_label);
- $html.find('#control_fileformat').val(rowJson.control_fileformat);
- if (rowJson.control_required == 1) {
- $html.find('#control_required').attr("checked", 'checked');
- } else {
- $html.find('#control_required').removeAttr("checked");
- }
- $html.find('#control_label').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_label').find('span').html(value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_fileformat').keyup(function (e) {
- var value = $(this).val();
- e_row.find('.item_field_value').html('上传文件/' + value);
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- $html.find('#control_required').click(function (e) {
- var value = 0;
- if ($(this).attr("checked")) {
- value = 0;
- $(this).attr("checked", false);
- e_row.find('.item_field_label').find('font').remove();
- } else {
- value = 1;
- $(this).attr("checked", true);
- e_row.find('.item_field_label').append('<font face="宋体">*</font>');
- }
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- function dataitemlistProperty(e_row) {
- }
- //绑定数据表字段
- function setControlField(rowJson, e_row, $html) {
-
- var _value = (rowJson.control_field == "" ? newGuid() : rowJson.control_field);
- if (options.isSystemTable == 0) {
- $html.find("#control_field").parents('.field_control').html('<input id="control_field" type="text" class="form-control" disabled data-text="' + _value + '" value="' + _value + '" />');
- rowJson.control_field = _value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- }
- else {
- $html.find("#control_field").parents('.field_control').html('<div class="field_control"><div id="control_field" type="select" class="ui-select"></div></div>');
- $html.find("#control_field").ComboBox({
- data: options.tablefiledJsonData,
- id: "f_column",
- text: "f_remark",
- description: "==请选择==",
- height: "230px",
- allowSearch: true
- });
- $html.find("#control_field").ComboBoxSetValue(rowJson.control_field);
- $html.find('#control_field').change(function (e) {
- var value = $(this).attr('data-value');
- rowJson[$(this).attr('id')] = value;
- options.controlDataJson[e_row.attr('data-value')] = rowJson;
- });
- }
- }
-
- return options;
- }
- //表单预览
- $.fn.frmPreview = function (options)
- {
- var $frmpreview= $(this);
- if (!$frmpreview.attr('id')) {
- return false;
- }
- $frmpreview.html("");
- var defaults = {
- tablecotent: [],
- width:0,
- datetime:new Date()
- };
- var options = $.extend(defaults, options);
- if (options.tablecotent == "")
- {
- return false;
- }
- var frmContentJson = eval('(' + options.tablecotent + ')');
-
- $.each(frmContentJson, function (id, item) {
- var $item_control = $('<div class="item_row"></div>');
- var controlrequired = item.control_required == '1' ? '<font face="宋体">*</font>' : '';
- var controlrequired1 = item.control_required == '1' ? 'isvalid="yes" checkexpession="NotNull"' : '';
- item.control_field = 'frm_' + item.control_field;
- $item_control.html('<div class="item_field_label"><span>' + item.control_label + '</span>' + controlrequired + '</div>');
- switch (item.control_type) {
- case "text":
- $item_control.append('<div class="item_field_value"><input id="' + item.control_field + '" type="text" class="form-control" ' + controlrequired1 + ' /></div>');
- break;
- case "textarea":
- $item_control.append('<div class="item_field_value"><textarea id="' + item.control_field + '" style=height:' + item.control_height + '; class="form-control" ' + controlrequired1 + ' /></div>');
- break;
- case "texteditor":
- $item_control.append('<div class="item_field_value"><textarea id="' + item.control_field + '" style=height:' + item.control_height + '; class="form-control" ' + controlrequired1 + ' /></div>');
- $frmpreview.append($item_control);
- new Simditor({
- textarea: $('#' + item.control_field),
- placeholder: '这里输入内容...',
- toolbar: ['color', 'title', 'bold', 'underline', 'strikethrough', '|', 'ol', 'ul', 'blockquote', 'table', '|', 'link', 'image']
- });
- $item_control = null;
- break;
- case "radio":
- var radiohtml = "";
- $.each(item.control_item, function (id, childitem) {
- radiohtml += '<div class="rdio rdio-' + childitem.color + '" ><input name="' + item.control_field + '" id = "' + item.control_field + childitem.identify + '" type="radio" data-value="' + childitem.identify + '" value="' + childitem.name + '" /><label for="' + item.control_field + childitem.identify + '">' + childitem.name + '</label></div>';
- });
- $item_control.append('<div class="item_field_value">' + radiohtml + '</div>');
- break;
- case "checkbox":
- var ckboxhtml = "";
- $.each(item.control_item, function (id, childitem) {
- ckboxhtml += '<div class="ckbox ckbox-' + childitem.color + '" ><input id = "' + item.control_field + childitem.identify + '" type="checkbox" data-value="' + childitem.identify + '" value="' + childitem.name + '" /><label for="' + item.control_field + childitem.identify + '">' + childitem.name + '</label></div>';
- });
- $item_control.append('<div class="item_field_value">' + ckboxhtml + '</div>');
- break;
- case "select":
- $item_control.append('<div class="item_field_value"><div id="' + item.control_field + '" type="select" class="ui-select" isvalid="yes" ' + controlrequired1 + '></div></div>');
- $frmpreview.append($item_control);
- $("#" + item.control_field).ComboBox({
- data: item.control_item,
- id: "name",
- text: "name",
- description: "==请选择==",
- height: "200px",
- allowSearch: true
- });
- $item_control = null;
- break;
- case "datetime":
- var dateformat = item.control_dateformat == 'date' ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm';
- var datedefault = "";
- switch (item.control_default)
- {
- case "Yesterday":
- datedefault = options.datetime.DateAdd('d',-1);
- break;
- case "Today":
- datedefault = options.datetime.DateAdd('d', 0);
- break;
- case "Tomorrow":
- datedefault = options.datetime.DateAdd('d', 1);;
- break;
- }
- datedefault = formatDate(datedefault, dateformat.replace(/H/g,'h'));
- $item_control.append('<div class="item_field_value"><input value="' + datedefault + '" onClick="WdatePicker({dateFmt:\'' + dateformat + '\',qsEnabled:false,isShowClear:false,isShowOK:false,isShowToday:false})" id="' + item.control_field + '" readonly type="text" class="form-control input-datepicker" ' + controlrequired1 + '/></div>');
- break;
- case "image":
- $item_control.append('<div class="item_field_value"><input id="' + item.control_field + '" type="file" /></div>');
- $frmpreview.append($item_control);
- fuploadify(item.control_field, "添加图片");
- $item_control = null;
- break;
- case "upload":
- $item_control.append('<div class="item_field_value"><input id="' + item.control_field + '" type="file" /></div>');
- $frmpreview.append($item_control);
- fuploadify(item.control_field, "添加附件");
- $item_control = null;
- break;
- case "departmentlist":
- break;
- case "dataitemlist":
- break;
- default:
- break;
- }
- if ($item_control != null)
- {
- $frmpreview.append($item_control);
- }
- });
- var _field_value_width = options.width - 132;
- if (options.width == 0) {
- _field_value_width = $frmpreview[0].scrollWidth - 132;
- }
- $frmpreview.find('.item_field_value').width(_field_value_width);
- function fuploadify(control_field,btnName) {
- $("#" + control_field).uploadify({
- method: 'post',
- uploader: '/FlowManage/FormDesign/UploadifyFile',
- swf: top.contentPath + '/Content/scripts/plugins/uploadify/uploadify.swf',
- buttonText: btnName,
- height: 30,
- width: 90,
- fileTypeExts: '*.avi;*.mp3;*.mp4;*.bmp;*.ico;*.gif;*.jpeg;*.jpg;*.png;*.psd; *.rar;*.zip;*.swf;*.log;*.pdf;*.doc;*.docx;*.ppt;*.pptx;*.txt; *.xls; *.xlsx;',
- removeCompleted: false,
- onSelect: function (file) {
- $("#" + file.id).prepend('<div style="float:left;width:50px;margin-right:2px;"><img src="/Content/images/filetype/' + file.type.replace('.', '') + '.png" style="width:40px;height:40px;" /></div>');
- $(".uploadify-queue-item").find('.cancel').find('a').html('<i class="fa fa-trash-o "></i>');
- $(".uploadify-queue-item").find('.cancel').find('a').attr('title','删除');
- $(".uploadify-queue-item").hover(function () {
- $(this).find('.cancel').find('a').show();
- }, function () {
- $(this).find('.cancel').find('a').hide();
- });
- },
- onUploadSuccess: function (file) {
- $("#" + file.id).find('.uploadify-progress').remove();
- $("#" + file.id).find('.data').html(' 恭喜您,上传成功!');
- $("#" + file.id).prepend('<a class="succeed" title="成功"><i class="fa fa-check-circle"></i></a>');
- Loading(false);
- },
- onUploadError: function (file) {
- $("#" + file.id).removeClass('uploadify-error');
- $("#" + file.id).find('.uploadify-progress').remove();
- $("#" + file.id).find('.data').html(' 很抱歉,上传失败!');
- $("#" + file.id).prepend('<span class="error" title="失败"><i class="fa fa-exclamation-circle"></i></span>');
- },
- onUploadStart: function () {
- $('#' + control_field + '-queue').show();
- },
- onCancel: function (file) {
- }
- });
- $("#" + control_field + "-button").prepend('<i style="opacity: 0.6;" class="fa fa-cloud-upload"></i> ');
- $('#' + control_field + '-queue').hide();
- }
- }
- //获取表单数据
- $.fn.frmGetData = function () {
- var reVal = ""; var checkboxValue = {};
- $(this).find('input,select,textarea,.ui-select').each(function (r) {
- var id = $(this).attr('id');
- if (id != undefined)
- {
- var filedid = id.replace('frm_', '');
- var type = $(this).attr('type');
- switch (type) {
- case "checkbox":
- var datavalue = $("#" + id).attr('data-value');
- var value = $("#" + id).val();
- if ($("#" + id).is(":checked")) {
- //reVal += '"' + filedid.replace(datavalue, '') + '"' + ':' + '"' + $.trim(value) + '",'
- if (checkboxValue[filedid.replace(datavalue, '')] == undefined) {
- checkboxValue[filedid.replace(datavalue, '')] = "";
- }
- else {
- checkboxValue[filedid.replace(datavalue, '')] += '|';
- }
- checkboxValue[filedid.replace(datavalue, '')] += $.trim(value);
- }
- break;
- case "radio":
- var datavalue = $("#" + id).attr('data-value');
- var value = $("#" + id).val();
- if ($("#" + id).is(":checked")) {
- reVal += '"' + filedid.replace(datavalue, '') + '"' + ':' + '"' + $.trim(value) + '",'
- }
- break;
- case "select":
- var value = $("#" + id).attr('data-value');
- if (value == "") {
- value = " ";
- }
- reVal += '"' + filedid + '"' + ':' + '"' + $.trim(value) + '",'
- break;
- case "selectTree":
- var value = $("#" + id).attr('data-value');
- if (value == "") {
- value = " ";
- }
- reVal += '"' + filedid + '"' + ':' + '"' + $.trim(value) + '",'
- break;
- default:
- var value = $("#" + id).val();
- if (value == "") {
- value = " ";
- }
- reVal += '"' + filedid + '"' + ':' + '"' + $.trim(value) + '",'
- break;
- }
- }
- });
- for (var i in checkboxValue)
- {
- reVal += '"' + i + '"' + ':' + '"' + checkboxValue[i] + '",'
- }
- reVal = reVal.substr(0, reVal.length - 1);
- reVal = reVal.replace(/\\/g, '\\\\');
- reVal = reVal.replace(/\n/g, '\\n');
- var postdata = jQuery.parseJSON('{' + reVal + '}');
- //阻止伪造请求
- //if ($('[name=__RequestVerificationToken]').length > 0) {
- // postdata["__RequestVerificationToken"] = $('[name=__RequestVerificationToken]').val();
- //}
- return postdata;
- }
- //设置表单数据
- $.fn.frmSetData = function (data) {
- //console.log("data:"+JSON.stringify(data));
- var $id = $(this)
- for (var key in data) {
- var id = $id.find('#frm_' + key);
- var value = $.trim(data[key]).replace(/ /g, '');
- if (id.attr('id')) {
- var type = id.attr('type');
- switch (type) {
- case "radio":
- break;
- case "checkbox":
- if (value == 1) {
- id.attr("checked", 'checked');
- } else {
- id.removeAttr("checked");
- }
- break;
- case "select":
- id.ComboBoxSetValue(value);
- break;
- case "selectTree":
- id.ComboBoxTreeSetValue(value);
- break;
- default:
- id.val(value);
- break;
- }
- }
- else {
- $(this).find('input').each(function (r) {
- var checkid = $(this).attr('id');
- var checkfiledid = checkid.replace('frm_', '');
- var checktype = $(this).attr('type');
- var checkValue = $(this).val();
- switch (checktype) {
- case "checkbox":
- var datavalue = $(this).attr('data-value');
- if ((key + datavalue) == checkfiledid )
- {
- var vlist = value.split('|');
- for (var i in vlist)
- {
- if (vlist[i] == checkValue)
- {
- $(this).attr("checked", 'checked');
- break;
- }
- }
- }
- break;
- case "radio":
- var datavalue = $(this).attr('data-value');
- if ((key + datavalue) == checkfiledid && checkValue == value) {
- $(this).attr("checked", 'checked');
- }
- break;
- default:
- break;
- }
- });
- }
- }
- }
|