var procId = $.request("procId");
var taskId = $.request("taskId");
var stepId = $.request("stepId");
var actId = $.request("actId");
var organId = $.request("organId");

$(function () {
    if (!procId) procId = -1;
    if (!taskId) taskId = '00000000-0000-0000-0000-000000000000';
    if (!stepId) stepId = '00000000-0000-0000-0000-000000000000';
    if (!!actId) {
        $.ajax({
            url: top.contentPath + "/TaskManage/WfActivity/GetName",
            data: { keyValue: actId },
            dataType: "html",
            async: false,
            success: function (value) {
                if (!!value) $("#WfTitle").html(value);
            }
        });
    } else {
        actId = '00000000-0000-0000-0000-000000000000';
    }
    if (!organId) organId = -1;
})

function btn_flow() {
    $.dialogOpen({
        title: "查看流程处理过程",
        url: top.contentPath + "/TaskManage/WfTaskStep/FlowChart?procId=" + procId + "&taskId=" + taskId,
        width: "1024px",
        height: "550px",
        scrolling: "yes",
        btn: null,
        callBack: null
    });
}

function btn_save() {
    if (typeof saveFormEvent != undefined) {
        var newData = {};
        newData['PROC_ID'] = procId;
        newData['TASK_ID'] = taskId;
        newData['STEP_ID'] = stepId;
        newData['ACT_ID'] = actId;
        saveFormEvent(newData);
    }
}

function btn_users() {
    if (typeof usersFormEvent != undefined) {
        usersFormEvent();
    } else {
        //TODO
    }
}

function btn_document() {
    $.dialogOpen({
        title: "电子文档",
        url: top.contentPath + "/DocManage/WfUpload/Toolbar?procId=" + procId + "&taskId=" + taskId,
        width: "850px",
        height: "450px",
        scrolling: "yes",
        btn: null,
        callBack: null
    });
}

function btn_material() {
    alert('材料');
}

function btn_print() {
    if (typeof printFormEvent != undefined) {
        printFormEvent();
    }
}

function btn_meter() {
    if (typeof meterFormEvent != undefined) {
        meterFormEvent();
    }
}

function btn_pause() {
    $.deleteForm({
        prompt: "您确定要废止吗？",
        loading: "正在废止数据...",
        url: top.contentPath + "/TaskManage/WfTaskDeal/Status",
        param: { keyValue: taskId, Status: 2 },
        success: function () {
            window.setTimeout(function () {
                var iframeId = tabiframeId().replace(/^iframe/,'');
              //跳转我的任务
              top.OpenMyTasksTab();
              //关闭当前窗口
              top.CloseTab(iframeId);
            }, 100);
        }
    })
}

function btn_back() {
    $.dialogOpen({
        title: "流程退回",
        url: top.contentPath + "/TaskManage/MyTasks/Back?procId=" + procId + "&taskId=" + taskId + "&stepId=" + stepId + "&actId=" + actId,
        width: "500px",
        height: "290px",
        btn: ['确定', '取消'],
        callBack: function (iframeId) {
            var postData = top.frames[iframeId].getFormData();
            if (typeof backFormEvent != undefined) {
                var newData = {};
                newData['PROC_ID'] = procId;
                newData['TASK_ID'] = taskId;
                newData['STEP_ID'] = stepId;
                newData['ACT_ID'] = actId;
                newData['ORGAN_ID'] = organId;
                newData['BACK_ACT_IDS'] = postData['BackIds'];
                newData['STEP_NOTE'] = postData['Note'];
                newData['IS_SEND_SHORT'] = postData['SendShort'];
                newData['IS_SEND_SMS'] = postData['SendSM'];
                newData['IS_SEND_WX'] = postData['sendWX'];
                backFormEvent(newData);
            }
        }
    });
}

function btn_submit() {
    $.dialogOpen({
        title: "流程提交",
        url: top.contentPath + "/TaskManage/MyTasks/Commit?procId=" + procId + "&taskId=" + taskId + "&stepId=" + stepId + "&actId=" + actId,
        width: "500px",
        height: "250px",
        btn: ['确定', '取消'],
        callBack: function (iframeId) {
            var postData = top.frames[iframeId].getFormData();
            if (typeof submitFormEvent != undefined) {
                var newData = {};
                newData['PROC_ID'] = procId;
                newData['TASK_ID'] = taskId;
                newData['STEP_ID'] = stepId;
                newData['ACT_ID'] = actId;
                newData['ORGAN_ID'] = organId;
                newData['STEP_NOTE'] = postData['Note'];
                newData['IS_SEND_SHORT'] = postData['SendShort'];
                newData['IS_SEND_SMS'] = postData['SendSM'];
                newData['IS_SEND_WX'] = postData['sendWX'];
                submitFormEvent(newData);
            }
        }
    });
}