<#assign base=request.contextPath />
<#import "../common/defaultLayout.ftl" as defaultLayout>
<@defaultLayout.layout>
    <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">${procDefName!}</strong> /
                <small>任务配置</small>
            </div>
        </div>
        <input name="procDefId" id="procDefId" type="hidden" value="${procDefId!}"/>
        <div class="am-g">
            <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-date">回退任务节点</th>-->
                        <th class="table-set ">按人员设置审批人</th>
                        <th class="table-set ">按角色设置审批人</th>
                        <th class="table-set ">按类型设置审批人</th>
                        <th class="table-set am-text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    <#list  approveList as list>
                        <tr>
                            <td>${list_index+1}</td>
                            <td>${list.taskName!}</td>

                           <#-- <td>

                                <select data-am-selected="{btnSize: 'sm',btnWidth: '150px', maxHeight: 500}"
                                        id="rollbackTask_${list.id}">
                                    <#list  taskList as l>
                                        <option value="${l.taskKey}"
                                                <#if list.rollbackTaskKey == l.taskKey>selected</#if> >${l.taskName!}</option>
                                    </#list>
                                </select>

                            </td>-->

                            <td>

                                <select multiple
                                        data-am-selected="{btnSize: 'sm',btnWidth: '150px',maxHeight: 500,searchBox: 1}"
                                        id="userSelect_${list.id}">
                                    <#list  adminList as l>
                                        <option value="${l.id}"
                                                <#if list.candidateUserList?seq_contains(l.id?c)>selected</#if> >${l.realName!}</option>
                                    </#list>
                                </select>

                            </td>


                            <td>

                                <select multiple
                                        data-am-selected="{btnSize: 'sm',btnWidth: '150px',maxHeight: 500,searchBox: 1}"
                                        id="roleSelect_${list.id}">
                                    <#list  roleList as l>
                                        <option value="${l.id}"
                                                <#if list.candidateRoleList?seq_contains(l.id?c)>selected</#if> >${l.name!}</option>
                                    </#list>
                                </select>

                            </td>

                            <td>

                                <select multiple
                                        data-am-selected="{btnSize: 'sm',btnWidth: '150px',maxHeight: 500,searchBox: 1}"
                                        id="typeSelect_${list.id}">
                                    <option value="1" <#if list.candidateTypeList?seq_contains('1')>selected</#if> >发起人部门主管</option>
                                </select>

                            </td>


                            <td>

                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <button type="button"
                                                class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                onclick="saveConfig('${list.id}')">
                                            <span class="am-icon-pencil-square-o"></span>
                                            保存
                                        </button>

                                    </div>
                                </div>

                            </td>

                        </tr>
                    </#list>

                    </tbody>
                </table>


            </div>
        </div>

        <div class="am-margin">
            <#--<button type="submit" class="am-btn am-btn-primary am-btn-xs">提交保存</button>-->
            <button type="button" class="am-btn am-btn-warning am-btn-xs"
                    onclick="location.href='${base}/actProcDef/list'">返回
            </button>
        </div>
    </div>
</@defaultLayout.layout>

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


    var saveConfig = function (taskId) {
        var rollbackTaskKey = $("#rollbackTask_" + taskId + " option:selected").val();
        var endScript = $("#scriptSelect_" + taskId + " option:selected").val();
        var rollbackScript = $("#rollbackScriptSelect_" + taskId + " option:selected").val();

        var $userSelected = $("#userSelect_" + taskId + " option:selected");
        var userIds = '';
        $userSelected.each(function () {
            if (userIds == '') {
                userIds = $(this).val();
            } else {
                userIds = userIds + "#" + $(this).val();
            }
        });

        var $roleSelected = $("#roleSelect_" + taskId + " option:selected");
        var roleIds = '';
        $roleSelected.each(function () {
            if (roleIds == '') {
                roleIds = $(this).val();
            } else {
                roleIds = roleIds + "#" + $(this).val();
            }
        });

        var $typeSelected = $("#typeSelect_" + taskId + " option:selected");
        var typeIds = '';
        $typeSelected.each(function () {
            if (typeIds == '') {
                typeIds = $(this).val();
            } else {
                typeIds = typeIds + "#" + $(this).val();
            }
        });

        var params = {
            id: taskId,
            procDefId: $("#procDefId").val(),
            rollbackTaskKey: rollbackTaskKey,
            endScript: endScript,
            rollbackScript: rollbackScript,
            candidateUsers: userIds,
            candidateRoles: roleIds,
            candidateTypes: typeIds
        };
        $.ajax({
            url: '${base}/actTaskDef/saveConfig',
            data: params,
            dataType: "json",
            async: false,
            success: function (data) {
                layer.msg(data.msg);
            }
        });
    }


</script>
