<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
	contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html>
<html>

<head>
    <title>微信公众号管理</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <!-- bootstrap 3.0.2 -->

    <link href="<c:url value='/scripts/lib/layui/layui.css'/>" rel="stylesheet" type="text/css" />
    <link href="<c:url value='/styles/vehicleClean/home.css'/>" rel="stylesheet" type="text/css" />
    <link href="<c:url value='/styles/AdminLTE.css?2019-1-3'/>" rel="stylesheet" type="text/css" />
    <link href="<c:url value='/styles/orderDinner/accountManage.css'/>" rel="stylesheet" type="text/css" />
    <link href="<c:url value='/styles/lingling/deviceList.css'/>" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="<c:url value='/scripts/lib/jquery-1.8.2.min.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/lib/layui/layui.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/lib/template-native.js'/>"></script>
    <script type="text/javascript" src="${ctx}/scripts/jquery/ajaxfileupload.js"></script>
    <script type="text/javascript" src="<c:url value='/scripts/mobileBUGFix.mini.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/admin/lrz.bundle.js'/>"></script>
    <script type="text/javascript" src="<c:url value='/scripts/admin/cjqt.js'/>"></script>
</head>

<body>
    <input type="hidden" value="${ctx}" id="contextPath" />
    <input type="hidden" value="${imageServer}" id="imageServer" />
    <div class="bread-wp">
        设置中心 > 微信公众号管理
    </div>
    <div class="right-content device-list">
        <div class="main-content-mode-wp clearfloat email-publish-wp ">
            <form:form id="conditionform" class="clearfloat">
                <c:if test="${fn:length(organizationList) > 1}">
                    <div class=" part-wp">
                        <span class="search-tips">校区</span>
                        <input class="default-select" name="orgId" id="orgId" autocomplete="off" />
                        <span class="select_wrap _hide"></span>
                    </div>
                </c:if>
                <c:if test="${fn:length(organizationList) == 1}">
                    <input type="hidden" name="orgId" id="orgId" value="${organizationList[0].id}" org__id="${organizationList[0].id}" class="single-orgid">
                </c:if>
                <div class="part-wp">
                    <span class="search-tips">公众号名称</span>
                    <input class="small-input groupName" type="text" placeholder="请输入名称" />
                </div>
                <div class="part-wp">
                    <button class="search-btn bl_yellow fs16" type="button">查询</button>
                    <button class="set-btn bt_blue fs16" type="button">重置</button>
                    <button style="margin-left: 15px;" class="add-ele-btn bt_blue fs16" type="button">+新增</button>
                </div>
            </form:form>
            <table class="layui-hide" id="LAY_table_user" lay-filter="test"></table>
        </div>
    </div>
    <div class="alert-bo" onclick="closeAlert()">
        <div class="boost-bo">
            <img src="" alt="">
        </div>
    </div>
    <script type="text/html" id="indexTpl">
        {{d.LAY_TABLE_INDEX+1}}
	</script>
</body>
<script>
	// 设备列表
	$(function () {
	  var ERROK = 200;
	  var contextPath = $("#contextPath").val()
	  var imageServer = $("#imageServer").val()
	  var table;
	  var orgList = [];
	  var deviceList = [];
	  var departList = [];
	  var companyList = [];
	  var orgId = "";
	  var api = {
	    init: function () {
	      this.render();
	      this.bindEvent();
	    },
	    render: function () {
	      this.rendertable();
	    },
	    bindEvent: function () {
	      var _this = this;
	      //重置
	      $(".set-btn").on("click", function () {
	        var $orgId = $("#conditionform  .single-orgid");
			var $dom = $("#conditionform input,#conditionform select")
			if($orgId.length){
				$dom.val("").removeAttr('com__id dep__id')
			}else{
				$dom.val("").removeAttr('org__id com__id dep__id')
			}
			_this.againRenderTable({type:1});
	      });
      	//查询
        $('body').on('click', '#conditionform  .search-btn',function () {
          _this.againRenderTable();
	    });
	    // 新增
	    $(".add-ele-btn").click(function(){
			location.href="<c:url value='/pblic/no/form?funcid=${funcid}' />";
		});
	      // 模糊搜索
	      _this.search_fuzzy()
	    },
	    // 模糊搜索事件
	    search_fuzzy: function(){
	    	var default_option = {
	    		org_attrName:'org__id',
	    		com_attrName:'com__id',
	    		dep_attrName:'dep__id',
	    		org_spanName:'org__span',
	    		com_spanName:'com__span',
	    		dep_spanName:'dep__span',
	    		org_path:'/admin/templ/getOrgListByName',
	    		com_path:'/admin/templ/getVirList',
	    		dep_path:'/admin/templ/getDept',
	    		contextPath:$("#contextPath").val()
	    	}
	    	var option_1 = $.extend(true,{},default_option,{
	    		org_target:'.default-select#orgId',
	    	});
	    	function eve(option_,otherOption){
	    		var obj = $.extend(true, {}, option_, otherOption);
	    		var type = obj.type
	    		var _path, _target, _attrName, _spanName
	    		if(type == 1){
	    			_path = obj.org_path
	    			_target = obj.org_target
	    			_attrName = obj.org_attrName
	    			_spanName = obj.org_spanName
	    		}else if(type == 2){
	    			_path = obj.com_path
	    			_target = obj.com_target
	    			_attrName = obj.com_attrName
	    			_spanName = obj.com_spanName
	    		}else if(type == 3){
	    			_path = obj.dep_path
	    			_target = obj.dep_target
	    			_attrName = obj.dep_attrName
	    			_spanName = obj.dep_spanName
	    		}
	    		$('body').on("input",_target,function(event){
	    			var _this = $(this)
	    			var obj_input = $.extend(true,{}, obj,{"_this":_this});
	    			cjqt.search_fuzzy.event_input(_this,_attrName,_spanName,contextPath,_path,obj_input)
	    		});
	    		$('body').on("focus",_target,function(event){
	    			var _this = $(this)
	    			var obj_focus = $.extend(true,{},obj,{"_this":_this});
	    			cjqt.search_fuzzy.event_focus(_this,_attrName,_spanName,contextPath,_path,obj_focus)
	    		});
	    		$('body').on('blur',_target,function(event) {
	    			var _this = $(this)
	    			var obj_blur = $.extend(true,{},obj,{"_this":_this});
	    			cjqt.search_fuzzy.event_blur(_this,_attrName,obj_blur)
	    		});
	    		$('body').on('click',_target+'~.select_wrap>.'+_spanName, function(event) {
	    			event.preventDefault();
	    			event.stopPropagation();
	    			/* Act on the event */
	    			var _this = $(this)
	    			var obj_click = $.extend(true,{},obj,{"_this":_this});
	    			cjqt.search_fuzzy.event_click(_this,_attrName,_target,obj_click)
	    		});

	    	}
	    	// 搜索联动
	    	eve(option_1,{type:1})
	    },
	    rendertable: function () {
	      var _this = this;
	      layui.use(['table', 'laydate', 'form'], function () {
	        table = layui.table;
	        var form = layui.form,
	          layer = layui.layer,
	          laydate = layui.laydate;
	        //日期
	        laydate.render({
	          elem: '#date1'
	        });
	        //方法级渲染
	        table.render({
	          elem: '#LAY_table_user',
	          url: $("#contextPath").val() + "/pblic/no/getPubList",
	          method: "post",
	          skin: 'nob' //行边框风格
	            ,
	          even: true //开启隔行背景
	            ,
	          size: 'lg' //小尺寸的表格
	            ,
	          cols: [
	            [{
	              field: 'index',
	              title: '序号',
	              width: '80',
	              templet: '#indexTpl'
	            }, {
	              field: 'name',
	              title: '公众号名称',
	              minWidth: 200
	            }, {
	              field: 'deviceNames',
	              title: '公众号类型',
	              minWidth: 200,
	              templet: function (data) {
	              	if(data.developType == 2){
	              		return '服务号'
	              	}else if(data.developType == 1){
	              		return '订阅号'
	              	}
	              }
	            }, {
	              field: 'organizationName',
	              title: '关联校区',
	              minWidth: 500
	            }, {
	              field: 'creator',
	              title: '创建人',
	              minWidth: 200
	            }, {
	              field: 'createTime',
	              title: '创建时间',
	              minWidth: 200,
	              templet: function (data) {
	              	var time = data.createTime
	              	var timeDate = new Date(time)
	              	var year= timeDate.getFullYear()
	              	var month = timeDate.getMonth() + 1
	              	var day = timeDate.getDate()
	              	var hours = timeDate.getHours()
	              	var min = timeDate.getMinutes()
	              	var sec = timeDate.getSeconds()
	              	return year + '-' +(month<10?'0'+month:month)+ '-'+(day<10?'0'+day:day) + " "+(hours<10?'0'+hours:hours) + ":"+(min<10?'0'+min:min) + ":"+(sec<10?'0'+sec:sec) 
	              }
	            }, {
	              title: '操作',
	              fixed: 'right',
	              width: 260,
	              align: 'center',
	              templet: function (data) {
	                var str = '';
	                str += '<button class="t-btn t-red-btn t-detail-btn" data-id="' + data.ID + '" data-url="' + data.url + '">查看二维码</button>';
	                str += '<button class="t-btn t-red-btn t-edit-btn" data-id=' + data.ID + '  >修改</button>';
	                str += '<button class="t-btn t-red-btn t-delete-btn" data-id=' + data.ID + '>删除</button>';
	                return str;
	              }
	            }]
	          ],
	          id: 'testReload',
	          page: true,
	          response: {
	            statusName: 'code' //数据状态的字段名称，默认：code
	              ,
	            statusCode: 200 //成功的状态码，默认：0
	              ,
	            countName: "count" //数据总数的字段名称，默认：count
	              ,
	            dataName: "data" //数据列表的字段名称，默认：data
	          },
	          request: {
	            pageName: 'pageNo' //页码的参数名称，默认：page
	              ,
	            limitName: 'pageSize' //每页数据量的参数名，默认：limit
	          },
	          done: function (res, curr, count) {
	          	//二维码
	            $(".t-detail-btn").on("click", function () {
	              var  url = $(this).data("url");
	              if(url){
	              	window.open(imageServer + url);
	              }else{
	              	return
	              }
	            });
	            //删除
	            $(".t-delete-btn").on("click", function () {
	            	var id = $(this).data("id");
	            	layer.confirm('确定删除？', {
					  btn: ['确认','取消'] //按钮
					  ,yes: function(index){
					  	$.ajax({
					  	  type: "post",
					  	  url: contextPath + "/pblic/no/deleteGroup",
					  	  data: {
					  	    id: id
					  	  },
					  	  success: function (data) {
					  	    if (data.code == ERROK) {
					  	    	_this.againRenderTable();
					  	    	layer.close(index);
					  	    } else {
					  	      layer.msg(data.msg)
					  	    }
					  	  },
					  	  error: function (error) {
					  	    layer.msg('error')
					  	  }
					  	});
					  }
					  ,no: function(index){
					    layer.close(index);
					  }
					})
	            });
	            //修改
	            $(".t-edit-btn").on("click", function () {
	              var id = $(this).data("id");
	              location.href=contextPath + '/pblic/no/form?publicnoId=' + id;
	            });
	          }
	        });

	      });
	    },
	    /*重新渲染table*/
	    againRenderTable: function (option) {
	      var obj = $.extend(true, {}, option);
			var type =  obj.type || ''
			var $orgId = $("#conditionform  .single-orgid");
			var orgId = $("#conditionform  #orgId").attr('org__id')
			if(type == 1){
				table.reload('testReload', {
					where: {
						organizationId: $orgId.length?orgId:'',
						name: '',
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}else{
				table.reload('testReload', {
					where: {
						organizationId: orgId,
						name: $(".groupName").val() || '',
					},
					page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
	    },
	    /**
	     * 请求详情
	     * @param id
	     * @param callback
	     */
	    ajaxDetail: function (id, callback) {
	      var _this = this;
	      $.ajax({
	        type: "post",
	        url: contextPath + "/lingling/getDeviceGroupInfo",
	        data: {
	          id: id
	        },
	        success: function (data) {
	          if (data.code == ERROK) {
	            callback(data.data)
	          } else {
	            layer.msg(data.msg)
	          }
	        },
	        error: function (error) {
	          layer.msg('error')
	        }
	      });
	    },
	  };
	  api.init();
	})
</script>

</html>