<?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,#datatables2 {
        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-download"></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(['/user/pay/outpay'], 'post', ['id' => 'form1', 'target' => '_blank']) ?>
                        <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"><i class="fa fa-dollar"></i> 美元</button>
                                    </span>
                                    <input onkeyup="calculate()" id="usd" type="number" name="amount" class="form-control ">
                                </div>
                            </div>
                            <div class="col-sm-2" style="text-align:center;">
                                <div class="btn btn-default ">=</div>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-primary "><i class="fa fa-cny"></i> 人民币</button>
                                    </span>
                                    <input type="number" id="cny" class="form-control " readonly>
                                </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-primary "><i class="fa fa-dollar"></i> 通道</button>
                                    </span>
                                    <select id="payMethod" name="payMethod" class="form-control ">
                                        <?php foreach ($payMethods as $payMethod) :?>
                                            <option value="<?= $payMethod['name'] ?>"><?= $payMethod['label'] ?></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"><i class="fa fa-user"></i> &nbsp;&nbsp;&nbsp;账户</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-1"></div>
                        </div>
                        <div id="renren_bank_code" style="display: none">
                            <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-primary "><i class="fa fa-dollar"></i> 银行</button>
                                        </span>
                                        <select id="renrenBankCode" name="renrenBankCode" class="form-control ">
                                            <option value="">请选择</option>
                                            <option value="102">工商银行</option>
                                            <option value="103">农业银行</option>
                                            <option value="104">中国银行</option>
                                            <option value="105">建设银行</option>
                                            <option value="308">招商银行</option>
                                            <option value="301">交通银行</option>
                                            <option value="305">民生银行</option>
                                            <option value="302">中信银行</option>
                                            <option value="303">光大银行</option>
                                            <option value="309">兴业银行</option>
                                            <option value="4031000">北京银行</option>
                                            <option value="306">广发银行</option>
                                            <option value="304">华夏银行</option>
                                            <option value="403">邮储银行</option>
                                            <option value="310">浦发银行</option>
                                            <option value="4105840">平安银行</option>
                                            <option value="4012900">上海银行</option>
                                            <option value="4233310">杭州银行</option>
                                            <option value="316">浙商银行</option>
                                            <option value="4504520">青岛银行</option>
                                            <option value="4083320">宁波银行</option>
                                            <option value="4341100">天津银行</option>
                                            <option value="4478210">兰州银行</option>
                                            <option value="4243010">南京银行</option>
                                            <option value="4296510">成都银行</option>
                                            <option value="322">上海农商银行</option>
                                            <option value="4021000">北京农村商业银行</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-2" style="text-align:center;">
                                </div>
                                <div class="col-sm-1"></div>
                            </div>
                        </div>
                        <br>
                        <div id="sand_bank_code" style="display: none">
                            <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-primary btn-lg"><i class="fa fa-dollar"></i> 银行</button>
                                       </span>
                                        <select id="sandBankCode" name="sandBankCode" class="form-control input-lg">
                                            <option value="">请选择</option>
                                            <option value="01020000" >工商银行</option>
                                            <option value="01050000" selected="selected">建设银行</option>
                                            <option value="01030000">农业银行</option>
                                            <option value="03010000">交通银行</option>
                                            <option value="01040000">中国银行</option>
                                            <option value="03030000">光大银行</option>
                                            <option value="03050000">民生银行</option>
                                            <option value="04031000">北京银行</option>
                                            <option value="03060000">广发银行</option>
                                            <option value="01000000">中国邮储银行</option>

                                            <!--<option value="03090000">兴业银行</option>
                                            <option value="03020000">中信银行</option>
                                            <option value="03080000">招商银行</option>
                                            <option value="03100000">浦发银行</option>
                                            <option value="03070000">平安银行</option>
                                            <option value="03040000">华夏银行</option>
                                            <option value="04083320">宁波银行</option>
                                            <option value="03200000">东亚银行</option>
                                            <option value="04012900">上海银行</option>
                                            <option value="04243010">南京银行</option>
                                            <option value="65012900">上海农商行</option>
                                            <option value="03170000">渤海银行</option>
                                            <option value="64296510">成都银行</option>
                                            <option value="64296511">徽商银行</option>
                                            <option value="04341101">天津银行</option>-->
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-2" style="text-align:center;">
                                </div>
                                <div class="col-sm-1"></div>
                            </div>
                        </div>
						
                        <div id="kexing_bank_code" style="display: none">
                            <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-primary btn-lg"><i class="fa fa-dollar"></i> 银行</button>
                                       </span>
                                        <select id="kexingBankCode" name="kexingBankCode" class="form-control input-lg">
                                            <option value="">请选择</option>
											<option value="BOC" >中国银行</option>
                                            <option value="ICBC" >工商银行</option>
                                            <option value="CCB">建设银行</option>
                                            <option value="ABC">农业银行</option>
                                            <option value="BOCM">交通银行</option>
                                            <option value="PSBC">邮储银行</option>
                                            <option value="CEBB">光大银行</option>
                                            <option value="CMBC">民生银行</option>                                          
                                            <option value="GDB">广发银行</option>
                                            <option value="CIB">兴业银行</option>
                                            <option value="CNCB">中信银行</option>
                                            <option value="CMB">招商银行</option>
                                            <option value="SPDB">浦发银行</option>
                                            <option value="PAB">平安银行</option>
                                            <option value="HXB">华夏银行</option>
											<option value="BOB">北京银行</option>
                                            <option value="BOS">上海银行</option>
											<option value="GZCB">广州银行</option>
                                            
                                        </select>
                                    </div>
                                </div>
                                <div class="col-sm-2" style="text-align:center;">
                                </div>
                                <div class="col-sm-1"></div>
                            </div>
                        </div>

                        <br>
                        <div class="row">
                            <div class="col-sm-1"></div>
                            <div class="col-sm-10">
                                <table class="table invoice-total">
                                    <tbody>
                                    <tr>
                                        <td><strong>账户 :</strong></td>
                                        <td id="loginTd"></td>
                                    </tr>
                                    <tr>
                                        <td><strong>汇率 :</strong></td>
                                        <td><?= isset($rate['sellRate']) ? $rate['sellRate'] : 0 ?></td>
                                    </tr>
                                    <tr>
                                        <td><strong>合计 :</strong></td>
                                        <td id="amount">￥0</td>
                                    </tr>
                                    </tbody>
                                </table>
                                <div class="text-right">
                                    <button type="submit" class="btn btn-danger"><i class="fa fa-cny"></i> 马上支付
                                    </button>
                                </div>
                                <div class="well m-t"><strong>友情提示：</strong>
                                    银联入金，1个工作日到账。
                                </div>
                            </div>
                            <div class="col-sm-1"></div>
                        </div>
                        <?= 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>
                                </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 src="<?= STATIC_URL ?>/ui/js/plugins/validate/messages.cn.js"></script>
<script>
    $('#login').change(function () {
        var v = $(this).val();
        $('#loginTd').html(v)
    });
    function calculate() {
        var usd = parseFloat($('#usd').val());
        var money = isNaN(usd) ? 0 : (usd * <?= isset($rate['sellRate']) ? $rate['sellRate'] : 0 ?>).toFixed(2)
        $('#cny').val(money);
        $('#amount').html('￥' + money)
    }
    var changeBank =  function () {
        var payMethod = $("#payMethod").val();
        if (payMethod == 'renren') {
            $("#renren_bank_code").attr("style", "display:block");
        } else {
            $("#renren_bank_code").attr("style", "display:none");
        }
        if (payMethod == 'sand') {
            $("#sand_bank_code").attr("style", "display:block");
        } else {
            $("#sand_bank_code").attr("style", "display:none");
        }
		if (payMethod == 'kexing') {
            $("#kexing_bank_code").attr("style", "display:block");
        } else {
            $("#kexing_bank_code").attr("style", "display:none");
        }

    }
    changeBank()
    $("#payMethod").on("change", changeBank);
    var table,table2;
    $(document).ready(function () {
        $('#form1').validate({
            rules: {
                'amount': {
                    required: true,
					//min:500,
                },
                'login': {
                    required: true
                },
                "bankCode": {
                    required: true
                },
                "huayinBankCode": {
                    required: true
                },
                "aotuBankCode": {
                    required: true
                },
                "balpalBankCode": {
                    required: true
                }
            },
			 /*messages:{
				amount:{  
					min:"最小入金500美金！",  
				},  
			 }, */

			  /* 重写错误显示消息方法 */   
			showErrors: function(errorMap, errorList) {  
				var msg = "";  
				$.each( errorList, function(i,v){  
				  msg += (v.message+"\r\n");  
				});  
				if(msg!="") {
					 toastr.error(msg, "提示");
				} 
			}, 
			onfocusout: false,
			onclick:false,
			onkeyup:false,
			
			
        });
        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': 'type'
            }, {
                'data': 'amount'
            }, {
                'data': 'login'
            }, {
                'data': 'in_time'
            }],
            columnDefs: [{
                targets: 1,
                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-primary">成功</span>'
                    }
                },
                'orderable': true
            }, {
                targets: 4,
                render: function (data, type, row, meta) {
                    if (data != 0) {
                        return timeStamp2String(data)
                    } else {
                        return ''
                    }
                },
                'orderable': true
            }],
            'sPaginationType': 'full_numbers',
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [{
                extend: 'copy'
            },
                {
                    extend: 'csv'
                },
                {
                    extend: 'excel'
                },
                {
                    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')
                    }
                }]
        });
        table2 = $('#datatables2').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(['ssac-ajax']) ?>',
            'order': [[0, 'desc']],
            'columns': [{
                'data': 'id'
            }, {
                'data': 'type'
            }, {
                'data': 'amount'
            }, {
                'data': 'login'
            }, {
                'data': 'in_time'
            }],
            columnDefs: [{
                targets: 1,
                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-primary">成功</span>'
                    }
                },
                'orderable': true
            }, {
                targets: 4,
                render: function (data, type, row, meta) {
                    if (data != 0) {
                        return timeStamp2String(data)
                    } else {
                        return ''
                    }
                },
                'orderable': true
            }],
            'sPaginationType': 'full_numbers',
            dom: '<"html5buttons"B>lTfgitp',
            buttons: [{
                extend: 'copy'
            },
                {
                    extend: 'csv'
                },
                {
                    extend: 'excel'
                },
                {
                    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,#datatables2 tbody').on('click', 'tr',
            function () {
                if ($(this).hasClass('selected')) {
                    $(this).removeClass('selected')
                } else {
                    table.$('tr.selected').removeClass('selected');
                    $(this).addClass('selected')
                }
            })
    })
</script>
<?php $this->endBlock(); ?>
