<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>

    <style type="text/css">
        /**让所有的模态对话框都居中*/
        .am-modal.am-modal-prompt.am-modal-active {
            transform: translate(-50%, -50%) scale(1);
            left: 50%;
            top: 50%;
            margin-left: 0;
            margin-top: 0 !important;
        }

    </style>

    <link rel="stylesheet" href="${base}/assets/css/amazeui.switch.css"/>
    <div class="admin-content">
        <div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
            <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
            <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">工作流程</strong> /
                <small>审批过程和流程图</small>
            </div>
        </div>


        <div class="am-tabs am-margin" data-am-tabs>
            <ul class="am-tabs-nav am-nav am-nav-tabs">
                <li class="am-active"><a href="#tab2">审批过程</a></li>
                <li><a href="#tab3">流程图</a></li>
            </ul>

            <div class="am-tabs-bd">
                <div class="am-tab-panel am-fade am-in am-active" id="tab2">

                    <div class="am-u-sm-12 am-scrollable-horizontal">
                        <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr class="am-text-nowrap">
                                <th class="table-title">序号</th>
                                <th class="table-title">任务节点</th>
                                <th class="table-title">处理人</th>
                                <th class="table-date">开始时间</th>
                                <th class="table-date">结束时间</th>
                                <th class="table-date">用时</th>
                                <th class="table-set am-text-center">意见</th>
                                <th class="table-set am-text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <#if (taskList)?exists>
                                <#list  taskList as list>
                                    <tr>
                                        <td>${list_index+1!}</td>
                                        <td>${list.taskName!}</td>
                                        <td>${list.assign!}</td>
                                        <td>${list.startTime?datetime}</td>
                                        <td><#if list.endTime??>
                                                ${list.endTime?datetime}
                                            </#if></td>
                                        <td>${list.duration!}</td>
                                        <td>${list.comments!}</td>

                                        <td>
                                            <#if !list.endTime??>
                                                <button type="button"
                                                        class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                        onclick="toHandle('${list.procInsId}', '${list.taskId}')">
                                                    <span class="am-icon-pencil-square-o"></span>
                                                    审批
                                                </button>
                                            </#if>
                                        </td>
                                    </tr>
                                </#list>
                            </#if>
                            </tbody>
                        </table>
                    </div>


                </div>

            </div>

            <div class="am-tabs-bd">
                <div class="am-tab-panel am-fade am-in" id="tab3">
                    <img id="img" name="img" style="width: 950px" src="${base}/actProcIns/procInsPng/${procInsId}">
                </div>
            </div>

        </div>


        <div class="am-margin">
            <button type="button" class="am-btn am-btn-warning am-btn-xs"
                    onclick="location.href='${base}/actProcIns/list'">返回
            </button>
        </div>

    </div>

    <div class="am-modal am-modal-prompt" style="width: 600px;z-index: 1111;max-height:600px;overflow-y:auto;"
         tabindex="-1" id="my-approve">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">管理员审核</div>
            <div class="am-modal-bd">
                <form method="post" class="am-form" id="tmpForm" action="">
                    <div class="am-tabs am-margin" data-am-tabs>
                        <div class="am-tabs-bd">
                            <div class="am-tab-panel am-fade am-in am-active" id="tab1">

                                <div class="am-g am-form-group am-margin-top">
                                    <div class="am-u-sm-4 am-u-md-2 am-text-right">审核</div>
                                    <input type="hidden" id="handleProcInsId" value="">
                                    <input type="hidden" id="handleTaskId" value="">

                                    <div class="am-u-sm-6 am-u-md-8 switch-button"
                                         style="height: 25px;">
                                        <label class="am-radio-inline">
                                            <input type="radio" value="2" checked="checked"
                                                   name="docVlGender" required> 审核通过
                                        </label>
                                        <label class="am-radio-inline">
                                            <input type="radio" value="3" name="docVlGender"> 审核不通过
                                        </label>

                                    </div>
                                    <div class="am-u-sm-2 am-u-md-4 input-msg"></div>

                                </div>

                                <div class="am-g am-form-group am-margin-top" style="display: flex;">
                                    <div class="am-u-sm-4 am-u-md-2 am-text-right">
                                        <span style="color: red;">*</span>意见
                                    </div>
                                    <div class="am-u-sm-8 am-u-md-10">
                                                        <textarea id="doc-vld-ta-2" minlength="10"
                                                                  maxlength="100"></textarea>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="am-modal-footer">
                <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                <span class="am-modal-btn" data-am-modal-confirm onclick="handleTask()">确定</span>
            </div>
        </div>
    </div>
</@defaultLayout.layout>

<script src="${base}/assets/js/amazeui.switch.js"></script>
<script type="text/javascript">
    var urlBase = "${base}";
    var url;

    var toHandle = function (procInsId, taskId) {
        $('#my-approve').modal({
            relatedTarget: this,
            onConfirm: function (e) {
            },
            onCancel: function (e) {
            }
        });

        $("#handleProcInsId").val(procInsId);
        $("#handleTaskId").val(taskId);

    };

    var handleTask = function () {
        var message = $("#doc-vld-ta-2").val();
        var type = $("input[name='docVlGender']:checked").val();

        if (message == '') {
            message = "系统管理员审核";
        }

        var params = {
            procInsId: $("#handleProcInsId").val(),
            taskId: $("#handleTaskId").val(),
            type: type,
            message: message
        };

        $.ajax({
            url: '${base}/actTaskDef/completeTask',
            data: JSON.stringify(params),
            dataType: "json",
            contentType: "application/json",
            type: 'post',
            async: false,
            success: function (data) {
                layer.alert(data.msg);
                location.reload();
            }
        });
    };

</script>