<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('机种切换管理列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success btn-rounded btn-sm" onclick="$.operate.add()" shiro:hasPermission="nanjing:ProductChangeInfo:add"><i class="fa fa-plus"></i> 添加</a>
                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;查询全部</a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('nanjing:ProductChangeInfo:edit')}]];
        var removeFlag = [[${@permission.hasPermi('nanjing:ProductChangeInfo:remove')}]];
        var startPlan = [[${@permission.hasPermi('nanjing:ProductChangeInfo:start')}]];
        var endPlan = [[${@permission.hasPermi('nanjing:ProductChangeInfo:end')}]];
        var prefix = ctx + "nanjing/ProductChangeInfo";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                // startUrl:prefix+"/start",
                // endUrl:prefix+"/end",
                modalName: "机种切换管理",
                columns: [
                //     {
                //     checkbox: true
                // },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'tBdProductinfo.productName',
                    title: '机种型号',

                },
                {
                    field: 'personInCharge',
                    title: '生产负责人'
                },
                {
                    field: 'beginTime',
                    title: '开始时间'
                },
                {
                    field: 'endTime',
                    title: '结束时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + startPlan + '" href="javascript:void(0)" onclick="startP(\'' + row.id + '\')"><i class="fa fa-edit"></i>开始</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + endPlan + '" href="javascript:void(0)" onclick="endP(\'' + row.id + '\')"><i class="fa fa-remove"></i>结束</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function startP(id){
            var formData = new FormData();
            formData.append("id",id);
            $.ajax({
                type: "post",
                url: prefix+"/start",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        $.table.refresh();
                    }else{
                        alert(result.msg);
                    }
                }
            })
        }

        function endP(id){
            var formData = new FormData();
            formData.append("id",id);
            $.ajax({
                type: "post",
                url: prefix+"/end",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (result) {
                    console.log(result.msg);
                    if (result.code == web_status.SUCCESS){
                        $.table.refresh();
                    }else{
                        alert(result.msg);
                    }
                }
            })
        }
    </script>
</body>
</html>