<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"></c:set>

<link rel="stylesheet" href="${contextPath}/static/assets/css/jquery-ui.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/datepicker.css" />
<link rel="stylesheet" href="${contextPath}/static/assets/css/ui.jqgrid.css" />

<style>
    .white_content {
        display: none;
        position: absolute;
        top: -50px;
        left: 25%;
        width: 35%;
        /*border: 2px solid #d3d3d3;
        */background-color: white;
        z-index: 1002;

        /* overflow: auto; */

    }
</style>

<div style="background: rgba(1,1,2,0.05)">
    <br>
    搜索：<input type="text" class="input-sm"  id="keywords"/>
    &nbsp;&nbsp;
    筛选日期：<input type="text" class="input-sm" placeholder="开始日期"  id="startDate"/>
    <input type="text" class="input-sm" placeholder="结束日期"  id="endDate"/>
    &nbsp;<button id="searchd" type="button" class="btn" >搜索</button>
    &nbsp;<button id="addd" type="button" class="btn" >增加</button>
    <br>
    <br>
</div>


<div class="row">
    <div class="col-xs-12">
        <table id="grid-table"></table>
        <div id="grid-pager"></div>
        <script type="text/javascript">
            var $path_base = "${contextPath}/static";//in Ace demo this will be used for editurl parameter
        </script>
        <!-- PAGE CONTENT ENDS -->
    </div><!-- /.col -->
</div><!-- /.row -->

<div  id="MyDiv" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv('MyDiv')" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                抖音律师信息
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip" class="red clearfix"></div>
            <div class="form-group">
                <label for="dyName">抖音号名</label>
                <input class="form-control" name="lawyerName"  id="dyName" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="dyAccount">抖音号</label>
                <input id="dyId" style="display: none" value=""><%--存放抖音账号Id,不显示--%>
                <input class="form-control" name="phone"   id="dyAccount" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="dyFance">粉丝数</label>
                <input class="form-control" name="phone"   id="dyFance" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="dyGood">总点赞数</label>
                <input class="form-control" name="phone"   id="dyGood" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="dyLawyerHoner">律师荣誉</label>
                <textarea class="form-control" name="phone"   id="dyLawyerHoner" type=""  ></textarea>
            </div>
            <div class="form-group">
                <label for="dyLawyerInfo">律师简介</label>
                <textarea class="form-control" name="phone"   id="dyLawyerInfo" type="text"></textarea>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="saveDyLawyer() " id="mod-add-submit" type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        保存
                    </button>
                    <button  onclick="CloseDiv('MyDiv')" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

    </div><!-- /.modal-dialog -->
</div>
<div id="MyAdddDiv" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseMyAddDiv('MyAdddDiv')" type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                新增抖音律师信息
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip2" class="red clearfix"></div>
            <div class="form-group">
                <label for="myAdddDivKeywords">搜索律师：</label>
                <input type="text" class="input-sm" id="myAdddDivKeywords" name="myAdddDivKeywords" value="" placeholder="请输入律师姓名或手机号码"/>
                <button class="btn btn-large" onclick="searchMyAdddDivKeywords()">搜索</button>
            </div>
            <div class="form-group">
                <label for="myAdddDivSelect">选择律师：</label>
                <select id='myAdddDivSelect' name="myAdddDivSelect">
                    <option selected value="">请选择律师</option>
                </select>
            </div>
            <div class="form-group">
                <label for="phone">电话</label>
                <input class="form-control" name="phone"  id="phone" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="account">抖音号</label>
                <input class="form-control" name="account"  id="account" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="accountName">抖音平台网名</label>
                <input class="form-control" name="accountName"   id="accountName" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="introduction">简介</label>
                <input class="form-control" name="introduction"  id="introduction" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="honorInfo">律师荣誉</label>
                <textarea class="form-control" name="honorInfo"   id="honorInfo" type="text"></textarea>
            </div>
            <div class="form-group">
                <label for="likeNum">点赞数</label>
                <input class="form-control" name="likeNum"  id="likeNum" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="fanNum">粉丝数</label>
                <input class="form-control" name="fanNum"  id="fanNum" type="text" value="" />
            </div>
            <div class="form-group"  >
                <label class="col-sm-3 control-label">抖音律师大头像:</label>
                <div class="col-sm-8 input-group">
                    <img  id="edit-qrcode" src="" style="height: 200px; width: 200px;"/>
                    <input type="text" hidden id="dyLawyerPic">
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="btn btn-large" onclick="uploadPicFun()">上传图片</button>
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="saveMyAddDyLawyer()" id="mod-add-dyLawyer-submit" type="button"
                            class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        保存
                    </button>
                    <button  onclick="CloseDiv('MyAdddDiv')" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="EditMyAdddDiv" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseEditMyAdddDiv('EditMyAdddDiv')" type="button" class="close" data-dismiss="modal"
                        aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                修改抖音律师信息
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip3" class="red clearfix"></div>
            <div class="form-group">
                <label for="editMyAdddDivKeywords">搜索律师：</label>
                <input type="text" class="input-sm" id="editMyAdddDivKeywords" name="editMyAdddDivKeywords" value=""
                       placeholder="请输入律师电话或律师姓名"/>
                <button class="btn btn-large" onclick="searchEditMyAdddDivKeywords()">搜索</button>
            </div>
            <div class="form-group">
                <label for="editMyAdddDivSelect">选择律师：</label>
                <select id='editMyAdddDivSelect' name="editMyAdddDivSelect">
                    <option selected value="">请选择律师</option>
                </select>
            </div>
            <div class="form-group">
                <input id="editLawyerId" style="display: none" value="">
            </div>
            <div class="form-group">
                <label for="editRealName">律师姓名</label>
                <input class="form-control" name="editRealName"  id="editRealName" type="text" value="" readonly="readonly" />
            </div>
            <div class="form-group">
                <label for="editPhone">律师电话</label>
                <input class="form-control" name="editPhone"  id="editPhone" type="text" value="" readonly="readonly" />
            </div>
            <div class="form-group">
                <label for="editAccount">抖音号</label>
                <input class="form-control" name="editAccount" id="editAccount" type="text" value=""
                       readonly="readonly" />
            </div>
            <div class="form-group">
                <label for="editAccountName">抖音平台网名</label>
                <input class="form-control" name="editAccountName" id="editAccountName" type="text" value=""
                       readonly="readonly" >
            </div>
            <div class="form-group">
                <label for="editIntroduction">简介</label>
                <input class="form-control" name="editIntroduction"  id="editIntroduction" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="editHonorInfo">律师荣誉</label>
                <textarea class="form-control" name="editHonorInfo"   id="editHonorInfo" type="text"></textarea>
            </div>
            <div class="form-group">
                <label for="editLikeNum">点赞数</label>
                <input class="form-control" name="editLikeNum"  id="editLikeNum" type="text" value="" />
            </div>
            <div class="form-group">
                <label for="editFanNum">粉丝数</label>
                <input class="form-control" name="editFanNum"  id="editFanNum" type="text" value="" />
            </div>
            <div class="form-group"  >
                <label class="col-sm-3 control-label">抖音律师大头像:</label>
                <div class="col-sm-8 input-group">
                    <img  id="editqrcode" src="" style="height: 200px; width: 200px;"/>
                    <input type="text" hidden id="editDyLawyerPic">
                    &nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="btn btn-large" onclick="uploadPicFun()">上传图片</button>
                </div>
            </div>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="editMyAddDyLawyer() " id="mod-add-edit-dyLawyer-submit" type="button"
                            class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        修改
                    </button>
                    <button  onclick="CloseEditMyAdddDiv('EditMyAdddDiv')" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 图片上传 -->
<div id="mod-pic" class="modal fade" tabindex="-1" style="z-index: 99999">
    <div class="modal-dialog" style="max-width: 500px;">
        <div class="modal-content">
            <div class="modal-header no-padding">
                <div class="table-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                        <span class="white">&times;</span>
                    </button>
                    图片上传
                </div>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS  -->
                        <form id="picform" >
                            <input id="lawsuitId" type="text" style="display: none" />
                            <input id="picFileId" type="file" name="picfile" multiple="multiple" />
                            <div class="hr hr-12 dotted"></div>
                            <div class="text-center">
                                <button type="button" class="btn btn-sm btn-primary" onclick="updatePic()">上传</button>
                                <button type="reset" class="btn btn-sm">清除</button>
                            </div>
                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
</div>

<div  id="MyDiv1" class="modal-dialog white_content">
    <div class="modal-content">
        <div class="modal-header no-padding">
            <div class="table-header">
                <button onclick="CloseDiv1('MyDiv1')" type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span  class="white">&times;</span>
                </button>
                抖音视频信息
            </div>
        </div>
        <div class="modal-body" style="overflow-y: scroll;">
            <div id="mod-add-tip1" class="red clearfix"></div>
            <div class="form-group">
                <label for="videoDate">抖音视频日期</label><br />
                <input id="lawyerId" style="display: none" value=""><%--存放抖音视频所属律师Id,不显示--%>
                <input class="form-control" name="date" id="videoDate" type="text" placeholder="选择日期" value="" >
            </div>
            <div class="form-group">
                <%--<label for="videoName">视频名字</label>--%>
                <input id="videoId" style="display: none" value=""><%--存放抖音视频Id,不显示--%>
                <%--<input class="form-control" name="lawyerName"  id="videoName" type="text" value="" />--%>
            </div>
            <div class="form-group">
                <label for="videoBfNum">视频播放量</label>
                <input class="form-control" name="phone"   id="videoBfNum" type="text" value="" >
            </div>
            <%--<div class="form-group">
                <label for="videoFwNum">视频访问量</label>
                <input class="form-control" name="phone"   id="videoFwNum" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="videoLink">视频链接</label>
                <input class="form-control" name="phone"   id="videoLink" type="text" value="" >
            </div>
            <div class="form-group">
                <label for="remark">备注</label>
                <textarea class="form-control" name="phone"   id="remark" type=""  ></textarea>
            </div>--%>
            <div class="modal-footer no-margin-top">
                <div class="text-center">
                    <button onclick="saveVideo() " id="mod-add-submit1" type="button" class="btn btn-sm btn-primary">
                        <i class="ace-icon fa fa-floppy-o bigger-160"></i>
                        保存
                    </button>
                    <button  onclick="CloseDiv1('MyDiv1')" class="btn btn-sm" data-dismiss="modal">
                        <i class="ace-icon fa fa-share bigger-160"></i>
                        取消
                    </button>
                </div>
            </div>
        </div><!-- /.modal-content -->

    </div><!-- /.modal-dialog -->
</div>

<script type="text/javascript">
    var myGrid = null;
    var scripts = [ null,
        "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js",
        "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js",
        "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js",
        "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js",
        "http://gosspublic.alicdn.com/aliyun-oss-sdk-4.3.0.min.js?v="+Math.random(),
        "${contextPath}/static/js/contract/picupload.js?v="+Math.random(),
        "${contextPath}/static/js/contract/fileupload.js?v="+Math.random(),
        "${contextPath}/static/assets/js/date-time/bootstrap-datepicker.js",
        "${contextPath}/static/assets/js/bootstrap-typeahead.js",
        "${contextPath}/static/js/contract/uuid.js",
        "${contextPath}/static/assets/js/date-time/locales/bootstrap-datepicker.zh-CN.js",
        "${contextPath}/static/assets/js/jqGrid/jquery.jqGrid.js",
        "${contextPath}/static/assets/js/jqGrid/i18n/grid.locale-cn.js",
        "${contextPath}/static/assets/js/lazyload/jquery.lazyload.js",
        "${contextPath}/static/js/datatimepicker/bootstrap-datetimepicker.zh-CN.js",
        "${contextPath}/static/js/datatimepicker/bootstrap-datetimepicker.min.js",
        "${contextPath}/static/js/datatimepicker/bootstrap-datetimepicker.min.css",
        null
    ];

    $('.page-content-area').ace_ajax('loadScripts', scripts, function() {
        jQuery(function ($) {

            var grid_selector = "#grid-table";
            var pager_selector = "#grid-pager";
            var searchType = "day";

            /*搜索框  主要对Jquery grid进行刷新 带参数刷新    */
            $("#searchd").click(function(){
                var keywords = $("#keywords").val();
                var endDate = $("#endDate").val();
                var startDate = $("#startDate").val();
                myGrid.setGridParam({postData:{startDate:startDate,endDate:endDate,keywords:keywords ,page:1},
                    url : '${contextPath}/ads/douyin/getInfo',page:1}).trigger('reloadGrid');
            });
            $("#addd").click(function() {
                $("#account").val("");
                $("#accountName").val("");
                $("#introduction").val("");
                $("#honorInfo").val("");
                $("#likeNum").val("");
                $("#fanNum").val("");
                // $("#edit-qrcode").attr("src","");
                $("#phone").val("");
                $("#dyLawyerPic").val("");
                $("#myAdddDivSelect").empty();
                $("#MyAdddDiv").show();
            });
            $("#myAdddDivSelect").change(function() {
                $("#phone").val("")
                var lawyerId = $(this).children('option:selected').val()
                $.ajax({
                    dataType : "json",
                    url : "${contextPath}/ads/douyin/bindDataWhenClickSelect",
                    type : "post",
                    data : {
                        'lawyerId' : lawyerId
                    },
                    complete: function(ret) {
                        console.log(ret)
                        if (ret.responseJSON.length > 0) {
                            for (var i = 0; i < 1; i++) {
                                $("#phone").val(ret.responseJSON[0].phone)
                            }
                        }
                    },
                    fail: function(ret) {
                        alert("加载律师信息失败！")
                    }
                });
            })

            $("#editMyAdddDivSelect").change(function() {
                $("#editPhone").val("")
                var lawyerId = $(this).children('option:selected').val()
                $.ajax({
                    dataType : "json",
                    url : "${contextPath}/ads/douyin/bindDataWhenClickEditSelect",
                    type : "post",
                    data : {
                        'lawyerId' : lawyerId
                    },
                    complete : function(ret) {
                        console.log(ret)
                        if (ret.responseJSON.length > 0) {
                            for (var i = 0; i < 1; i++) {
                                $("#editPhone").val(ret.responseJSON[0].editPhone)
                                $("#editRealName").val(ret.responseJSON[0].editRealName)
                            }
                        }
                    },
                    fail : function(ret) {
                        alert("加载律师信息失败！")
                    }
                });
            })
            $("#videoDate").change(function(){
                /* $("#videoName").val("");*/
                $("#videoBfNum").val("");
                /*$("#videoFwNum").val("");
                $("#videoLink").val("");
                $("#remark").val("");*/
                var lawyerId = $("#lawyerId").val();
                var videoDate = $("#videoDate").val();
                $.ajax({
                    dataType : "json",
                    url : "${contextPath}/ads/douyin/getVideoInfo",
                    type : "post",
                    data : {
                        'lawyerId' : lawyerId,
                        'nowDate' : videoDate
                    },
                    complete : function(ret) {
                        if(ret.responseText !== "") {
                            var ret = eval("(" + ret.responseText + ")");
                            $("#videoDate").val(videoDate);
                            /*$("#videoName").val(ret.videoName);*/
                            $("#videoBfNum").val(ret.bfCount);
                            /* $("#videoFwNum").val(ret.fwCount);
                             $("#videoLink").val(ret.videoLink);
                             $("#remark").val(ret.remark);*/
                        }else {
                            $("#videoBfNum").val(0);
                        }
                    }
                });
            });


            $(document).keydown(function (event) {
                var key = window.event ? event.keyCode : event.which;
                if (key == 13) {
                    $("#searchd").click();
                }
            });

            // $('#infoDate').datepicker({
            //     language: 'zh-CN',
            //     pickTime: false,
            //     todayBtn: true,
            //     autoclose: true,
            //     minView: '2',
            //     forceParse: false,
            //     format:"yyyy-mm-dd"
            // });
            $('#startDate').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });$('#endDate').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });
            $('#videoDate').datepicker({
                language: 'zh-CN',
                pickTime: false,
                todayBtn: true,
                autoclose: true,
                minView: '2',
                forceParse: false,
                format:"yyyy-mm-dd"
            });



            myGrid=	jQuery(grid_selector).jqGrid({
                subGrid : false,
                url : "${contextPath}/ads/douyin/getInfo",
                datatype : "json",
                mtype:'POST',//设置http方式为post以解决乱码问题
                colNames : ['合作律师', '律师电话','律师Id','抖音平台网名','视频播放量',
                    '用户访问数','订单总数','订单总金额','订单总分成','操作'],
                colModel : [{
                    name : 'realName',
                    index : 'realName',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'phone',
                    index : 'phone',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'id',
                    index : 'id',
                    width : 150,
                    hidden : true,
                },{
                    name : 'nickName',
                    index : 'nickName',
                    width : 150,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'bfCount',
                    index : 'bfCount',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'fwCount',
                    index : 'fwCount',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'orderCount',
                    index : 'orderCount',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'orderMoney',
                    index : 'orderMoney',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{
                    name : 'lawyerDividend',
                    index : 'lawyerDividend',
                    width : 120,
                    search : false,
                    editable : false,
                    //sorttype : 'date'
                },{	name : 'type',
                    index : 'type',
                    label : '操作',
                    width : 250,
                    editable : false,
                    search : false,
                    sortable : false,
                    fixed:true,
                    formatter : optionFormatter
                }],
                //scroll : 1, // set the scroll property to 1 to enable paging with scrollbar - virtual loading of records
                sortname : "realname",
                sortorder : "asc",
                viewrecords : true,
                rowNum : 10,
                rowList : [ 10, 20, 30 ],
                pager : pager_selector,
                altRows : true,
                height:"auto",//自动根据每页条数弹性调整表格高度
                loadComplete : function() {
                    var table = this;
                    setTimeout(function(){
                        /*styleCheckbox(table);
                        updateActionIcons(table);*/
                        updatePagerIcons(table);
                        enableTooltips(table);
                    }, 0);
                }
            });

            function updatePagerIcons(table) {
                var replacement = {
                    'ui-icon-seek-first' : 'ace-icon fa fa-angle-double-left bigger-140',
                    'ui-icon-seek-prev' : 'ace-icon fa fa-angle-left bigger-140',
                    'ui-icon-seek-next' : 'ace-icon fa fa-angle-right bigger-140',
                    'ui-icon-seek-end' : 'ace-icon fa fa-angle-double-right bigger-140'
                };
                $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function() {
                    var icon = $(this);
                    var $class = $.trim(icon.attr('class').replace('ui-icon', ''));

                    if ($class in replacement)
                        icon.attr('class', 'ui-icon ' + replacement[$class]);
                })
            }

            function enableTooltips(table) {
                $('.navtable .ui-pg-button').tooltip({
                    container : 'body'
                });
                $(table).find('.ui-pg-div').tooltip({
                    container : 'body'
                });
            }
            function optionFormatter(cellvalue, options, cell) {
                var template = "<button data-toggle='modal' onclick='location.href=\"http://admin.duowenlvshi.com/sys/sysuser/home#page/adsOrderDetails?aaa="+cell.id+"\"' class='btn btn-minier btn-default'>订单信息</button>&nbsp;|&nbsp;";

                // var template = "<button data-toggle='modal' onclick='window.location.href=\"http://localhost:8080/duowenadmin/sys/sysuser/home#page/adsOrderDetails?aaa="+cell.id+"\"' class='btn btn-minier btn-default'>订单</button>&nbsp;|&nbsp;";
                template += "<button data-toggle='modal' onclick='lawyerInfo(\""+cell.nickName+"\")' class='btn btn-minier btn-default'>律师</button>&nbsp;|&nbsp;";
                template += "<button data-toggle='modal' onclick='videoInfo(\""+cell.id+"\")' class='btn btn-minier btn-default'>视频</button> ";
                template += "<button data-toggle='modal' onclick='updateInfo(\""+cell.id+"\")' class='btn btn-minier btn-default'>编辑</button> ";
                template += "<button data-toggle='modal' onclick='deleteInfo(\""+cell.id+"\")' class='btn btn-minier btn-default'>删除</button> ";
                return template;
            }
        });
    });
    function lawyerInfo(accountName) {
        $("#dyId").val("");
        $("#dyName").val("");
        $("#dyAccount").val("");
        $("#dyFance").val("");
        $("#dyGood").val("");
        $("#dyLawyerInfo").val("");
        $("#dyLawyerHoner").val("");
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/getAdsLawyer",
            type : "post",
            data : {
                'accountName' : accountName,
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText+ ")");
                $("#dyId").val(ret.id);
                $("#dyName").val(ret.accountName);
                $("#dyAccount").val(ret.account);
                $("#dyFance").val(ret.fanNum);
                $("#dyGood").val(ret.likeNum);
                $("#dyLawyerInfo").val(ret.introduction);
                $("#dyLawyerHoner").val(ret.honorInfo);
                $("#MyDiv").show();
            },
            error : function (ret) {
                alert("此律师信息未完善！")
            }
        });
    }
    function saveDyLawyer() {
        var id = $("#dyId").val();
        var accountName = $("#dyName").val();
        var account = $("#dyAccount").val();
        var fanNum = $("#dyFance").val();
        var likeNum = $("#dyGood").val();
        var introduction = $("#dyLawyerInfo").val();
        var honorInfo = $("#dyLawyerHoner").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/saveAdsLawyer",
            type : "post",
            data : {
                'id' : id,
                'accountName' : accountName,
                'account' : account,
                'fanNum' : fanNum,
                'likeNum' : likeNum,
                'introduction' : introduction,
                'honorInfo' : honorInfo
            },
            complete : function(ret) {
                var ret = eval("(" + ret.responseText+ ")");
                alert(ret.isSucc);
                $("#MyDiv").hide();
                myGrid.trigger("reloadGrid");
            }
        });
    }
    function videoInfo(lawyerId) {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var nowDate = year + "-" + month + "-" + day;
        $("#lawyerId").val(lawyerId);
        $("#videoDate").val(nowDate);
        $("#videoId").val("");
        /*$("#videoName").val("");*/
        $("#videoBfNum").val("0");
        /*$("#videoFwNum").val("");
        $("#videoLink").val("");
        $("#remark").val("");*/
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/getVideoInfo",
            type : "post",
            data : {
                'lawyerId' : lawyerId,
                'nowDate' : nowDate
            },
            complete : function(ret) {
                if (ret.responseText !== ""){
                    var ret = eval("(" + ret.responseText + ")");
                    $("#videoBfNum").val(ret.bfCount);
                    /*$("#videoId").val(ret.id);
                    $("#videoName").val(ret.videoName);
                    $("#videoBfNum").val(ret.bfCount);
                    $("#videoFwNum").val(ret.fwCount);
                    $("#videoLink").val(ret.videoLink);
                    $("#remark").val(ret.remark);*/
                }
                $("#MyDiv1").show();
            },
            fail : function(ret) {
                alert("此视频信息未完善！")
            }
        });
    }
    function updateInfo(lawyerId) {
        $("#editLawyerId").val(lawyerId);
        $("#editMyAdddDivSelect").empty()
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/getUpdateInfoByLawyerId",
            type : "post",
            data : {
                'lawyerId' : lawyerId
            },
            complete : function(ret) {
                console.log(ret)
                if (ret.success) {
                    $("#editMyAdddDivSelect").append("<option value='" + ret.responseJSON.lawyerId + "' " +
                        "data-id='" + ret.responseJSON.lawyerId + "'>" + ret.responseJSON.editRealName +
                        "</option>");
                    $("#editRealName").val(ret.responseJSON.editRealName);
                    $("#editPhone").val(ret.responseJSON.editPhone);
                    $("#editAccount").val(ret.responseJSON.editAccount);
                    $("#editAccountName").val(ret.responseJSON.editAccountName);
                    $("#editIntroduction").val(ret.responseJSON.editIntroduction);
                    $("#editHonorInfo").val(ret.responseJSON.editHonorInfo);
                    $("#editLikeNum").val(ret.responseJSON.editLikeNum);
                    $("#editFanNum").val(ret.responseJSON.editFanNum);
                    $("#editqrcode").attr("src", ret.responseJSON.editqrcode);
                    $("#editDyLawyerPic").val(ret.responseJSON.editDyLawyerPic);
                    $('#editMyAdddDivSelect')[0].selectedIndex = 0;
                    $("#EditMyAdddDiv").show();
                }
            },
            fail : function(ret) {
                alert("加载合作律师信息失败！")
            }
        });
    }
    function deleteInfo(lawyerId) {
        var lawyerId = lawyerId;
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/deleteInfoByLawyerId",
            type : "post",
            data : {
                'lawyerId' : lawyerId
            },
            complete : function(ret) {
                alert(ret.responseJSON.isSucc);
                myGrid.trigger("reloadGrid");
            },
            fail : function(ret) {
                alert("删除合作律师信息失败！")
            }
        });
    }
    function searchMyAdddDivKeywords() {
        var myAdddDivKeywords = $("#myAdddDivKeywords").val();
        $("#phone").val("")
        $("#myAdddDivSelect").empty();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/searchMyAdddDivKeywords",
            type : "post",
            data : {
                'myAdddDivKeywords' : myAdddDivKeywords
            },
            complete : function(ret) {
                console.log(ret)
                if (ret.responseJSON.isSucc == "false") {
                    alert("关键字：" + myAdddDivKeywords + "未找到对应律师！")
                    return;
                }
                for (var i = 0; i < ret.responseJSON.length; i++) {
                    $("#myAdddDivSelect").append("<option value='" + ret.responseJSON[i].lawyerId + "' " +
                        "data-id='" + ret.responseJSON[i].lawyerId + "'>" + ret.responseJSON[i].realName +
                        "</option>");
                    if (i == 0) {
                        $("#phone").val(ret.responseJSON[i].phone)
                    }
                }
                $('#myAdddDivSelect')[0].selectedIndex = 0;
                alert("搜索成功！")
            },
            fail : function(ret) {
                alert("搜索律师信息失败！")
            }
        });
    }
    function searchEditMyAdddDivKeywords() {
        var editMyAdddDivKeywords = $("#editMyAdddDivKeywords").val();
        $("#editPhone").val("")
        $("#editRealName").val("")
        $("#editMyAdddDivSelect").empty()
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/searchEditMyAdddDivKeywords",
            type : "post",
            data : {
                'editMyAdddDivKeywords' : editMyAdddDivKeywords
            },
            complete : function(ret) {
                console.log(ret)
                if (ret.responseJSON.isSucc == "false") {
                    alert("关键字：" + editMyAdddDivKeywords + "未找到对应的抖音律师！")
                    return;
                }
                for (var i = 0; i < ret.responseJSON.length; i++) {
                    $("#editMyAdddDivSelect").append("<option value='" + ret.responseJSON[i].lawyerId + "' " +
                        "data-id='" + ret.responseJSON[i].lawyerId + "'>" + ret.responseJSON[i].realName +
                        "</option>");
                    if (i == 0) {
                        $("#editPhone").val(ret.responseJSON[i].editPhone)
                        $("#editRealName").val(ret.responseJSON[i].realName)
                    }
                }
                $('#editMyAdddDivSelect')[0].selectedIndex = 0;
                alert("搜索成功！")
            },
            fail : function(ret) {
                alert("搜索抖音平台律师信息失败！")
            }
        });
    }
    function editMyAddDyLawyer() {
        var editLawyerId = $("#editLawyerId").val();
        var editAccount = $("#editAccount").val();
        var editAccountName = $("#editAccountName").val();
        var editIntroduction = $("#editIntroduction").val();
        var editHonorInfo = $("#editHonorInfo").val();
        var editLikeNum = $("#editLikeNum").val();
        var editFanNum = $("#editFanNum").val();
        var editqrcode = $("#editqrcode")[0].src;
        var editDyLawyerPic = $("#editDyLawyerPic").val();
        var editPhone = $("#editPhone").val();
        var phonereg = /^1(3|4|5|6|7|8|9)\d{9}$/;
        if (editAccount == "") {
            alert("抖音号不能为空！");
            return;
        }
        if (editAccountName == "") {
            alert("抖音平台网名不能为空！");
            return;
        }
        if (editPhone == "") {
            alert("手机号不能为空！");
            return;
        }
        if (!phonereg.test(editPhone)){
            alert("请输入正确的手机号");
            $("#phone").val("");
            return;
        }
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/editMyAddDyLawyer",
            type : "post",
            data : {
                'editLawyerId' : editLawyerId,
                'editAccount' : editAccount,
                'editAccountName' : editAccountName,
                'editIntroduction' : editIntroduction,
                'editHonorInfo' : editHonorInfo,
                'editLikeNum' : editLikeNum,
                'editFanNum' : editFanNum,
                'editqrcode' : editqrcode,
                'editDyLawyerPic' : editDyLawyerPic,
                'editPhone' : editPhone
            },complete : function(ret) {
                console.log(ret)
                alert(ret.responseJSON.isSucc);
                if (ret.responseJSON.message == "false") {
                    return;
                }
                $("#EditMyAdddDiv").hide();
                myGrid.trigger("reloadGrid");
            }
        })
    }

    function saveVideo() {
        var lawyerId = $("#lawyerId").val();
        var bfCount = $("#videoBfNum").val();
        var nowDate = $("#videoDate").val();
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/saveVideo",
            type : "post",
            data : {
                'bfCount' : bfCount,
                'lawyerId' : lawyerId,
                'nowDate' : nowDate
            },complete : function(ret) {
                console.log(ret);
                var ret = eval("(" + ret.responseText+ ")");
                alert(ret.isSucc);
                $("#MyDiv1").hide();
                myGrid.trigger("reloadGrid");
            }
        });
    }
    function getCount() {
        var infoDate = $("#infoDate").val();
        //默认查询昨天的记录
        if (infoDate == "") {
            var date = new Date((+new Date()));
            infoDate = date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + (date.getDate() - 1);
            $("#infoDate").val(infoDate);
        }
    }
    // getCount();
    function CloseDiv(show_div){
        document.getElementById(show_div).style.display='none';

    }
    function CloseDiv1(show_div){
        document.getElementById(show_div).style.display='none';

    }
    function CloseMyAddDiv(show_div){
        $("#account").val("")
        $("#accountName").val("")
        $("#introduction").val("")
        $("#honorInfo").val("")
        $("#likeNum").val("")
        $("#fanNum").val("")
        $("#phone").val("")
        $("#dyLawyerPic").val("")
        $("#editqrcode").attr("src", "");
        document.getElementById(show_div).style.display='none';
    }
    function CloseEditMyAdddDiv(show_div){
        $("#editIntroduction").val("")
        $("#editHonorInfo").val("")
        $("#editLikeNum").val("")
        $("#editFanNum").val("")
        $("#editDyLawyerPic").val("")
        $("#editqrcode").attr("src", "");
        $("#editPhone").val("")
        $("#editMyAdddDivSelect").empty();
        document.getElementById(show_div).style.display='none';
    }
    function uploadPicFun() {
        document.getElementById('picform').reset();
        $("#mod-pic").modal("toggle");
    }
    function updatePic() {
        applyTokenDo(picUpload);
    }
    function saveMyAddDyLawyer() {
        var account = $("#account").val();
        var accountName = $("#accountName").val();
        var introduction = $("#introduction").val();
        var honorInfo = $("#honorInfo").val();
        var likeNum = $("#likeNum").val();
        var fanNum = $("#fanNum").val();
        var dyLawyerPic = $("#dyLawyerPic").val();
        var phone = $("#phone").val();
        var phonereg = /^1(3|4|5|6|7|8|9)\d{9}$/;
        if (account == "") {
            alert("抖音号不能为空！");
            return;
        }
        if (accountName == "") {
            alert("抖音平台网名不能为空！");
            return;
        }
        if (phone == "") {
            alert("手机号不能为空！");
            return;
        }
        if (!phonereg.test(phone)){
            alert("请输入正确的手机号");
            $("#phone").val("");
            return;
        }
        $.ajax({
            dataType : "json",
            url : "${contextPath}/ads/douyin/saveMyAddDyLawyer",
            type : "post",
            data : {
                'account' : account,
                'accountName' : accountName,
                'introduction' : introduction,
                'honorInfo' : honorInfo,
                'likeNum' : likeNum,
                'fanNum' : fanNum,
                'dyLawyerPic' : dyLawyerPic,
                'phone' : phone
            },complete : function(ret) {
                console.log(ret)
                alert(ret.responseJSON.isSucc);
                if (ret.responseJSON.message == "false") {
                    return;
                }
                $("#MyAdddDiv").hide();
                myGrid.trigger("reloadGrid");
            }
        });
    }
    /*-------------------------OSS上传图片-------------------------*/

    var appServer = 'http://b.duowenlvshi.com/oss/token?name=video';
    var bucket = '${oss_bucket_ssdb}';
    var region = 'oss-cn-shenzhen';
    var applyTokenDo = function (func) {
        var url = appServer;
        $.ajax({
            type: "POST",
            url: url,
            data: "",
            dataType: "jsonp",
            success: function (e) {
                console.log("6666");
                console.log(e);
                var client = new OSS.Wrapper({
                    region: region,
                    accessKeyId: e.AccessKeyId,
                    accessKeySecret: e.AccessKeySecret,
                    stsToken: e.SecurityToken,
                    bucket: bucket
                });
                return func(client);
            },
            error: function (data) {
                console.log(data);
            }
        });
    };

    var picUpload = function(client){
        var file=document.getElementById('picFileId').files[0];
        var file_name=file.name;
        console.log("源文件名==："+file_name);
        var storeAs = "duowenadmin/"+file_name;
        console.log(file.name + ' => ' + storeAs);
        client.multipartUpload(storeAs, file).then(function (result) {
            if (result.url == undefined) {
                console.log("result=:"+"http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#edit-qrcode").attr("src","http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#picUrl").val("http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#edit-qrcode1").attr("src","http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#picUrl1").val("http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#mod-pic").modal("toggle");
                $("#dyLawyerPic").val("http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#editqrcode").attr("src","http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
                $("#editDyLawyerPic").val("http://duowen-ssdb.oss-cn-shenzhen.aliyuncs.com/duowenadmin/" + file_name);
            } else {
                console.log("result=:"+result.url);
                $("#edit-qrcode").attr("src",result.url);
                $("#picUrl").val(result.url);
                $("#edit-qrcode1").attr("src",result.url);
                $("#picUrl1").val(result.url);
                $("#mod-pic").modal("toggle");
                $("#dyLawyerPic").val(result.url);
                $("#editqrcode").attr("src",result.url);
                $("#editDyLawyerPic").val(result.url);
            }
        }).catch(function (err) {
            console.log("err", err);
            console.log("err.name : " + err.name);
            console.log("err.message : " + err.message);
        });
    };


    /*-------------------------OSS上传图片-------------------------*/

</script>