<?php
/* @var $this \yii\web\View */
/* @var $content string  */
use yii\helpers\Html;
use yii\helpers\Url;

/** @var \backend\models\MemberIdentity $identity */
$identity = Yii::$app->getUser()->getIdentity(false);
$this->title = '出金';
?>
<?php $this->beginBlock('header_script'); ?>
<link href="<?= STATIC_URL ?>/ui/css/plugins/dataTables/datatables.min.css" rel="stylesheet">
<style>
    label.error {
        display: none !important;
    }

    #datatables {
        width: 100% !important;
    }
</style>
<?php $this->endBlock(); ?>
<div class="row">
    <div class="col-md-3">
        <?= $this->render('/common/_left_menu.php') ?>
    </div>
    <div class="col-md-9">
        <div class="tabs-container">
            <ul class="nav nav-tabs">
                <li class="active" style="background:none;">
                    <a data-toggle="tab" href="#tab-1"><i class="fa fa-upload"></i> 出金</a>
                </li>
                <li class="" style="background:none;">
                    <a data-toggle="tab" href="#tab-2"><i class="fa fa-th"></i> 出金记录</a>
                </li>
            </ul>
            <div class="tab-content">
                <div id="tab-1" class="tab-pane active">
                    <div class="panel-body">
                        <br><br><br><br>
                        <?= Html::beginForm('', 'post', ['id' => 'form']) ?>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary">申请账户</button>
                                    </span>
                                    <select name="login" id="login" class="form-control">
                                        <!--
                                        <option value="">请选择</option>
                                        -->
                                        <?php foreach (explode(',', $identity->logins) as $login):?>
                                            <option value="<?= $login ?>"><?= $login ?></option>
                                        <?php endforeach;?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary">出金金额</button>
                                    </span>
                                    <input type="number" name="amount" class="form-control" placeholder="美元" autocomplete="off">
                                </div>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">&nbsp;&nbsp;&nbsp;收款人</button>
                                    </span>
                                    <input type="text" name="true_name" class="form-control" value="<?= $identity->name ?>" readonly>
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;"></div>
                            <div class="col-sm-4">
                                <p>
                                    汇率：<b style="color:red">CNY:USD=1:<?= isset($rate['buyRate']) ? $rate['buyRate'] : 0 ?></b>
                                    手续费：<b style="color:red">$:<span id="fee">0</span></b>
                                </p>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">所在省份</button>
                                    </span>
                                    <input type="text" name="bank_province" class="form-control">
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">所在城市</button>
                                    </span>
                                    <input type="text" name="bank_city" class="form-control">
                                </div>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">收款银行</button>
                                    </span>
                                    <!--<input type="text" name="bank_name" class="form-control">-->
									<select id="renrenBankCode" name="bank_name" class="form-control ">
                                            <option value="">请选择</option>
                                            <option value="工商银行">工商银行</option>
                                            <option value="农业银行">农业银行</option>
                                            <option value="中国银行">中国银行</option>
                                            <option value="建设银行">建设银行</option>
                                            <option value="招商银行">招商银行</option>
                                            <option value="交通银行">交通银行</option>
                                            <option value="民生银行">民生银行</option>
                                            <option value="中信银行">中信银行</option>
                                            <option value="光大银行">光大银行</option>
                                            <option value="兴业银行">兴业银行</option>
                                            <option value="北京银行">北京银行</option>
                                            <option value="广发银行">广发银行</option>
                                            <option value="华夏银行">华夏银行</option>
                                            <option value="中国邮储银行">中国邮储银行</option>
                                            <option value="浦发银行">浦发银行</option>
                                            <option value="平安银行">平安银行</option>
                                            <option value="上海银行">上海银行</option>
                                            <option value="杭州银行">杭州银行</option>
                                            <option value="浙商银行">浙商银行</option>
                                            <option value="青岛银行">青岛银行</option>
                                            <option value="宁波银行">宁波银行</option>
                                            <option value="天津银行">天津银行</option>
                                            <option value="兰州银行">兰州银行</option>
                                            <option value="南京银行">南京银行</option>
                                            <option value="成都银行">成都银行</option>
											<option value="东亚银行">东亚银行</option>
											<option value="渤海银行">渤海银行</option>
											<option value="徽商银行">徽商银行</option>                                      
                                            <option value="上海农商银行">上海农商银行</option>
                                            <option value="北京农村商业银行">北京农村商业银行</option>
                                        </select>
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">所属支行</button>
                                    </span>
                                    <input type="text" name="bank_sub_name" class="form-control">
                                </div>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">收款卡号</button>
                                    </span>
                                    <input type="text" name="bank_card_no" class="form-control">
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                            </div>
                            <!--<div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">swift代码</button>
                                    </span>
                                    <input type="text" name="swift" class="form-control"> 
                                </div>
                            </div> -->
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-default">联系手机</button>
                                    </span>
                                    <input type="text" name="mobile" class="form-control" value="<?= $identity->mobile ?>">
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                            </div>
                            <!--<div class="col-sm-4">
                                <p>友情提示：<a href="http://www.swiftcode.cn" target="_blank">点我查询银行swift代码</a>
                            </div>-->
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-10">
                                <div class="text-left">
                                    <div id="submit" class="btn btn-danger">
                                        <i class="fa fa-upload"></i> 提交申请
                                    </div>
                                </div>
                                <div class="well m-t"><strong>友情提示：</strong>
                                    阁下每一笔出金将收取5美金手续费，详情请咨询你的客户经理。
                                </div>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <br>
                        <?= Html::endForm() ?>
                        <br><br>
                    </div>
                </div>
                <div id="tab-2" class="tab-pane">
                    <div class="panel-body">
                        <div class="table-responsive" style="margin:30px 10px 0px 10px;">
                            <table id="datatables" class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>账户</th>
                                    <th>状态</th>
                                    <th>金额</th>
                                    <th>手续费</th>
                                    <th>汇率</th>
                                    <th>收款人</th>
                                    <th>收款银行</th>
                                    <th>银行卡号</th>
                                    <th>时间</th>
                                    <th>备注</th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->beginBlock('footer_script'); ?>
<script src="<?= STATIC_URL ?>/ui/js/plugins/dataTables/datatables.min.js"></script>
<script>
    $("#login").change(function () {
        var v = $(this).val();
        $("#loginTd").html(v);
    });
    function calculate() {
        var usd = $("#usd").val();
        $("#cny").val(usd * <?= isset($rate['buyRate']) ? $rate['buyRate'] : 0 ?>);
        $("#amount").html("￥" + <?= isset($rate['buyRate']) ? $rate['buyRate'] : 0 ?>);
    }
    $("#submit").on("click", function () {
        if ($("#form").valid()) {
            $.ajax({
                type: "POST",
                url: "<?= Url::to(['save']) ?>",
                data: $('#form').serialize(),
                dataType: "json",
                beforeSend: function () {
                },
                success: function (data) {
                    if (data.isSuccess) {
                        toastr.success(data.msg, "提示");
                    } else {
                        toastr.error(data.msg, "提示");
                    }
                },
                complete: function (XMLHttpRequest, textStatus) {
                },
                error: function () {
                }
            });
        }
    });
    var table;
    $(document).ready(function () {
        $("#form1").validate({
            rules: {
                "amount": {
                    required: true
                },
                "login": {
                    required: true
                }
            }
        });
        table = $('#datatables').DataTable({
            "aLengthMenu": [[20, 50, 100, 500, 999999999], [20, 50, 100, 500, "ALL"]],
            language: {
                "sProcessing": "处理中...",
                "sLengthMenu": "显示 _MENU_ 项结果",
                "sZeroRecords": "没有匹配结果",
                "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                "sInfoPostFix": "",
                "sSearch": "搜索:",
                "sUrl": "",
                "sEmptyTable": "表中数据为空",
                "sLoadingRecords": "载入中...",
                "sInfoThousands": ",",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "上页",
                    "sNext": "下页",
                    "sLast": "末页"
                },
                "oAria": {
                    "sSortAscending": ": 以升序排列此列",
                    "sSortDescending": ": 以降序排列此列"
                }
            },
            "processing": true,
            "serverSide": true,
            "ajax": '<?= Url::to(['ajax']) ?>',
            "order": [[0, "desc"]],
            "columns": [{
                "data": "id"
            }, {
                "data": "login"
            }, {
                "data": "type"
            }, {
                "data": "amount"
            }, {
                "data": "fee"
            }, {
                "data": "rate"
            }, {
                "data": "true_name"
            }, {
                "data": "bank_name"
            }, {
                "data": "bank_card_no"
            }, {
                "data": "in_time"
            }, {
                "data": "memo"
            }],
            columnDefs: [{
                targets: 2,
                render: function (data, type, row, meta) {
                    if (data == 0) {
                        return '<span class="label label-danger">等待审核</span>';
                    } else if (data == 1) {
                        return '<span class="label label-danger">不通过</span>';
                    } else if (data == 2) {
                        return '<span class="label label-primary">已出金</span>';
                    } else if (data == 3) {
                        return '<span class="label label-primary">管理员撤销</span>';
                    } else if (data == 4) {
                        return '<span class="label label-primary">未分享朋友圈</span>';
                    } else if (data == 5) {
                        return '<span class="label label-primary">暂不处理</span>';
                    } else if (data == 6) {
                        return '<span class="label label-danger">处理中</span>';
                    }
                },
                "orderable": true
            }, {
                targets: 9,
                render: function (data, type, row, meta) {
                    if (data != 0) {
                        return timeStamp2StringForEcharts(data);
                    } else {
                        return "";
                    }
                },
                "orderable": true
            }],
            "sPaginationType": "full_numbers",
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [{
                extend: 'copy'
            },
                {
                    extend: 'csv',
                    exportOptions: {
                        format: {
                            body: function (data, column, row, node) {
                                if (column == 8 || column == 1 || column == 3 || column == 4 || column == 5) {
                                    return "\u200C"+data;
                                } else if (column == 2) {
                                    if (data == '<span class="label label-danger">等待审核</span>') {
                                        return '等待审核';
                                    } else if (data == '<span class="label label-danger">不通过</span>') {
                                        return '不通过';
                                    } else if (data == '<span class="label label-primary">已出金</span>') {
                                        return '已出金';
                                    } else if (data == '<span class="label label-primary">管理员撤销</span>') {
                                        return '管理员撤销';
                                    } else if (data == '<span class="label label-primary">未分享朋友圈</span>') {
                                        return '未分享朋友圈';
                                    } else if (data == '<span class="label label-primary">暂不处理</span>') {
                                        return '暂不处理';
                                    } else if (data == '<span class="label label-danger">处理中</span>') {
                                        return '处理中';
                                    }
                                } else {
                                    return data;
                                }
                            }
                        }
                    }
                },
                {
                    extend: 'excel',
                    exportOptions: {
                        format: {
                            body: function (data, column, row, node) {
                                if (column == 8 || column == 1 || column == 3 || column == 4 || column == 5) {
                                    return " "+data;
                                } else if (column == 2) {
                                    if (data == '<span class="label label-danger">等待审核</span>') {
                                        return '等待审核';
                                    } else if (data == '<span class="label label-danger">不通过</span>') {
                                        return '不通过';
                                    } else if (data == '<span class="label label-primary">已出金</span>') {
                                        return '已出金';
                                    } else if (data == '<span class="label label-primary">管理员撤销</span>') {
                                        return '管理员撤销';
                                    } else if (data == '<span class="label label-primary">未分享朋友圈</span>') {
                                        return '未分享朋友圈';
                                    } else if (data == '<span class="label label-primary">暂不处理</span>') {
                                        return '暂不处理';
                                    } else if (data == '<span class="label label-danger">处理中</span>') {
                                        return '处理中';
                                    }
                                } else {
                                    return data;
                                }
                            }
                        }
                    }
                },
                {
                    extend: 'pdf'
                },
                {
                    extend: 'print',
                    customize: function (win) {
                        $(win.document.body).addClass('white-bg');
                        $(win.document.body).css('font-size', '10px');
                        $(win.document.body).find('table').addClass('compact').css('font-size', 'inherit');
                    }
                }]
        });
        $('#datatables tbody').on('click', 'tr',
            function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected');
                } else {
                    table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected');
                }
            });

        // 输入出金金额计算出手续费，保留两位小数四舍五入
        $('[name="amount"]').keyup(function () {
            var amount = $(this).val();
            amount = Math.abs(amount);
            var fee = amount * 0.005;
            fee = Math.round(fee * 100) / 100;
           // $('#fee').text(fee);
            $('#fee').text(5);
        });
    });
</script>
<?php $this->endBlock(); ?>
