<?php

function request_by_curl($remote_server, $post_string) {  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $remote_server);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json;charset=utf-8'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
    // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $data = curl_exec($ch);
    curl_close($ch);  
    return $data;  
}

function dopost($remote_server, $post_string) {  
    $ch = curl_init();  
    curl_setopt($ch, CURLOPT_URL, $remote_server);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); 
    #curl_setopt($ch, CURLOPT_HTTPHEADER, array ('Content-Type: application/json;charset=utf-8'));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
    // 线下环境不用开启curl证书验证, 未调通情况可尝试添加该代码
    curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
    $data = curl_exec($ch);
    curl_close($ch);  
    return $data;  
}

function push($title,$text,$to){
	//今天设置过菜单
	$webhook = "http://v3.legu.cc/senddmsg/push.php?act=push";
	$contArr = array(
		'msgtype'=>'action_card',
		'action_card'=>array(
			'title'=>$title,
			"markdown"=> $text,
			'single_title'=>'查看详情',
			'single_url'=>'http://10.0.0.5/leguevent/',
		),
	);
	$data_string = array(
		'name'=>$to,
		'cont'=>json_encode($contArr)
	);
	$result = dopost($webhook, $data_string);
}


function sendNotice($title,$text,$token){
	//今天设置过菜单
	$webhook = "https://oapi.dingtalk.com/robot/send?access_token={$token}";

	$data = array(
		'msgtype'=>'actionCard',
		'actionCard'=>array(
			'title'=>$title,
			"text"=> $text,
			'hideAvatar'=>'0',
			'btnOrientation'=>'0',
			'btns' => array(
				array(
					'title'=>'查看详情',
					'actionURL'=>'http://10.0.0.5/leguevent/',
				)
			)
		),
		"at"=>array(
			 "isAtAll"=>true
		)
	);

	$data_string = json_encode($data);
	$result = request_by_curl($webhook, $data_string);  
}

function getOneEvent($id){
	$rs = DB::getOne("select * from calendar where id='{$id}'");
	return $rs;
}


$user = SESS::get('EVENTUserInfo');
// if(isn($user))exit();
$user = json_decode($user, true);
$canEdit = in_array($user['name'], $ROLES);
$isgxvrole ='1'; //in_array($user['name'], $GXVROLES);    //更新信息查看区浏览权限
$isgxyyerole = in_array($user['name'], $GXYYEROLES);//更新运营中心编辑权限
$isgxcperole = in_array($user['name'], $GXCPEROLES);//更新产品中心编辑权限
$isgxyferole = in_array($user['name'], $GXYFEROLES);//更新研发中心编辑权限
$isxfvrole = in_array($user['name'], $XFVROLES);    //修复信息查看区浏览权限
$isxfyyerole = in_array($user['name'], $XFYYEROLES);//修复运营中心编辑权限

$isdbvrole ='1'; //in_array($user['name'], $DBVROLES);    //打包信息查看区浏览权限
$isdbyyerole = in_array($user['name'], $DBYYEROLES);//打包运营中心编辑权限
$isdbcperole = in_array($user['name'], $DBCPEROLES);//打包产品中心编辑权限
$isdbyferole = in_array($user['name'], $DBYFEROLES);//打包研发中心编辑权限

//上线

$issxyyerole = in_array($user['name'], $SXYYEROLES); //上线运营编辑
$issxarole = in_array($user['name'], $SXAROLES); //可以添加上线卡片

//延期评论
$isyqeroles = in_array($user['name'], $YQEROLES);

//调试
$user['name'] = "罗松柏";
$canEdit = 1;
//$isgxyyerole=1;
//$isgxcperole=1;
//$isgxyferole=1;
//$isxfvrole=1;
//$isxfyyerole=1;
//$isdbcperole=1;
//$isdbyferole=1;
//$isyqeroles =1;

function fix2($v)
{
    $x = '00' . $v;
    return substr($x, -2);
}

//we(getOneEvent(7442));

$act = r('act');
$type = r('type');
if ($act == 'newevent') {
    $keys = array('start', 'end', 'game', 'allday', 'shour', 'smin', 'event', 'title');
    $dict = array();
    foreach ($keys as $k) {
        $dict[$k] = r($k);
    }
    $sql = DB::insert('calendar', $dict);
    DB::exe($sql);
	
	if($dict['event'] == '上线'){
		sendNotice('Event新增了上线节点',"**Event新增了上线节点**\n\n【{$dict['game']}】{$dict['title']}\n\n时间：{$dict['start']}",'1a9389969a7b6decc779c86c0969c23cfd7c3d4bf02fe3bb78da348fb526e227');

		sendNotice('Event新增了上线节点',"**Event新增了上线节点**\n\n【{$dict['game']}】{$dict['title']}\n\n时间：{$dict['start']}",'0be37dacbaa5c76893fb85d4dab5bc23e6b981b5fa3c33908132af8e29eacf8c');

		sendNotice('Event新增了上线节点',"**Event新增了上线节点**\n\n【{$dict['game']}】{$dict['title']}\n\n时间：{$dict['start']}",'66766a72c2e5e6950ffbdc26cf8fa3fb5503d25162d80f6dd441057849ef0d4d');

		push('Event新增了上线节点',"**Event新增了上线节点**\n\n【{$dict['game']}】{$dict['title']}\n\n时间：{$dict['start']}",'邓定坤,邓定斌');
	}

    we('1');
} else if ($act == 'edityunying') {
    $id = r('id');
    $content = stripslashes(r('content'));
    $data_array = json_decode($content,true);
    $data_array['date'] =date("Y-m-d H:i:s");
    $dict = array(
        'yunying_remark' => json_encode($data_array)
    );

    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);

	$info = getOneEvent($id);
	if($info['event'] == '上线'){
		sendNotice('Event上线节点',"**Event上线节点信息补充**\n\n【{$info['game']}】{$info['title']}\n\n时间：{$info['start']}\n\n{$data_array['msg']}",'1a9389969a7b6decc779c86c0969c23cfd7c3d4bf02fe3bb78da348fb526e227');

		sendNotice('Event上线节点',"**Event上线节点信息补充**\n\n【{$info['game']}】{$info['title']}\n\n时间：{$info['start']}\n\n{$data_array['msg']}",'0be37dacbaa5c76893fb85d4dab5bc23e6b981b5fa3c33908132af8e29eacf8c');

		sendNotice('Event上线节点',"**Event上线节点信息补充**\n\n【{$info['game']}】{$info['title']}\n\n时间：{$info['start']}\n\n{$data_array['msg']}",'66766a72c2e5e6950ffbdc26cf8fa3fb5503d25162d80f6dd441057849ef0d4d');

		push('Event上线节点',"**Event上线节点信息补充**\n\n【{$info['game']}】{$info['title']}\n\n时间：{$info['start']}\n\n{$data_array['msg']}",'邓定坤,邓定斌');
	}

    we('1');
} else if ($act == 'edityanfa') {
    $id = r('id');
    $content = stripslashes(r('content'));
    $data_array = json_decode($content,true);
    $data_array['date'] =date("Y-m-d H:i:s");
    $dict = array(
        'yanfa_remark' => json_encode($data_array)
    );

    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);
    we('1');
} else if ($act == 'editchanpin') {
    $id = r('id');
    $content = stripslashes(r('content'));
    $data_array = json_decode($content,true);
    $data_array['date'] =date("Y-m-d H:i:s");
    $dict = array(
        'chanpin_remark' => json_encode($data_array)
    );

    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);
    we('1');
}  else if ($act == 'edityanqi') {
    $id = r('id');
    $idx = r('idx');
    $del = r('del');
    $content = stripslashes(r('content'));
    $dict = array();
    $event = DB::getone("select yanqi_history from calendar where id={$id}");
    $yanqi_history = $event['yanqi_history'];
    if(!$del) {
        $yanqi_history[$idx]['reason'] = $content;
    }
    else{
        unset($yanqi_history[$idx]);
    }

    $dict['yanqi_history']=json_encode($yanqi_history,true);
    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);
    we('1');
} else if ($act == 'modievent') {
    $id = r('id');
    $keys = array('start', 'end', 'game', 'allday', 'shour', 'smin', 'event', 'title');
    $dict = array();
    foreach ($keys as $k) {
        $dict[$k] = r($k);
    }
    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);
    we('1');
} else if ($act == 'movevent') {

    $id = r('id');
    $reason = r('reason');
    $keys = array('start', 'end');
    $dict = array();
    foreach ($keys as $k) {
        $dict[$k] = r($k);
    }
    if (isn($dict['end'])) $dict['end'] = $dict['start'];
    $event = DB::getone("select game,event,start,`end`,yanqi_history from calendar where id={$id}");
    $yanqi_history=$event['yanqi_history'];
    if (!$yanqi_history) $yanqi_history = '[]';
    $yanqi_history = json_decode($yanqi_history,true);
    $isYanqi = strtotime($event['start'])<strtotime($dict['end'])?1:2;
    array_unshift($yanqi_history,array('isYanqi'=>$isYanqi,'date1'=>$event['start'],'date2'=>$dict['end'],'user'=>$user['name'],'reason'=>$reason));
    $dict['yanqi_history']=json_encode($yanqi_history,true);

    $sql = DB::update('calendar', $dict, "id='{$id}'");
    DB::exe($sql);
    we('1');
} else if ($act == 'delevent') {
    $id = r('id');
    $sql = "delete from calendar where id='{$id}'";
    DB::exe($sql);
    we('1');
} else if ($act == 'getEventByid') {
    $id = r('id');
    $sql = "select * from calendar where id='{$id}'";
    $rs = DB::getOne($sql);
    we(json_encode($rs));
} else if ($act == 'getEvents') {
    $start = r('start');
    $end = r('end');
    $game = r('game');
    $where = "";

    if (!isn($game)) {
        $where .= " and game='{$game}'";
    }

    $startDate = date('Y-m-d', $start);
    $endDate = date('Y-m-d', $end);
    $month = date('Y-m', ($start + $end) / 2);


    $sql = "select * from calendar where ((start>='{$startDate}' and start<='{$endDate}') or (end>='{$startDate}' and end<='{$endDate}'))  {$where}";
    $rss = DB::getArray($sql);
    $eventTypeCnt = array(
        '节点' => 0,
        '打包' => 0,
        '版本更新' => 0,
        '上线' => 0,
        '修复外网' => 0


    );
    $eventTypeCntMonth = array(
        '节点' => 0,
        '打包' => 0,
        '版本更新' => 0,
        '上线' => 0,
        '修复外网' => 0


    );
    $eventCount = array(
        '总更新&总修复' => array(
            'dangerCount' => 0,
            'purpleCount' => 0
        )
    );

    $res = array();
    foreach ($rss as $rs) {
        if (!$eventCount[$rs['game']]) {
            $eventCount[$rs['game']] = array(
                'dangerCount' => 0,
                'purpleCount' => 0
            );
        }
        $eventTypeCnt[$rs['event']] += 1;

        if (strstr($rs['end'], $month)) {
            $eventTypeCntMonth[$rs['event']] += 1;
        }

        $class = "light";
        if ($rs['event'] == '节点') {
            $class = "success";
        } elseif ($rs['event'] == '打包') {
            $class = "warning";
        } elseif ($rs['event'] == '版本更新') {
            $class = "danger";
            $eventCount[$rs['game']]['dangerCount'] += 1;
            $eventCount['总更新&总修复']['dangerCount'] += 1;
        } elseif ($rs['event'] == '上线') {
            $class = "pink";
        } elseif ($rs['event'] == '修复外网') {
            $class = "purple";
            $eventCount[$rs['game']]['purpleCount'] += 1;
            $eventCount['总更新&总修复']['purpleCount'] += 1;
        }


        $gameName = $rs['game'];
        $yanqi_history = json_decode($rs['yanqi_history'],true);
        $isYanqi = $yanqi_history?end($yanqi_history)['isYanqi']:0;

        $row = array(
            'id' => $rs['id'],
            'title' => '【' . $gameName . '】' . $rs['event'] . "：" . $rs['title'],
            'start' => $rs['start'],
            'end' => $rs['end'],
            'className' => 'label-' . $class,
            'isYanqi'=> $isYanqi
        );
        $row['allDay'] = true;
        $res[] = $row;
    }

    uasort($eventCount,function ($x,$y){
        return $x['dangerCount']<$y['dangerCount'];
    });

    $eventCharts = array(array('product', '更新次数', '修复次数'));
    $eventTable = array([], []);
    foreach ($eventCount as $key => $value) {
        if ($eventCount[$key]['purpleCount'] != 0 || $eventCount[$key]['dangerCount'] != 0)
            $eventCharts[] = array($key, $eventCount[$key]['dangerCount'], $eventCount[$key]['purpleCount']);
    }
    foreach ($eventCharts as $value) {
        $eventTable[0][] = $value[0];
        $eventTable[1][0][] = $value[1];
        $eventTable[1][1][] = $value[2];
        if ($eventCount[$value[0]]['dangerCount'] == 0)
            $eventTable[1][2][] = '0.00%';
        else
            $eventTable[1][2][] = number_format($eventCount[$value[0]]['purpleCount'] * 100 / $eventCount[$value[0]]['dangerCount'], 2) . '%';
    }

    // we(json_encode(array('charts'=>$eventCharts,'table'=>$eventTable)));


    $json = array(
        'calendarData' => $res
    );

    if (!isn($game)) {
        $where = " and game='{$game}'";
        $sql = "select * from calendar where 1=1 {$where} order by end";
        $rss = DB::getArray($sql);
        $res = array();
        foreach ($rss as $rs) {
            $res[] = array(
                "end" => $rs['end'],
                "gamename" => $rs['game'],
                "event" => $rs['event'],
                "title" => $rs['title']
            );
        }
        $json["gameInfo"] = $res;
    }
    if ($type == 'charts')
        // we(json_encode($eventCharts));
        we(json_encode(array('charts' => $eventCharts, 'table' => $eventTable,'count'=>$eventTypeCnt)));
    else{
        $json['count'] = $eventTypeCntMonth;
        we(json_encode($json));
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>乐谷游戏管理系统</title>
    <meta charset="utf-8"/>
    <meta http-equiv="Pragma" content="no-cache">
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <!-- basic styles -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="assets/css/font-awesome.min.css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css"/>
    <![endif]-->
    <!--link rel="stylesheet" href="http://fonts.useso.com/css?family=Open+Sans:400,300" /-->
    <!-- ace styles -->
    <link rel="stylesheet" href="assets/css/ace.min.css?_=1607684955"/>
    <link rel="stylesheet" href="assets/css/ace-rtl.min.css?_=1607684955"/>
    <link rel="stylesheet" href="assets/css/ace-skins.min.css?_=1607684955"/>

    <!--[if lte IE 8]>
    <link rel="stylesheet" href="assets/css/ace-ie.min.css"/>
    <![endif]-->
    <script src="assets/js/ace-extra.min.js?_veri=20151101"></script>
    <!--[if lt IE 9]>
    <script src="assets/js/html5shiv.js"></script>
    <script src="assets/js/respond.min.js"></script>
    <![endif]-->
    <script src="assets/tmpl.js"></script>
    <style>html, body, h1 {
            font-family: "微软雅黑" !important
        }</style>


    <!--[if !IE]> -->
    <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-2.0.3.min.js'>" + "<" + "script>");
    </script>
    <!-- <![endif]-->

    <!--[if IE]>
    <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/js/jquery-1.10.2.min.js'>" + "<" + "script>");
    </script>
    <![endif]-->

    <script type="text/javascript">
        if ("ontouchend" in document) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>" + "<" + "script>");
    </script>

    <script src="assets/js/bootstrap.min.js"></script>
    <script src="assets/js/typeahead-bs2.min.js"></script>

    <!-- page specific plugin scripts -->

    <!--[if lte IE 8]>
    <script src="assets/js/excanvas.min.js"></script>
    <![endif]-->
    <script src="assets/js/jquery-ui-1.10.3.custom.min.js"></script>
    <script src="assets/js/jquery.ui.touch-punch.min.js"></script>
    <script src="assets/js/jquery.slimscroll.min.js"></script>
    <script src="assets/js/jquery.easy-pie-chart.min.js"></script>
    <script src="assets/js/jquery.sparkline.min.js"></script>
    <script src="assets/js/flot/jquery.flot.min.js"></script>
    <script src="assets/js/flot/jquery.flot.pie.min.js"></script>
    <script src="assets/js/flot/jquery.flot.resize.min.js"></script>
    <!-- ace scripts -->
    <script src="assets/js/ace-elements.min.js"></script>
    <script src="assets/js/ace.min.js"></script>
    <script src="assets/jedate.js"></script>
    <script src="assets/doT.js"></script>
    <script src="assets/echarts.min.js"></script>
    <script src="assets/public.js?_=123"></script>
    <!-- inline scripts related to this page -->

    <link rel="stylesheet" href="assets/css/fullcalendar.css"/>
</head>

<body>

<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <div class="main-container-inner">

        <div class="main-content">
            <div class="page-content">
                <div class="page-header">
                    <!-- <h1>LeGu Event</h1> -->
                    <img src="assets/images/logo.png">
                    <div class='xian2'></div>
                </div>
                    <!-- 筛选： -->
<!--                     <a href="./?app=edit" class='btn btn-minier btn-pink'>编辑游戏</a>-->
                <div class='xsqb-box'  id="left_box">
                    <div class="left_box">
                        <button value='' onclick='onlyShowGame(this)' class='btn btn-minier btn-info left'>显示全部</button>
                        <button class='btn btn-minier left' value='风暴奇兵' onclick='onlyShowGame(this)'>风暴奇兵</button>
                        <button class='btn btn-minier left' value='歌手cocos' onclick='onlyShowGame(this)'>歌手cocos</button>
                        <button class='btn btn-minier left' value='中古战锤' onclick='onlyShowGame(this)'>中古战锤</button>
                        <button class='btn btn-minier left' value='妖灵战姬' onclick='onlyShowGame(this)'>妖灵战姬</button>
                        <button class='btn btn-minier left' value='生化纪元' onclick='onlyShowGame(this)'>生化纪元</button>
                        <button class='btn btn-minier left' value='诙谐三国' onclick='onlyShowGame(this)'>诙谐三国</button>
                        <button class='btn btn-minier left' value='像素项目' onclick='onlyShowGame(this)'>像素项目</button>
                        <div class='xsqb' id="xsqb" onclick='gamesbtndis()'>展开</div>
                    </div>
                </div>

                <div id="gamesbtn" style="padding:0 11px 15px 11px;">
                    <?php if ($canEdit) { ?><a href="./?app=edit" class='btn btn-minier btn-pink'>编辑游戏</a><? } ?>
                   <!-- <a href="./?app=edit" class='btn btn-minier btn-pink'>编辑游戏</a> -->
                    <button value='' onclick='onlyShowGame(this)' class='btn btn-minier btn-info'>显示全部</button>
                    <?php
                    foreach ($GAMES as $g) {
                        echo "<button value='{$g}' onclick='onlyShowGame(this)' class='btn btn-minier'>{$g}</button> ";
                    } ?>
                    <button class='btn btn-minier shouhui' id="xsqbsh" onclick='gamesbtndis()'>收回</button>
                    <div class="space-6"></div>

                </div>

                <style>
                html,body {
                    height: 100%;
                    overflow: auto;
                }
                .shouhui { 
                    background-color:#0078f7 !important;
                    color:#fff !important;
                 }
                .xsqb-box {
                    display: flex;
                    flex-flow: row wrap;
                    align-items: center;
                }
                .left {
                    margin-left: 5px;
                    margin-top: 5px !important;
                }
                .left_box {
                    display: flex;
                    flex-flow: row wrap;
                    align-items: center;
                }
                .xsqb { 
                    width: 60px;
                    background-color:#0078f7 !important;
                    color:#fff;
                    height: 23px;
                    text-align: center;
                    border-radius: 8px;
                    font-size: 12px;
                    line-height: 23px;
                    margin-left: 11px;
                    cursor: pointer;
                    margin-top: 5px;
                 }
                #gamesbtn {
                    display: none;
                }
                    .xian2 {
                        width: calc(100% - 200px);
                        height: 1px;
                        background-color:#f3f3f3;
                    }
                    .datarepair {
                        z-index: 1000;
                        width: 100px;
                        height: 27px;
                        line-height: 27px;
                        position: relative;
                        top: 60px;
                        color: #0078f7;
                        margin: 0 auto;
                        cursor: pointer;
                        font-size: 12px;
                        display: flex;
                        background-color:#ffffff;
                        border-radius: 8px;
                        text-align: center;
                        margin-bottom: 15px;
                        border: 1px solid #0078f7;
                    }

                    .datarepair img {
                        width: 12px;
                        height: 12px;
                        margin-right: 10px;
                        margin-left: 15px;
                        margin-top: 7px;
                    }

                    #gameinfo {
                        margin: 0 0 20px 0;
                        /* background-color:#f5f5f9; */
                    }

                    #gameinfo li {
                        padding: 0px 0 0 20px;
                        line-height: 40px;
                        background: #50abe4;
                        display: inline-block;
                        color: #fff;
                        position: relative;
                        display: inline-block;
                        margin: 5px

                    }

                    #gameinfo li:after {
                        content: '';
                        display: block;
                        border-top: 20px solid transparent;
                        border-bottom: 20px solid transparent;
                        border-left: 20px solid #50abe4;
                        position: absolute;
                        right: -20px;
                        top: 0;
                        z-index: 10;
                    }

                    #gameinfo li:before {
                        content: '';
                        display: block;
                        border-top: 20px solid transparent;
                        border-bottom: 20px solid transparent;
                        border-left: 20px solid #fff;
                        position: absolute;
                        left: 0px;
                        top: 0;
                    }

                    .fc-header {
                        position: relative;
                        top: -40px;
                    }
                    .xian3 {
                        height: 13px;
                        width:100%;
                        background-color:#f3f3f3;
                    }
                </style>

                <div id="gameinfo" style="display:block">
                    <ul>

                    </ul>
                </div>

                <div class="xian3"></div>

                <style>
                    .fc-event {
                        border: none;
                        min-height: 30px;
                    }

                    .data_box {
                        display: none;
                        overflow: scroll;
                        /* width: 800px; */
                        width: 100%;
                    }

                    .data_tab {
                        width: 480px;
                        display: flex;
                        justify-content: center;
                        flex-flow: row wrap;
                        align-items: center;
                        position: relative;
                        top: 18px;
                        right: 11px;
                        z-index: 1000;
                        float: right;
                    }

                    .data-box {
                        width: 90px;
                        text-align: center;
                        display: flex;
                        align-items: center;
                        margin-right: 5px;
                        white-space:nowrap;
                    }

                    .data-box img {
                        width: 25px;
                        /* margin: 0 auto; */
                        margin-right: 5px
                    }

                    .data-box .data-name {
                        font-size: 12px;
                        color: #8e8e8e;
                        text-align: center;
                    }

                    .data-box .data-num {
                        font-size: 14px;
                        color: #a0a0a0;
                        text-align: center;
                    }
                    .formtab {
                        padding: 27px 0px !important;
                        color:#474747 !important;
                        border: 0px !important;
                        text-align: center;
                    }
                    .fc-week {
                        background-color:#f7f7f7;
                    }
                    .echarts-time {  width: 100%;  position: relative; top: -20px; display: none;}
                    .echarts-time-box { max-width: 700px; height: 30px; margin: 0 auto; justify-content:space-evenly; display: flex; position: absolute; left: 0; right: 0;}
                    .yearclass { width: 100px; }
                </style>
                <div class='datarepair' id="datarepair" onclick="datarepair()">
                    <img src='assets/images/tongji.png' id="dataimg"/><span id='datarepairname'>查看统计</span>
                </div>
                <div class='data_tab'>
                    <div class='data-box'>
                        <img src="assets/images/dabao.png"/>
                        <p class="data-name">打包</p>
                        <p class="data-num" id="dabaonum"></p>
                    </div>

                    <div class='data-box'>
                        <img src="assets/images/gengxin.png"/>
                        <p class="data-name">更新</p>
                        <p class="data-num" id="gengxinnum"></p>
                    </div>

                    <div class='data-box'>
                        <img src="assets/images/xiufu.png"/>
                        <p class="data-name">修复</p>
                        <p class="data-num" id="xiufunum"></p>
                    </div>

                    <div class='data-box'>
                        <img src="assets/images/jeidian.png"/>
                        <p class="data-name">节点</p>
                        <p class="data-num" id="jeidiannum"></p>
                    </div>
                    <div class='data-box'>
                        <img src="assets/images/shangxian.png"/>
                        <p class="data-name">上线</p>
                        <p class="data-num" id="shangxainnum"></p>
                    </div>
                </div>
                <div class='echarts-time' id='echarts-time'>
                    <div class="echarts-time-box">
                            <div style='float: left;'>
                                开始时间：
                                <input class="yearclass" type='text' id='startyear' />
                                <select name="drop2" class="ui-select" id="startmonth" style="width: 100px;">
                                    <option value="1">1月</option>
                                    <option value="2">2月</option>
                                    <option value="3">3月</option>
                                    <option value="4">4月</option>
                                    <option value="5">5月</option>
                                    <option value="6">6月</option>
                                    <option value="7">7月</option>
                                    <option value="8">8月</option>
                                    <option value="9">9月</option>
                                    <option value="10">10月</option>
                                    <option value="11">11月</option>
                                    <option value="12">12月</option>
                                </select>
                            </div>
                        
                            <div style='float: right;'>
                                结束时间：
                                <input class="yearclass" type='text' id='endyear' />
                                <select name="drop2" class="ui-select" id="endmonth" style="width: 100px;">
                                    <option value="1">1月</option>
                                    <option value="2">2月</option>
                                    <option value="3">3月</option>
                                    <option value="4">4月</option>
                                    <option value="5">5月</option>
                                    <option value="6">6月</option>
                                    <option value="7">7月</option>
                                    <option value="8">8月</option>
                                    <option value="9">9月</option>
                                    <option value="10">10月</option>
                                    <option value="11">11月</option>
                                    <option value="12">12月</option>
                                </select>
                            </div>
                        </div>
                </div>
                

                
                <div class='data_box' id='data_box'>

                    <div id="chart" class="chartbox" style="width:100%;height:400px; margin-top:90px;"></div>

                    <div class="card-body" style="margin: 0 2% 0 3%;">
                        <table class="table table-bordered table-striped" style='border:1px solid #f0f0f0 !important; min-width: 800px; text-align:center;'>
                            <thead id="thead-title" class="thead" ></thead>
                            <tbody id="tbody-content"></tbody>
                        </table>
                    </div>

                </div>

                <div class="col-xm-12" id="calendardiv">
                    <div id="calendar"></div>
                </div>
            </div>
        </div>

    </div>

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="icon-double-angle-up icon-only bigger-110"></i>
    </a>
</div>
<!-- <div id="aa"></div>
<div id="bb"></div> -->
<script>
	// $("#aa").html("修复查看"+"<?=$isxfvrole?>")
	// $("#bb").html("修复权限"+"<?=$isxfyyerole?>")
</script>
 
<style>
    /* */
    .popup-bg {
        width: 100%;
        height: 100%;
        min-height: 100%;
        background-color: rgba(000, 000, 000, 0.5);
        position: fixed;
        top: 0;
        z-index: 100000;
        display: flex;
        display: none;
    }

    .yiny {
        width: calc(100% - 350px);
        height: 100%;
        min-height: 100%;
        position: fixed;
        top: 0;
        z-index: 1000000;
    }

    .popup-box {
        width: 350px;
        height: 100%;
        min-height: 100%;
        background-color: #fff;
        position: fixed;
        right: 0;
        z-index: 1001;
        overflow: scroll;
    }

    ::-webkit-scrollbar {
        /*隐藏滚轮*/
        display: none;
    }

    .pop-top {
        width: 100%;
        background-color: #ececec;
        display: flex;
        padding: 15px 20px;
    }

    .bianji {
        width: 20px;
        height: 20px;
        cursor: pointer;
    }

    .bianji img {
        width: 100%;
    }

    .pop-title {
        color: #494949;
        font-size: 18px;
        margin: 0 auto;
        cursor: pointer;
    }

    .list-box {
        margin: 10px 20px 0 20px;
        border: 1px solid #f2f2f2;
    }

    .list-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border-bottom: 1px solid #f2f2f2;
    }

    .tit {
        display: flex;
        align-items: center;
        font-size: 16px;
        color: #686868;
    }

    .xian {
        width: 7px;
        height: 15px;
        background-color: #5fadff;
        margin-left: 10px;
        margin-right: 5px;
    }

    .cptime {
        font-size: 12px;
        color: #c1c1c1;
        margin-right: 14px;
    }

    .cptext-box {
        border-bottom: 1px solid #f2f2f2;
    }

    .cptext-box textarea {
        width: 100%;
        min-height: 111px;
        max-height: 160px;
        padding: 20px 14px;
        font-size: 12px;
        color: #626262;
        border: 0;
        resize: none;
        line-height: 18px;
    }

    .fujian {
        display: flex;
        flex-flow:row wrap;
        align-items: center;
        font-size: 12px;
        color: #b8b8b8;
    }

    .fujianinfo {
        display: flex;
        align-items: center;
        margin-top: 5px;
    }

    .fujian img {
        width: 14px;
        margin-right: 7px;
        margin-left: 14px;
    }
    .ximg {
        margin-right: 0px !important;
        margin-left: 5px !important;
        margin-top: 2px;
        cursor:pointer;
    }

    .tianjia {
        margin-right: 0px;
        margin-top: 10px;
    }

    .fujian-box {
        /* display: flex;
        justify-content: space-between;
        align-items: center; */
        padding: 10px 0;
    }

    .tianjiainp {
        display: none !important;
    }

    .fujian a {
        color: #61adfe;
    }

    input[type="file"] {
        padding: 0 14px;
    }

    .tijaioanniu {
        display: flex;
        justify-content: space-between;
        align-items: center;
        /* padding: 10px 0;  */
    }

    .tijiao {
        width: 280px;
        height: 34px;
        line-height:34px;
        background-color: #5fadff;
        font-size: 14px;
        text-align: center;
        color: #fff;
        border-radius: 8px;
        float: right;
        cursor: pointer;
        margin-top: -5px;
    }
    .upfujian {
        width: 100%;
        margin: 0 13px;
    }
    .listhove {
        box-shadow: 0px 0px 5px #40a9ff;
    }
    
    input::-webkit-input-placeholder,textarea::-webkit-input-placeholder { /* WebKit browsers*/
        color:#bababa;
    }
    input:-moz-placeholder {  /* Mozilla Firefox 4 to 18*/
        color:#bababa;
    }
    input:-moz-placeholder {  /* Mozilla Firefox 19+*/
        color:#bababa;
    }
    input:-ms-input-placeholder { /* Internet Explorer 10+*/
        color:#bababa;
    }
    input:disabled, textarea:disabled {
        -webkit-text-fill-color: #626262;
        -webkit-opacity: 1;
        color: #626262;
    }
    .recording-box { margin: 10px 20px 0 20px; color:#626262; font-size: 12px; }
    .recording—title { font-size: 16px; color:#686868; }
    .recording—title span{ font-size: 12px; color:#686868; }
    .recording—name { float: right; }
    .recording—con-box { margin-top: -16px; padding-bottom: 50px; }
    .yanqi { position: absolute; top:0; right:0;}
</style>
<div class='popup-bg' id='popup-bg'>
    <div class="yiny" id='yiny' onclick="guanbi()"></div>
    <div class='popup-box'>
        <div class="pop-top">
            <div class='bianji' onclick='bianji()'><img src='assets/images/bianji.png'/></div>
            <div class="pop-title" id='pop-title' onclick='Info()'></div>
        </div>
        <div class="list-box" id='listcp'>
            <div class='list-title'>
                <div class='tit'>
                    <div class='xian'></div>
                    产品中心
                </div>
                <div class='cptime' id='cptime'></div>
            </div>
            <div class='cptext-box'>
                <textarea disabled='disabled' id='cptext' placeholder="添加产品中心对本节点的描述"></textarea>
            </div>
            <div class='fujian-box'>

                <!-- 附件 -->
                <div class='fujian' id='fujianname' ></div>
                <!-- <div class='fujian xz' id='xzfujianname' ></div> -->
                <div class="tijaioanniu">
                    <div style=" position: relative; display: none" class="upfujian" id="upfujian_cp">
                        <img class='tianjia' src='./assets/images/jia.png'/>
                        <iframe id="_hideiframe" name="_hideiframe" style="display: none;"></iframe>
                        <form method="post" id="uploader" style="display: block; clear: both; margin-top: 10px;;"
                              target="_hideiframe" action="" enctype="multipart/form-data">
                            <input name="cid" type="hidden" value="<%=DATA.lastShowCardID%>" style='opacity: 0; position: absolute;z-index: 1001;'/>
                            <input type="file" id="fujian" name="fujian[]" multiple
                                   onchange="document.getElementById('uploader').submit()"  style='opacity: 0; position: absolute; top:20px; z-index: 1001;'>
                        </form>
                        <div class='tijiao' id="cptijiao">提交</div>

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

        <div class="list-box" id='listyy'>
            <div class='list-title'>
                <div class='tit'>
                    <div class='xian'></div>
                    运营中心
                </div>
                <div class='cptime' id='yytime'></div>
            </div>
            <div class='cptext-box'>
                <textarea disabled='disabled' id='yytext' placeholder="填写本次更新概要，详细更新内容请使用附件"></textarea>
            </div>
            <div class='fujian-box'>
            
                <!-- 附件 -->
                <div class='fujian' disabled='disabled' id='yyfujian'></div>
                <!-- <div class='fujian xz' id='yyxzfujian'></div> -->
                <!-- <div style=" position: relative;display: inline-block;">
                    <img class='tianjia' src='/assets/images/jiahao.png'/>
                    <input name="customer_file" type="file" id="excelFile2"
                           style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;z-index: 1001;opacity: 0;filter:alpha(opacity=0);">
                </div> -->
                <div class="tijaioanniu">
                    <div style=" position: relative;display: none;" class="upfujian" id="upfujian_yy">
                        <img class='tianjia' src='./assets/images/jia.png'/>
                        <iframe id="_hideiframe2" name="_hideiframe" style="display: none;"></iframe>
                        <form method="post" id="uploader_yy" style="display: block; clear: both; margin-top: 10px;;"
                              target="_hideiframe" action="" enctype="multipart/form-data">
                            <input name="cid" type="hidden" value="<%=DATA.lastShowCardID%>" style='opacity: 0; position: absolute;z-index: 1001;'/>
                            <input type="file" id="fujian_yy" name="fujian[]" multiple
                                   onchange="document.getElementById('uploader_yy').submit()" style='opacity: 0;position: absolute; top:20px; z-index: 1001;'>
                        </form>
                        <div class='tijiao' id="yytijiao">提交</div>
                    </div>
                </div>


            </div>
        </div>

        <div class="list-box" id='listyf'>
            <div class='list-title'>
                <div class='tit'>
                    <div class='xian'></div>
                    研发中心
                </div>
                <div class='cptime' id='yftime'></div>
            </div>
            <div class='cptext-box'>
                <textarea disabled='disabled' id='yftext' placeholder="添加研发中心对本节点的描述"></textarea>
            </div>
            <div class='fujian-box'>
            
                <!-- 附件 -->
                <div class='fujian' id='yffujian'></div>
                <!-- <div class='fujian xz' id='yfxzfujian'></div> -->
                <div class="tijaioanniu">
                    <div style=" position: relative;display: none;" class="upfujian" id="upfujian_yf">
                        <img class='tianjia' src='./assets/images/jia.png'/>
                        <iframe id="_hideiframe3" name="_hideiframe" style="display: none;"></iframe>
                        <form method="post" id="uploader_yf" style="display: block; clear: both; margin-top: 10px;"
                              target="_hideiframe" action="" enctype="multipart/form-data">
                            <input name="cid" type="hidden" value="<%=DATA.lastShowCardID%>" style='opacity: 0; position: absolute;z-index: 1001;'/>
                            <input type="file" id="fujian_yf" name="fujian[]" multiple
                                   onchange="document.getElementById('uploader_yf').submit()" style='opacity: 0; position: absolute; top:20px; z-index: 1001;'>
                        </form>
                        <div class='tijiao' id="yftijiao">提交</div>
                    </div>
                </div>

            </div>
        </div>
        
        <!-- 延期原因 -->
        <div class='recording-box' id="recording-box">
            <div class='recording—title'>延迟记录 <span>(双击记录可更改)</span> </div>
            <div class="recording—con-box" id="recording-content">
                
            </div>
        </div>


    </div> 
</div>

<link rel="stylesheet" href="assets/css/jquery.gritter.css"/>
<script src="assets/js/jquery.gritter.min.js"></script>

<script src="assets/js/bootbox.min.js"></script>
<script src="assets/js/fullcalendar.min.js"></script>

<link rel="stylesheet" href="assets/css/daterangepicker.css"/>
<script src="assets/js/date-time/moment.min.js"></script>
<script src="assets/js/date-time/daterangepicker.min.js"></script>

<script type="text/x-dot-template" id="thead-dot">
    <tr style="background:#fafafa !important;">
        {{~it:item:index}}

        <th class='formtab' style="padding: 25px 0px; color:#474747; border: 0px;">{{=item}}</th>

        {{~}}
    </tr>
</script>

<script type="text/x-dot-template" id="tbody-dot">
    {{ for(var i in it) { }}
    <tr>
        {{? i != 1}}
            {{ for(var k in it[i]) { }}
                {{? k !=1}}
                    <td style="border-top: 1px solid #f0f0f0; color:#474747; padding: 25px 0; background-color:#fff; border-bottom:0px; border-left:0px; border-right:0px; ">{{= it[i][k]}}</td>
                {{??}}
                    <td style="border-top: 1px solid #f0f0f0; color:#474747; padding: 25px 0; background-color:#fff; border-bottom:0px; border-left:0px; border-right:0px; color:#007efa !important;">{{= it[i][k]}}</td>
                {{?}}
            {{ } }}
        {{??}}
            {{ for(var k in it[i]) { }}
                {{? k !=1}}
                    <td style="border-top: 1px solid #f0f0f0; color:#474747; padding: 25px 0; background-color:#fafafa; border-bottom:0px; border-left:0px; border-right:0px; ">{{= it[i][k]}}</td>
                {{??}}
                    <td style="border-top: 1px solid #f0f0f0; color:#474747; padding: 25px 0; background-color:#fafafa; border-bottom:0px; border-left:0px; border-right:0px; color:#007efa !important;">{{= it[i][k]}}</td>
                {{?}}
            {{ } }}
        {{?}}
    </tr>
    {{ } }}
</script>

<script type="text/x-dot-template" id="fujian-dot">
    {{~it:item:index}}
        <div class='fujianinfo'>
            <img src="./assets/images/xiazai.png"/ class='xiazaiimg'>
            <div id='cpfuinfo'>
                <a href='{{= window.location.href.split('?')[0]+item.file}}' target="_blank">{{= item.name}}</a>
            </div>
            <img src="./assets/images/x.png" class='ximg' onclick="deletefujian('{{= item.key}}')"/>
        </div>
    {{~}}
</script>

<script type="text/x-dot-template" id="fujiankong-dot">
    {{~it:item:index}}
        <div class='fujian'>
            <img src="./assets/images/fujian.png"/>
            未添加附件
        </div>
    {{~}}
</script>

<script type="text/x-dot-template" id="recording-dot">
    {{~it:item:index}}
        <div style="margin-top: 32px;">
            <p><span style='font-weight: bold;'>《{{= item.project}}》</span>项目{{=item.type}}从<span style='color:#77da80'>{{=item.date1}}</span>日{{=item.timetype}}到<span style='color:#ff7f7f'>{{=item.date2}}</span>日</p>
            <div style='margin-top: 6px;'> 调整理由为：{{=item.reason}}</div>
            <P class='recording—name' style='margin-top: 6px;'>调整人：{{=item.user}}</p>
            <img src='./assets/images/dian.png' onclick='recordingdel({{=index}})' style='cursor:pointer'>
            <img src='./assets/images/dian.png'>
        </div>
    {{~}}
</script>


<script>
    var showGame = "";
    var starttime, endtime;
    var dstr = ''
    var dict = {};
    var bumen;
    var notid;
    var arrcp = [];
    var arryy = [];
    var arryf = [];
    var starts ='';

    // console.log("<?=$user['name']?>")

    $("#startmonth").change(function(){
        datechoice()
    })

    $("#endmonth").change(function(){
        datechoice()
    })

    $("#startyear").blur(function(){
        datechoice();
    })
    $("#endyear").blur(function(){
        datechoice();
    })

    function recordingdel(idx){
        if ("<?=$canEdit?>" != "1"  && "<?=$issxarole?>" != "1") return;
        if (confirm("确定删除这条记录？")) {
            $.ajax({
                url: './?app=pmcalendar',
                dataType: 'json',
                data: {
                    act: 'edityanqi',
                    id: notid,
                    idx: idx,
                    del: 1
                },
                success: function (res) {
                    console.log(res);
                    alert('删除成功');
                    showEventData(notid);
                    // textdisabled();
                },
                error: function () {
                    alert('数据异常,请稍后重试!!!');
                    showEventData(notid);
                    // textdisabled();
                }
            });
        }
    }

    function datechoice() {

        var stmonth = $("#startmonth").val();
        var startyear = $("#startyear").val();
        var start = startyear+"-"+moment(stmonth).startOf("month").format("MM-DD")+" " + '00:00:00'
        var startdate = new Date(start);
        var startmonth = Date.parse(startdate)/1000;

        var enmonth = $("#endmonth").val();
        var endyear = $("#endyear").val();
        var end = endyear + "-" + moment(enmonth).endOf('month').format("MM-DD")+" " + "23:59:59"
        var enddate = new Date(end);
        var endmonth = Date.parse(enddate)/1000;

        if(startyear > endyear){
            alert('结束年份不能小于开始年份！！！');
            return;
        } else if(startyear == endyear){
            if(parseInt(stmonth) < parseInt(enmonth)){
                var title = $("#startyear").val()+"年"+stmonth+"月"+"至"+enmonth+"月";
            }else if(parseInt(stmonth) > parseInt(enmonth)){
                alert('同年时结束月份不能小于开始月份！！！');
                return;
            }else {
                    var title = $("#startyear").val()+"年"+stmonth+"月"
                }
        }else {
            var title = $("#startyear").val()+"-"+ $("#endyear").val() +"年"+stmonth+"月"+"至"+enmonth+"月";
        }

        // if(stmonth != enmonth){
        //     var title = $("#startyear").val()+"年"+stmonth+"月"+"至"+enmonth+"月";
        // }else {
        //     var title = $("#startyear").val()+"年"+stmonth+"月"
        // }

        console.log(title);

            $.ajax({
                url: './?app=pmcalendar&act=getEvents',
                dataType: 'json',
                data: {
                    start: startmonth,
                    end: endmonth,
                    game: showGame,
                    type: 'charts'
                },

                success: function (res) {
                    var myChart = echarts.init(document.getElementById('chart'));
                    var chartsdata = res.charts;

                    var option = {
                        title: {
                            text: title,
                            left: 'center',
                            textStyle: {
                                fontWeight: 'normal',
                                color: '#6fb3e0',
                            }
                        },
                        color: ['#ff7f7f', '#a494f9'],
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            right: '0%',
                            top: 'center',
                            feature: {
                                mark: {show: true},
                                dataView: {show: true, readOnly: false},
                                magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                                restore: {show: true},
                                saveAsImage: {show: true}
                            }
                        },
                        legend: {
                            left: '3%',
                            top: '20',
                            itemHeight: 11,
                            itemWidth: 6,
                            color:"#5f5f5f"
                        },
                        tooltip: {},
                        grid: {
                            left: '3%',
                            right: '3%',
                            bottom: '5%',
                            // top: '0%',
                            containLabel: true
                        },
                        color: ['#ff7f7f', '#a494f9'],
                        dataset: {
                            source: chartsdata
                        },
                        dataZoom: [
                            {
                                id: 'dataZoomX',
                                type: 'slider',
                                xAxisIndex: [0],
                                filterMode: 'filter'
                            }
                        ],
                        xAxis: {
                            type: 'category',
                            axisLabel:{
                                show: true,
                                textStyle:{
                                    color:"#969696"
                                }
                            },
                            axisLine:{
                                lineStyle:{
                                    color:'#bfbfbf',
                               }
                            }
                        },
                        yAxis: {
                            axisLabel:{
                                textStyle:{
                                    color:"#bfbfbf"
                                }
                            },
                            "axisLine": {       //y轴
                                "show": false
                            },
                            "axisTick": {       //y轴刻度线
                                "show": false
                            },
                            "splitLine": {     //网格线
                                "show": true,
                                'coloe': '#bfbfbf'
                            }
                        },
                        // Declare several bar series, each will be mapped
                        // to a column of dataset.source by default.
                        series: [
                            {
                                type: 'bar',
                                barCategoryGap : 60,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'insideBottom',
                                            distance: 15,
                                            align: 'left',
                                            verticalAlign: 'middle',
                                            rotate: 1,
                                            fontSize: 16,
                                            textStyle: { //数值样式
                                                color: '#000',
                                                fontSize: 13
                                            }
                                        }
                                    }
                                }
                            },
                            {
                                type: 'bar',
                                barCategoryGap : 60,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'insideBottom',
                                            distance: 15,
                                            align: 'left',
                                            verticalAlign: 'middle',
                                            rotate: 1,
                                            fontSize: 16,
                                            textStyle: { //数值样式
                                                color: '#000',
                                                fontSize: 13
                                            }
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);

                    $("#dabaonum").html("("+res.count['打包']+")");
                    $("#gengxinnum").html("("+res.count['版本更新']+")");
                    $("#xiufunum").html("("+res.count['修复外网']+")");
                    $("#jeidiannum").html("("+res.count['节点']+")");
                    $("#shangxainnum").html("("+ res.count['上线'] +")");

                    var titleAdd = res.table[0];
                    titleAdd[0] = "";
                    var tbdyArr = res.table[1];
                    tbdyArr[2][0] = '占比';
                    tmpltxt = doT.template(document.getElementById("thead-dot").innerHTML);//生成模板方法
                    document.getElementById("thead-title").innerHTML = tmpltxt(titleAdd);//数据渲染

                    tmpltxt = doT.template(document.getElementById("tbody-dot").innerHTML);//生成模板方法
                    document.getElementById("tbody-content").innerHTML = tmpltxt(tbdyArr);//数据渲染

                },
                error: function () {
                    alert('数据异常,请稍后重试!!!')
                }
            });

    }




    function gamesbtndis(){
        var type = $("#gamesbtn").css('display');
        // console.log($("#xsqb").html());
        if(type == 'none'){
            $("#gamesbtn").show();
            $("#xsqb").html('收回');
            $("#left_box").hide();
        }else {
            $("#gamesbtn").hide();
            $("#xsqb").html('显示全部');
            $("#left_box").show();
        }
        // console.log($("#xsqb").html());
        if(type == 'none'){
            $("#gamesbtn").show();
            $("#xsqb").html('收回');
        }else {
            $("#gamesbtn").hide();
            $("#xsqb").html('展开');
        }
    }

    function deletefujian(id){

        if("<?=$isxfvrole?>" != "1" && "<?=$isxfyyerole?>" != "1" && "<?=$canEdit?>" != "1" && "<?=$isgxvrole?>" != "1" && "<?=$isgxyyerole?>" != "1" && "<?=$isgxcperole?>" != "1" && "<?=$isgxyferole?>" != "1" && "<?=$canEdit?>" != "1")return
        if (confirm("确定删除该附件？")) {
            $.ajax({
                url: './?app=uploader&act=del',
                dataType: 'json',
                data: {
                    id: notid,
                    key: id
                },
                success: function (res) {
                    console.log(res);
                    alert('删除成功');
                    showEventData(notid);
                    // textdisabled();
                },
                error: function () {
                    alert('数据异常,请稍后重试!!!');
                    showEventData(notid);
                    // textdisabled();
                }
            });
        }
    }

    $('#fujian').change(function () {
        var wenjianname = $('#fujian').val();
        var obj = document.getElementById("fujian");
        var len = obj.files.length;
        var temp;
        for (var i = 0; i < len; i++) {
            // temp = obj.files[i].name;
            var data = {};
            data['name'] = obj.files[i].name
            data['file'] = "#"
            arrcp.push(data)
        }
        $("#fujianname").empty();
        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
        document.getElementById("fujianname").innerHTML = tmpltxt(arrcp);//数据渲染
        // console.log('arr');
    })

    $("#fujian_yy").change(function () {
        var wenjianname = $('#fujian_yy').val();
        var obj = document.getElementById("fujian_yy");
        var len = obj.files.length;
        var temp;
        for (var i = 0; i < len; i++) {
            // temp = obj.files[i].name;
            var data = {};
            data['name'] = obj.files[i].name
            data['file'] = "#"
            arryy.push(data)
        }
        $("#yyfujian").empty();
        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
        document.getElementById("yyfujian").innerHTML = tmpltxt(arryy);//数据渲染
    })

    $("#fujian_yf").change(function () {
        var wenjianname = $('#fujian_yf').val();
        var obj = document.getElementById("fujian_yf");
        var len = obj.files.length;
        var temp;
        // var arr = [];
        for (var i = 0; i < len; i++) {
            // temp = obj.files[i].name;
            var data = {};
            data['name'] = obj.files[i].name
            data['file'] = "#"
            arryf.push(data)
        }
        $("#yffujian").empty();
        console.log(arryf);
        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
        document.getElementById("yffujian").innerHTML = tmpltxt(arryf);//数据渲染
    })

    //产品提交
    $('#cptijiao').click(function () {
        var cptext = $("#cptext").val();
        var myDate = new Date();
        var year = myDate.getFullYear();       //获取当前年份(2位)
        var month = myDate.getMonth()+1;
        var day = myDate.getDate();
        var branch = myDate.getHours();       //获取当前小时数(0-23)
        var second = myDate.getMinutes();     //获取当前分钟数(0-59)

        var arr = {}
        arr['msg'] = cptext,
        arr['date'] = year + '-' + month + '-' + day + ' ' + branch + ':' + second,
        arr['user'] = "<?=$user['name']?>"
        arr = JSON.stringify(arr)
        $.ajax({
            url: './?app=pmcalendar&act=editchanpin',
            dataType: 'application/x-www-form-urlencoded',
            type: "post",
            async: "true",
            data: {
                id: notid,
                content: arr
            },
            success: function (res) {
                console.log(res);
                alert('提交成功');
                i=0;
                showEventData(notid);
                textdisabled();
            },
            error: function () {
                alert('数据异常,请稍后重试!!!');
                i=0;
                showEventData(notid);
                textdisabled();
            }
        });
    })
    //运营
    $('#yytijiao').click(function () {
        var yytext = $("#yytext").val();
        var myDate = new Date();
        var year = myDate.getFullYear();       //获取当前年份(2位)
        var month = myDate.getMonth()+1;
        var day = myDate.getDate();
        var branch = myDate.getHours();       //获取当前小时数(0-23)
        var second = myDate.getMinutes();     //获取当前分钟数(0-59)

        var arr = {}
        arr['msg'] = yytext,
        arr['date'] = year + '-' + month + '-' + day + ' ' + branch + ':' + second,
        arr['user'] = "<?=$user['name']?>"
        arr = JSON.stringify(arr)
        $.ajax({
            url: './?app=pmcalendar&act=edityunying',
            dataType: 'json',
            data: {
                id: notid,
                content: arr
            },
            success: function (res) {
                console.log(res);
                alert('提交成功');
                i=0;
                showEventData(notid);
                textdisabled();
            },
            error: function () {
                alert('数据异常,请稍后重试!!!');
                i=0;
                showEventData(notid);
                textdisabled();
            }
        });
    })

    //研发
    $('#yftijiao').click(function () {
        var yftext = $("#yftext").val();
        var myDate = new Date();
        var year = myDate.getFullYear();       //获取当前年份(2位)
        var month = myDate.getMonth()+1;
        var day = myDate.getDate();
        var branch = myDate.getHours();       //获取当前小时数(0-23)
        var second = myDate.getMinutes();     //获取当前分钟数(0-59)
        var arr = {}
        arr['msg'] = yftext,
        arr['date'] = year + '-' + month + '-' + day + ' ' + branch + ':' + second,
        arr['user'] = "<?=$user['name']?>"
        arr = JSON.stringify(arr)
        $.ajax({
            url: './?app=pmcalendar&act=edityanfa',
            dataType: 'json',
            data: {
                id: notid,
                content: arr
            },
            success: function (res) {
                console.log(res);
                alert('提交成功');
                i=0;
                showEventData(notid);
                textdisabled();
            },
            error: function () {
                alert('数据异常,请稍后重试!!!');
                i=0;
                showEventData(notid);
                textdisabled();
            }
        });
    })

    function textdisabled(){
        $('#yytext').attr('disabled', false)
        $('#yftext').attr('disabled', false)
        $('#cptext').attr('disabled', false)
        $("#upfujian_yy").hide();
        $("#upfujian_cp").hide();
        $("#upfujian_yf").hide();
    }

    var i = 0;

    $(document).ready(function() {
        $('html,body').scrollTop(0)
    })

    function bianji() {
        if(bumen == 'label-danger'){
            if ("<?=$isgxyyerole?>" == "1") {
                if (i == 0) {
                    $('#yytext').attr('disabled', false)
                    $("#upfujian_yy").show();
                    i = 1;
                } else {
                    $('#yytext').attr('disabled', true)
                    $("#upfujian_yy").hide();
                    i = 0;
                }
            };
        } else if(bumen == 'label-pink'){
            if ("<?=$issxyyerole?>" == "1") {
                if (i == 0) {
                    $('#yytext').attr('disabled', false)
                    $("#upfujian_yy").show();
                    i = 1;
                } else {
                    $('#yytext').attr('disabled', true)
                    $("#upfujian_yy").hide();
                    i = 0;
                }
            };
        } else if( bumen == "label-warning" ){

            if ("<?=$isdbyyerole?>" == "1") {
                if (i == 0) {
                    $('#yytext').attr('disabled', false)
                    $("#upfujian_yy").show();
                    i = 1;
                } else {
                    $('#yytext').attr('disabled', true)
                    $("#upfujian_yy").hide();
                    i = 0;
                }
            };
            if ("<?=$isdbcperole?>" == "1") {
                if (i == 0) {
                    $('#cptext').attr('disabled', false)
                    $("#upfujian_cp").show();
                    i = 1;
                } else {
                    $('#cptext').attr('disabled', true)
                    $("#upfujian_cp").hide();
                    i = 0;
                }
            };
            if ("<?=$isdbyferole?>" == "1") {
                if (i == 0) {
                    $('#yftext').attr('disabled', false)
                    $("#upfujian_yf").show();
                    i = 1;
                } else {
                    $('#yftext').attr('disabled', true)
                    $("#upfujian_yf").hide();
                    i = 0;
                }
            };
        } else {
            if ("<?=$isxfyyerole?>" == "1") {
                if (i == 0) {
                    $('#yytext').attr('disabled', false)
                    $("#upfujian_yy").show();
                    i = 1;
                } else {
                    $('#yytext').attr('disabled', true)
                    $("#upfujian_yy").hide();
                    i = 0;
                }
            };
        }
        
    }

    function onlyShowGame(o) {
        // console.log(o);
        if (o.value != '') {
            $('#datarepair').hide();
            $('.xian3').css('background-color','#fff');
        } else {
            $('#datarepair').show();
            $('.xian3').css('background-color','#f5f5f9');
        }
        showGame = (o.value);
        calendar.fullCalendar('refetchEvents');
        $('#gamesbtn button').removeClass('btn-purple').removeClass('btn-info');
        $('#left_box button').removeClass('btn-purple').removeClass('btn-info');
        $(o).addClass('btn-info');
    }

    function fix2(v) {
        var v = '00' + v;
        return v.substr(v.length - 2, 2);
    }

    $(function () {
        /* initialize the calendar
    -----------------------------------------------------------------*/

        var date = new Date();
        var d = date.getDate();
        var m = date.getMonth();
        var y = date.getFullYear();

        var calendar = window.calendar = $('#calendar').fullCalendar({
            buttonText: {
                prev: '<i class="icon-chevron-left"></i>',
                next: '<i class="icon-chevron-right"></i>',
                prevYear: '去年',
                nextYear: '明年',
                today: '',
                month: '月',
                week: '周',
                day: '日'
            },
            timeFormat: 'H:mm',
            monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            monthNamesShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
            dayNames: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
            dayNamesShort: ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],

            header: {
                left: 'prev,next today',
                center: 'title',
                right: 'month,agendaWeek,agendaDay'
            },
            //events: './?app=calendar&act=getEvents&game='+showGame,
            events: function (start, end, callback) {
                starttime = start;
                endtime = end;

                console.log("11111")

                $.ajax({
                    url: './?app=pmcalendar&act=getEvents',
                    dataType: 'json',
                    data: {
                        start: Math.round(start.getTime() / 1000),
                        end: Math.round(end.getTime() / 1000),
                        game: showGame
                    },
                    success: function (doc) {
                        console.log(doc);
                        callback(doc.calendarData);
                        // console.log(doc);\
                        $("#dabaonum").html("("+doc.count['打包']+")");
                        $("#gengxinnum").html("("+doc.count['版本更新']+")");
                        $("#xiufunum").html("("+doc.count['修复外网']+")");
                        $("#jeidiannum").html("("+doc.count['节点']+")");
                        $("#shangxainnum").html("("+ doc.count['上线'] +")");
                        console.log(doc.calendarData)
                        if (doc.gameInfo && doc.gameInfo.length > 0) {
                            var _html = [];
                            for (var i = 0; i < doc.gameInfo.length; i++) {
                                var _v = doc.gameInfo[i];
                                _html.push("<li>" + _v.end + " " + _v.event + " " + _v.title + "</li>");
                            }
                            
                            $('#gameinfo ul').html(_html.join(''));
                        } else {
                            $('#gameinfo ul').html('');
                        }
                    }
                });
            },

            eventRender: function (event, element) {
                // console.log(event)
                // console.log(element)
                if(event.isYanqi == 1){
                    element.html(event.title + '<img class="yanqi" src="assets/images/yanqi.png"/>');
                }else if(event.isYanqi == 0) {
                    element.html(event.title);
                } else {
                    element.html(event.title + '<img class="yanqi" src="assets/images/tiqian.png"/>');
                }
            },

            editable: <?=$canEdit ? "true" : "false"?>,
            eventDrop: function (event, dayDelta, minuteDelta, allDay, revertFunc) {
                console.log("3333")
                dict = {id: event.id};
                dict.start = $.fullCalendar.formatDate(event.start, 'yyyy-MM-dd');
                dict.end = $.fullCalendar.formatDate(event.end, 'yyyy-MM-dd');
                loading.show();
                dict.reason = prompt("请输入延期原因");

                $.post('./?app=pmcalendar&act=movevent', dict, function (txt) {
                    loading.hide();
                    if (txt == '1') {
                        calendar.fullCalendar('refetchEvents');
                    }
                });
                return false;
            }
            ,
            selectable: true,
            selectHelper: true,
            select: function (start, end, allDay) {
                console.log("22222")
                console.log(start)
                console.log(end)
                console.log(allDay)
                if ("<?=$canEdit?>" != "1"  && "<?=$issxarole?>" != "1") return;
                dict = {};
                // console.log('select', start, end, allDay);

                dict.start = $.fullCalendar.formatDate(start, 'yyyy-MM-dd');
                dict.end = $.fullCalendar.formatDate(end, 'yyyy-MM-dd');

                showEventInfo(dict.start, {
                    "save": {
                        "label": "<i class='icon-check'></i> 保存",
                        "className": "btn-sm btn-success",
                        "callback": function () {
                            dict.game = $('#game').val();
                            dict.allday = 1;

                            dict.title = $('#title').val();
                            dict.event = $('#event').val();

                            if (dict.game == '' || dict.title == '') return;

                            loading.show();
                            $.post('./?app=pmcalendar&act=newevent', dict, function (txt) {
                                loading.hide();
                                if (txt == '1') {
                                    calendar.fullCalendar('refetchEvents');
                                }
                            });
                        }
                    },
                    "close": {
                        "label": "<i class='icon-remove'></i> Close",
                        "className": "btn-sm"
                    }
                }, 'new');
                calendar.fullCalendar('unselect');
            }
            ,
            eventClick: function (calEvent, jsEvent, view) {
                bumen = calEvent.className[0]
                console.log(calEvent.className[0])
                notid = calEvent.id;
                starts = calEvent.start;
                // if ("<?=$canEdit?>" != "1") {
                    if (calEvent.className[0] == 'label-danger') {
                        if ("<?=$isgxvrole?>" != "1" && "<?=$isgxyyerole?>" != "1" && "<?=$isgxcperole?>" != "1" && "<?=$isgxyferole?>" != "1" && "<?=$canEdit?>" != "1") {
                            return
                        } else {
                            $('#uploader').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=chanpin&act=add');
                            $('#uploader_yy').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yunyig&act=add')
                            $("#uploader_yf").attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yanfa&act=add')

                            $("#listcp").hide();
                            $("#listyf").hide();

                            $("#yytext").attr('placeholder','填写本次更新概要，详细更新内容请使用附件')

                            dict = {};
                            $.post('./?app=pmcalendar&act=getEventByid', {id: calEvent.id}, function (txt) {
                                var j = JSON.parse(txt);
                                dict.start = j.start;
                                dict.end = j.end;
                                dict.id = calEvent.id;
                                $('#game').val(j.game);
                                $('#hour').val(j.shour);
                                $('#min').val(j.smin);
                                $('#event').val(j.event);
                                $('#title').val(j.title);
                                hourChange($('#hour'));
                            });
                            dstr = $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd');
                            showEventData(calEvent.id);
                        }
                        ;
                    } else if (calEvent.className[0] == 'label-purple') {
                        if ("<?=$isxfvrole?>" != "1" && "<?=$isxfyyerole?>" != "1" && "<?=$canEdit?>" != "1") {
                            return
                        } else {
                            $('#uploader').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=chanpin&act=add');
                            $('#uploader_yy').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yunyig&act=add')
                            $("#uploader_yf").attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yanfa&act=add')
                            $("#listcp").hide();
                            $("#listyf").hide();
                            // $("#yytext").attr('placeholder','填写本次更新概要，详细更新内容请使用附件')
                            //console.log($('#uploader').attr('action')) 

                            dict = {};
                            $.post('./?app=pmcalendar&act=getEventByid', {id: calEvent.id}, function (txt) {
                                var j = JSON.parse(txt);
                                dict.start = j.start;
                                dict.end = j.end;
                                dict.id = calEvent.id;
                                $('#game').val(j.game);
                                $('#hour').val(j.shour);
                                $('#min').val(j.smin);
                                $('#event').val(j.event);
                                $('#title').val(j.title);
                                hourChange($('#hour'));
                            });
                            dstr = $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd');
                            showEventData(calEvent.id);
                        }
                        ;
                    } else if(calEvent.className[0] == 'label-warning'){

                        if ("<?=$isdbvrole?>" != "1" && "<?=$isdbyyerole?>" != "1" && "<?=$isdbcperole?>" != "1" && "<?=$isdbyferole?>" != "1" && "<?=$canEdit?>" != "1") {
                            return
                        } else {
                            $('#uploader').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=chanpin&act=add');
                            $('#uploader_yy').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yunyig&act=add')
                            $("#uploader_yf").attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yanfa&act=add')

                            $("#listcp").show();
                            $("#listyf").show();
                            $("#cptext").attr('placeholder','请填写版本计划内容概要，内容较多请使用附件');
                            $("#yytext").attr('placeholder','请填写版本内容或更新内容，预计更新时间计划以及其他要点概要，内容较多请使用附件');
                            $("#yftext").attr('placeholder','请填写本次节点修改内容注意事项，内容较多请使用附件');


                            //console.log($('#uploader').attr('action'))

                            dict = {};
                            $.post('./?app=pmcalendar&act=getEventByid', {id: calEvent.id}, function (txt) {
                                var j = JSON.parse(txt);
                                dict.start = j.start;
                                dict.end = j.end;
                                dict.id = calEvent.id;
                                $('#game').val(j.game);
                                $('#hour').val(j.shour);
                                $('#min').val(j.smin);
                                $('#event').val(j.event);
                                $('#title').val(j.title);
                                hourChange($('#hour'));
                            });
                            dstr = $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd');
                            showEventData(calEvent.id);
                        }
                        ;

                    }else if( calEvent.className[0] == 'label-pink'){

                        if ("<?=$isgxvrole?>" != "1" && "<?=$issxyyerole?>" != "1" && "<?=$canEdit?>" != "1") {
                            return
                        } else {
                            $('#uploader').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=chanpin&act=add');
                            $('#uploader_yy').attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yunyig&act=add')
                            $("#uploader_yf").attr('action', './?app=uploader&id=' + calEvent.id + '&bumen=yanfa&act=add')

                            $("#listcp").hide();
                            $("#listyf").hide();

                            $("#yytext").attr('placeholder','填写本次更新概要，详细更新内容请使用附件')


                            //console.log($('#uploader').attr('action')) 

                            dict = {};
                            $.post('./?app=pmcalendar&act=getEventByid', {id: calEvent.id}, function (txt) {
                                var j = JSON.parse(txt);
                                dict.start = j.start;
                                dict.end = j.end;
                                dict.id = calEvent.id;
                                $('#game').val(j.game);
                                $('#hour').val(j.shour);
                                $('#min').val(j.smin);
                                $('#event').val(j.event);
                                $('#title').val(j.title);
                                hourChange($('#hour'));
                            });
                            dstr = $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd');
                            showEventData(calEvent.id);
                        }
                        ;

                    } else {
                        if ("<?=$canEdit?>" == "1" && "<?=$issxarole?>" != "1") {
                            dict = {};
                            // $.post('./?app=pmcalendar&act=getEventByid', {id: calEvent.id}, function (txt) {
                            //     var j = JSON.parse(txt);
                            //     dict.start = j.start;
                            //     dict.end = j.end;
                            //     dict.id = calEvent.id;
                            //     $('#game').val(j.game);
                            //     $('#hour').val(j.shour);
                            //     $('#min').val(j.smin);
                            //     $('#event').val(j.event);
                            //     $('#title').val(j.title);
                            //     hourChange($('#hour'));
                            // });
                            dstr = $.fullCalendar.formatDate(calEvent.start, 'yyyy-MM-dd');
                           Info();

                        }else {
                            return
                        }
                    }
            }

        });

    });

    function datarepair() {
        var dis = $("#data_box").css('display');
        if (dis == 'none') {
            $('#data_box').show();
            $('#echarts-time').show();
            $('#calendardiv').hide();

            $('#datarepairname').html('返回Event');
            $("#dataimg").attr("src",'assets/images/fanhui.png');
            var time = (Math.round(starttime.getTime()) + Math.round(endtime.getTime())) / 2;
            time = new Date(time);
            var year = time.getFullYear() + '年';
            var month = time.getMonth() + 1 + '月';
            console.log(month);
            $("#startyear").val(time.getFullYear());
            $("#startmonth").val(time.getMonth() + 1);
            $("#endyear").val(time.getFullYear());
            $("#endmonth").val(time.getMonth() + 1);

            var start = time.getFullYear() + "/"+ (time.getMonth() + 1) +"/"+ "01" +" " + '00:00:00';
            console.log(start);
            var startdate = new Date(start);
            var startmonth = Date.parse(startdate)/1000;

            var monthEndDate = new Date(time.getFullYear(), time.getMonth() + 1, 0);
            var endmonth=Date.parse(monthEndDate)/1000;//s
            endmonth = endmonth+24*60*60 - 1
            $.ajax({
                url: './?app=pmcalendar&act=getEvents',
                dataType: 'json',
                data: {
                    start: startmonth,
                    end: endmonth,
                    game: showGame,
                    type: 'charts'
                },

                success: function (res) {
                    var myChart = echarts.init(document.getElementById('chart'));
                    var chartsdata = res.charts;

                    var option = {
                        title: {
                            text: [year, month].join(''),
                            left: 'center',
                            textStyle: {
                                fontWeight: 'normal',
                                color: '#6fb3e0',
                            }
                        },
                        color: ['#ff7f7f', '#a494f9'],
                        toolbox: {
                            show: true,
                            orient: 'vertical',
                            right: '1.5%',
                            top: 'center',
                            feature: {
                                mark: {show: true},
                                dataView: {show: true, readOnly: false},
                                magicType: {show: true, type: ['line', 'bar', 'stack', 'tiled']},
                                restore: {show: true},
                                saveAsImage: {show: true}
                            }
                        },
                        legend: {
                            left: '3%',
                            top: '20',
                            itemHeight: 11,
                            itemWidth: 6,
                            color:"#5f5f5f"
                        },
                        tooltip: {},
                        grid: {
                            left: '3%',
                            right: '3%',
                            bottom: '5%',
                            // top: '0%',
                            containLabel: true
                        },
                        color: ['#ff7f7f', '#a494f9'],
                        dataset: {
                            source: chartsdata
                        },
                        dataZoom: [
                            {
                                id: 'dataZoomX',
                                type: 'slider',
                                xAxisIndex: [0],
                                filterMode: 'filter'
                            }
                        ],
                        xAxis: {
                            type: 'category',
                            axisLabel:{
                                show: true,
                                textStyle:{
                                    color:"#969696"
                                }
                            },
                            axisLine:{
                                lineStyle:{
                                    color:'#bfbfbf',
                               }
                            }
                        },
                        yAxis: {
                            axisLabel:{
                                textStyle:{
                                    color:"#bfbfbf"
                                }
                            },
                            "axisLine": {       //y轴
                                "show": false
                            },
                            "axisTick": {       //y轴刻度线
                                "show": false
                            },
                            "splitLine": {     //网格线
                                "show": true,
                                'coloe': '#bfbfbf'
                            }
                        },
                        // Declare several bar series, each will be mapped
                        // to a column of dataset.source by default.
                        series: [
                            {
                                type: 'bar',
                                barCategoryGap : 60,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'insideBottom',
                                            distance: 15,
                                            align: 'left',
                                            verticalAlign: 'middle',
                                            rotate: 1,
                                            fontSize: 16,
                                            textStyle: { //数值样式
                                                color: '#000',
                                                fontSize: 13
                                            }
                                        }
                                    }
                                }
                            },
                            {
                                type: 'bar',
                                barCategoryGap : 60,
                                itemStyle: {
                                    normal: {
                                        label: {
                                            show: true,
                                            position: 'insideBottom',
                                            distance: 15,
                                            align: 'left',
                                            verticalAlign: 'middle',
                                            rotate: 1,
                                            fontSize: 16,
                                            textStyle: { //数值样式
                                                color: '#000',
                                                fontSize: 13
                                            }
                                        }
                                    }
                                }
                            }
                        ]
                    };
                    myChart.setOption(option);

                    var titleAdd = res.table[0];
                    titleAdd[0] = "";
                    var tbdyArr = res.table[1];
                    tbdyArr[2][0] = '占比';
                    tmpltxt = doT.template(document.getElementById("thead-dot").innerHTML);//生成模板方法
                    document.getElementById("thead-title").innerHTML = tmpltxt(titleAdd);//数据渲染

                    tmpltxt = doT.template(document.getElementById("tbody-dot").innerHTML);//生成模板方法
                    document.getElementById("tbody-content").innerHTML = tmpltxt(tbdyArr);//数据渲染

                },
                error: function () {
                    alert('数据异常,请稍后重试!!!')
                }
            });

        } else {
            $('#data_box').hide();
            $("#echarts-time").hide();
            $('#datarepairname').html('查看统计');

            $("#dataimg").attr("src",'assets/images/tongji.png');
            $('#calendardiv').show();
            $.ajax({
                    url: './?app=pmcalendar&act=getEvents',
                    dataType: 'json',
                    data: {
                        start: Math.round(starttime.getTime() / 1000),
                        end: Math.round(endtime.getTime() / 1000),
                        game: showGame
                    },
                    success: function (doc) {
                        console.log(doc);
                        $("#dabaonum").html("("+doc.count['打包']+")");
                        $("#gengxinnum").html("("+doc.count['版本更新']+")");
                        $("#xiufunum").html("("+doc.count['修复外网']+")");
                        $("#jeidiannum").html("("+doc.count['节点']+")");
                        $("#shangxainnum").html("("+ doc.count['上线'] +")");
                 
                    }
                });
        }

    }


    function showEventData(id) {
        // $("#cptext").val('15346546')
        $('#popup-bg').show();
        $('body,html').css('overflow', 'hidden')
        $.ajax({
            url: './?app=pmcalendar&act=getEventByid',
            dataType: 'json',
            async: "true",
            data: {
                id: id,
            },
            success: function (res) {
                $('#pop-title').html('【' + res.game + '】' + res.event + ':' + res.title);
                arrcp = [];
                arryy = [];
                arryf = [];
                $("#fujianname").empty();
                $("#yyfujian").empty();
                $("#yffujian").empty();
                // console.log(res.chanpin_remark)
                if(res.event == '打包' || res.event=="版本更新"){//延期记录只有打包和更新才有
                    console.log(8888)
                    if(res.yanqi_history != null){
                        var recording = JSON.parse(res.yanqi_history);
                        for(let i in recording){
                            recording[i]['project'] = res.game;
                            recording[i]['type'] = res.event;
                            var date1 = new Date(recording[i].date1);
                            var timec1 = Date.parse(date1)/1000;
                            var date2 = new Date(recording[i].date2);
                            var timec2 = Date.parse(date2)/1000;
                            if(timec1 > timec2){
                                recording[i]['timetype'] = "提前";
                            }else {
                                recording[i]['timetype'] = "延期";
                            }
                        }
                        // console.log(recording)
                        tmpltxt = doT.template(document.getElementById("recording-dot").innerHTML);//生成模板方法
                        document.getElementById("recording-content").innerHTML = tmpltxt(recording);//数据渲染
                    }
                }else {
                    $("#recording-box").css('display','none');
                }
                

                if (res.chanpin_remark != "" && res.chanpin_remark != null) {
                    var chanpin_remark = JSON.parse(res.chanpin_remark)
                    var cptime = chanpin_remark.user + " " + chanpin_remark.date;
                    document.getElementById("cptext").value = chanpin_remark.msg;
                    document.getElementById("cptime").innerHTML = cptime;
                    if(chanpin_remark.msg.length >= 100){
                        $("#cptext").css('height','150px');
                    }else {
                        $("#cptext").css('height','111px');
                    }
                }else {
                    document.getElementById("cptext").value = '';
                    document.getElementById("cptime").innerHTML = '';
                }
                // console.log(res.yunying_remark)
                if (res.yunying_remark != "" && res.yunying_remark != null) {
                    var yunying_remark = JSON.parse(res.yunying_remark);

                    var yytime = yunying_remark.user + " " + yunying_remark.date;

                    document.getElementById("yytext").value = yunying_remark.msg;
                    document.getElementById("yytime").innerHTML = yytime;
                    if(yunying_remark.msg.length >= 100){
                        $("#yytext").css('height','150px');
                    }else {
                        $("#yytext").css('height','111px');
                    }
                }else {
                    document.getElementById("yytext").value = '';
                    document.getElementById("yytime").innerHTML = '';
                }
                if (res.yanfa_remark != "" && res.yanfa_remark != null) {
                    var yanfa_remark = JSON.parse(res.yanfa_remark);
                    var yftime = yanfa_remark.user + " " + yanfa_remark.date;
                    document.getElementById("yftext").value = yanfa_remark.msg;
                    document.getElementById("yftime").innerHTML = yftime;
                    if(yanfa_remark.msg.length >= 100){
                        $("#yftext").css('height','150px');
                    }else {
                        $("#yftext").css('height','111px');
                    }
                }else {
                    document.getElementById("yftext").value = '';
                    document.getElementById("yftime").innerHTML = '';
                }
                
                // if(res.fujian != null){
                    if(res.fujian != ""){
                        var fujian = JSON.parse(res.fujian);
                        for (let i in fujian) {
                            if (fujian[i]['bumen'] == 'chanpin') {
                                arrcp.push(fujian[i])
                            } else if (fujian[i]['bumen'] == 'yunyig') {
                                arryy.push(fujian[i])
                            } else if (fujian[i]['bumen'] == 'yanfa') {
                                arryf.push(fujian[i])
                            }
                        }
                    }
                    

                    if(arrcp.length != 0){
                        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
                        document.getElementById("fujianname").innerHTML = tmpltxt(arrcp);//数据渲染
                    }else {
                        var data = "<div class='fujian'><img src='./assets/images/fujian.png'/>未添加附件</div>";
                        $('#fujianname').html(data);
                    }

                    if(arryy.length != 0){
                        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
                        document.getElementById("yyfujian").innerHTML = tmpltxt(arryy);//数据渲染
                    }else {
                        var data = "<div class='fujian'><img src='./assets/images/fujian.png'/>未添加附件</div>";
                        $('#yyfujian').html(data);
                    }

                    if(arryf.length != 0){
                        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
                        document.getElementById("yffujian").innerHTML = tmpltxt(arryf);//数据渲染
                    }else {
                        var data = "<div class='fujian'><img src='./assets/images/fujian.png'/>未添加附件</div>";
                        $('#yffujian').html(data);
                    }
                
            },
            error: function () {
                alert('数据异常,请稍后重试!!!')
            }
        });
    }

    function guanbi(){
        var showGame = "";
        starttime, endtime;
        dstr = ''
        dict = {};
        bumen;
        notid;
        arrcp = [];
        arryy = [];
        arryf = [];
        i = 0;
        starts='';

        $('#yytext').val('')
        $('#cptext').val('')
        $('#yftext').val('')

        $('#yytext').attr('disabled', true)
        $('#cptext').attr('disabled', true)
        $('#yftext').attr('disabled', true)
        $("#upfujian_yy").hide();
        $("#upfujian_cp").hide();
        $("#upfujian_yf").hide();
        $("#popup-bg").hide();
        $('body,html').css('overflow', 'auto')
    }

    // $("#yiny").click(function () {
    //     var showGame = "";
    //     starttime, endtime;
    //     dstr = ''
    //     dict = {};
    //     bumen;
    //     notid;
    //     arrcp = [];
    //     arryy = [];
    //     arryf = [];
    //     starts=''
    //     $("#popup-bg").hide();
    //     $('body,html').css('overflow', 'auto')
    // })

    function Info() {

        if ("<?=$canEdit?>" != "1" && "<?=$issxarole?>" != "1") return;
        dict = {};
        $.post('./?app=pmcalendar&act=getEventByid', {id: notid}, function (txt) {
            var j = JSON.parse(txt);
            dict.start = j.start;
            dict.end = j.end;
            dict.id = notid;
            $('#game').val(j.game);
            $('#hour').val(j.shour);
            $('#min').val(j.smin);
            $('#event').val(j.event);
            $('#title').val(j.title);
            hourChange($('#hour'));
        });

        showEventInfo(dstr, {
            "save": {
                "label": "<i class='icon-check'></i> 保存",
                "className": "btn-sm btn-success",
                "callback": function () {

                    dict.game = $('#game').val();
                    dict.allday = 1;

                    dict.event = $('#event').val();
                    dict.title = $('#title').val();

                    if (dict.game == '' || dict.event == '') return;

                    loading.show();
                    $.post('./?app=pmcalendar&act=modievent', dict, function (txt) {
                        loading.hide();
                        if (txt == '1') {
                            calendar.fullCalendar('refetchEvents');
                        }
                    });
                }
            },
            "delete": {
                "label": "<i class='icon-trash'></i> 删除事件",
                "className": "btn-sm btn-danger",
                "callback": function () {
                    if (confirm('确认要【删除】这个事件吗？')) {
                        loading.show();
                        $.post('./?app=pmcalendar&act=delevent', {id: notid}, function (txt) {
                            loading.hide();
                            if (txt == '1') {
                                calendar.fullCalendar('refetchEvents');
                            }
                            guanbi();
                        });
                    }
                }
            },

            "close": {
                "label": "<i class='icon-remove'></i> Close",
                "className": "btn-sm"
            }
        }, 'modify');
    }

    $('#excelFile').change(function (e) {
        // e.target得到的是input标签，e.target.files得到是一串filelist，
        // e.target.files[0]得到的是图片的一些参数，这些参数可以根据自己的需要提取
        var fileName = e.target.files[0].name;
        var arr = [];
        arr.push(fileName)
        tmpltxt = doT.template(document.getElementById("fujian-dot").innerHTML);//生成模板方法
        document.getElementById("fujian").innerHTML = tmpltxt(arr);//数据渲染
        // $(this).prev().find('span').text(fileName);

    })

    function showEventInfo(start, btns, stype) {
        var form = $("<form class=''><label>选择游戏和事件类型 (" + start + ")</label><div class='space-1'></div></form>");
        if("<?=$issxarole?>" != "1"){
            form.append('<?=gameGameListSelect('game')?>&nbsp<select id="event"><option value="打包">打包</option><option value="版本更新">版本更新</option><option value="修复外网">修复外网</option><option value="上线">上线</option><option value="节点">节点</option></select>');
        }else {
            form.append('<?=gameGameListSelect('game')?>&nbsp<select id="event"><option value="上线">上线</option></select>');
        }
        
        form.append("<div class='space-5'></div><label for='form-field-mask-1'>事件内容</label><input class='form-control' id='title' autocomplete=off type=text value='' /> ");

        var div = bootbox.dialog({
            message: form,
            buttons: btns
        });


        form.on('submit', function () {
            //calEvent.title = form.find("input[type=text]").val();
            //calendar.fullCalendar('updateEvent', calEvent);
            div.modal("hide");
            return false;
        });
    };


    function hourChange(o) {
        if ($(o).val() == '-1') {
            $('#min').hide();
        } else {
            $('#min').show();
        }
    }

</script>
</body>
</html>