@{
    ViewBag.Title = "Details";
    Layout = "~/Views/Shared/_Form.cshtml";
}
<link href="~/js/lay-module/flow/WaterFlow.css" rel="stylesheet" />
<link href="~/js/lay-module/formDesigner/formPreview.css" rel="stylesheet" />
<style type="text/css">
    div.layui-table-cell {
        color: rgb(102, 102, 102) !important;
    }
</style>
<script>
    //参数传递到表单页
    //表单数据
    var formtext;
    //只读参数
    var readonly = true;
    //允许修改表单数据
    var canWriteFormItems = [];
    var NextNodeDesignateType = "";
    layui.use(['form', 'table', 'layer', 'element', 'jquery', 'waterflow', 'flowlayout', 'common', 'formPreview'], function () {
        var form = layui.form, element = layui.element,
            table = layui.table,
            layer = layui.layer,
            common = layui.common,
            formPreview = layui.formPreview,
            $ = layui.jquery;
        var keyValue = $.request("keyValue");
        $("#F_FlowInstanceId").val(keyValue);
        //权限字段
        common.authorizeFields('adminform');
        var flowDesignPanel;
        table.render({
            elem: '#mainList',
            page: false,
            url: '/FlowManage/Flowinstance/QueryHistories',
            where: { time: new Date().Format("yyyy-MM-dd hh:mm:ss") },
            cols: [[ //标题栏
                { field: 'F_Content', title: '流转记录', minWidth: 150 }
                , { field: 'F_CreatorUserName', title: '操作人', width: 150 }
                , {
                    field: 'F_CreatorTime', title: '创建时间', width: 180,
                    templet: function (d) {
                        if (d.F_CreatorTime) {
                            var time = new Date(d.F_CreatorTime);
                            return time.Format("yyyy-MM-dd hh:mm:ss");
                        }
                        return '';
                    }
                },
            ]]
            , where: {
                keyValue: keyValue
            }
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": res.state, //解析接口状态
                    "msg": res.message, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
        });
        var renderForm;
        $(function () {
            common.ajax({
                url: '/FlowManage/Flowinstance/GetFormJson',
                dataType: 'json',
                data: { keyValue: keyValue },
                async: false,
                success: function (data) {
                    var schemeContent = JSON.parse(data.F_SchemeContent);
                    if (!!data.CurrentMakerName) {
                        $('#CurrentMakerName').val(data.CurrentMakerName);
                    }
                    else {
                        $('#CurrentMakerName').parent().parent().remove();
                    }
                    NextNodeDesignateType = data.NextNodeDesignateType;
                    if (!data.NextNodeDesignateType && data.CurrentNodeDesignateType != "MORE_USER_MANAGER") {
                        $('#NextMakerName').parent().parent().remove();
                    }
                    else if (data.NextNodeDesignateType == "RUNTIME_SPECIAL_ROLE") {
                        $('#NextMakerName').removeAttr('disabled');
                        $('#NextMakerName').attr('placeholder','请点击选择角色');
                    }
                    else if (data.NextNodeDesignateType == "RUNTIME_SPECIAL_USER") {
                        $('#NextMakerName').removeAttr('disabled');
                        $('#NextMakerName').attr('placeholder','请点击选择用户');
                    }
                    else {
                        $('#NextMakerName').val(data.NextMakerName);
                        if (!data.NextMakerName) {
                            $('#NextMakerName').val("所有人");
                        }
                    }
                    canWriteFormItems = data.CanWriteFormItems;
                    flowDesignPanel = $('#flowPanel').flowdesign({
                        haveTool: false
                        , isprocessing: true
                        , activityId: data.F_ActivityId
                        , nodeData: schemeContent.nodes
                        , flowcontent: schemeContent
                    });
                    formtext = data.F_FrmData;
                    if (data.F_FrmType == 0) {
                        var dataJson = JSON.parse(data.F_FrmContent);
                        //表单设计器
                        renderForm= formPreview.render({
                            data: dataJson,
                            elem: '#frmPreview',
                            readonly:true,
                            canformitems: canWriteFormItems
                        });
                        renderForm.setFormData(JSON.parse(formtext));
                    }
                    else {

                        $("#frmPreview").load(document.location.origin + '/form/' + data.F_DbName + '.html');
                    }
                    $("#valueList").val(data.F_FrmContentData);
                    flowDesignPanel.reinitSize($(window).width() * 2 / 3 - 40, $(window).height() - 100);
                }
            });
            form.render();
        });
        $(window).resize(function () {
            flowDesignPanel.reinitSize($(window).width() * 2 / 3 - 40, $(window).height() - 100);
        });
        wcLoading.close();
        form.on('select(VerificationFinally)',
            function (data) {
                if (data.value != "1") {
                    $('#NextMakerName').parent().parent().remove();
                }
            });
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var postData={};
            $.extend(true, postData, data.field)
            if(!!renderForm)
            {
                var tempdata = renderForm.getFormData();
                postData.F_FrmData = JSON.stringify(tempdata);
            }
            else{
                delete data.field.CurrentMakerName;
                delete data.field.NextMakerName;
                delete data.field.F_FlowInstanceId;
                delete data.field.F_VerificationFinally;
                delete data.field.file;
                delete data.field.NextNodeDesignates;
                delete data.field.F_VerificationOpinion;
                postData.F_FrmData = JSON.stringify(data.field);
            }
            postData.NodeDesignateType = NextNodeDesignateType;
            postData.NodeDesignates = postData.NextNodeDesignates?postData.NextNodeDesignates.split(','):[];
            common.submitForm({
                url: "/FlowManage/Flowinstance/Verification?keyValue=" + keyValue,
                param: postData,
                success: function () {
                    common.parentreload("data-search-btn");
                    common.reloadIframe("/FlowManage/Flowinstance/Index", 'data-search-btn');
                    common.reloadIframe("/FlowManage/Flowinstance/DoneFlow", 'data-search-btn');
                }
            })
            return false;
        });
    });
    function search() {
        layui.use(['jquery', 'form', 'common'], function () {
            var form = layui.form,
                $ = layui.$,
                common = layui.common;
            //不同弹窗
            if (NextNodeDesignateType == 'RUNTIME_SPECIAL_ROLE') {
                common.modalOpen({
                    title: "选择角色",
                    url: "/SystemOrganize/Role/AddForm?name=" + "NextMakerName" + "&value=" + "NextNodeDesignates" + "&ids=" + $('#NextNodeDesignates').val(),
                    width: "650px",
                    height: "600px",
                });
            }
            else if (NextNodeDesignateType == 'RUNTIME_SPECIAL_USER') {
                common.modalOpen({
                    title: "选择用户",
                    url: "/SystemOrganize/User/AddForm?name=" + "NextMakerName" + "&value=" + "NextNodeDesignates" + "&ids=" + $('#NextNodeDesignates').val(),
                    width: "650px",
                    height: "600px",
                });
            }
        });
    }
</script>

<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form" lay-filter="adminform">
            <div class="layui-row ">
                <div class="layui-col-xs8">
                    <div class="layui-tab layui-tab-brief" lay-filter="tab" style="margin: 0px">
                        <ul class="layui-tab-title">
                            <li class="layui-this">表单信息</li>
                            <li>流程信息</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form layuimini-form" lay-filter="FrmData">
                                    <div class="layui-form-item">
                                        <fieldset class="layui-elem-field" style="padding-top:15px;">
                                            <div id="frmPreview"></div>
                                        </fieldset>
                                    </div>
                                </form>
                            </div>
                            <div class="layui-tab-item">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">当前审核人</label>
                                    <div class="layui-input-block">
                                        <input id="CurrentMakerName" name="CurrentMakerName" class="layui-input" disabled>
                                    </div>
                                </div>
                                <table class="layui-table" id="mainList">
                                </table>
                                <div id="flowPanel"></div>
                            </div>
                        </div>
                    </div>

                </div>
                <div class="layui-col-xs4" style="background-color: #1e9fff7d; min-height: 500px;">
                    <input type="hidden" id="F_FlowInstanceId" name="F_FlowInstanceId" />

                    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label">审核结果</label>
                        <div class="layui-input-block">
                            <select id="F_VerificationFinally" name="F_VerificationFinally" lay-filter='VerificationFinally' required lay-verify="required" lay-search>
                                <option value="1">同意</option>
                                <option value="2">不同意</option>
                                <option value="3">驳回</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item  layui-hide">
                        <label class="layui-form-label">审核意见</label>
                        <div class="layui-input-block">
                            <textarea name="F_VerificationOpinion" id="F_VerificationOpinion"
                                      placeholder="" autocomplete="off" class="layui-textarea"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <label class="layui-form-label">下一步审核</label>
                        <div class="layui-input-block">
                            <input type="text" name="NextMakerName" disabled="disabled" id="NextMakerName" lay-verify="required" onclick="search()" class="layui-input">
                            <input type="text" name="NextNodeDesignates" id="NextNodeDesignates" class="layui-input layui-hide">
                        </div>
                    </div>
                    <div class="layui-form-item layui-hide">
                        <button class="layui-btn site-demo-active" lay-submit id="submit" lay-filter="saveBtn">确认保存</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>