|
@@ -0,0 +1,169 @@
|
|
|
|
+var tpl_input='<input type="text" class="form-control" id="{s_label}" >'
|
|
|
|
+var tpl_text='<textarea class="form-control" id="{s_label}" rows="{rows}"></textarea>'
|
|
|
|
+var tpl_hidden='<input type="hidden" id="{s_label}">'
|
|
|
|
+var tpl_small='<div class="small srule">{s_label}</div>'
|
|
|
|
+var tpl_list_local='<div class="input-group">'+
|
|
|
|
+ '<input type="text" class="form-control" id="s_show">'+
|
|
|
|
+ '<input type="hidden" hid="hid" id="{s_label}">'+
|
|
|
|
+ '<div class="input-group-btn">'+
|
|
|
|
+ '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1">'+
|
|
|
|
+ '<span class="caret"></span></button>'+
|
|
|
|
+ '<ul class="dropdown-menu pull-right" id="u_list"></ul></div></div>';
|
|
|
|
+var tpl_list_ajax='<div class="input-group">'+
|
|
|
|
+ '<div id="s_show"></div>'+
|
|
|
|
+ '<input type="hidden" hid="hid" id="{s_label}">'+
|
|
|
|
+ '<div class="input-group-btn">'+
|
|
|
|
+ '<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" tabindex="-1">'+
|
|
|
|
+ '<span class="caret"></span></button>'+
|
|
|
|
+ '<ul class="dropdown-menu pull-right" id="u_list"></ul></div></div>';
|
|
|
|
+
|
|
|
|
+var tag_head='<div class="row form-group"><label for="lastname" class="col-sm-2 control-label" >{label}</label><div class="col-sm-10">{type}</div></div>'
|
|
|
|
+var notag_head='<div class="row form-group"><div class="col-sm-12">{type}</div></div>'
|
|
|
|
+
|
|
|
|
+//设置对话窗口内容并弹出对话窗口
|
|
|
|
+function OpenDialog(obj,data,callback){
|
|
|
|
+ $("#_tt").text(obj.title);
|
|
|
|
+ //生成表单
|
|
|
|
+ makeTag(obj)
|
|
|
|
+ //生成按钮
|
|
|
|
+ makeBts(obj)
|
|
|
|
+ //填充数据
|
|
|
|
+ if(data){
|
|
|
|
+ //Put值进去
|
|
|
|
+ $("#_con").find("input,textarea,div").each(function(i,el){
|
|
|
|
+ var attrid=$(el).attr("id")
|
|
|
|
+ if(attrid=="s_show"){
|
|
|
|
+ //分div中的alert或者是input放值
|
|
|
|
+ if (el.tagName=="DIV"){
|
|
|
|
+ var parent1=$(el).closest("div.input-group")
|
|
|
|
+ var tid=parent1.find("input[type=hidden]").attr("id")
|
|
|
|
+ var sc=data[tid]
|
|
|
|
+ if (sc){
|
|
|
|
+ $(sc.split(",")).each(function(n,v){
|
|
|
|
+ $("li[_id='"+v+"']",parent1).click()
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ var tid=$(el).closest("div.input-group").find("input[type=hidden]").attr("id")
|
|
|
|
+ $(el).val($("li[_id='"+data[tid]+"']",$(el).closest("div")).text())
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ $(el).val(data[attrid])
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ //设置默认
|
|
|
|
+ if(obj.tag){
|
|
|
|
+ for(var i=0;i<obj.tag.length;i++){
|
|
|
|
+ if(obj.tag[i].default!=undefined&&!$("#"+obj.tag[i]["s_label"]).val()){
|
|
|
|
+ $("#"+obj.tag[i]["s_label"]).closest("div.input-group").find("li[_id="+obj.tag[i].default+"]").click()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //显示对话框
|
|
|
|
+ $('#myModal').modal('show');
|
|
|
|
+ //关闭后回调函数
|
|
|
|
+ if(callback){
|
|
|
|
+ $('#myModal').on('hide.bs.modal', function () {
|
|
|
|
+ callback()
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+//按钮生成
|
|
|
|
+function makeBts(obj){
|
|
|
|
+ var btn='<button type="button" class="btn {class}">{label}</button>'
|
|
|
|
+ var str=[]
|
|
|
|
+ $("#_bts").html("");
|
|
|
|
+ if(obj.bts){
|
|
|
|
+ for(var i=0;i<obj.bts.length;i++){
|
|
|
|
+ var s=$(btn.replace(/\{(.*?)\}/g,function(a,b){return obj.bts[i][b]}))
|
|
|
|
+ if(obj.bts[i]["fun"])s.click(obj.bts[i]["fun"])
|
|
|
|
+ str.push(s)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (str.length>0){
|
|
|
|
+ $("#_bts").append(str)
|
|
|
|
+ }
|
|
|
|
+ //不能为空的表单判断
|
|
|
|
+ $("input[must],textarea[must]").closest(".row").find("label").css("color","red");
|
|
|
|
+}
|
|
|
|
+//下拉框生成
|
|
|
|
+function makeSel(obj){
|
|
|
|
+ var list;
|
|
|
|
+ if (obj.url){
|
|
|
|
+ $.ajax({
|
|
|
|
+ async: false,
|
|
|
|
+ type : "POST",
|
|
|
|
+ url : obj.url,
|
|
|
|
+ data:obj.data,
|
|
|
|
+ dataType : 'json',
|
|
|
|
+ success : function(data) {
|
|
|
|
+ if(data&&data.data){
|
|
|
|
+ list=data.data
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }else if (obj.list){
|
|
|
|
+ list=obj.list
|
|
|
|
+ }
|
|
|
|
+ var str=[]
|
|
|
|
+ if (list!=null){
|
|
|
|
+ for(var i=0;i<list.length;i++){
|
|
|
|
+ var el=$('<li _id="'+list[i]._id+'"><a href="#">'+list[i].s_name+'</a></li>')
|
|
|
|
+ if(obj["fun"]){
|
|
|
|
+ el.click(obj["fun"])
|
|
|
|
+ }else{
|
|
|
|
+ el.click(function(){
|
|
|
|
+ var to=$("#"+obj.s_label)
|
|
|
|
+ to.val($(this).attr("_id"))
|
|
|
|
+ $("#s_show",to.closest("div")).val($(this).text())
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+ str.push(el)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return str
|
|
|
|
+}
|
|
|
|
+//表单生成
|
|
|
|
+function makeTag(obj){
|
|
|
|
+ $("#_con").html("");
|
|
|
|
+ var str=[]
|
|
|
|
+ if(obj.tag){
|
|
|
|
+ for(var i=0;i<obj.tag.length;i++){
|
|
|
|
+ var t=obj.tag[i]["type"]||"tpl_input";
|
|
|
|
+ //提取对应的模板
|
|
|
|
+ obj.tag[i]["type"]=eval("("+t+")");
|
|
|
|
+ obj.tag[i]["type"]=obj.tag[i]["type"].replace(/\{(.*?)\}/g,function(a,b){
|
|
|
|
+ return obj.tag[i][b]
|
|
|
|
+ })
|
|
|
|
+ var el=$(obj.tag[i]["type"])
|
|
|
|
+ if (t!="tpl_hidden"){
|
|
|
|
+ var thisTmp=tag_head //有标签和没标签的区别
|
|
|
|
+ if(!obj.tag[i]["label"]){
|
|
|
|
+ thisTmp=notag_head
|
|
|
|
+ }
|
|
|
|
+ el=$(thisTmp.replace(/\{(.*?)\}/g,function(a,b){
|
|
|
|
+ return obj.tag[i][b]
|
|
|
|
+ }))
|
|
|
|
+ if(t.indexOf("tpl_list")==0){//放list
|
|
|
|
+ el.find("#u_list").append(makeSel(obj.tag[i]))
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //val,disabled,placeholder属性值处理
|
|
|
|
+ if (obj.tag[i]["val"]){
|
|
|
|
+ el.val(obj.tag[i]["val"])
|
|
|
|
+ }
|
|
|
|
+ $(["disabled","placeholder","must"]).each(function(n,v){
|
|
|
|
+ if (obj.tag[i][v]){
|
|
|
|
+ el.find("input,textarea").attr(v,obj.tag[i][v])
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ str.push(el)
|
|
|
|
+ }
|
|
|
|
+ $("#_con").append(str)
|
|
|
|
+ }else if(obj.content){
|
|
|
|
+ $("#_con").html(obj.content)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Date.prototype.format=function(format){var o={"M+":this.getMonth()+1,"d+":this.getDate(),"h+":this.getHours(),"m+":this.getMinutes(),"s+":this.getSeconds(),"q+":Math.floor((this.getMonth()+3)/3),"S":this.getMilliseconds()};if(/(y+)/.test(format)){format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4-RegExp.$1.length))}for(var k in o){if(new RegExp("("+k+")").test(format)){format=format.replace(RegExp.$1,RegExp.$1.length==1?o[k]:("00"+o[k]).substr((""+o[k]).length))}}return format};function getDate(l){var date=new Date(l);pattern="yyyy-MM-dd hh:mm:ss";return date.format(pattern)};
|