<!-- 成员授权编辑页面 -->
<extend name="Public/base" />
<block name="body">
  <div class="main-place">
    <span class="main-placetitle">位置</span>
    <ul class="main-placeul">
      <li><a href="{:U('User/index')}">用户</a></li>
      <li><a href="{:U('User/index')}">管理组</a></li>
      <li><a href="#">{$meta_title}</a></li>
    </ul>
  </div>
  <div class="tab-wrap">
    <div class="tab_nav">
      <ul>
        <li><a href="{:U('AuthManager/access',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">访问授权</a></li>
        <li><a href="{:U('AuthManager/category',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">分类授权</a></li>
<!--        <li><a href="{:U('AuthManager/dataempower',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">数据授权</a></li>-->
        <li class="current"><a href="javascript:;">数据授权</a></li>
        <li><a href="{:U('AuthManager/user',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">成员授权</a></li>
        <if condition="$_GET['group_id'] eq 11 or $_GET['group_id'] eq 12 or $_GET['group_id'] eq 21">
          <li><a href="{:U('AuthManager/AuthMarketMember',array('group_name'=>I('group_name') ,'group_id'=> I('group_id')))}">市场专员分成</a></li>
        </if>
<!--        <li class="current"><a href="javascript:;">成员授权</a></li>-->
        <li class="fr tab_select">
          <select name="group">
            <volist name="auth_group" id="vo">
              <option value="{:U('AuthManager/dataempower',array('group_id'=>$vo['id'],'group_name'=>$vo['title']))}" <eq name="vo['id']" value="$_GET['group_id']">selected</eq> >{$vo.title}</option>
            </volist>
          </select>
        </li>
      </ul>
    </div>


    <div class="tab-wrap">

      <div class="tab-content tabcon1711"  style="margin-top: 20px;">
        <span style="font-size: 20px;font-weight: 600;padding-left: 15px;padding-bottom: 30px">数据授权</span>
        <!-- 表单 -->
        <form id="form" action="{:U('dataEmpowerSave?model='.$model['id'])}" method="post" class="form-horizontal">
          <!-- 基础文档模型 -->
          <div id="tab1" class="tab-pane in tab1"  style="margin-top: 10px;">
            <table  border="0" cellspacing="0" cellpadding="0">
              <tbody>
              <tr>
                <td class="l" style="padding-left: 15px;">数据授权类型:</td>
                <td class="r table_radio">
                        <span class="form_radio table_btn" style="width: auto">
                            <label >
                                <input type="radio"  value="1" name="data_empower_type" <eq name="data_empower_type" value="1">checked="checked"</eq>>可查看全部数据
                            </label >
                            <label >
                                <input type="radio"  value="2" name="data_empower_type" <eq name="data_empower_type" value="2">checked="checked"</eq>>可查看部分数据
                            </label>
                            <label >
                                <input type="radio"  value="3" name="data_empower_type" <eq name="data_empower_type" value="3">checked="checked"</eq>>只能查看自己创建的会长数据
                            </label>
                        </span>
<!--                  <span class="notice-text">锁定状态下,推广员账号则无法登录</span>-->
                <input type="hidden" name="group_id" id="group_id" value="{$_GET['group_id']}">
                  <input type="hidden"  name="promote_data" id="promote_data" value="[]">
                </td>
              </tr>

              <tr>
                <td class="l noticeinfo" style="padding-left: 15px;">数据展示权限:</td>
                <td class="r table_radio">
                                <span class="form_radio table_btn">
                                    <label>
                                        <input type="radio" class="inp_radio" value="1"  name="show_data"
                                        <if condition="$show_data==1"> checked </if>> 是
                                    </label>
                                    <label>
                                        <input type="radio" class="inp_radio" value="0"  name="show_data"
                                        <if condition="$show_data==0"> checked </if>> 否
                                    </label>
                                </span>
                  <span class="notice-text"></span>
                </td>
              </tr>

              </tbody>
            </table>
          </div>
          <link rel="stylesheet" type="text/css" href="__STATIC__/layui-v2.5.5/css/layui.css">

          <if condition="$data_empower_type neq 2">
            <div id="test4" class="demo-transfer" style="margin-left: 100px;margin-top: 35px;display: none" ></div>
            <else/>
            <div id="test4" class="demo-transfer" style="margin-left: 100px;margin-top: 35px"></div>
          </if>

          <div class="form-item cf">
            <button class="submit_btn ajax-post mlspacing" id="submit" type="submit" target-form="form-horizontal" >
              确认
            </button>
            <a class="submit_btn " alt="返回上一页" title="返回上一页" href="{:U('index')}"  style="color:#000000;background:#ffffff;border: solid 1px #000">
              返回
            </a>
          </div>
        </form>
      </div>
    </div>


  </div>

  <div class="common_settings">
    <span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
    <form class="addShortcutIcon">
      <input type="hidden" name="title" value="{$m_title}">
      <input type="hidden" name="url" value="AuthManager/index">
    </form>
    <a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
  </div>

</block>


<block name="script">

  <script src="__STATIC__/layui-v2.5.5/layui.all.js"></script>

  <script>
    var dataTransfer = '';
    $.ajax({
      url: "{:U('getRootPromote')}",
      type: "post",
      data: {group_id: $('#group_id').val()},
      dataType: 'json',
      success: function (data) {
        // datas = data;
        layui.use(['transfer', 'layer', 'util'], function(){
          var $ = layui.$
            ,transfer = layui.transfer
            ,layer = layui.layer
            ,util = layui.util;

          var data1 =data;

          if (JSON.parse(data1).data_president) {
            var data2 = JSON.parse(data1).data_president.split(",");
          }
          // var dataTransfers = transfer.getData('key123');
          // $('#promote_data').val(JSON.stringify(dataTransfers));
          //显示搜索框
          transfer.render({
            elem: '#test4'
            ,data: JSON.parse(data1).list
            ,title: ['全部成员', '选中成员']
            ,showSearch: true,
            value: data2,
            id: 'key123',
            onchange: function(data, index){

              dataTransfer = transfer.getData('key123'); //获取右侧数据

              if (index == 0) {

                for (var i=0;i<data.length;i++) {
                  data2.push(data[i]['value']);
                }
                $('#promote_data').val(JSON.stringify(dataTransfer));
                return;
              } else if (index == 1){

                for(var i=0;i<data2.length;i++)
                {
                  console.log(data2[i])
                  for(var j=0;j<data.length;j++) {
                    if (data2[i]==data[j]['value']) {
                      data2.splice(i,1);
                      i=i-1;
                    }
                  }
                }

                // data2.push(data[0]['value']);
                console.log(data2)
                transfer.reload('key123',{elem: '#test4',data: JSON.parse(data1).list,title: ['全部成员', '选中成员'],showSearch: true,value: data2,id: 'key123'});
                dataTransfer = transfer.getData('key123');
                $('#promote_data').val(JSON.stringify(dataTransfer));
                return;
              }
              
            }
          })

          var dataTransfers = transfer.getData('key123');
          $('#promote_data').val(JSON.stringify(dataTransfers));
          transfets = transfer;
          //批量办法定事件
          util.event('lay-demoTransferActive', {
            getData: function(othis){
              var getData = transfer.getData('key123'); //获取右侧数据
              layer.alert(JSON.stringify(getData));
            }
            ,reload:function(){
              //实例重载
              transfer.reload('key123', {
                title: ['文人', '喜欢的文人']
                ,value: ['2', '5', '9']
                ,showSearch: true
              })
            }
          });

        });
      }
    });

    $(function () {
      var status = $('input:radio[name="data_empower_type"]:checked').val();
      $('#status').val(status);
    });
    $(":radio").click(function () {
      var status = $('input:radio[name="data_empower_type"]:checked').val();
      $('#status').val(status);
      if (status != 2) {
        $("#test4").css('display','none');
        $('#promote_data').val('[]');
      } else {
        $("#test4").css('display','block');
        $('#promote_data').val(JSON.stringify(dataTransfer));
      }
    })
  </script>

  <script type="text/javascript" charset="utf-8">
    $('select[name=group]').change(function(){
      location.href = this.value;
    });
    //导航高亮
    highlight_subnav('{:U('AuthManager/index')}');

  </script>
  <style>
    .layui-transfer-box{
      overflow: hidden;
      height: 410px!important;
    }
  </style>
</block>