{extend name="base" /}
{block name="body"}
  <input type="text" class="layui-input" id="test1" value="{:date('Y-m-d')}" style="width: 100px;z-index: 10;position: absolute;left: 350px;" readonly="readonly">
  <a href="#3" id="loginout" style="z-index: 10;position: absolute;right: 50px;">重新登录</a>
  <span style="position: absolute;right: 150px;">当前店：{:session('shop_name')}</span>

<div class="layui-tab" lay-filter="tab">
  <ul class="layui-tab-title">
    <li>未进店</li>
    <li class="layui-this">已进店未分配</li>
    <li>已进店已分配</li>
  </ul>
  <div class="layui-tab-content">
    <div class="layui-tab-item ">
      <table id="table1" lay-filter="table1"></table>
    </div>
    <div class="layui-tab-item layui-show">
      <table id="table2" lay-filter="table2"></table>
    </div>
    <div class="layui-tab-item">
      <table id="table3" lay-filter="table3"></table>
    </div>
  </div>
</div>
 

<script type="text/html" id="indexTpl">
    {{ d.LAY_INDEX }}
</script>
<script type="text/html" id="recepTpl">
    {{# if(d.reception_name == '' || d.reception_name == undefined) { }}
    <a href="#" onclick="updateReception({{d.id}})"  class="layui-table-link">分配门市</a>
    {{# } else { }}
    <a href="#" onclick="updateReception({{d.id}},{{d.reception_id}})" class="layui-table-link">{{d.reception_name}}</a>
    {{# } }}
</script>
<script type="text/javascript" id="intoTpl">
    {{# if (d.is_intostore == '1') { }}
        未进店
    {{# }else if (d.is_intostore == '2') { }}
        进客进店
    {{# }else if (d.is_intostore == '3') { }}
        非进客进店
    {{# }else if (d.is_intostore == '4') { }}
        邀约未进店
    {{# }else if (d.is_intostore == '5') { }}
        进店未成交
    {{# }else{ }}
        未知
    {{# } }}
</script>
{/block}
<script type="text/javascript">
{block name="bodyScript"}
var table,table1,table2,table3;
var current_date = '{:date("Y-m-d")}';
var today = '{:date("Y-m-d")}';

var tab_index = 2;
var lastRowColer = '';
var lastSelectRow = '';
layui.use(['table','laydate','element'], function(){
  table = table1 = table2 = table3 = layui.table;
  var element = layui.element;
  //第一个实例
  render_table();
  var laydate = layui.laydate;
  
  //执行一个laydate实例
  laydate.render({
    elem: '#test1' //指定元素
    ,done: function(value, date, endDate){
        current_date = value;
        render_table();
    }
  });


  element.on('tab(tab)', function(data){
      tab_index = data.index + 1
      render_table();
  });


});
function updateReception(into_id,oldid){
    if(today != current_date){
        alert('不是当天的客资不能分配门市');
        return false;
    }
    if(oldid){
        var url = '/mobile/intostore/updateReception.html?oldid='+oldid;
    }else{
        var url = '/mobile/intostore/updateReception.html';
    }
    load_page(url,'分客门市',function(){
        var id = $('#reception').val();
        var text = $('#reception').find("option:selected").text();
        if(!id){
            layer.alert('请选择一个门市');
            return false;
        }
        $.ajax({
            type: "POST",
            url: '/mobile/intostore/updateReception',
            data: {reception_id:id,reception_name:text,id:into_id},
            success: function(res){
                if(res.code == 200){
                    layer.alert('分配成功');
                }else{
                    layer.alert('分配失败，请重试。'+res.msg);
                }
            }
        });

    },false,450,400);
}
function loginout(){
    $.get('/crm/customer/logout.html',function(){
        location.reload();
    });
}
function render_table(){
    var index = tab_index;
    table.render({
      elem: '#table'+index
      //,height:'full-50'
      ,even:true
      ,url: '/mobile/intostore/index.html?tab='+index+'&date='+current_date //数据接口
      ,response:{statusCode: 200}
      ,cols: [[ //表头
        { title: '...', width:60, templet: '#indexTpl'}
        ,{field: 'customer_id', title: '客资ID', width:80}
        
        ,{field: 'customer_name', title: '顾客姓名', width:150,edit:true}
        ,{field: 'customer_tel', title: '手机号', width:150}
        ,{field: 'mate_tel', title: '配偶手机号', width: 150}
        ,{field: 'customer_sex', title: '性别', width:60}
        ,{field: 'reception_name', title: '接待门市', width: 100, sort: true ,templet:'#recepTpl'}
        ,{field: 'is_intostore', title: '进店状态', width: 100 ,templet:'#intoTpl'}
        ,{field: 'yjd_day', title: '预约时间', width: 200, sort: true}
        ,{field: 'syjd_day', title: '进店时间', width: 200, sort: true}
      ]]
    });
    table.on('row(table'+index+')', function(obj){
          if(lastSelectRow != ''){
              $(lastSelectRow).css("backgroundColor",lastRowColer);
          }
          var index = $(obj.tr.selector).attr('data-index');
          if(index%2 === 0){
              lastRowColer = '#fff';
          }else{
              lastRowColer = '#f2f2f2';
          }
          lastSelectRow = obj.tr.selector;
          console.log(lastRowColer);
          $(obj.tr.selector).css('backgroundColor','#b0d8ff');
    });
}
$('#loginout').click(function(){
    loginout();
});
{/block}
</script>