<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card layui-form">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <sfTags:pagePermission authFlag="FACTORY_MESSAGE_SET_T" html='<li class="layui-this">
						<a href="${ctx}/siteInformation/siteDataList">服务商资料设置</a>
					</li>'/>
                <button class="layui-btn f-r mt-10 mr-15 pl-10 pr-10 " id="searchBtn" data-type="reload">
                    <i class="layui-icon fs-12">&#xe615;</i>查询
                </button>
            </ul>
        </div>

        <div class="layui-card-body layuiadmin-card-header-auto" >
            <form class="layui-form layui-card" action="" id="searchForm">
            <div class="layui-form-item">
                <div class="layui-col-md2 layui-col-sm3">
                    <label class="layui-form-label">服务商名称：</label>
                    <div class="layui-input-block">
                        <input type="text" name="name" class="layui-input" id="siteName" >
                    </div>
                </div>
                <div class="layui-col-md2 layui-col-sm3">
                    <label class="layui-form-label">企业地址：</label>
                    <div class="layui-input-block">
                        <input type="text" name="province" class="layui-input" id="province" >
                    </div>
                </div>
                <div class="layui-col-md2 layui-col-sm3">
                    <label class="layui-form-label">企业电话：</label>
                    <div class="layui-input-block">
                        <input type="text" name="telephone" class="layui-input" id="telephone" >
                    </div>
                </div>
            </div>
            </form>
        </div>

            <div class="layui-card-body">
                <table class="layui-hide " id="test" lay-filter="test"></table>
            </div>

    </div>
</div>
<div id="toolbarDemo" class="layui-form-item layui-hide">
    <sfTags:pagePermission authFlag="XTSZ_FWSXX_FWSXX_DC_BTN" html='<button class="layui-btn layui-btn-sm" id="exportBtn" lay-event="exports"><i class="layui-icon layui-icon-export"></i>导出 </button>'/>
    <sfTags:pagePermission authFlag="XTSZ_FWSXX_FWSXX_SQST_BTN" html='<button class="layui-btn layui-btn-sm"  lay-event="authorize">授权使用 </button>'/>
    <sfTags:pagePermission authFlag="XTSZ_FWSXX_FWSXX_QXSQ_BTN" html='<button class="layui-btn layui-btn-sm"  lay-event="deleAuthorize">取消授权 </button>'/>
    <sfTags:pagePermission authFlag="XTSZ_FWSXX_FWSXX_QRHZ_BTN" html='<button class="layui-btn layui-btn-sm"  lay-event="cooperate">确认合作 </button>'/>
    <sfTags:pagePermission authFlag="XTSZ_FWSXX_FWSXX_QXHZ_BTN" html='<button class="layui-btn layui-btn-sm"  lay-event="deleCooperate">取消合作</button>'/>
</div>
</div>


<div class="layui-card mb-0 pr-30 hide siteRemarks">
    <div class="layui-card-body">
        <div class="layui-row">
            <div class="layui-col-xs12">
                <label class="layui-form-label"><i class="mark">*</i>备注：</label>
                <div class="layui-input-block">
                    <textarea name="siteRemarks" id="siteRemarks" class="layui-textarea" lay-verify="description"></textarea>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" id="siteId">
 <%--   <div class="layui-form-item  ">
        <input type="button" lay-submit lay-filter="sureSubmit" id="sureSubmit" value="确认">
    </div>--%>
    <div class="layui-col-xs12 text-c mt-20">
        <button class="layui-btn" lay-submit="siteRemarkUp" id="siteRemarkUp" lay-filter="siteRemarkUp">保存</button>
    </div>
</div>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/data.js"></script>
<script type="text/javascript">
    var saveMark = false;
    //初始数据
    var $form;
    var form;
    var upload;
    var $;
    var table;
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'tableExt', 'jquery', 'layer','laypage','laydate','form','excel'], function(){
        $ = layui.$
            ,form = layui.form
            ,tableExt = layui.tableExt;
            table = layui.table;
        var excel = layui.excel;
        //服务商信息列表
        tableExt.render({
            elem: '#test'
            , height: 'full-200'
            , id: 'test'
            , defaultToolbar: false
            , url: '${ctx}/siteInformation/site'
            , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
            , page: true
             ,toolbar:"#toolbarDemo"
            , limits: [20, 50, 100]
            , limit: 20
            , cols: [[
                {field: 'number', width: 50, title: '序号', align: 'center', type: 'numbers',rowspan:'2', fixed: 'left'}
                ,{field : 'id', width : '4%',checkbox : true,align : 'center',rowspan:'2' , fixed: 'left'}
                , {field: 'mobile', title: '操作', width: 260, align: 'center',rowspan:'2', fixed: 'left',
                    templet: function (d) {
                    var add;
                        if (isBlank(d.provincet)) {
                            add = '<a class="layui-btn layui-btn-xs" lay-event="add"><i class="layui-icon fs-16">&#xe654;</i>添加地址</a>';
                        }else{
                            add = '<a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon fs-16">&#xe642;</i>编辑地址</a>'
                        }
                        add =add+ ' <a class="layui-btn layui-btn-xs" lay-event="updateRem"><i class="layui-icon fs-16">&#xe642;</i>编辑备注</a>'
                   /*     if(d.site_type == 2){
                            add =add+ '<a class="layui-btn layui-btn-xs" onclick="denglsj(\'' + d.id + '\',\'' + d.user_id + '\')"><i class="layui-icon fs-16">&#xe642;</i>登陆后台</a>'
                        }*/
                        // href="${ctx}/sys/excellentMember/jumpToBackStage?id='+d.id+'&userId='+d.user_id+'"
                      /*  if (isBlank(d.namet)) {
                            edit = '<a class="layui-btn layui-btn-xs" lay-event="addNew"><i class="layui-icon fs-16">&#xe654;</i>添加品类</a>'
                        }else{
                            edit = '<a class="layui-btn layui-btn-xs" lay-event="editorNew"><i class="layui-icon fs-16">&#xe642;</i>修加品类</a>'
                        }*/
                     return add;
                    },
                }
                , {field: 'name', title: '服务商名称', width: 150, align: 'center',exportable:true ,rowspan:'2', fixed: 'left'}
                , {field: 'status', title: '是否授权', width: 100, align: 'center',exportable:true ,rowspan:'2',
                   templet:function(d){
                    if(d.status=='2'){
                       return "否";
                    }else{
                           return "是";
                       }
                   }
                   ,expFormat:function(d){
                        if(d.status=='2'){
                            return "否";
                        }else{
                            return "是";
                        }
                    }
                }
                , {field: 'status', title: '是否合作', width: 100, align: 'center',exportable:true ,rowspan:'2',
                    templet:function(d){
                        if(d.status=='2' || d.status=='4'){
                            return "否";
                        }else{
                            return "是";
                        }
                    }
                    ,expFormat:function(d){
                        if(d.status=='2' || d.status=='4'){
                            return "否";
                        }else{
                            return "是";
                        }
                    }
                }
                , {field: 'remarks', width: 150, title: '备注', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'contacts', width: 150, title: '联系人', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'mobile', width: 180, title: '联系电话', align: 'center',exportable:true ,rowspan:'2'}
                , {field: 'province', title: '企业地址', width: 400, align: 'center',exportable:true ,rowspan:'2',
                    templet: function (d) {
                        if (!isBlank(d.province) && !isBlank(d.city) && !isBlank(d.area) && !isBlank(d.address)) {
                            return d.province+d.city+d.area+d.address;
                        }else{
                            return "";
                        }
                    },
                    expFormat:function (d) {
                        if (!isBlank(d.province) && !isBlank(d.city) && !isBlank(d.area) && !isBlank(d.address)) {
                            return d.province+d.city+d.area+d.address;
                        }else{
                            return "";
                        }
                    }
                }

                , {field: 'provincet', title: '计算里程默认地址', width: 400, align: 'center',exportable:true ,rowspan:'2',
                    templet: function (d) {
                        if (!isBlank(d.provincet) && !isBlank(d.cityt) && !isBlank(d.areat) && !isBlank(d.addresst)) {
                            return d.provincet+d.cityt+d.areat+d.addresst;
                        }else{
                            return "";
                        }
                    },
                    expFormat:function (d) {
                        if (!isBlank(d.provincet) && !isBlank(d.cityt) && !isBlank(d.areat) && !isBlank(d.addresst)) {
                            return d.provincet+d.cityt+d.areat+d.addresst;
                        }else{
                            return "";
                        }
                    }
                }
                , {field: 'create_time', title: '注册时间', width: 200, align: 'center',exportable:true ,rowspan:'2'}
                , {align: 'center', title: '派单品类',colspan:'4',exportable:true }
                , {title: '服务品类',colspan:'4', align: 'center',exportable:true}
            ],
                [
                    {field:'namet',title:'安装' ,width:200 ,align: 'center',exportable:true
                    ,templet: function (d) {
                        console.log(d.cate);
                        var html = "<a href=\"#\" class=\"layui-table-link\" onclick=\"addCatory('安装','"+d.id+"')\">添加</a>";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '安装'){
                                        html = "<a href=\"#\" class=\"layui-table-link\" title=\"编辑\" onclick=\"editCatory('安装','"+d.id+"')\">"+htm+"</a>";
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }
                    ,expFormat:function(d){
                        var html="";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '安装'){
                                        html = htm;
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }
                    }
                    ,{field:'namet',title:'上门维修' ,width:200 ,align: 'center',exportable:true
                    ,templet: function (d) {
                        var html = "<a href=\"#\" class=\"layui-table-link\" onclick=\"addCatory('上门维修','"+d.id+"')\">添加</a>";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '上门维修'){
                                        html = "<a href=\"#\" class=\"layui-table-link\" title=\"编辑\" onclick=\"editCatory('上门维修','"+d.id+"')\">"+htm+"</a>";
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }}
                    ,{field:'namet',title:'用户送修' ,width:200 ,align: 'center',exportable:true
                    ,templet: function (d) {
                        var html = "<a href=\"#\" class=\"layui-table-link\" onclick=\"addCatory('用户送修','"+d.id+"')\">添加</a>";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '用户送修'){
                                        html = "<a href=\"#\" class=\"layui-table-link\" title=\"编辑\" onclick=\"editCatory('用户送修','"+d.id+"')\">"+htm+"</a>";
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }}
                    ,{field:'namet',title:'清洗保养' ,width:200 ,align: 'center',exportable:true
                    ,templet: function (d) {
                        var html = "<a href=\"#\" class=\"layui-table-link\" onclick=\"addCatory('清洗保养','"+d.id+"')\">添加</a>";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '清洗保养'){
                                        html = "<a href=\"#\" class=\"layui-table-link\" title=\"编辑\" onclick=\"editCatory('清洗保养','"+d.id+"')\">"+htm+"</a>";
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }}

                   , {field:'category_name',title:'安装' ,width:200 ,align: 'center' ,exportable:true
                , templet: function (d) {
                        var html="";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.category_name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '安装'){
                                        html = htm;
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }
                }
                    ,{field:'category_name',title:'上门维修' ,width:200 ,align: 'center' ,exportable:true
                    , templet: function (d) {
                        var html="";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.category_name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '上门维修'){
                                        html = htm;
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }
                }
                    ,{field:'category_name',title:'用户送修' ,width:200 ,align: 'center' ,exportable:true
                    , templet: function (d) {
                        var html="";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.category_name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '用户送修'){
                                        html = htm;
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }}
                    ,{field:'category_name',title:'清洗保养' ,width:200 ,align: 'center'  ,exportable:true
                    , templet: function (d) {
                        var html="";
                        if(d.cate.length>0){
                            $.each(d.cate, function(i, value) {
                                var setType = value.service_type;
                                var htm=value.category_name;
                                if(isBlank(htm)){
                                    return ;
                                }else{
                                    if(setType == '清洗保养'){
                                        html = htm;
                                        return ;
                                    }
                                }
                            });
                        }
                        return html;
                    }}
                ]
            ]
            ,exportOpt:{                           //导出选项配置
                ele:'#exportBtn',                   //导出的Dom元素
                headerTitle: '服务商信息',             //excel表格的标题
                pageData:false,                     //true:导出的数据为页面数据，false:最大导出maxAmount条数据
                maxAmount: 1000,                    //当pageData为false生效
                fileName: '服务商信息',
                where: function (){
                    console.log(_serializeJson($("#searchForm")));//当pageData为false时生效，过滤的条件
                    return _serializeJson($("#searchForm"));
                }
            }
        });

          table.on('toolbar(test)',function(obj){
              var checkStatus = table.checkStatus(obj.config.id);
              if (obj.event === 'authorize') {//授权使用
                  var data = checkStatus.data;
                  if (data.length < 1) {
                      layer.msg("请选择数据",{icon:5,anim:6});
                      return;
                  }
                  var ids="";
                  for(var i=0;i<data.length;i++){
                      if(data[i].status!='2'){
                          layer.msg("有数据已授权，请重新选择!",{icon:5,anim:6});
                          return;
                      }
                      if(data[i].site_type=='1'){
                          layer.msg("思方服务商不能操作此功能，请重新选择!",{icon:5,anim:6});
                          return;
                      }
                      ids+=data[i].id+",";
                  }
                  layer.confirm("确认要给选中的网点授权使用系统吗？", {icon: 3}, function(index){
                      $.ajax({
                          url: '${ctx}/siteInformation/authorize',
                          type: 'post',
                          data: {
                              ids: ids,
                          },
                          success: function(data) {
                              console.log(data);
                              if(data.code=="200"){
                                  layer.msg("授权成功！");
                                  table.reload('test'); //数据刷新
                              }else{
                                  layer.msg(data.msg ,{icon:5,anim:6});
                              }
                          }
                      });
                  })
              }
              if(obj.event === 'deleAuthorize'){ //取消授权
                  var data = checkStatus.data;
                  if (data.length < 1) {
                      layer.msg("请选择数据",{icon:5,anim:6});
                      return;
                  }
                  var ids="";
                  for(var i=0;i<data.length;i++){
                      if(data[i].status=='2'){
                          layer.msg("有数据未授权，请重新选择!",{icon:5,anim:6});
                          return;
                      }
                      if(data[i].site_type == '1'){
                          layer.msg("思方服务商不能操作此功能，请重新选择!",{icon:5,anim:6});
                          return;
                      }
                      ids+=data[i].id+",";
                  }
                  layer.confirm("确认要将选中的网点取消授权使用系统吗？", {icon: 3}, function(index){
                      $.ajax({
                          url: '${ctx}/siteInformation/deleAuthorize',
                          type: 'post',
                          data: {
                              ids: ids,
                          },
                          success: function(data) {
                              console.log(data);
                              if(data.code=="200"){
                                  layer.msg("取消成功！");
                                  table.reload('test'); //数据刷新
                              }else{
                                  layer.msg(data.msg ,{icon:5,anim:6});
                              }
                          }
                      });
                  })
              }
              if(obj.event === 'cooperate'){//确认合作
                  var data = checkStatus.data;
                  if (data.length < 1) {
                      layer.msg("请选择数据",{icon:5,anim:6});
                      return;
                  }
                  var ids="";
                  for(var i=0;i<data.length;i++) {
                      if (data[i].status != "4") {
                          layer.msg("有数据不能操作此功能，请重新选择!", {icon: 5, anim: 6});
                          return;
                      }
                      if (data[i].site_type == '1') {
                          layer.msg("思方服务商不能操作此功能，请重新选择!", {icon: 5, anim: 6});
                          return;
                      }
                      ids += data[i].id + ",";
                  }
                  layer.confirm("确认要与选中的网点合作吗？确认后即可给该网点派工", {icon: 3}, function(index){
                      $.ajax({
                          url: '${ctx}/siteInformation/cooperate',
                          type: 'post',
                          data: {
                              ids: ids,
                          },
                          success: function(data) {
                              console.log(data);
                              if(data.code=="200"){
                                  layer.msg("合作成功！");
                                  table.reload('test'); //数据刷新
                              }else{
                                  layer.msg(data.msg ,{icon:5,anim:6});
                              }
                          }
                      });
                  })
              }
              if(obj.event === 'deleCooperate'){//取消合作
                  var data = checkStatus.data;
                  if (data.length < 1) {
                      layer.msg("请选择数据",{icon:5,anim:6});
                      return;
                  }
                  var ids="";
                  for(var i=0;i<data.length;i++) {
                      if (data[i].status != "0") {
                          layer.msg("有数据不能操作此功能，请重新选择!", {icon: 5, anim: 6});
                          return;
                      }
                      if (data[i].site_type == '1') {
                          layer.msg("思方服务商不能操作此功能，请重新选择!", {icon: 5, anim: 6});
                          return;
                      }
                      ids += data[i].id + ",";
                  }
                  layer.confirm("确认要取消与该网点合作吗？", {icon: 3}, function(index){
                      $.ajax({
                          url: '${ctx}/siteInformation/deleCooperate',
                          type: 'post',
                          data: {
                              ids: ids,
                          },
                          success: function(data) {
                              console.log(data);
                              if(data.code=="200"){
                                  layer.msg("取消成功！");
                                  table.reload('test'); //数据刷新
                              }else{
                                  layer.msg(data.msg ,{icon:5,anim:6});
                              }
                          }
                      });
                  })

              }

          })
       //监听事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'add') {//添加地址
                var editId = data.id;
                layer.open({type: 2,
                    title: '添加地址',
                    content: '${ctx}/siteInformation/addRess?id='+editId,
                    area: ['500px', '360px'],
                    btn : [ '保存', '取消' ],
                    yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-front-addRess'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            addMark(field, index,editId);
                        });
                        submit.trigger('click');
                    },
                    success : function(layero) {
                    layero.find('.layui-layer-btn').css('text-align', 'center');
                    layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                }
                });
            }else if (obj.event === 'edit') {//编辑地址
                var editId = data.id;
                layer.open({
                    type: 2
                    ,
                    title: '编辑地址'
                    ,
                    content: '${ctx}/siteInformation/editAddRess?id='+editId
                    ,
                    area: ['500px', '360px']
                    ,
                    btn : [ '保存', '取消' ],
                    yes: function (index, layero) {
                        var iframeWindow = window['layui-layer-iframe' + index]
                            , submitID = 'LAY-user-front-addRess'
                            , submit = layero.find('iframe').contents().find('#' + submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                            var field = data.field; //获取提交的字段
                            editAddressMark(field, index,editId);
                        });
                        submit.trigger('click');
                    },
                    success : function(layero) {
                        layero.find('.layui-layer-btn').css('text-align', 'center');
                        layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
                    }
                });
            }
            else if(obj.event =='updateRem'){
                var editId = data.id;
                $("#siteId").val(editId);
                $("#siteRemarks").val(data.remarks);
                layer.open({
                    type: 1,
                    title:"编辑备注",
                    content: $('.siteRemarks') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    ,area: ['500px', '260px']
                });

            }
        });

        form.on('submit(siteRemarkUp)', function (data) {
        var siteRemarks = $("#siteRemarks").val();
        var siteId = $("#siteId").val();
        if(isBlank(siteRemarks)){
            layer.msg("请输入备注!",{icon:2})
            return
        }
            $.ajax({
                type:"POST",
                url:"${ctx}/siteInformation/updateSiteRemarks",
                data:{
                    siteId:siteId,
                    siteRemarks:siteRemarks
                },
                success:function(result){
                    layer.msg("添加成功!",{icon:1,time:1000},function(){
                        table.reload('test'); //数据刷新
                        layer.closeAll(); //关闭弹层
                    })

                }
            })
        })

        //编辑地址
        var noRepeatAdd = false;
        function editAddressMark(data, index,id) {
            if (noRepeatAdd) {
                return;
            }
            noRepeatAdd = true;
            $.ajax({
                url: '${ctx}/siteInformation/editorAddressSave',
                type: 'post',
                data: {
                    id:id,
                    province: data.province,
                    city: data.city,
                    area: data.area,
                    address: data.address
                },
                success: function (data) {
                    if (data.code == "200") {
                        layer.msg("添加成功！", {icon: 1});
                        table.reload('test'); //数据刷新
                        layer.close(index); //关闭弹层
                    } else if (data.code == "205") {
                        layer.msg("添加失败！", {icon: 2});
                        table.reload('test'); //数据刷新
                    }
                },
                complete: function () {
                    noRepeatAdd = false;
                }
            });
        }


        //新增地址
        var noRepeatAdd = false;
        function addMark(data, index,id) {
            if (noRepeatAdd) {
                return;
            }
            noRepeatAdd = true;
            $.ajax({
                url: '${ctx}/siteInformation/addRessSave',
                type: 'post',
                data: {
                    id:id,
                    province: data.province,
                    city: data.city,
                    area: data.area,
                    address: data.address
                },
                success: function (data) {
                    if (data.code == "200") {
                        layer.msg("添加成功！", {icon: 1});
                        table.reload('test'); //数据刷新
                        layer.close(index); //关闭弹层
                    } else if (data.code == "205") {
                        layer.msg("添加失败！", {icon: 2});
                        table.reload('test'); //数据刷新
                    }
                },
                complete: function () {
                    noRepeatAdd = false;
                }
            });
        }

        function isBlank(val) {
            if (val == null || val == '' || val == undefined) {
                return true;
            }
            return false;
        }
        $('#searchBtn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        var active = {
            reload: function(){
                table.reload('test', {
                    where: {
                        name: $('#siteName').val().trim(),
                        province:$("#province").val().trim(),
                        telephone:$("#telephone").val().trim(),
                        site_type:$("#site_type").val()
                    }
                });
            }
        };
    });
    function addCatory(serviceType,id){
        layer.open({
            type: 2,
            title: '添加品类',
            content: '${ctx}/siteInformation/addCategory?serviceType='+serviceType+'&siteId='+id,
            area: ['600px', '430px'],
            btn : [ '保存', '取消' ],
            yes: function (index, layero) {
                var iframeWindow = window['layui-layer-iframe' + index]
                    , submitID = 'LAY-user-front-addCategory'
                    , submit = layero.find('iframe').contents().find('#' + submitID);

                //监听提交
                iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                    var field = data.field; //获取提交的字段
                    var datas = [];
                    var service_type=field.service_type;
                    var siteId=field.siteId;
                    layero.find('iframe').contents().find(".layui-form-checked").each(function (index) {
                        var name = $(this).prev().val();
                        if(index==0 && name=="all"){

                        }else{
                            datas.push(name);
                        }
                    });
                   /* console.log(service_type);*/
                  addCategoryMark(datas, index,service_type,siteId);
                });
                submit.trigger('click');
            },
            success : function(layero) {
                layero.find('.layui-layer-btn').css('text-align', 'center');
                layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
            }
        });
    }

    function editCatory(serviceType,id){
        layer.open({type: 2,
            title: '编辑品类',
            content: '${ctx}/siteInformation/editorCategory?serviceType='+serviceType+'&siteId='+id,
            area: ['600px', '430px'],
            btn : [ '保存', '取消' ],
            yes: function (index, layero) {
                var iframeWindow = window['layui-layer-iframe' + index]
                    , submitID = 'LAY-user-front-addCategory'
                    , submit = layero.find('iframe').contents().find('#' + submitID);

                //监听提交
                iframeWindow.layui.form.on('submit(' + submitID + ')', function (data) {
                    var field = data.field; //获取提交的字段
                    var datas = [];
                    var service_type=field.service_type;
                    var siteId=field.siteId;
                    layero.find('iframe').contents().find(".layui-form-checked").each(function (index) {
                        var name = $(this).prev().val();
                        datas.push(name);
                    });
                    editorCategoryMark(datas, index,service_type,siteId);
                });
                submit.trigger('click');
            },
            success : function(layero) {
                layero.find('.layui-layer-btn').css('text-align', 'center');
                layero.find('.layui-layer-btn').find(".layui-layer-btn0").css("background-color","#009688");
            }
        });

    }
    //编辑品类
    var noRepeat = false;
    function editorCategoryMark(datas, index,serviceType,siteId) {
        if (noRepeat) {
            return;
        }
        noRepeat = true;
        $.ajax({
            url: '${ctx}/siteInformation/editorCategorySave',
            type: 'post',
            data: {
                siteId:siteId,
                data: datas.join(","),
                serviceType:serviceType,
            },
            success: function (data) {
                if (data.code == "200") {
                    layer.msg("编辑成功！", {icon: 1});
                    table.reload('test'); //数据刷新
                    layer.close(index); //关闭弹层
                } else if (data.code == "205") {
                    layer.msg("编辑失败！", {icon: 2});
                    table.reload('test'); //数据刷新
                }
            },
            complete: function () {
                noRepeat = false;
            }
        });
    }

    //新增品类
    var noRepeatAdd = false;
    function addCategoryMark(datas, index,serviceType,siteId) {
        if (noRepeatAdd) {
            return;
        }
        noRepeatAdd = true;
        $.ajax({
            url: '${ctx}/siteInformation/addCategorySave',
            type: 'post',
            data: {
                serviceType:serviceType,
                data:datas.join(","),
                siteId:siteId
            },
            success: function (data) {
                if (data.code == "200") {
                    layer.msg("添加成功！", {icon: 1});
                    table.reload('test'); //数据刷新
                    layer.close(index); //关闭弹层
                } else if (data.code == "205") {
                    layer.msg("添加失败！", {icon: 2});
                    table.reload('test'); //数据刷新
                }
            },
            complete: function () {
                noRepeatAdd = false;
            }
        });
    }

    function  denglsj(id,userId) {
        console.log("siteInfo" + id +" userId : "+ userId)
       parent.denglusdj(id,userId);
    }

</script>
</body>
</html>
