<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>
                <!-- .content -->
                <div id="table"></div>
                <div id="toolbar" style="height: auto;">
                    <form id="searchForm" class="col-sm-pull-12" action="/admin/dynamic/data/export" method="post"
                        target="_blank">
                        <div class="col-sm-12">
                            <label for="erbanNo" class="col-sm-1 control-label">平台号:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="erbanNo" id="erbanNo"></div>

                            <label for="nick" class="col-sm-1 control-label">昵称:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="nick" id="nick"></div>

                            <label for="wolrdId" class="col-sm-1 control-label">话题类型:</label>
                            <div class="col-sm-2">
                                <select name="wolrdId" id="wolrdId" data-btn-class="btn-warning" class="form-control">
                                    <option value="" selected="selected">全部</option>
                                    <option value="-1">非话题动态</option>
                                </select>
                            </div>
                            <label for="wolrdId" class="col-sm-1 control-label">是否置顶:</label>
                            <div class="col-sm-2">
                                <select name="topStatus" id="topStatus" data-btn-class="btn-warning" class="form-control">
                                    <option value="" selected="selected">全部</option>
                                    <option value="1">广场置顶</option>
                                    <option value="2">话题置顶</option>
                                    <option value="-1">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="col-sm-12">
                            <label class="col-sm-1 control-label">发布时间:</label>
                            <div class="col-sm-2"><input type="text" class="form-control" name="beginDate" id="beginDate">
                            </div><span class="col-sm-1">至</span>
                            <div class="col-sm-2"><input type="text" class="form-control" name="endDate" id="endDate"></div>

                            <!--<label  class="col-sm-1 control-label">热度值:</label>
                        <div class="col-sm-2"><input type="text" class="form-control" name="hotValueStart"
                                                     id="hotValueStart" placeholder="请输入热度值"></div><span class="col-sm-1">至</span>
                        <div class="col-sm-2"><input type="text" class="form-control" name="hotValueEnd" id="hotValueEnd" placeholder="请输入热度值"></div>-->

                            <label for="wolrdId" class="col-sm-1 control-label">标签类型:</label>
                            <div class="col-sm-2">
                                <select name="dynamicLab" id="dynamicLab" data-btn-class="btn-warning" class="form-control">
                                    <option value="" selected="selected">全部</option>
                                    <option value="1">官方</option>
                                    <option value="2">活动</option>
                                    <option value="3">互动</option>
                                    <option value="4">热门</option>
                                    <option value="5">推荐</option>
                                    <option value="6">新</option>
                                    <option value="-1">无</option>
                                </select>
                            </div>
                            <label for="partitionId" class="col-sm-1 control-label">地区：</label>
                            <div class="col-sm-2">
                                <select name="partitionId" id="partitionId" class="form-control">
                                </select> 
                            </div>

                        </div>
                    </form>
                    <div class="col-sm-12">
                        <button id="btnSearch" class="btn btn-default">
                            <i class="glyphicon glyphicon-search"></i>查询
                        </button>
                        <button id="btnReset" class="btn btn-default">
                            <i class="glyphicon glyphicon-remove"></i>重置
                        </button>
                        <button id="btnExport" class="btn btn-default">
                            <i class="glyphicon glyphicon-export"></i>导出
                        </button>
                    </div>
                    <!--<div class="col-sm-12">
                    热度值规则：分享人数 * <span id="shareRule">0</span> + 评论人数 * <span id="commentRule">0</span> + 点赞人数 * <span id="likeRule">0</span>
                    <button id="btnEdit" class="btn btn-default">修改规则</button>
                </div>-->
                </div>
            </div>
        </div>
    </section>

    <div class="modal fade" id="showModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 500px;">
                <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">
                    <div class="show" style="margin-left: 60px">

                    </div>
                </div>
                <div id="imgMask"><img src="" alt=""></div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="modalLabe2">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 600px;">
                <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="modalLabe2">修改热度值</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="editForm">
                        <input type="hidden" name="id" id="dynamicId" />
                        <!--<input type="hidden" name="status" id="status1"/>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">自然热度值:</label>
                        <div class="col-sm-8">
                            <span class="control-span" id="cusHotValue"></span>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-1 control-label"></label>
                        <div class="col-sm-8">
                            <input type="text" name="hotValue" id="hotValueChange" class="form-control" placeholder="请输入热度值" />
                        </div>
                    </div>-->

                        <label class="col-sm-3 control-label">标签：</label>
                        <div class="col-sm-8">
                            <input type="checkbox" id="dynamic_lab_1" name="dynamicLab" value="1" />官方&nbsp;&nbsp;
                            <input type="checkbox" id="dynamic_lab_2" name="dynamicLab" value="2" />活动&nbsp;&nbsp;
                            <input type="checkbox" id="dynamic_lab_3" name="dynamicLab" value="3" />互动<br /><br />
                            <input type="checkbox" id="dynamic_lab_4" name="dynamicLab" value="4" />热门&nbsp;&nbsp;
                            <input type="checkbox" id="dynamic_lab_5" name="dynamicLab" value="5" />推荐&nbsp;&nbsp;
                            <input type="checkbox" id="dynamic_lab_6" name="dynamicLab" value="6" />新
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="editLabSave">保存</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="editRuleModal" tabindex="-1" role="dialog" aria-labelledby="modalLabe3">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 600px;">
                <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="modalLabe3">修改规则</h4>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" id="ruleForm">
                        <div class="form-group">
                            <label class="control-label">热度值 = 分享人数*</label>
                            <input type="text" name="hotValue" id="shareNum" placeholder="请输入整数" />
                            <label class=" control-label"> + 评论人数 * </label>
                            <input type="text" name="hotValue" id="commentNum" placeholder="请输入整数" />
                            <label class="control-label" style="margin-left: 45px"> + 点赞人数 * </label>
                            <input type="text" name="hotValue" id="likeNum" placeholder="请输入整数" />
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="save_rule">保存</button>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="showContentModal" tabindex="-1" role="dialog" aria-labelledby="modalLabe4">
        <div class="modal-dialog" role="document">
            <div class="modal-content" style="width: 500px;">
                <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="modalLabe4">查看动态内容详情</h4>
                </div>
                <div class="modal-body">
                    <span id="dynamic-content"></span>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';
import { showLoading, hideLoading } from '@/utils/maintainer';
import { getPartitionInfoList } from '@/api/partition/partitionInfo';
import { buildSelectOption } from '@/utils/system-helper';


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);
});
export default {
    name: "DynamicDataView",
    setup() {
        function showVideo(resUrl, id) {
            var html = '<video width="320" height="240" controls autoplay><source src="' + resUrl + '" type="video/mp4"></video>';
            // 打开编辑弹窗
            $("#showModal").modal('show');
            $("#dynamicId").val(id);
            $(".show").html(html);
        }
        function showPic(resUrl, id) {
            var html = '<div style="width: 320px;">';
            console.log(resUrl);
            if (resUrl != null && resUrl != '' && resUrl != undefined) {
                var resUrls = resUrl.split(",");
                for (var i = 0; i < resUrls.length; i++) {
                    if (resUrls[i] != null && resUrls[i] != undefined && resUrls[i] != "") {
                        html += '<img id="imgs" src="' + resUrls[i] + '" style="width: 100px;height: 100px;">';
                    }
                }
            }
            html += '</div>';
            // 打开编辑弹窗
            $("#showModal").modal('show');
            $("#dynamicId").val(id);
            $(".show").html(html);
        }
        function showContent(note) {
            var content = $(note).parent().find('input').val();
            $('#dynamic-content').text(content);
            $('#showContentModal').modal('show');
        }
        window.showVideo = showVideo;
        window.showPic = showPic;
        window.showContent = showContent;
        return {
            showVideo,
            showPic,
            showContent
        };
    },
    created() {
        this.$nextTick(function () {
            this.initPartition();
            this.initData();
        });
    },
    methods: {
        initData() {

            $(function () {
                $('#table').bootstrapTable('destroy');
                setTypeSelectOption();
                getHotValueRule();
                $('#table').bootstrapTable({
                    columns: [
                        //{field: 'id', title: 'id', align: 'center', width: '5%'},
                        { field: 'tmp', title: 'id', align: 'center', checkbox: true, width: '5%' },
                        { field: 'erbanNo', title: '平台号', align: 'center', width: '5%' },
                        { field: 'nick', title: '昵称', align: 'center', width: '5%' },
                        { field: 'gender', title: '性别', align: 'center', width: '5%' },
                        { field: 'worldName', title: '话题', align: 'center', width: '5%' },
                        {
                            field: 'content',
                            title: '动态内容',
                            align: 'center',
                            width: '5%',
                            formatter: function (val, row, index) {
                                if (isEmpty(val)) {
                                    return "-";
                                } else {
                                    if (val.length > 50) {
                                        var content = "<input type='hidden' id='input-content' value='" + val + "'>";
                                        return val.substring(0, 50) + "..." + content + "<button href='#' class='btn btn-sm' style='color: #00acd6;background:none' onclick=showContent(this) style='margin-left: 10px;'>查看更多</a>";
                                    } else {
                                        return val;
                                    }
                                }
                            }
                        },
                        { field: 'dynamicLab', title: '标签', align: 'center', width: '5%' },
                        {
                            field: 'resUrl',
                            title: '图片/视频/语音',
                            align: 'center',
                            width: '5%',
                            formatter: function (val, row, index) {
                                if (row.type == 1) {
                                    return '<audio controls="controls"><source src="' + val + '" type="audio/mpeg"></audio>';
                                } else if (row.type == 2) {
                                    return "<button href='#' class='btn btn-sm' style='color: #00acd6;background:none' onclick=showPic('" + row.resUrl + "'," + row.id + ")>查看图片</button>";
                                } else if (row.type == 3) {
                                    return "<button href='#' class='btn btn-sm' style='color: #00acd6;background:none' onclick=showVideo('" + row.resUrl + "'," + row.id + ")>查看视频</button>";
                                }
                            }
                        },
                        {field: 'partitionDesc', title: '分区', align: 'center', width: '5%'},
                        /*{field: 'share', title: '分享人数/次数', align: 'center', width: '5%'},
                        {field: 'commment', title: '评论人数/次数', align: 'center', width: '5%'},
                        {field: 'like', title: '点赞人数/次数', align: 'center', width: '5%'},
                        {field: 'readNum', title: '阅读数', align: 'center', width: '5%'},
                        {field: 'hotValue', title: '热度值', align: 'center', width: '5%'},*/
                        {
                            field: 'createTime',
                            title: '发布时间',
                            align: 'center',
                            width: '5%',
                            valign: 'middle',
                            formatter: function (val, row, index) {
                                if (val) {
                                    var date = new Date(val);
                                    return date.format("yyyy-MM-dd hh:mm:00");
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'id',
                            title: '操作',
                            align: 'center',
                            width: '5%',
                            formatter: function (val, row, index) {
                                var editLabel = '<button class="btn btn-sm btn-info opt-label-edit" data-id=' + val + ' data-status=1 data-value=' + row.hotValue + ' data-tip=' + row.hotChangeFlag + '>编辑标签</button>';
                                var openSquareTop;
                                if (row.squareTop == null || row.squareTop == undefined || row.squareTop == 0) {
                                    openSquareTop = '<button class="btn btn-sm btn-success square_top_switch" data-id=' + val + ' data-status=1 data-value=' + row.hotValue + ' data-squareTop=' + row.squareTop + '>开启广场置顶</button>';
                                } else if (row.squareTop == 1) {
                                    openSquareTop = '<button class="btn btn-sm btn-info square_top_switch" data-id=' + val + ' data-status=1 data-value=' + row.hotValue + ' data-squareTop=' + row.squareTop + '>关闭广场置顶</button>';
                                }

                                var openTopicTop = '';
                                if (row.isHaveTopic) {
                                    if (row.topicTop == null || row.topicTop == undefined || row.topicTop == 0) {
                                        openTopicTop = '<button class="btn btn-sm btn-success topic_top_switch" data-id=' + val + ' data-status=1 data-value=' + row.hotValue + ' data-topicTop=' + row.topicTop + '>开启话题置顶</button>';
                                    } else if (row.topicTop == 1) {
                                        openTopicTop = '<button class="btn btn-sm btn-info topic_top_switch" data-id=' + val + ' data-status=1 data-value=' + row.hotValue + ' data-topicTop=' + row.topicTop + '>关闭话题置顶</button>';
                                    }
                                }


                                /*var edit = '<button class="btn btn-sm btn-danger opt-edit" data-id=' + val + ' data-status=1 data-value=' + row.hotValue +' data-tip=' + row.hotChangeFlag +'>修改热度值</button>';
                                var recovery = '<button class="btn btn-sm btn-primary opt-recovery" data-id=' + val + ' data-status=0>恢复</button>';*/
                                return editLabel + "</br>" + openSquareTop + "</br>" + openTopicTop;
                            }
                        }
                    ],
                    cache: false,
                    striped: true,
                    showRefresh: false,
                    pageSize: 10,
                    pagination: true,
                    pageList: [10, 20, 50, 100],
                    search: false,
                    sidePagination: "server", //表示服务端请求
                    //设置为undefined可以获取pageNumber，pageSize，searchText，sortName，sortOrder
                    //设置为limit可以获取limit, offset, search, sort, order
                    queryParamsType: "-",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            pageNumber: params.pageNumber,
                            pageSize: params.pageSize,
                            erbanNo: $('#erbanNo').val(),
                            nick: $('#nick').val(),
                            beginDate: $('#beginDate').val(),
                            endDate: $('#endDate').val(),
                            wolrdId: $('#wolrdId').val(),
                            dynamicLab: $('#dynamicLab').val(),
                            /*hotValueStart : $('#hotValueStart').val(),
                            hotValueEnd : $('#hotValueEnd').val(),*/
                            topStatus: $('#topStatus').val(),
                            partitionId: $('#partitionId').val(),
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    url: '/admin/dynamic/data/list.action',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });

                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });

                //重置
                $('#btnReset').on('click', function () {
                    $('#erbanNo').val("");
                    $('#nick').val("");
                    $('#beginDate').val("");
                    $('#endDate').val("");
                    $('#wolrdId').val("");
                    /*$('#hotValueStart').val("");
                    $('#hotValueEnd').val("");*/
                    $('#topStatus').val("");
                    $('#dynamicLab').val("");
                });

                //导出
                $('#btnExport').on('click', function () {
                    var erbanNo = $('#erbanNo').val();
                    var nick = $('#nick').val();
                    var beginDate = $('#beginDate').val();
                    var endDate = $('#endDate').val();
                    var wolrdId = $('#wolrdId').val();
                    var topStatus = $('#topStatus').val();
                    var dynamicLab = $('#dynamicLab').val();
                    if (isEmpty(erbanNo) && isEmpty(nick) && isEmpty(beginDate) && isEmpty(endDate) && isEmpty(wolrdId) && isEmpty(topStatus) && isEmpty(dynamicLab)) {
                        $("#tipMsg").text("请输入导出条件!");
                        $("#tipModal").modal('show');
                        return;
                    }
                    $('#searchForm').submit();
                });
                //图片放大
                $('#showModal').on('mouseenter', '#imgs', function (e) {
                    //console.log($(this), e.clientX);
                    var src = $(this).attr('src');
                    $('#imgMask img').attr('src', src);
                    $('#imgMask').show();
                    $('#imgMask').css({
                        top: e.clientY + 20,
                    })
                });
                $('#showModal').on('mouseleave', '#imgs', function (e) {
                    console.log('移出');
                    $('#imgMask').hide();
                });
                /*$("#table").on("click", '.opt-edit', function () {
                    var id = $(this).attr("data-id");
                    var status = $(this).attr("data-status");
                    var cusValue = $(this).attr("data-value");
                    var tip = $(this).attr("data-tip");
                    if(id == 'undefined'){
                        $("#tipMsg").text("id参数有误");
                        $("#tipModal").modal('show');
                        return;
                    }
                    if(status == 'undefined'){
                        $("#tipMsg").text("状态参数有误");
                        $("#tipModal").modal('show');
                        return;
                    }
                    $("#dynamicId1").val(id);
                    $("#status1").val(status);
                    if (!isEmpty(cusValue) && tip == 2) {
                        $("#cusHotValue").text(cusValue);
                    }else if (tip != 2) {
                        //不是自动更新的时候,查询热度值
                        $.ajax({
                            type: 'post',
                            url: "/admin/dynamic/data/getHotValue.action",
                            data: {
                                id: id,
                            },
                            dataType: "json",
                            success: function (json) {
                                $("#cusHotValue").text(json);
                            }
                        });
                    }else{
                        $("#cusHotValue").text("-");
                    }
                    // 打开编辑弹窗
                    $("#editModal").modal('show');
                    $("#hotValueChange").val("");
                });*/

                //恢复热度值
                $("#table").on("click", '.opt-recovery', function () {
                    var id = $(this).attr("data-id");
                    var status = $(this).attr("data-status");
                    if (id == 'undefined') {
                        $("#tipMsg").text("id参数有误");
                        $("#tipModal").modal('show');
                        return;
                    }
                    if (status == 'undefined') {
                        $("#tipMsg").text("状态参数有误");
                        $("#tipModal").modal('show');
                        return;
                    }
                    editHotValue(null, status, id, "恢复");
                });

                $('#btnEdit').click(function () {
                    // 打开编辑弹窗
                    $("#editRuleModal").modal('show');
                });
                /**
                 * 保存动态热度值规则
                 */
                $('#save_rule').click(function () {
                    var shareNum = $('#shareNum').val();
                    var likeNum = $('#likeNum').val();
                    var commentNum = $('#commentNum').val();
                    var shareNum1 = parseInt(shareNum);
                    var likeNum1 = parseInt(likeNum);
                    var commentNum1 = parseInt(commentNum);
                    if (isEmpty(shareNum) || isEmpty(likeNum) || isEmpty(commentNum)) {
                        $("#tipMsg").text("规则参数有误");
                        $("#tipModal").modal('show');
                        return;
                    }
                    if (isNaN(shareNum1) || isNaN(likeNum1) || isNaN(commentNum1)) {
                        $("#tipMsg").text("规则参数必须为数字");
                        $("#tipModal").modal('show');
                        return;
                    }
                    var value = shareNum + "," + commentNum + "," + likeNum;

                    if (confirm("你确认修改热度值规则吗?")) {
                        showLoading();
                        $.ajax({
                            type: 'post',
                            url: "/admin/dynamic/data/setHotValueRule.action",
                            data: {
                                rule: 'dynamic_hot_value_rule',
                                value: value,
                            },
                            dataType: "json",
                            success: function (json) {
                                hideLoading();
                                if (json.success == 'true') {
                                    $("#editRuleModal").modal('hide');
                                    $("#tipMsg").text("操作成功");
                                    $("#tipModal").modal('show');
                                    getHotValueRule();
                                    TableHelper.doRefresh("#table");
                                } else {
                                    $("#tipMsg").text("操作失败");
                                    $("#tipModal").modal('show');
                                }
                            }
                        });
                    }
                });

                $("#table").on("click", '.opt-label-edit', function () {
                    var id = $(this).attr("data-id");
                    $("#dynamicId").val(id)

                    //查询并渲染标签
                    $.ajax({
                        type: 'post',
                        url: "/admin/dynamic/data/getDynamicLabById.action",
                        data: {
                            id: id,
                        },
                        dataType: "json",
                        success: function (json) {
                            //清空checkbox
                            $("#editForm").find('input[name="dynamicLab"]').each(function () {
                                //$("#chk1").find('input:checkbox').eq(0).prop("checked",true);
                                $(this).prop("checked", false);
                            });


                            if (json != null && json != undefined) {
                                var labArr = json.labStr.split(",");
                                var len = labArr.length;
                                for (var i = 0; i < len; i++) {
                                    $("#editForm").find('input[name="dynamicLab"]').each(function () {
                                        if ($(this).val() == labArr[i]) $(this).prop("checked", true);
                                    });
                                }
                            }


                        }
                    });

                    // 打开编辑弹窗
                    $("#editModal").modal('show');
                });

                //标签编辑保存
                $("#editLabSave").click(function () {
                    var id = $("#dynamicId").val();

                    var dynamicLab = [];
                    $("#editForm").find('input[name="dynamicLab"]:checked').each(function () {
                        dynamicLab.push($(this).val());
                    });
                    if (dynamicLab.length > 3) {
                        $("#tipMsg").text("动态最多只能拥有3个标签");
                        $("#tipModal").modal('show');
                        return;
                    }
                    var dynamicStr = dynamicLab.join(",");
                    editLabSave(id, dynamicStr);
                });


                //广场置顶
                $("#table").on("click", '.square_top_switch', function () {
                    var id = $(this).attr("data-id");
                    var oldSquareTop = $(this).attr("data-squareTop");

                    var squareTop;

                    if (oldSquareTop == 0) {
                        squareTop = 1;
                    } else {
                        squareTop = 0;
                    }
                    //$("#dynamicId").val(id)
                    //查询并渲染标签
                    $.ajax({
                        type: 'post',
                        url: "/admin/dynamic/data/getTopInfo.action",
                        data: {
                            id: id,
                            topType: 1
                        },
                        dataType: "json",
                        success: function (json) {
                            if (json.success == 'true') {
                                if (json.data != undefined && json.data != null && json.data != '' && json.data != 'null') {
                                    if (confirm("广场已存在置顶动态(平台号：" + json.data + ")\n是否要更换置顶状态?")) {
                                        switchSquareTop(id, squareTop);
                                    }
                                } else {
                                    switchSquareTop(id, squareTop);
                                }

                            } else {
                                $("#tipMsg").text("操作失败");
                                $("#tipModal").modal('show');
                            }

                        }
                    });

                    //查询并渲染标签

                });


                //话题置顶
                $("#table").on("click", '.topic_top_switch', function () {
                    var id = $(this).attr("data-id");
                    var oldTopicTop = $(this).attr("data-topicTop");

                    var topicTop;

                    if (oldTopicTop == 0) {
                        topicTop = 1;
                    } else {
                        topicTop = 0;
                    }

                    $.ajax({
                        type: 'post',
                        url: "/admin/dynamic/data/getTopInfo.action",
                        data: {
                            id: id,
                            topType: 2
                        },
                        dataType: "json",
                        success: function (json) {
                            if (json.success == 'true') {
                                if (json.data != undefined && json.data != null && json.data != '' && json.data != 'null') {
                                    if (confirm("话题已存在置顶动态(平台号：" + json.data + ")\n是否要更换置顶状态?")) {
                                        switchTopicTop(id, topicTop);
                                    }
                                } else {
                                    switchTopicTop(id, topicTop);
                                }
                            } else {
                                $("#tipMsg").text("操作失败");
                                $("#tipModal").modal('show');
                            }

                        }
                    });

                });
            });
        },
        initPartition() {
            getPartitionInfoList().then(res => {
                let data = res.data;
                buildSelectOption(
                    "#partitionId",
                    null,
                    [{
                        value: '',
                        text: '全部'
                    }].concat(data.map((v) => {
                    return {
                        value: v.id,
                        text: v.desc,
                    };
                    }))
                );
            });
        },
    },

};


//修改/恢复热度值
function editHotValue(value, status, id, text) {
    if (confirm("你确认" + text + "该动态的热度值吗?")) {
        showLoading();
        $.ajax({
            type: 'post',
            url: "/admin/dynamic/data/changeHotValue.action",
            data: {
                dynamicId: id,
                status: status,
                value: value
            },
            dataType: "json",
            success: function (json) {
                hideLoading();
                $("#editModal").modal('hide');
                if (json.success == 'true') {
                    $("#tipMsg").text("操作成功");
                    $("#tipModal").modal('show');
                    TableHelper.doRefresh("#table");
                } else {
                    $("#tipMsg").text("操作失败");
                    $("#tipModal").modal('show');
                }
            }
        });
    }
}
//判断空值
function isEmpty(data) {
    if (data == null || data == undefined || data == "" || data == 'undefined') {
        return true;
    }
    return false;
}


function setTypeSelectOption() {
    $.ajax({
        type: 'get',
        url: "/admin/world/list.action",
        data: {
            status: 1,
            pageNumber: 1,
            pageSize: 1000
        },
        dataType: "json",
        success: function (json) {
            if (json.total > 0) {
                var rows = json.rows;
                for (var i = 0; i < rows.length; i++) {
                    $('#wolrdId').append('<option value="' + rows[i].id + '">' + rows[i].name + '</option>');
                }
            }
        }
    });
}

/**
 * 获取动态热度值规则
 */
function getHotValueRule() {
    $.ajax({
        type: 'get',
        url: "/admin/dynamic/data/getHotValueRule.action",
        data: {
            rule: 'dynamic_hot_value_rule'
        },
        dataType: "json",
        success: function (json) {
            if (!isEmpty(json)) {
                var value = json;
                if (value.length == 3) {
                    for (var i = 0; i < value.length; i++) {
                        $('#shareRule').text(value[0]);
                        $('#commentRule').text(value[1]);
                        $('#likeRule').text(value[2]);
                    }
                }
            }
        }
    });
}


function editLabSave(id, labStr) {
    $.ajax({
        type: 'post',
        url: "/admin/dynamic/data/editLabel.action",
        data: {
            id: id,
            labStr: labStr
        },
        dataType: "json",
        success: function (json) {
            $("#editModal").modal('hide');
            if (json.success == 'true') {
                $("#tipMsg").text("操作成功");
                $("#tipModal").modal('show');
                TableHelper.doRefresh("#table");
            } else {
                $("#tipMsg").text("操作失败");
                $("#tipModal").modal('show');
            }
        }
    });
}


function switchSquareTop(id, squareTop) {
    $.ajax({
        type: 'post',
        url: "/admin/dynamic/data/switchSquareTop.action",
        data: {
            id: id,
            squareTop: squareTop
        },
        dataType: "json",
        success: function (json) {
            if (json.success == 'true') {
                $("#tipMsg").text("操作成功");
                $("#tipModal").modal('show');
                TableHelper.doRefresh("#table");
            } else {
                $("#tipMsg").text("操作失败");
                $("#tipModal").modal('show');
            }


        }
    });
}


function switchTopicTop(id, topicTop) {
    debugger
    $.ajax({
        type: 'post',
        url: "/admin/dynamic/data/switchTopicTop.action",
        data: {
            id: id,
            topicTop: topicTop
        },
        dataType: "json",
        success: function (json) {
            if (json.success == 'true') {
                $("#tipMsg").text("操作成功");
                $("#tipModal").modal('show');
                TableHelper.doRefresh("#table");
            } else {
                $("#tipMsg").text("操作失败:" + json.message);
                $("#tipModal").modal('show');
            }


        }
    });
}
</script>

<style scoped>
#imgMask {
    position: absolute;
    top: 0;
    left: 0;
    min-width: 150px;
    padding: 4px;
    background: #fff;
    z-index: 999;
    display: none;
}

#imgMask img {
    max-height: 600px;
    max-width: 600px;
    vertical-align: top;
}

.fixed-table-body {
    height: auto !important;
}</style>