
<div class="layui-fluid">

    <style>
        #withdrawalcategoryTreeBar{padding:10px 15px;border:1px solid #e6e6e6;background-color:#f2f2f2}
        #withdrawalcategoryTree{border:1px solid #e6e6e6;border-top:none;padding:10px 5px;overflow:auto;height:-webkit-calc(100vh - 290px);height:-moz-calc(100vh - 290px);height:calc(100vh - 290px)}
        .layui-tree-entry .layui-tree-txt{padding:0 5px;border:1px transparent solid;text-decoration:none!important}
        .layui-tree-entry.organ-tree-click .layui-tree-txt{background-color:#fff3e0;border:1px #ffe6b0 solid}
        .files_itemwwithdrawal{width:30px;height:30px;line-height:30px;cursor:pointer;padding:1px;background:#fff;display:-webkit-box;-moz-box-align:center;-webkit-box-align:center;-moz-box-pack:center;-webkit-box-pack:center;}
        .files_itemwwithdrawal img{max-width:28px;max-height:28px;border:0}
    </style>

            <div class="layui-card">
                <div class="layui-card-header">
                    <form class="layui-form render">
                        <input type="hidden" name="groupid" id="withdrawal-groupid" value=""/>
                        <div class="layui-form-item">

                            <div class="layui-inline" style="width:250px;"><input type="text" name="kw" placeholder="提现单号" autocomplete="off" class="layui-input" lay-affix="clear"/></div>
                            <div class="layui-inline" style="width:250px;"><input type="text" name="user" placeholder="用户名，用户手机" autocomplete="off" class="layui-input" lay-affix="clear"/></div>
                            <div class="layui-inline" style="width:150px;">
                                <select name="sh_status" id="statusselect-tixian">
                                    <option value="-1">审核状态</option>
                                    <option value="0"  {php}if(input('sh_status') === '0'){echo 'selected';}{/php}>待审核</option>
                                    <option value="1"  {php}if(input('sh_status') == 1){echo 'selected';}{/php}>审核失败</option>
                                    <option value="2"  {php}if(input('sh_status') == 2){echo 'selected';}{/php}>审核通过</option>
                                </select>
                            </div>

                            <div class="layui-inline" style="width:150px;">
                                <select name="dk_status" id="dkstatusselect-tixian">
                                    <option value="-1">打款状态</option>
                                    <option value="0"  {php}if(input('dk_status') === '0'){echo 'selected';}{/php}>未打款</option>
                                    <option value="1"  {php}if(input('dk_status') == 1){echo 'selected';}{/php}>打款中</option>
                                    <option value="2"  {php}if(input('dk_status') == 2){echo 'selected';}{/php}>打款失败</option>
                                    <option value="3"  {php}if(input('dk_status') == 3){echo 'selected';}{/php}>已打款</option>
                                </select>
                            </div>
                            <div class="layui-inline">
                                <div class="layui-btn-group">
                                    <button  class="layui-btn" lay-submit lay-filter="search-withdrawal"><i class="layui-icon layui-icon-search"></i> 搜索</button>
                                    <button  class="layui-btn" lay-submit lay-filter="excel-withdrawal"><i class="layui-icon layui-icon-download-circle"></i> 导出</button>
                                    <a class="layui-btn" lay-submit lay-filter="search-withdrawal-all" onclick="$('#withdrawal-groupid').val('')"><i class="layui-icon layui-icon-light"></i>全部</a>


                                </div>
                            </div>
                        </div>
                    </form>
                </div>


                    <div class="layui-card-body">
                    <table lay-filter="withdrawal" id="withdrawal"></table>
                    </div>

            </div>
</div>

<script type="text/html" id="withdrawalDemo">
    <div class="layui-clear-space">
        {{# if (d.sh_status === 0) { }}
            <a class="layui-btn layui-btn-xs" lay-event="shenhei">审核</a>
        {{# } }}
        {{# if (d.dk_status < 2) { }}
            <a class="layui-btn layui-btn-xs" lay-event="dakuan">打款</a>
        {{# } }}
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>

    </div>
</script>

<script type="text/html" id="withdrawalstatus-demo">
    {{# if (d.sh_status === 2) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" >{{=d.sh_status_text}}</a>
    {{# } else { }}
    {{# if(d.sh_status === 1) { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="statuserror">{{=d.sh_status_text}}</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs">{{=d.sh_status_text}}</a>
    {{# } }}
    {{# } }}
</script>
<script type="text/html" id="withdrawaldk-demo">
    {{# if (d.dk_status === 3) { }}
    <a class="layui-btn layui-btn-xs layui-btn-normal" >{{=d.dk_status_text}}</a>
    {{# } else { }}
    {{# if(d.dk_status === 2) { }}
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="dakuanerror">{{=d.dk_status_text}}</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs">{{=d.dk_status_text}}</a>
    {{# } }}
    {{# } }}
</script>
<!--JS部分-->
<script>

    layui.use(['vinfo', 'buildItems','dropdown'], function(){
        var map_root = layui.cache.maps;
        var app_root = map_root + 'caiwu.withdrawal/';
        var layer = layui.layer,table=layui.table,form=layui.form,admin=layui.admin;


        var sh_status = $("#statusselect-tixian").val();
        var dk_status = $("#dkstatusselect-tixian").val();
        /*渲染数据*/
        table.render({
            elem: '#withdrawal',
            page: true,
            limit:{$limit},
            height: 'full-341',
            // toolbar: 'default', //开启工具栏，此处显示默认图标，可以自定义模板，详见文档
            url: app_root+"index?&do=json",
            where:{sh_status:sh_status,dk_status:dk_status},
            // css: 'td .layui-table-cell{height:80px;line-height:80px;padding:0 5px;}',
            cols: [[
                {type:'checkbox',fixed:'left'},
                {field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
                {field:'sn',align:'center',title:'提现单号'},
                {field:'username',align:'center',title:'用户名',templet:'<div>{{= d.getuserdata.username}}</div>'},
                {field:'mobile',align:'center',title:'用户手机',templet:'<div>{{= d.getuserdata.mobile}}</div>'},
                {field:'tx_money',align:'center',width:100,title:'提现金额'},
                {field:'tx_commission',align:'center',width:100,title:'提现手续费'},
                {field:'tx_sj_money',align:'center',width:100,title:'实际到账金额'},
                {field:'account',align:'center',title:'提现账号'},
                {field:'sh_status',width:100,align:'center',title:'审核状态',templet:'#withdrawalstatus-demo'},
                {field:'status',width:100,align:'center',title:'打款状态',templet:'#withdrawaldk-demo'},
                {field:'createtime',width:120,align:'center',title:'发布时间'},
                {fixed:'right',width:150,align:'center', templet: '#withdrawalDemo',title:'操作'}
            ]],
            done: function(){ admin.vShow($('[lay-table-id="withdrawal"]'));

            }
        });

        // 状态 - 开关操作
        form.on('switch(is_sell-chang)', function(obj){
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            var av = obj.elem.checked ? 1 : 0;
            admin.req(app_root+"editup",{id:json.id,av:av,af:obj.elem.name},function(res){
                layer.tips(res.msg,obj.othis,{time:1000});
                if(res.code === 0) obj.elem.checked = parseInt(obj.value);
            },'post',{headersToken:true});
        });

        form.on('submit(excel-withdrawal)', function(data){
            var checkStatus = table.checkStatus('withdrawal');
            var checkRows = checkStatus.data;
            var ids = checkRows.map(function(d){return d.id;});
            var field = data.field; // 获得表单字段
            field.ids = ids;
            layer.load();
            $.ajax({
                method: "post",
                url: app_root+'/excelwithdrawal',
                data: field,
                dataType: "json",
                success: function (res){
                    layer.closeAll();
                    if(res.code===1) {
                        window.location.href = res.data.url;
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
            return false; // 阻止默认 form 跳转
        });

        /*快编监听*/
        table.on('edit(withdrawal)',function(obj){
            admin.req(app_root+"editup",{id:obj.data.id,av:obj.value,af:obj.field},function(res){
                layer.msg(res.msg,{shade:[0.4,'#000'],time:500});
            },'post',{headersToken:true});
        });/**/

        /*工具条监听*/
        table.on('tool(withdrawal)', function(obj){
            var data = obj.data;
            var id = data.id;
            if(obj.event === 'detail'){
                withdrawalOpen(data.id);
            }else if(obj.event === 'del'){
                del(id);
            }else if(obj.event === 'withdrawal-event-image'){
                var src = $(this).attr('src'), alt = $(this).attr('alt');
                layer.photos({photos:{data:[{alt:alt,src:src}],start:'0'},anim:5,shade:[0.4,'#000']});
            }else if(obj.event === 'more'){

            }else if(obj.event === 'shenhei'){

                layer.confirm('选择审核状态？', {
                    btn: ['审核通过', '审核不通过'],
                    btn1: function(index, layero, that){

                        shajax(data.id,2);
                    },
                    btn2: function(index, layero, that){
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '请输入失败原因',
                        }, function(value, index, elem){

                            shajax(data.id,1,value);

                        });
                    },
                });
            }else if(obj.event === 'dakuan'){

                layer.confirm('选择打款状态？', {
                    btn: ['打款成功', '打款失败'],
                    btn1: function(index, layero, that){

                        dkajax(data.id,3);
                    },
                    btn2: function(index, layero, that){
                        layer.prompt({
                            formType: 2,
                            value: '',
                            title: '请输入打款失败原因',
                        }, function(value, index, elem){

                            dkajax(data.id,2,value);

                        });
                    },
                });
            }else if(obj.event === 'statuserror'){
                layer.alert(data.sh_status_desc,{title:'失败原因'});
            }else if(obj.event === 'dakuanerror'){
                layer.alert(data.dk_status_desc,{title:'失败原因'});
            }
        });/**/


        /*删除*/
        function del(ids){
            layer.confirm('确定要删除所选记录吗？', function(){
                admin.req(app_root+"del",{id:ids},function(res){
                    layer.msg(res.msg,{shade:[0.4,'#000'],time:1500},function(){
                        if(res.code==1) table.reloadData('withdrawal');
                    });
                },'post',{headersToken:true});
            });
        }/**/
        /*顶部删除按钮*/
        $('#withdrawal-del').on('click', function(){
            var checkRows = table.checkStatus('withdrawal').data;

            if(checkRows.length === 0){return layer.msg('请选择需删除的记录');}
            var ids = checkRows.map(function(d){return d.id;});
                console.log(ids);
            del(ids);
        });/**/

        /*弹出窗*/
        function withdrawalOpen(id='',type=''){
            var title = "项目详情";

            layer.open({
                type: 2,
                area: ['900px', '850px'],
                title: title,
                btn: ['确定', '关闭'],
                fixed: false, //不固定
                content: app_root+'/detail?id='+id+'&type='+type,
                yes: function(index, layero){
                    layer.close(index);
                },
            });
        }/**/


        function shajax(id,shstatus,errordesc=''){
            $.ajax({
                method: "post",
                url: app_root+'/shenhewithdrawal',
                data: {id:id,shstatus:shstatus,errordesc:errordesc},
                dataType: "json",
                success: function (res){
                    if(res.code===1) {
                        layer.msg(res.msg,{icon:1,shade:[0.4,'#000'],time:1500},function (){
                            layer.closeAll();
                            table.reloadData('withdrawal');
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
        }

        function dkajax(id,shstatus,errordesc=''){
            $.ajax({
                method: "post",
                url: app_root+'/dakuanwithdrawal',
                data: {id:id,shstatus:shstatus,errordesc:errordesc},
                dataType: "json",
                success: function (res){
                    if(res.code===1) {
                        layer.msg(res.msg,{icon:1,shade:[0.4,'#000'],time:1500},function (){
                            layer.closeAll();
                            table.reloadData('withdrawal');
                        });
                    }else{
                        layer.msg(res.msg,{icon:2,shade:[0.4,'#000'],time:1500},function (){

                        });
                    }


                }
            });
        }


    });
</script>