<link rel="stylesheet" href="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/css/bootstrap-datepicker.standalone.min.css">
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
<script src="<?php echo base_url();?>public/js/vendor/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>

<div class="content_wrapper">
    <div class="container-fluid">
    	<button type="button" style="margin:5px;" class="btn btn-primary " id="add">添加术语</button>
        <aside>
            <header><i class="fa fa-fw fa-file"></i>统计术语</header>
            <section>
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-sm-12">
                        	<table class="table table-striped">
                        		<thead>
									<tr>
										<th>名称</th>
										<th>EN名称</th>
										<th>描述</th>
										<th>计算方法</th>
										<th>详细说明</th>
										<th>操作</th>
									</tr>
								</thead>
								<tbody>
									<?php
										foreach($data as $k => $v){
									?>	
									<tr>
										<td><?php echo $v['name']; ?></td>
										<td><?php echo $v['en_name']; ?></td>
										<td><?php echo $v['describe']; ?></td>
										<td><?php echo $v['computing_method']; ?></td>
										<td>
											<button type="button" class="btn btn-primary" id="view" bid="<?php echo $v['id']; ?>">查看详细</button>
										</td>
										<td>
											<button type="button" class="btn btn-success" id="edit" bid="<?php echo $v['id']; ?>">修改</button>
											<button type="button" class="btn btn-danger" id="del" bid="<?php echo $v['id']; ?>">删除</button>
										</td>
									</tr>
									<?php
										}
									?>
								</tbody>
							</table>
                        </div>
                    </div>
                </div>
            </section>
        </aside>
    </div>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:800px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">添加术语</h4>
            </div>
            <div id="msg-tip"></div>

            <form class="form-horizontal" role="form" method="post" action="#" id="reportForm">
                <div class="modal-body" style="overflow:auto;">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">EN名称:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="en_name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述:</label>
                            <div class="col-sm-9">
                                <textarea class="form-control" name="describe"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">计算方法:</label>
                            <div class="col-sm-9">
                                <textarea class="form-control" name="computing_method"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细说明:</label>
                            <div class="col-sm-9">
                                <textarea id="container" style="width:500px;" name="content"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="submitBtn">提交</button>
                </div>
            </form>

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

<div class="modal fade" id="myModalView" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:800px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title" id="myModalLabel">详细</h4>
            </div>
            <div id="msg-tip"></div>

            <div class="modal-body">
	        	
	    	</div>

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

<div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="min-width:800px;">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                <h4 class="modal-title">修改术语</h4>
            </div>
            <div id="msg-tip"></div>

            <form class="form-horizontal" role="form" method="post" action="#" id="reportFormEdit">
                <input type="hidden" value="" id="id" name="id"/>
                <div class="modal-body" style="overflow:auto;">
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">EN名称:</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="en_name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述:</label>
                            <div class="col-sm-9">
                                <textarea class="form-control" name="describe"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">计算方法:</label>
                            <div class="col-sm-9">
                                <textarea class="form-control" name="computing_method"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">详细说明:</label>
                            <div class="col-sm-9">
                                <textarea id="container2" style="width:500px;" name="content"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn btn-primary" id="submitBtnEdit">提交</button>
                </div>
            </form>

        </div>
    </div>
</div>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/highcharts.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/exporting.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/highcharts/modules/export-data.js"></script>
<script src="<?php echo base_url();?>public/js/common.js?version=1"></script>

<script type="text/javascript" src="<?php echo base_url();?>public/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="<?php echo base_url();?>public/js/ueditor/ueditor.all.js"></script>

<script>
	window.UEDITOR_HOME_URL = "/public/js/ueditor/";
	var ue = UE.getEditor('container', {
	    autoHeight: true
	});
	var ue2 = UE.getEditor('container2', {
	    autoHeight: true
	});

	$(document).on("click","#add",function(){
		$('#myModal').modal();
	});
	
	var msgTip = $('#msg-tip');
    $('#submitBtn').click(function () {
        //ajax将修改后的数据提交到后台
        var data = $('#reportForm').serialize();
        $.ajax({
            type: 'POST',
            url: rootPath + 'welcome/addCmsTerm',
            dataType: 'json',
            data: data,
            success: function (data) {
                if(data.ret == 0) {
                    window.location.reload();
                }else {
                    msgTip.messager().error(data.msg);
                }
            },
            error: function () {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });
    
    $(document).on("click","#del",function(){
    	var id = $(this).attr("bid");
    	if(confirm('确定删除吗?')){
	        $.ajax({
	            type: 'POST',
	            url: rootPath + 'welcome/delCmsTerm',
	            dataType: 'json',
	            data: {id:id},
	            success: function (data) {
	                if(data.ret == 0) {
	                    window.location.reload();
	                }else {
	                    msgTip.messager().error(data.msg);
	                }
	            },
	            error: function () {
	                msgTip.messager().error('网络错误，请刷新后重试');
	            }
	        });
	    }
    	
    });
    
    $(document).on("click","#view",function(){
    	var id = $(this).attr("bid");
    	$.ajax({
            type: 'POST',
            url: rootPath + 'welcome/viewCmsTerm',
            dataType: 'json',
            data: {id:id},
            success: function (data) {
                if(data.ret == 0) {
                    $("#myModalView").find(".modal-body").text(data.data.content);
                    $('#myModalView').modal();
                }
            },
            error: function () {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });

    $(document).on("click","#edit",function(){
    	var id = $(this).attr("bid");
    	$.ajax({
            type: 'POST',
            url: rootPath + 'welcome/viewCmsTerm',
            dataType: 'json',
            data: {id:id},
            success: function (data) {
                if(data.ret == 0) {
                	$("#myModalEdit").find("input[name='id']").val(id);
                    $("#myModalEdit").find("input[name='name']").val(data.data.name);
                    $("#myModalEdit").find("input[name='en_name']").val(data.data.en_name);
                    $("#myModalEdit").find("textarea[name='describe']").text(data.data.describe);
                    $("#myModalEdit").find("textarea[name='computing_method']").text(data.data.computing_method);
                    //$("#myModalEdit").find("textarea[name='content']").text(data.data.content);
                    ue2.setContent(data.data.content);
                    $('#myModalEdit').modal();
                }
            },
            error: function () {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });
    
    $('#submitBtnEdit').click(function () {
        //ajax将修改后的数据提交到后台
        var data = $('#reportFormEdit').serialize();
        $.ajax({
            type: 'POST',
            url: rootPath + 'welcome/editCmsTerm',
            dataType: 'json',
            data: data,
            success: function (data) {
                if(data.ret == 0) {
                    window.location.reload();
                }else {
                    msgTip.messager().error(data.msg);
                }
            },
            error: function () {
                msgTip.messager().error('网络错误，请刷新后重试');
            }
        });
    });
</script>