<template>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1 id="itemTitle"></h1>
                </section>
                <div id="toolbar">
                    <form id="searchForm" action="/admin/audit/audio/export" method="get" target="_blank">
                        <div class="col-sm-12">
                            <label for="erbanNo" class="qry_col control-label">房间号:</label>
                            <div class="col-sm-1"><input type="text" class="form-control" name="erbanNo" id="erbanNo"></div>


                            <label for="riskLevel" class="qry_col control-label">数美判断结果:</label>
                            <div class="col-sm-1"><select name="riskLevel" id="riskLevel" class="col-sm-1 form-control"
                                    data-btn-class="btn-warning">
                                    <option value="" selected="selected"> </option>
                                    <option value="1">可疑</option>
                                    <option value="2">违规</option>
                                </select></div>

                            <label for="riskType" class="qry_col control-label">违规类型:</label>
                            <div class="col-sm-1"><select name="riskType" id="riskType" class="col-sm-1 form-control"
                                    data-btn-class="btn-warning">
                                    <option value="" selected="selected"> </option>
                                    <option value="100">涉政</option>
                                    <option value="200">色情</option>
                                    <option value="210">辱骂</option>
                                    <option value="250">娇喘</option>
                                    <option value="300">广告</option>
                                </select></div>

                            <label for="operatorName" class="qry_col control-label">操作人:</label>
                            <div class="col-sm-1"><input type="text" class="form-control" name="operatorName"
                                    id="operatorName"></div>


                            <label for="manualAuditResult" class="qry_col control-label">人工审核结果:</label>
                            <div class="col-sm-1"><select name="manualAuditResult" id="manualAuditResult"
                                    class="col-sm-1 form-control" data-btn-class="btn-warning">
                                    <option value="" selected="selected"> </option>
                                    <option value="0">待处理</option>
                                    <option value="1">正常</option>
                                    <option value="2">警告</option>
                                    <option value="3">封号24小时</option>
                                    <option value="4">封号3天</option>
                                    <option value="5">封号7天</option>
                                    <option value="6">永久封禁</option>
                                    <option value="7">已解禁</option>
                                </select></div>

                            <!--<label for="systemAuditResult" class="qry_col control-label">系统审核结果:</label>
                        <div class="col-sm-1"><select name="systemAuditResult" id="systemAuditResult" class="col-sm-1 form-control" data-btn-class="btn-warning">
                            <option value="" selected="selected"> </option>
                            <option value="3">封号24小时</option>
                            <option value="4">封号3天</option>
                            <option value="6">永久封禁</option>
                        </select></div>-->
                        </div>
                        <div class="col-sm-12">
                            <label class="qry_col control-label">风险值:</label>
                            <div class="col-sm-1"><input type="text" class="qry_col form-control" name="startScore"
                                    id="startScore"></div><span class="qry_col">至</span>
                            <div class="col-sm-1"><input type="text" class="qry_col form-control" name="endScore"
                                    id="endScore"></div>
                            <label class="qry_col control-label">违规次数:</label>
                            <div class="col-sm-1"><input type="text" class="qry_col form-control" name="startRejectCount"
                                    id="startRejectCount"></div><span class="qry_col">至</span>
                            <div class="col-sm-1"><input type="text" class="qry_col form-control" name="endRejectCount"
                                    id="endRejectCount"></div>

                            <label class="qry_col control-label">发生时间:</label>
                            <div class="col-sm-2"><input type="text" class="qry_col form-control" name="beginDate"
                                    id="beginDate"></div><span class="qry_col">至</span>
                            <div class="col-sm-2"><input type="text" class="qry_col form-control" name="endDate"
                                    id="endDate"></div>

                        </div>

                    </form>
                    <div class="col-sm-12">
                        <button id="btnSearch" class="btn btn-default">
                            <i class="glyphicon glyphicon-search"></i>查询
                        </button>
                        <button id="btnExport" class="btn btn-default">
                            <i class="glyphicon glyphicon-export"></i>导出
                        </button>
                    </div>

                </div>
                <!-- .content -->
                <div id="table"></div>
            </div>
        </div>
    </section>

    <div class="modal fade" id="rejectModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="modalLabel">违规处理</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="handle_reject">
                        <input type="hidden" name="recordId" id="recordId" />

                        <div class="form-group">
                            <label for="resultValue" class="col-sm-3 control-label">处罚类型：</label>
                            <div class="col-sm-9">
                                <select name="resultValue" id="resultValue" class="col-sm-5 control-label">
                                    <option value=""> </option>
                                    <option value="2">警告</option>
                                    <option value="3">封号24小时</option>
                                    <option value="4">封号3天</option>
                                    <option value="5">封号7天</option>
                                    <option value="6">永久封禁</option>
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="risk_type" class="col-sm-3 control-label">违规类型：</label>
                            <div class="col-sm-9">
                                <select name="riskType" id="risk_type" class="col-sm-5 control-label">
                                    <option value=""> </option>
                                    <option value="100">涉政</option>
                                    <option value="200">色情</option>
                                    <option value="210">辱骂</option>
                                    <option value="250">娇喘</option>
                                    <option value="300">广告</option>
                                    <option value="700">黑名单</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">

                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-prim ary" id="add">确定</button>
                </div>

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

    <div class="modal fade" id="blockModal" tabindex="-1" role="dialog" aria-labelledby="blockModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="blockModalLabel">违规处理</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="handle_block">
                        <input type="hidden" name="recordId1" id="recordId1" />
                        <div class="form-group">
                            <label for="resultValue1" class="col-sm-3 control-label">处罚类型：</label>
                            <div class="col-sm-9">
                                <select name="resultValue1" id="resultValue1" class="col-sm-5 control-label">
                                    <option value="3">封号24小时</option>
                                    <option value="4">封号3天</option>
                                    <option value="5">封号7天</option>
                                    <option value="6">永久封禁</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">

                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-prim ary" id="addBlock">确定</button>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';

export default {
    name: "AuditAudioView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        /* {field: 'recordId', title: '', align: 'center', valign: 'middle', width: '1%', visible: false},*/
                        {
                            field: 'sel', title: '编号', align: 'center', valign: 'middle', width: '5%',
                            formatter: function (value, row, index) {
                                //获取每页显示的数量
                                var pageSize = $('#table').bootstrapTable('getOptions').pageSize;
                                //获取当前是第几页
                                var pageNumber = $('#table').bootstrapTable('getOptions').pageNumber;
                                //返回序号，注意index是从0开始的，所以要加上1
                                return pageSize * (pageNumber - 1) + index + 1;
                            }
                        },
                        { field: 'erbanNo', title: '房间号', align: 'center', valign: 'middle', width: '5%' },
                        { field: 'roomUid', title: '房主UID', align: 'center', valign: 'middle', width: '5%' },
                        {
                            field: 'audioUrl', title: '语音url', align: 'center', width: '15%', formatter: function (val, row, index) {
                                return '<audio controls="controls"><source src="' + row.audioUrl + '" type="audio/mpeg"></audio>';
                            }
                        },
                        { field: 'score', title: '风险值', align: 'center', valign: 'middle', width: '5%' },

                        {
                            field: 'riskLevel', title: '数美判断结果', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                if (val == 1) {
                                    return '可疑';
                                } else if (val == 2) {
                                    return '违规';
                                } else {
                                    return '-';
                                }

                            }
                        },
                        {
                            field: 'riskType', title: '违规类型', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                switch (val) {
                                    case 100:
                                        return '涉政';
                                    case 200:
                                        return '色情';
                                    case 210:
                                        return '辱骂';
                                    case 250:
                                        return '娇喘';
                                    case 300:
                                        return '广告';
                                    case 700:
                                        return '黑名单';
                                    default:
                                        return '-';
                                }

                            }
                        },

                        {
                            field: 'manualAuditResult', title: '人工审核结果', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                switch (val) {
                                    case 0:
                                        return '待处理';
                                    case 1:
                                        return '正常';
                                    case 2:
                                        return '警告';
                                    case 3:
                                        return '封号24小时';
                                    case 4:
                                        return '封号3天';
                                    case 5:
                                        return '封号7天';
                                    case 6:
                                        return '永久封禁';
                                    case 7:
                                        return '已解禁';
                                    default:
                                        return '-';
                                }

                            }
                        },
                        {
                            field: 'systemAuditResult', title: '系统审核结果', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                switch (val) {
                                    case 2:
                                        return '警告';
                                    case 3:
                                        return '封号24小时';
                                    case 4:
                                        return '封号3天';
                                    case 6:
                                        return '永久封禁';
                                    default:
                                        return '-';
                                }

                            }
                        },
                        { field: 'rejectCount', title: '历史违规次数', align: 'center', valign: 'middle', width: '5%' },

                        {
                            field: 'createTime', title: '发生时间', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                if (val) {
                                    var date = new Date(val);
                                    return date.format('yyyy-MM-dd hh:mm:ss');
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'updateTime', title: '处理时间', align: 'center', valign: 'middle', width: '10%',
                            formatter: function (val, row, index) {
                                if (val) {
                                    var date = new Date(val);
                                    return date.format('yyyy-MM-dd hh:mm:ss');
                                } else {
                                    return '-';
                                }
                            }
                        },
                        { field: 'operatorName', title: '操作人', align: 'center', valign: 'middle', width: '5%' },
                        {
                            field: 'recordId',
                            title: '操作',
                            align: 'center',
                            valign: 'middle',
                            width: '5%',
                            formatter: function (val, row, index) {
                                if (row.manualAuditResult == 0) {//如果是待处理
                                    return '<button class="btn btn-success btn-sm" id="handlePass" data-id=' + val + '>正常</button>' +
                                        '<button class="btn btn-danger btn-sm" id="handleReject" data-id=' + val + '>违规</button>';
                                } else if (row.blockId != null && row.manualAuditResult != 1 && row.manualAuditResult != 2 && row.manualAuditResult != 7) {
                                    return '<button class="btn btn-primary btn-sm" id="unBlock" data-id=' + val + '>解禁</button>';
                                } else if (row.systemAuditResult == 2 && (row.manualAuditResult == 'undefined' || row.manualAuditResult != 7)) {
                                    return '<button class="btn btn-danger btn-sm" id="handleBlock" data-id=' + val + '>封号</button>';
                                } else {
                                    return '-';
                                }

                            }
                        }

                    ],
                    undefinedText: '-',
                    cache: false,
                    striped: true,
                    showRefresh: false,
                    pageSize: 20,
                    pagination: true,
                    pageList: [20, 50, 100, 200, 300, 500],
                    search: false,
                    sidePagination: "server", //表示服务端请求
                    queryParamsType: "undefined",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            pageNum: params.pageNumber,
                            pageSize: params.pageSize,
                            erbanNo: $('#erbanNo').val(),
                            riskLevel: $('#riskLevel').val(),
                            riskType: $('#riskType').val(),
                            operatorName: $('#operatorName').val(),
                            //systemAuditResult: $('#systemAuditResult').val(),
                            manualAuditResult: $('#manualAuditResult').val(),
                            beginDate: $('#beginDate').val(),
                            endDate: $('#endDate').val(),
                            startRejectCount: $('#startRejectCount').val(),
                            endRejectCount: $('#endRejectCount').val(),
                            startScore: $('#startScore').val(),
                            endScore: $('#endScore').val()
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/audit/audio/list',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });


                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });
                // 导出EXCEL
                $('#btnExport').on('click', function () {
                    $("#searchForm").submit();
                });

                $("#table").on("click", '#handlePass', function () {
                    var id = $(this).attr("data-id");
                    $.ajax({
                        type: "post",
                        url: "/admin/audit/audio/handle/pass",
                        data: { recordId: id },
                        dataType: "json",
                        success: function (json) {
                            if (json.code == 200) {
                                $("#tipMsg").text("处理成功");
                                $("#tipModal").modal('show');
                                TableHelper.doRefresh("#table");
                            } else {
                                $("#tipMsg").text("处理失败，错误信息：" + json.data);
                                $("#tipModal").modal('show');
                                TableHelper.doRefresh("#table");
                            }
                        }
                    });
                });
                $("#table").on("click", '#unBlock', function () {
                    var id = $(this).attr("data-id");
                    $.ajax({
                        type: "post",
                        url: "/admin/audit/audio/handle/unBlock",
                        data: { recordId: id },
                        dataType: "json",
                        success: function (json) {
                            if (json.code == 200) {
                                $("#tipMsg").text("解禁成功");
                                $("#tipModal").modal('show');
                                TableHelper.doRefresh("#table");
                            } else {
                                $("#tipMsg").text("解禁失败，错误信息：" + json.data);
                                $("#tipModal").modal('show');
                                TableHelper.doRefresh("#table");
                            }
                        }
                    });
                });

                $("#table").on("click", '#handleReject', function () {
                    var id = $(this).attr("data-id");
                    $('#recordId').val(id);
                    $('#resultValue').val('');
                    $('#risk_type').val('');
                    $("#rejectModal").modal('show');
                });
                $("#table").on("click", '#handleBlock', function () {
                    var id = $(this).attr("data-id");
                    $('#recordId1').val(id);
                    $('#resultValue1').val('');
                    $("#blockModal").modal('show');
                });
                $("#add").click(function () {
                    var recordId = $("#recordId").val();
                    var resultValue = $("#resultValue").val();
                    var riskType = $("#risk_type").val();

                    if (!resultValue) {
                        $("#tipMsg").text("请选择处罚类型");
                        $("#tipModal").modal('show');
                        return;
                    }
                    if (!riskType) {
                        $("#tipMsg").text("请选择违规类型");
                        $("#tipModal").modal('show');
                        return;
                    }

                    if ($("#modalLabel").validationEngine('validate')) {
                        $.ajax({
                            type: "post",
                            url: "/admin/audit/audio/handle/reject",
                            data: {
                                recordId: recordId,
                                resultValue: resultValue,
                                riskType: riskType
                            },
                            dataType: "json",
                            success: function (json) {
                                if (json.code == 200) {
                                    $("#tipMsg").text("保存成功");
                                    $("#tipModal").modal('show');
                                    TableHelper.doRefresh("#table");
                                    $("#rejectModal").modal('hide');
                                } else {
                                    $("#tipMsg").text("保存失败，错误信息：" + json.data);
                                    $("#tipModal").modal('show');
                                }
                            }
                        });
                    }

                });
                $("#addBlock").click(function () {
                    var recordId = $("#recordId1").val();
                    var resultValue = $("#resultValue1").val();
                    if (!resultValue) {
                        $("#tipMsg").text("请选择处罚类型");
                        $("#tipModal").modal('show');
                        return;
                    }

                    if ($("#blockModalLabel").validationEngine('validate')) {
                        $.ajax({
                            type: "post",
                            url: "/admin/audit/audio/handle/reject",
                            data: {
                                recordId: recordId,
                                resultValue: resultValue
                            },
                            dataType: "json",
                            success: function (json) {
                                if (json.code == 200) {
                                    $("#tipMsg").text("保存成功");
                                    $("#tipModal").modal('show');
                                    TableHelper.doRefresh("#table");
                                    $("#blockModal").modal('hide');
                                } else {
                                    $("#tipMsg").text("保存失败，错误信息：" + json.data);
                                    $("#tipModal").modal('show');
                                }
                            }
                        });
                    }

                });

                var picker1 = $("#beginDate").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    autoclose: true,
                    todayBtn: true
                });
                var picker2 = $("#endDate").datetimepicker({
                    format: 'yyyy-mm-dd hh:ii:00',
                    autoclose: true,
                    todayBtn: true
                });
                picker1.on('changeDate', function () {
                    var date = $('#beginDate').datetimepicker('getDate');
                    picker2.datetimepicker('setStartDate', date);
                });
                picker2.on('changeDate', function () {
                    var date = $('#endDate').datetimepicker('getDate');
                    picker1.datetimepicker('setEndDate', date);
                });
            });
        }
    },

};
</script>

<style scoped>.qry_col {
    float: left;
}</style>