<!DOCTYPE html>
<!--[if IE 8]>
<html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]>
<html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <base href="#springUrl('/assets/adminlte/')"/>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>工作台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.5 -->
    <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="plugins/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="plugins/ionicons/css/ionicons.min.css">

    <!-- DataTables -->
    <link rel="stylesheet" href="plugins/datatables/dataTables.bootstrap.css">

    <!-- Theme style -->
    <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
    <!-- iCheck -->
    <link rel="stylesheet" href="plugins/iCheck/flat/blue.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="plugins/morris/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="plugins/datepicker/datepicker3.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="plugins/daterangepicker/daterangepicker-bs3.css">
    <!-- Select2 -->
    <link rel="stylesheet" href="plugins/select2/select2.min.css">
    <link rel="stylesheet"
          href="plugins\bootstrap-fileinput\fileinput.min.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet"
          href="plugins/ztree/css/metroStyle/metroStyle.css" type="text/css"/>
    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        #QySendMassMyModal label {
            font-weight: 400;
        }

        div[id^="whereSearch"] {
            display: none;
        }
    </style>
</head>
<body class="hold-transition skin-blue sidebar-mini">


<div class="wrapper">
    <div class="content-wrapper" style="margin-left:0;">
        <div id="importExcelDiv"></div>

        <section class="content-header">
            <h1>
                内容管理
                <small>文章管理</small>
            </h1>
            <ol class="breadcrumb">
                <li><a><i class="fa fa-dashboard"></i>首页</a></li>
                <li><a class="active">文章管理列表</a></li>
            </ol>
        </section>

        <input id="previewOpenId" style="display: none;">


        <div id="MassMyModal" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
             style="z-index:9999">
            <form id="MassSendForm">
                <div class="modal-dialog" style="width:50%">
                    <div class="modal-content" style="width:80%;margin:0px auto;">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">选择群发对象</h4>
                        </div>
                        <!-- dialog body -->
                        <div class="modal-body" style="width:100%;">
                            <!--<div class="form-group form-md-line-input">-->
                            <!--<label style="width:100%">群发方式</label>-->
                            <!--<label><input type="radio" name="sendType" value="0" checked>全部用户</label>-->
                            <!--<label><input type="radio" name="sendType" value="1">按条件</label>-->
                            <!--</div>-->
                            <div style="display:none" id="sex">
                                <label style="clear:both;width:100%">性别</label>
                                <select class="form-control select2 select2-hidden-accessible"
                                        name="sex" style="width: 100%;" tabindex="-1"
                                >
                                    <option value="">全部</option>
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </div>
                            <div class="form-group form-md-line-input" style="display:none" id="massSendArea">
                                <label style="clear:both;width:100%">地区</label>
                                <p style="-webkit-box-flex: 1;float:left;width:80%;" rows="2" type="text"
                                   class="form-control" name="area" id="area"
                                   maxlength="2000" placeholder="请点击选择按钮选择地区" disabled></p>
                                <input type="text" class="form-control" name="areaIds"
                                       id="areaIds" value="" maxlength="2000"
                                       disabled style="display: none">
                                <a style="width: 15%;-webkit-box-flex: 0; margin-left: 20px; margin-top: 2px;float:left"
                                   class="btn btn-primary btn-sm" id="areaselect">选择</a>
                            </div>
                            <div class="form-group form-md-line-input" style="display:none" id="massSendTag">
                                <label style="clear:both;width:100%">选择标签</label>
                                <select class="form-control select2" multiple='multiple' style="width: 100%"
                                        id="addlabel" name="tags" data-placeholder='请选择标签'>
                                </select>
                            </div>
                            <div class="box-footer" style="clear:both;">
                                <a class="btn btn-primary" id="massSend">群发</a>
                                <a id="massSendCanel" class="btn btn-default close">取消</a>
                            </div>
                            <input name="newMedias" style="display:none;"/>
                        </div>
                        <!-- dialog buttons -->
                    </div>
                </div>
            </form>
        </div>


        <div id="QySendMassMyModal" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"
             style="">
            <form id="QyMassSendForm">
                <div class="modal-dialog" style="width:50%">
                    <div class="modal-content" style="width:80%;margin:0px auto;">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title" id="QymyModalLabel">选择发送对象</h4>
                        </div>
                        <!-- dialog body -->
                        <div class="modal-body" style="width:100%;">

                            <div class="form-group form-md-line-input">
                                <label style="clear:both;width:100%">应用</label>
                                <select class="form-control select2 select2-hidden-accessible"
                                        name="agent" style="width: 100%;" tabindex="-1">
                                </select>
                            </div>

                            <div class="form-group form-md-line-input">
                                <label style="width:100%">发送方式</label>
                                <label><input type="radio" name="sendType" value="0" checked>全部用户</label>
                                <label><input type="radio" name="sendType" value="1">按条件</label>
                            </div>
                            <div class="form-group form-md-line-input" style="display: none">
                                <label style="clear:both;width:100%">性别</label>
                                <select class="form-control select2 select2-hidden-accessible"
                                        name="sex" style="width: 100%;" tabindex="-1">
                                    <option value="">全部</option>
                                    <option value="1">男</option>
                                    <option value="2">女</option>
                                </select>
                            </div>
                            <div class="form-group form-md-line-input" id="whereSearchOrg">
                                <div class="input-group">
                                    <input type="text" id="orgId" name="orgId" value=""
                                           class="form-control" style="display: none">
                                    <span class="input-group-btn">
                                            <button type="button" id="orgSelect"
                                                    class="btn btn-info btn-flat">选择部门</button>
                                    </span>

                                </div>
                            </div>
                            <p id="orgName" name="orgName" value="" style="width:100%;">
                            </p>
                            <div class="form-group form-md-line-input" id="whereSearchTag">
                                <label>企业标签</label>
                                <select class="form-control select2" multiple="multiple" data-placeholder="选择企业标签"
                                        style="width: 100%;" id="taglist">

                                </select>
                            </div>
                            <div class="form-group form-md-line-input" id="whereSearchQyUser">
                                <div class="input-group">
                                    <input type="text" id="userid" name="userid"
                                           class="form-control" style="display: none">
                                    <input type="text" id="wxUserName" name="wxUserName"
                                           class="form-control" style="display: none;">
                                    <span class="input-group-btn">
                                            <button type="button" id="orgtypeSelect"
                                                    class="btn btn-info btn-flat">选择人员</button>
                                         </span>
                                </div>
                            </div>
                            <p id="searchName" name="searchName" value="" style="width:100%;">
                            </p>
                            <div class="box-footer" style="clear:both;">
                                <a class="btn btn-primary" id="qyMassSend">发送</a>
                                <a id="qyMassSendCanel" class="btn btn-default" data-dismiss="modal">取消</a>
                            </div>
                        </div>
                        <!-- dialog buttons -->
                    </div>
                </div>
            </form>
        </div>


        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-md-3">
                    <div class="box">

                        <div class="box-body">
                            <div class="zTreeDemoBackground left">
                                <ul id="tree" class="ztree"></ul>
                            </div>
                        </div>
                        <!-- /.box-body -->
                    </div>
                    <!-- /.box -->
                </div>
                <div class="col-xs-9">
                    <div class="box">
                        <div class="box-header">
                            <form id="seachTableForm" action="#springUrl('/a/cfarticle/list')" method="get">
                                <div class="col-xs-2">
                                    <input type="text" class="form-control"
                                           placeholder="文章标题" name="title"
                                           value="">
                                </div>
                                <div class="col-xs-2">
                                    <div class="input-group date">
                                        <div class="input-group-addon">
                                            <i class="fa fa-calendar"></i>
                                        </div>
                                        <input type="text" class="form-control pull-right datepicker"
                                               value="$!{startTime}"
                                               name="startTime" placeholder="发布时间"
                                               readonly="readonly">
                                    </div>
                                </div>
                                <div>
                                    <input type="text" class="form-control" name="column" style="display: none;">
                                </div>
                                <a class="search btn btn-primary">搜索</a>
                                #if($shiro.hasPermission("qy:cfarticle:edit"))
                                <a href="#springUrl('/a/cfarticle/form')" class="btn btn-primary">新增文章</a>

                                #end
                                #if($shiro.hasPermission("mp:article:mass"))
                                <a href="javascript:void(0)" id="sendMessageMass" class="btn bg-olive">生成微信图文素材</a>

                                #end
                                #if($shiro.hasPermission("qy:article:sendMass"))
                                <a href="javascript:void(0)" id="qysendMessageMass" class="btn bg-olive">企业号发送</a>
                                #end

                            </form>
                        </div><!-- /.box-header -->
                        <div class="box-body">
                            <table id="table" class="table table-bordered table-striped">
                                <thead>
                                <tr>

                                    <th>选择</th>
                                    <th>文章标题</th>
                                    <th>所属栏目</th>
                                    <th>创建时间</th>
                                    <th>是否推荐文章</th>
                                    <th>是否推荐banner图</th>
                                    <th>是否发布文章</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody id="tablebody" class="tablebody">
                                </tbody>

                            </table>
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->
    <div class="modal fade" tabindex="-1" role="dialog" id="myModal">
        <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">操作提示</h4>
                </div>
                <div class="modal-body">
                    <p>是否确认</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="show()">取消</button>
                    <button type="button" class="btn btn-primary" onclick="save()">确认</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->

    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div><!-- ./wrapper -->
<!-- jQuery 2.1.4 -->
<script src="plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- Bootstrap 3.3.5 -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables/extensions/i18n/lanauage_ch.js"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<!-- FastClick -->
<script src="plugins/fastclick/fastclick.min.js"></script>
<!-- Select2 -->
<script src="plugins/select2/select2.full.min.js"></script>
<!--fileinput js-->
<script src="plugins\bootstrap-fileinput\fileinput.js"></script>
<script src="plugins/bootstrap-fileinput/zh.js"></script>
<script src="plugins/bootstrap-fileinput/zh2.js"></script>
<!-- AdminLTE App -->
<script src="dist/js/app.min.js"></script>
<script type="text/javascript"
        src="plugins/jquery-validation/js/jquery.validate.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="plugins/ztree/js/jquery.ztree.all.min.js"
        type="text/javascript"></script>
<script>
    var csrfheader = {name: '_csrf_header', value: '${_csrf.headerName}'};
    var csrftoken = {name: '_csrf', value: '${_csrf.token}'};
</script>

<script src="common/js/cfapp.js"></script>
<script>
    function formatDates(now) {
        var now = new Date(now);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return year + "-" + month + "-" + date + "   " + hour + ":"
            + minute + ":" + second;
    }

    var articleTreeUri = "#springUrl('/a/column/getfetchDataChild')";//树形栏目数据
    var fanssList = "#springUrl('/a/managefanss/fanss/fetchdata')";//粉丝数据

    var searchOrg = "#springUrl('/a/orgunit/treeData')";  //选择部门tree

    var sQyUserSource = "#springUrl('/a/qyuser/listData')";//选择人员

    var mpselectedArticles = [];

    var qySendMassMessageUrl = "#springUrl('/a/qyMessage/sendMessage')";//企业号发送文章

    var qyagentListUrl = "#springUrl('/a/qyagent/listData')";
    var protocol = window.location.protocol;
    var host = window.location.host;
    var domain = protocol + '//' + host;


    /**
     * 组织选择
     */
    $('#orgSelect').on('click',
        function () {
            Cfapp.treeSelect({
                title: '部门选择',
                url: searchOrg,
                displayFields: 'orgName',
                storeFields: 'orgId',
                success: function () {
                    console.log('success');
                },
                cancel: function () {
                    console.log('cancel');
                }
            })
        });

    /**
     * 加载企业标签
     */
    var getTagList = function () {
        var tagids = $('#tagIds').val();
        var tagArr = [];
        if (tagids && tagids != '') {
            tagArr = tagids.split(',');
        }
        var tagList = "#springUrl('/a/qytag/listData')";
        var formdata = {
            iDisplayStart: 0,
            iDisplayLength: 0
        };
        $.getJSON(tagList, formdata, function (retData) {
            var htmlStr = '';
            if (retData.aaData && retData.aaData.length > 0) {

                for (var i = 0, j = retData.aaData.length; i < j; i++) {

                    var tagObj = retData.aaData[i];
                    htmlStr += '<option value="' + tagObj.id + '">' + tagObj.name + '</option>';

                }
            }
            ;
            $('#taglist').html(htmlStr);
            $(".select2").val(tagArr).trigger('change');
        });
    };

    /**
     *人员选择
     * */
    $('#orgtypeSelect').on('click',
        function () {
            Cfapp.f7({
                dataUrl: sQyUserSource,  //导入的action Url
                checkType: 'multi', // 多选为multi
                title: "绑定微信人员",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '头像', '姓名', '手机号码', '职位', '所属组织'],
                isSearch: '0',  //0搜索  1：不搜索
                searchColumns: ["name", "mobile"],//搜索的字段名称
                searchColumnsRemarks: ["人员姓名", "手机号"],//搜索的字段备注
                aoColumns: [{
                    "mData": "id"
                }, {
                    "mData": "avatar"
                }, {
                    "mData": "name"
                }, {
                    "mData": "mobile"
                }, {
                    "mData": "positionName"
                }, {
                    "mData": "orgName"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return '<input type="checkbox" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.name + '">';
                    }
                }, {
                    "aTargets": [1],
                    "mData": "avatar",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        if (a && a != '') {
                            return '<img src="' + a + '" width="60px" height="60px">';
                        } else {
                            return '';
                        }
                    }
                }],
                success: function () {
                    if ($("#wxUserName").val()) {
                        $("#searchName").html($("#wxUserName").val());
                    }
                },   //确定处理
                cancel: function () {

                },    // 取消的处理
                displayFields: 'wxUserName',  //显示的字段
                storeFields: 'userid' // 储存的字段
            })
        });

    /**
     *
     * checkBox选择控制
     */
    function recordingOne(ele) {
        //判断是选中还是取消
        if ($(ele).is(":checked")) {
            //选中记录value
            if (mpselectedArticles.length <= 10) {
                mpselectedArticles.push($(ele).val());
            } else {
                $(ele).prop("checked", false);
            }
        } else {
            //取消删除value
            mpselectedArticles.splice($.inArray($(ele).val(), mpselectedArticles), 1);
        }
    }


    $('#areaselect').on('click',
        function () {
            Cfapp.treeSelect({
                title: '地区选择',
                url: areaUrl,
                displayFields: 'area',
                storeFields: 'areaIds',
                success: function () {
                    console.log('success');
                },
                cancel: function () {
                    console.log('cancel');
                }
            })
        });


    $("#qyMassSend").click(function () {//企业号发送

        var qyMassSendData = {};

        qyMassSendData.sendType = $("input[name='sendType']:checked").val();
        qyMassSendData.sex = $("select[name='sex']").val();
        qyMassSendData.orgId = $("#orgId").text();
        qyMassSendData.taglist = $("#taglist").val();
        qyMassSendData.userid = $("#userid").val();
        qyMassSendData.articlesId = mpselectedArticles.toString();
        qyMassSendData.agentId = $("select[name='agent']").val();

        qyMassSendData.domain = domain;
        $.ajax({
            "type": "POST",
            "url": qySendMassMessageUrl,
            "dataType": "json",
            "data": qyMassSendData, //以json格式传递
            "success": function (data) {

            }
        });
    })

    function initMenuTree() {
        var menuTree = $('#tree');
        var getMenuTreeData = function () {
            $.ajax({
                "type": "POST",
                "url": articleTreeUri,
                "data": {_csrf_header: csrfheader.value, _csrf: csrftoken.value},
                "dataType": "json",
                "success": buildOrgTree
            });
        };
        var buildOrgTree = function (data) {
            var setting = {
                data: {simpleData: {enable: true}}, callback: {
                    beforeClick: function (id, node) {
                        var menuid = node.id;
                        if (menuid == 0) {
                            $("input[name='column']").val('');
                        } else {
                            $("input[name='column']").val(menuid);
                        }
                        $("#table").dataTable().fnClearTable();
                    }
                }
            };
            var zNodes = data.aaData;
            tree = $.fn.zTree.init(menuTree, setting, zNodes);

            tree.expandAll(true);
            tree.expandNode(tree.getNodesByFilter(function (node) {
                return node.level == 0;
            }, true), true, false, false);
        };
        getMenuTreeData();
    }

    function seachTable() {
        var sSource = "#springUrl('/a/cfarticle/listData?type=0')";
        var aoData = {
            iDisplayStart: 1,
            iDosplayLength: 10
        }
        var retrieveData = function (sSource, aoData, fnCallback) {

            $("#seachTableForm input").each(function () {
                var params = {
                    name: $(this).attr("name"),
                    value: $(this).val()
                };
                aoData.push(params);
            })

            $.ajax({
                "type": "GET",
                "url": sSource,
                "dataType": "json",
                "data": aoData, //以json格式传递
                "success": fnCallback
            });
        };

        dateformatId = function (a, b, c, d) {
            if (a.id) {
                if (mpselectedArticles.indexOf(a.id + '') >= 0) {
                    return '<input type="checkbox" onchange="recordingOne(this)" class="checkchild" checked="true"  value="' + a.id + '" />';
                } else {
                    return '<input type="checkbox" onchange="recordingOne(this)" class="checkchild"  value="' + a.id + '" />';
                }
            } else {
                return '';
            }
        }

        function alertHtml(msg) {//alert公共方法
            Cfapp.alert({
                message: msg,
                btntext: "确定",
                success: function () {

                }
            })
        }

        $("#sendMessageMass").click(function () {//组合图文,进行群发

            if (mpselectedArticles.length < 1) {
                alertHtml("请选择图文,在进行生成");
            } else {
                Cfapp.confirm({
                    message: "确定要生成吗?共计" + mpselectedArticles.length + "篇文章",
                    btnoktext: "确定",
                    btncanceltext: "取消",
                    success: function () {
                        $(".modal-backdrop").fadeOut();
                        var warningMsg = Cfapp.warning({
                            content: '正在生成中,请稍后',  //
                            title: "提示"
                        });
                        $.ajax({
                            type: "POST",
                            url: "#springUrl('/a/cfarticle/mergeArticles')",
                            data: {
                                articles: mpselectedArticles.toString(),
                                domain: domain,
                                _csrfheader: csrfheader.value,
                                _csrf: csrftoken.value
                            },
                            dataType: "json",
                            success: function (data) {
                                warningMsg.destory();
                                if (data.errorNo == 0) {
                                    var mediaId = data.mediaId;
                                    preview(mediaId);
                                } else {
                                    Cfapp.alert({
                                        message: "生成失败,请检查数据！",
                                        btntext: "确定",
                                        success: function () {
                                            location.href = "#springUrl('/a/cfarticle/list')";
                                        }
                                    });
                                }
                            },
                            error: function () {
                            }
                        })
                    },
                    cancel: function () {
                        $(".modal-backdrop").fadeOut();
                    }
                });
            }
        })


        $("#qysendMessageMass").click(function () {
            if (mpselectedArticles.length < 1) {
                alertHtml("请选择图文,在进行发送");
            } else {
                $("#QySendMassMyModal").modal("show");
            }
        })


        /**
         * 预览功能
         */
        function preview(mediaId) {
            Cfapp.f7({
                dataUrl: fanssList,
                checkType: 'single', // 多选为multi
                title: "选择粉丝进行预览",
                btnoktext: "确定",
                btncanceltext: "取消",
                columns: ['选择', '头像', '昵称'],
                isSearch: '0',
                searchColumns: ["nickname"],//搜索的字段名称
                searchColumnsRemarks: ['昵称'],//搜索的字段备注
                aoColumns: [{
                    "mData": "openid"
                }, {
                    "mData": "headimgurl"
                }, {
                    "mData": "nickname"
                }],
                aoColumnDefs: [{
                    "aTargets": [0],
                    "mData": "openid",
                    "mRender": function (a, b, c, d) {
                        return '<input type="radio" id="' + a + '" name="sel" data-value="' + a + '" data-name="' + c.nickname + '">';
                    }
                }, {
                    "aTargets": [1],
                    "mData": "img",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return "<img src='" + a + "' style='width: 80px;height:80px;' />";
                    }
                }],
                success: function () {
                    OKpreview(mediaId);
                },
                cancel: function () {

                },
                storeFields: 'previewOpenId', // 储存的字段
                displayFields: ''
            })
        }

        function OKpreview(mediaId) {

            $.ajax({
                type: "get",
                url: "#springUrl('/a/article/preview')",
                data: {openId: $("#previewOpenId").val(), mediaId: mediaId},
                dataType: "json",
                success: function (previewData) {
                    if (previewData.errorNo == 0) {
                        Cfapp.alert({
                            message: "预览文章发送成功,请在手机上查看",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/cfarticle/list')";
                            }
                        });
                    }
                }
            })
        }

        $('#table').DataTable({
            "lengthChange": false,
            "searching": false,
            "ordering": false,
            "bFiltered": false,
            "bStateSave": true, // save datatable state(pagination, sort, etc) in cookie.
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": sSource,
            "fnServerData": retrieveData,
            "pagingType": "full_numbers",
            "aoColumns": [

                {
                    "mData": dateformatId
                },
                {
                    "mData": "title"
                },
                {
                    "mData": "columnName"
                },
                {
                    "mData": "createTime"
                }
                ,
                {
                    "mData": "recommended"
                }
                ,
                {
                    "mData": "whetherBanner"
                }
                ,
                {
                    "mData": "article"
                },
                {
                    "mData": "id"
                }],
            "aoColumnDefs": [

                {
                    "aTargets": [1],
                    "mData": "title",
                    "mRender": function (a, b, c, d) {
                        if (c.type == 0) {
                            return '<a href="#springUrl("/a/cfarticle/form?id=' + c.id + '")" data-id="' + c.id + '" data-action="view">' + a + '</a>';
                        } else {
                            return '<a href="#springUrl("/a/cfarticle/picform?id=' + c.id + '")" data-id="' + c.id + '" data-action="view">' + a + '</a>';
                        }
                    }
                }, {
                    "aTargets": [3],
                    "mData": "createTime",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        return formatDates(a, "yyyy-MM-dd HH:mm:ss");
                    }
                }, {
                    "aTargets": [4],
                    "mData": "recommended",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        var html = ''
                        if (a == 1) {
                            html += '<input type="checkbox" id="recommended" name="recommended" value="' + a + '" checked="true" onchange="onreco(event)">';
                        } else {
                            html += '<input type="checkbox" id="recommended" name="recommended" value="' + a + '" onchange="onreco(event)">';
                        }
                        return html;
                    }
                }, {
                    "aTargets": [5],
                    "mData": "whetherBanner",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        var html = ''
                        if (a == 1) {
                            html += '<input type="checkbox" id="whetherBanner" name="whetherBanner" value="' + a + '" checked="true" onchange="onBanner(event)">';
                        } else {
                            html += '<input type="checkbox" id="whetherBanner" name="whetherBanner" value="' + a + '" onchange="onBanner(event)">';
                        }
                        return html;
                    }
                },
                {
                    "aTargets": [6],
                    "mData": "article",
                    "mRender": function (a, b, c, d) {//a表示createtime对应的值，c表示当前记录行对象
                        var html = ''
                        if (a == 1) {
                            html += '<input type="checkbox" id="article" name="article" value="' + a + '" checked="true" onchange="onArticle(event)">';
                        } else {
                            html += '<input type="checkbox" id="article" name="article" value="' + a + '" onchange="onArticle(event)">';
                        }
                        return html;
                    }
                },
                {
                    "aTargets": [7],
                    "mData": "id",
                    "mRender": function (a, b, c, d) {//a表示id对应的值，c表示当前记录行对象

                        var html = '#if($shiro.hasPermission("qy:cfarticle:edit"))';//
                        if (c.type == 0) {
                            html += '<a href="#springUrl("/a/cfarticle/form?id=' + a + '")" data-id="' + a + '" data-action="view" class="btn green">修改</a>';
                        } else {
                            html += '<a href="#springUrl("/a/cfarticle/picform?id=' + a + '")" data-id="' + a + '" data-action="view" class="btn green">修改</a>';
                        }
                        html += '<a href="javascript:void(0);" data-id="' + a + '" data-action="remove" onclick="removeData(' + a + ')" class="btn red">删除</a>';
                        html += '<input type="checkbox" id="id" name="id" value="' + a + '" style="display: none" >';
                        html += '#end';
                        html += '#if($shiro.hasPermission("qy:review:view"))';

                        //html+= '<a href="#springUrl("/a/review/list?entityId=' + a + '")" data-id="' + a + '" data-action="view" class="btn green">评论</a>';
                        html += '#end';
                        return html;
                    }
                }

            ]
        });
    }

    var or = 0;

    function onreco(e) {
        if (e.target.value == 1) {
            Cfapp.confirm({
                message: "是否确认取消推荐",
                btntext: "确定",
                success: function () {
                    select(e)
                },
                cancel: function () {
                    location.href = "#springUrl('/a/cfarticle/list')";
                }
            });
        } else {
            f(e)
        }
    }

    function onArticle(e) {
        if (e.target.value == 1) {
            Cfapp.confirm({
                message: "是否确认取消推荐文章",
                btntext: "确定",
                btncanceltext: "取消",
                success: function () {
                    if (e.target.value == '0') {
                        e.target.value = '1'
                    } else if (e.target.value == '1') {
                        e.target.value = '0'
                    }
                   save()
                },
                cancel: function () {
                    location.href = "#springUrl('/a/cfarticle/list')";
                }
            });
        } else if (e.target.value == 0){
            Cfapp.confirm({
                message: "是否确认推荐文章",
                btntext: "确定",
                btncanceltext: "取消",
                success: function () {
                    if (e.target.value == '0') {
                        e.target.value = '1'
                    } else if (e.target.value == '1') {
                        e.target.value = '0'
                    }
                    save()
                },
                cancel: function () {
                    location.href = "#springUrl('/a/cfarticle/list')";
                }
            });
        }

    }



    function onBanner(e) {
        if (e.target.value == 1) {
            Cfapp.confirm({
                message: "是否确认取消推荐",
                btntext: "确定",
                btncanceltext: "取消",
                success: function () {
                    select(e)
                },
                cancel: function () {
                    location.href = "#springUrl('/a/cfarticle/list')";
                }
            });
        } else {
            if (e.target.value == '0') {
                e.target.value = '1'
            } else if (e.target.value == '1') {
                e.target.value = '0'
            }
            save()
        }
    }

    function select(e) {
        if (e.target.value == '0') {
            e.target.value = '1'
        } else if (e.target.value == '1') {
            e.target.value = '0'
        }
        save()
    }

    function show() {
        $('#myModal').modal('hide')
    }

    function f(e) {
        var url = "#springUrl('/a/cfarticle/selectYes')"
        $.ajax({
            url: url,
            type: "POST",
            data: {_csrf_header: csrfheader.value, _csrf: csrftoken.value},
            success: function (rsp) {
                if (rsp.errorNo == "0") {
                    if (rsp.data >= 4) {
                        Cfapp.alert({
                            message: "所选推荐不能超过四个",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/cfarticle/list')";
                            }
                        });
                    } else {
                        Cfapp.confirm({
                            message: "是否确认推荐",
                            btntext: "确定",
                            btncanceltext: "取消",
                            success: function () {
                                select(e)
                            },
                            cancel: function () {

                            }
                        });
                    }
                }
            }

        });
    }

    function b() {
        var url = "#springUrl('/a/cfarticle/selectBanner')"
        $.ajax({
            url: url,
            type: "POST",
            data: {_csrf_header: csrfheader.value, _csrf: csrftoken.value},
            success: function (rsp) {

                if (rsp.errorNo == "0") {
                    if (rsp.data >= 4) {
                        Cfapp.alert({
                            message: "所选推荐不能超过四个",
                            btntext: "确定",
                            success: function () {
                                location.href = "#springUrl('/a/cfarticle/list')";
                            },
                            cancel: function () {
                                location.href = "#springUrl('/a/cfarticle/list')";
                            }
                        });

                    } else {
                        Cfapp.confirm({
                            message: "是否确认推荐",
                            btntext: "确定",
                            success: function () {
                                select(e)

                            },
                            cancel: function () {
                                location.href = "#springUrl('/a/cfarticle/list')";
                            }
                        });

                    }
                }
            }

        });
    }

    function save() {
        $('#myModal').modal('hide')
        var datas = [];
        var counta = 0;
        var countb = 0;
        $('.tablebody').children().each(function (index, item) {
            const id = $(item).find('[name="id"]').val()
            const recommended = $(item).find('[name="recommended"]').val()
            const whetherBanner = $(item).find('[name="whetherBanner"]').val()
            const article = $(item).find('[name="article"]').val()

            datas.push({
                id: id,
                recommended: recommended,
                whetherBanner: whetherBanner,
                article : article
            })

        })

        var url = "#springUrl('/a/cfarticle/updatecom')"
        $.ajax({
            url: url,
            type: "POST",
            dateType: 'json',
            data: {_csrf_header: csrfheader.value, _csrf: csrftoken.value, datas: JSON.stringify(datas)},
            success: function (rsp) {
                console.log(rsp);
                if (rsp.errorNo == "0") {
                    Cfapp.alert({
                        message: "修改成功",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/cfarticle/list')";
                        }
                    });
                } else {
                    Cfapp.alert({
                        message: "修改失败",
                        btntext: "确定",
                        success: function () {
                            location.href = "#springUrl('/a/cfarticle/list')";
                        }
                    });
                }
            }

        });

    }

    jQuery(document).ready(function () {


        $(".select2").select2();
        seachTable();
        initMenuTree();
        getTagList();
        $('.datepicker').datepicker({
            show: true,
            format: 'yyyy-mm-dd',
            autoclose: true,
            language: 'zh-CN',
            todayBtn: 'linked',
            clearBtn: 'linked'

        });
        $('.search').click(function () {
            $("#table").dataTable().fnClearTable();
        });

        $("#QySendMassMyModal input[name='sendType']").change(function () {
            if ($(this).val() == "1") {
                $("div[id^='whereSearch']").show();
                $("#searchName").show();
                $("#orgName").show();
            } else {
                $("div[id^='whereSearch']").hide();
                $("#searchName").hide();
                $("#orgName").hide();
            }
        })


        $.ajax({
            "type": "GET",
            "url": qyagentListUrl,
            "dataType": "json",
            "data": {iDisplayStart: 0, iDisplayLength: 0}, //以json格式传递
            "success": function (data) {
                if (data && data.aaData) {
                    var list = data.aaData;
                    var agentHTML = "";
                    for (var i = 0; i < list.length; i++) {
                        agentHTML += "<option value='" + list[i].agentId + "'>" + list[i].name + "</option>";
                    }
                    $("select[name='agent']").append(agentHTML);
                }
            }
        });
    });

    Cfapp.init();

    function removeData(data) {
        Cfapp.confirm({
            message: "确定要删除吗",
            btnoktext: "确定",
            btncanceltext: "取消",
            success: function () {
                $.ajax({
                    type: "POST",
                    url: "#springUrl('/a/cfarticle/delete')",
                    data: {id: data, _csrf_header: csrfheader.value, _csrf: csrftoken.value},
                    dataType: "json",
                    success: function (data) {
                        if (data.errorNo == 0) {
                            Cfapp.alert({
                                message: "删除成功",
                                btntext: "确定",
                                success: function () {
                                    location.href = "#springUrl('/a/cfarticle/list')";
                                }
                            });
                        }
                    },
                    error: function () {
                    }
                })
            },
            cancel: function () {
                $(".modal-backdrop").fadeOut();
            }
        });
    }


</script>

</body>
</html>
