<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
	<link rel="stylesheet" th:href="@{/css/common/base.css}" />
	<link rel="stylesheet" th:href="@{/css/common/page_new.css}" />
	<link rel="stylesheet" th:href="@{/js/plugins/bootstrapselect/css/product_list.css}" />
</head>
<style type="text/css">
	.box .search_pro .cx input{
		background: #00B983;
		width: 100px;
		height: 39px;
		color:white;
		margin-right: 10px;
		padding: 10px -1px;
	}
	.content p span input{
		background: #00B983;
		color:white;
		margin-right: 10px;
		padding: 10px 20px;
		border:1px solid #EEEEEE;
		text-indent: 5px;
	}
</style>
<body>
<div class="box">
	<h2><span></span>流程列表<button onclick="location.reload()">刷新</button></h2>
	<div class="search">
		<p class="title">筛选查询</p>
		<p class="search_pro">
			<span><b>流程名称：</b><input type="text" name="modelName" placeholder="请输入"/></span>
			<span class="cx">
                <input type="button" style=" border: 1px solid #000000;background-color: #2b2b2b;width: 64px;height: 35px;color: white;border-radius: 0px;text-align: center;line-height: 30px;" value="查询" onclick="getBargainProduct()">
			</span>
		</p>
	</div>
	<div class="content">
		<p class="title list_ti"><span>数据列表</span></p>
		<table border="" cellspacing="" cellpadding="">


		</table>
	</div>
	<div class="footer" style="display: flex;justify-content: space-between;align-items:center;padding:10px 10px;border:1px solid #e4e4e4;font-size:14px;color:#999">
		<div style="flex-grow: 1;display: flex;justify-content: flex-end;">
			<p style="line-height:33px">共<span style="color:#d00" id="pages">0</span>页/<span style="color:#d00" id="total">0</span>条数据</p>
			<div class="pagediv" style="clear:both;"></div>
		</div>
	</div>
</div>
</body>
</html>
<script src="/js/plugins/jquery.min.js"></script>
<script src="/js/plugins/layer/layer.js"></script>
<script type="text/javascript" src="/js/plugins/page_new.js"></script>
<script type="text/javascript">
    $(function(){
        $.post(
            "/api/bpm/model/modelList",
            {
                pageSize:10,
                pageNum:1,
                teamName:"",
                status:""
            },
            function (data) {
                var size = data.data.data.pages;
                if (!data.data.data.pages){
                    size = 0;
                }
                var current = data.data.data.pageNum;
                /*分页*/
                $(".pagediv").createPage({
                    pageNum: size,//总页码
                    current: current,//当前页
                    shownum: 10,//每页显示个数
                    showPageNum: true, //显示总页数
                    showToPage: true, //显示跳转页码
                    backfun: function (page) {
                        flushHtml(page.current);
                    }
                });
            },
            'json'
        );
        flushHtml();
    });
    function flushHtml(current) {
        var pageNum = 1;
        if(current){
            pageNum = current;
        }
        var teamName = $("[name='teamName']").val();
        var status = $("[name='status']").val();
        $.post(
            "/api/bpm/model/modelList",
            {
                pageSize:10,
                pageNum:pageNum,
                teamName:teamName,
                status:status
            },
            function (data) {
                selectListAll(data.data.data);
            },'json'
        );
    }
    function selectListAll(data) {
        var pages = data.pages;
        var total = data.total;
        data = data.list;
        var content = '';
        content += '<tr><th>编号</th><th>流程名称</th><th style="width: 8%">KEY</th><th>创建时间</th><th style="width: 8%">更新时间</th><th style="width: 8%">META_INFO_</th><th style="width: 8%">版本</th><th style="width: 15%">操作</th></tr>';
        if(data!=null){
            for (var i in data) {
                content += '<tr>';
                content += '<td class="product_name" style="width: 5%;">'+data[i].id+'</td>';
                content += '<td class="product_num">'+data[i].name+'</td><td class="product_num">'+data[i].KEY_+'</td>';
                content += '<td class="product_num">'+data[i].createTime+'</td><td class="product_num">'+data[i].updateTime+'</td>';
                content += '<td class="product_num">'+data[i].metaInfo+'</td><td class="product_num">'+data[i].version+'</td>';


                content += '<td class="cao_zuo"><span onclick="toActivityDetail('+data[i].id+')">查看</span></span><span onclick="deploymentModel('+data[i].id+',\''+data[i].name+'\')">部署流程</span><span onclick="deleteDeployMent('+data[i].id+',\''+data[i].name+'\')">删除</span></td></tr>';
            }
            $('#pages').text(pages);
            $('#total').text(total);
        }else{
            content+= '<div class="tipImg"><img src="/images/non.png" ><p class="tipNon">暂无数据</p></div>';
            $('#pages').text(0);
            $('#total').text(0);
        }
        $('table').html(content);
    }
    /*条件查询*/
    function getBargainProduct() {
        var name = $("[name='modelName']").val();
        $.post("/api/bpm/model/modelList",
            {
                pageSize:10,
                pageNum:1,
                modelName:name
            },function (data) {
                selectListAll(data.data.data);
                var size = data.data.data.pages;
                if (!data.data.data.pages){
                    size = 0;
                }
                /*分页*/
                $(".pagediv").createPage({
                    pageNum: size,//总页码
                    current: 1,//当前页
                    shownum: 10,//每页显示个数
                    showPageNum: true, //显示总页数
                    showToPage: true, //显示跳转页码
                    backfun: function (page) {
                        flushHtml(page.current);
                    }
                });
            },'json')
    }

    /*查看流程 */
    function toActivityDetail(id) {
        location.href="/model/createNew?newID="+id
    }


    //部署流程
	function deploymentModel(id,name){
        layer.open({
            id:1,
            type: 1,
            title:'确认部署',
            skin:'layui-layer-rim',
            area:['300px', '165px'],
            content: '<div style="margin-top: 22px;margin-left: 8px;">您确定部署'+name+"流程吗？</div>"
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                layer.msg('上传文件中', {
                    icon: 16,
                    time : -1
                });
                $.post("/api/bpm/model/deploymentModel",
                    {
                        modelId:id
                    },function (data) {
                        if(data.code==200){
                            layer.msg('部署成功',{time:1000},function () {
                                location.reload();
                            });
                        }else {
                            layer.msg('部署失败',{time:1000},function () {
                                location.reload();
                            });
                        }
                    },'json')
            },
            btn2:function (index,layero) {
                layer.close(index);
            }
        });





	}


    /*删除流程 */
    function deleteDeployMent(id,name) {
        layer.open({
            id:1,
            type: 1,
            title:'确认删除吗',
            skin:'layui-layer-rim',
            area:['300px', '165px'],
            content: '<div style="margin-top: 22px;margin-left: 8px;">您确定删除'+name+"流程吗？</div>"
            ,
            btn:['保存','取消'],
            btn1: function (index,layero) {
                $.post("/api/bpm/model/deleteModel",
                    {
                        modelId:id
                    },function (data) {
                        if(data.code==200){
                            layer.msg('删除成功',{time:1000},function () {
                                location.reload();
                            });
                        }else {
                            layer.msg('删除失败',{time:1000},function () {
                                location.reload();
                            });
                        }
                    },'json')
            },
            btn2:function (index,layero) {
                layer.close(index);
            }
        });
    }
</script>