<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>收佣管理</title>
</head>
<body>
<h2 class="title">收佣管理</h2>
<br/>
<form action="" method="POST" enctype="multipart/form-data" id="commissionManage" class="form-inline">
    <div class="row" >
        <div class="col-md-10">
            <div class="row">
                <div class="col-md-8">
                    <div id="staffImg">
                    </div><br />
                    <button type="button" class="button action" data-toggle="modal" data-target="#myConsultant" id="recConsultantBt">
                        选择员工
                    </button>
                </div>
            </div>
            <br/>
            <div class="row">
                <div class="col-md-8">
                    <label for="intent">目标业绩：</label>
                    <input name="intent" id="intent" type="text"  class="form-control" disabled="true">
                </div>
            </div>
            <br/>
            <div class="row">
                <div class="col-md-8">
                    <label for="completeRate">达成率：</label>
                    <input id="completeRate" type="text"  class="form-control" readonly>
                </div>
            </div>
            <br/>
            <div class="row">
                <div class="col-md-8">
                    <label for="accounts">应收佣金：</label>
                    <input name="accounts" id="accounts" type="text"  class="form-control">
                </div>
            </div>
            <br/>
            <div class="row">
                <div class="col-md-8">
                    <button type="button" class="button action" id="paid">
                        添加实收佣金
                    </button>
                </div>
            </div>
            <table class="form-table">
                <tbody id="paidTbody">

                </tbody>
            </table>

        </div>
        <div class="col-md-2">
            <div  class="row" style="position: fixed;top:100px;">
                <select name="businessType">
                    <option value="0">买卖</option>
                    <option value="1">租赁</option>
                </select>
            </div>
            <div class="row">
                <input type="submit" id="submit" class="button action" style="position: fixed;top:150px">
            </div>
        </div>
    </div>
</form>
{% include 'recConsultant.html' %}
{{ block('recConsultant') }}
<script>
    (function($){
        $(document).ready(function(){
            var d = new Date();
            var month = d.getMonth()+1;
            var day = d.getDate();
            var output = d.getFullYear() + '/' +
                    (month<10 ? '0' : '') + month + '/' +
                    (day<10 ? '0' : '') + day;

            init_modal_myConsultantList(addStaff);
            $("form").on('click','#paid',function(){
                var tr = $("<tr>");
                var th = $("<th>");
                var td = $("<td>");
                var paidTime = $("<input>").attr({"type":"text","value":output}).addClass("form-control");
                var paid = $("<input>").attr({"type":"text"}).addClass("form-control");
                var paiiDelet =  $("<input>").attr({"type":"button","value":"删除"}).addClass("button action paiiDelet form-control");
                var th1 = th.clone().append("实收时间：");
                var td1 = td.clone().append(paidTime);
                var th2 = th.clone().append("实收佣金：");
                var td2 = td.clone().append(paid);
                var td3 = td.clone().append(paiiDelet);
                tr.append(th1).append(td1).append(th2).append(td2).append(td3);
                $("#paidTbody").append(tr);
            });


            $("#staffImg").on("click",".consultantCancel",function(){
                $(this).parents("p").remove();
            });

            $("#accounts").change(function(){
                if($("#accounts").val().length > 0){
                    $("#intent").removeAttr("disabled");
                }else{
                    $("#intent").attr("disabled","true");
                }
            });

            $("#paidTbody").on("click",".paiiDelet",function(){
                $(this).parents("tr").remove();
            })




        });
        function addStaff(data){
            var row = $("<div>").addClass("row").css("margin-bottom","10px");
            var left = $("<div>").addClass("col-md-2");
            var img = $("<img>").attr({"src":data.imageUrl,"height":100,"width":100,"style":"margin-right:50px"});
            left.append(img);
            var mid = $("<div>").addClass("col-md-2");
            var label = $("<label>").append(data.name);
            mid.append(label);
            var mid2 =$("<div>").addClass("col-md-6");
            var input = $("<input>").attr({"type":"text"});
            var label2 = $("<label>").append("部门：").append(input);
            mid2.append(label2);
            var right = $("<div>").addClass("col-md-2");
            var cancel = $("<input>").attr({"type":"button","value":"删除"}).addClass("button action consultantCancel");
            right.append(cancel);
            var recommendConsultant = $("<input>").attr({"type":"hidden","name":"data[recConsultant][]","value":data.id});
            row.append(left).append(mid).append(mid2).append(right);
            var p = $("<p>").append(row).append(recommendConsultant);
            $("#consultantImg").append(p);
            $("#staffImg").append(p);
            controlCommand("staffImg",1,1);
        }
    })(jQuery);
</script>
</body>
</html>