<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>编辑</title>
    <link rel="stylesheet" th:href="@{/lib/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" lay-filter="formDemo">
                    <div class="layui-form layuimini-form" style="padding-bottom: 100px">
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">费用申请</label>
                            <div class="layui-input-inline" style="width: 70%">
                                <input type="hidden" id="id" name="id" class="layui-input" th:value="${approveInfo.id}">
                                <input type="hidden" id="xmid" name="xmid" class="layui-input" th:value="${approveInfo.xmid}">
                                <input type="hidden" id="tablename" name="tablename" class="layui-input"
                                       th:value="${approveInfo.tablename}">
                                <input type="text" id="xm" name="xm" class="layui-input" readonly th:value="${approveInfo.xm}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">申请金额(元)</label>
                            <div class="layui-input-inline" style="width: 20%">
                                <input type="text" id="sqje" name="sqje" class="layui-input" readonly th:value="${approveInfo.sqje}">
                            </div>
                            <label class="layui-form-label" style="width: 5%">状态</label>
                            <div class="layui-input-inline" style="width: 20%">
                                <input type="hidden" id="spzt" name="spzt" class="layui-input" th:value="${approveInfo.zt}">
                                <input type="text" id="zt" name="zt" class="layui-input" readonly th:value="${approveInfo.zt}">
                            </div>
                            <div class="layui-input-inline" style="width: 20%">
                                <input type="text" value="项目费用申请" class="layui-input" readonly>
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">审批操作</label>
                            <div class="layui-input-inline" style="width: 70%">
                                <select id="spcz" name="spcz" class="layui-input">
                                    <option value="提交审批">提交审批</option>
                                </select>
                            </div>
                        </div>
                        <!--        <div class="layui-form-item layui-inline" style="width: 100%">-->
                        <!--            <label class="layui-form-label" style="width: 10%">返回意见</label>-->
                        <!--            <div class="layui-input-inline" style="width: 70%">-->
                        <!--                <textarea id="yj" name="yj"  class="layui-textarea" style="width: 70%;height: 100px" th:text="${approveInfo.yj}"></textarea>-->
                        <!--            </div>-->
                        <!--        </div>-->
                        <!--        <div class="layui-form-item layui-inline" style="width: 100%">-->
                        <!--            <label class="layui-form-label" style="width: 10%">选择常用语</label>-->
                        <!--            <div class="layui-input-inline" style="width: 750px">-->
                        <!--                <input type="text" id="cyy" name="cyy" class="layui-input" readonly>-->
                        <!--            </div>-->
                        <!--            <button type="button" class="layui-btn" lay-filter="cyySaveBtn" style="width: 80px">常用语</button>-->
                        <!--        </div>-->
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">提交人</label>
                            <div class="layui-input-inline" style="width: 30%">
                                <input type="hidden" id="userId" name="userId" class="layui-input" th:value="${userInfo.userId}">
                                <input type="hidden" id="tjr" name="tjr" class="layui-input" th:value="${approveInfo.tjr}">
                                <input type="text" id="tjrxm" name="tjrxm" class="layui-input" readonly th:value="${approveInfo.tjrxm}">
                            </div>
                            <label class="layui-form-label" style="width: 10%">提交时间</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <input type="hidden" id="shr" name="shr" class="layui-input" th:value="${approveInfo.tjr}">
                                <input type="hidden" id="shsj" name="shsj" class="layui-input" readonly>
                                <input type="text" id="tjsj" name="tjsj" class="layui-input" readonly th:value="${approveInfo.tjsj}">
                            </div>
                        </div>
                        <div class="layui-form-item layui-inline" style="width: 100%">
                            <label class="layui-form-label" style="width: 10%">“审批”操作岗位</label>
                            <div class="layui-input-inline" style="width: 30%">
                                <input type="hidden" id="sjshgw" name="sjshgw" class="layui-input" th:value="${postInfo.postId}">
                                <input type="text" id="sjshgwmc" name="sjshgwmc" th:value="${postInfo.postName}" class="layui-input"
                                       readonly>
                            </div>
                            <label class="layui-form-label" style="width: 10%">“审批”操作人</label>
                            <div class="layui-input-inline" style="width: 25%">
                                <input type="hidden" id="sjshr" name="sjshr" class="layui-input">
                                <input type="text" id="sjshrxm" name="sjshrxm" lay-verify="required" lay-reqtext='“审批”操作人不能为空'
                                       class="layui-input" readonly>
                            </div>
                        </div>
                        <!--        <div class="layui-form-item layui-inline" style="width: 100%">-->
                        <!--            <label class="layui-form-label" style="width: 10%">当前岗位人员</label>-->
                        <!--            <div class="layui-input-inline" style="width: 370px">-->
                        <!--                <input type="hidden" id="dqgw" name="dqgw" class="layui-input" th:value="${userInfo.userId}">-->
                        <!--                <input type="text" id="dqgwxm" name="dqgwxm" class="layui-input" th:value="${userInfo.name}" readonly>-->
                        <!--            </div>-->
                        <!--        </div>-->

                        <!-- 右侧悬浮按钮 -->
                        <div class="right-bottom-btn">
                            <button type="button" class="layui-btn" lay-filter="viewFysqBtn">
                                <i class="layui-icon layui-icon-file"></i>查看费用申请
                            </button>
                            <button type="button" class="layui-btn" lay-filter="viewSplistBtn">
                                <i class="layui-icon layui-icon-file"></i>审批列表
                            </button>
                            <button type="button" class="layui-btn" lay-submit lay-filter="saveBtn">
                                <i class="layui-icon layui-icon-ok"></i>提交
                            </button>
                            <button class="layui-btn" lay-filter="cancleBtn">
                                <i class="layui-icon layui-icon-close"></i>取消
                            </button>
                        </div>
                    </div>
                </form>

<script th:src="@{/lib/jquery-3.4.1/jquery-3.4.1.min.js}" charset="utf-8"></script>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<script th:src="@{/lib/coco-message/coco-message.js}" charset="utf-8"></script>
<script th:src="@{/lib/xm-select-v1.2.2/xm-select.js}" charset="utf-8"></script>
<script th:src="@{/js/lay-config.js}" charset="utf-8"></script>

<script type="text/javascript" th:inline="javascript">
    AjaxUtil.ctx = /*[[@{/}]]*/'';
        // 结束
        // 审核数据
        var xmApproval = parent.getXmApproval();
        //提交时间
        laydate.render({
            elem: '#shsj',
            type: 'datetime',
            value: new Date()
        });

        //“审批”操作人
        var postId = $("#sjshgw").val();
        if (postId != "") {
            tableSelect.render({
                elem: '#sjshrxm',
                checkedKey: 'userId',
                searchKey: 'name',
                searchPlaceholder: '搜索姓名',
                table: {
                    url: AjaxUtil.ctx + 'sysUserPost/postUserlist/' + postId,
                    cols: [
                        [
                            {type: "radio", fixed: 'left'},
                            {type: 'numbers', align: 'center'},
                            {field: 'name', width: '40%', title: '姓名', align: 'left'},
                            {field: 'account', title: '账号', align: 'left'}
                        ]
                    ]
                },
                done: function (elem, data) {
                    var NEWJSON = [];
                    var NEWJSON1 = [];
                    layui.each(data.data, function (index, item) {
                        NEWJSON.push(item.name);
                        NEWJSON1.push(item.userId);
                    })
                    elem.val(NEWJSON.join(","));
                    $("#sjshr").val(NEWJSON1.join(","));
                }
            });
        }
        // 自动填充审批操作人gst
        var postId = $("#sjshgw").val();
        if (postId !== "") {
            AjaxUtil.get({
                url: AjaxUtil.ctx + 'sysUserPost/postUserlist/' + postId,
                success: function (res) {
                    var users = res.data;
                    var userIds = [];
                    var userNames = [];

                    /* for (var i = 0 ; i <users.length; i++) {
                    if (i==0) {
                    userIds.push(users[i].userId);
                    userNames.push(users[i].name);
                    }
                    break;
                    }


                    */
                    userIds.push(users[0].userId);
                    userNames.push(users[0].name);

                    $("#sjshr").val(userIds.join(","));
                    $("#sjshrxm").val(userNames.join(","));
                },
                error: function (error) {
                }
            });
        }
        // 监听查看可研报告按钮
        $("button[lay-filter='viewFysqBtn']").click(function () {
            parent.layer.open({
                title: '查看费用申请',
                type: 2,
                shade: 0.3,
                maxmin: true,
                shadeClose: true,
                area: ['1020px', layerheight + 'px'],
                content: AjaxUtil.ctx + 'staBudgetapproval/forApplyView/' + xmApproval.xmid,
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 监听审批列表按钮
        $("button[lay-filter='viewSplistBtn']").click(function () {
            parent.layer.open({
                title: '审批列表',
                type: 2,
                shade: 0.3,
                maxmin: true,
                shadeClose: true,
                area: ['1300px', '750px'],
                content: AjaxUtil.ctx + 'staBudgetapproval/forApproveList',
                end: function (index) {
                    layer.close(index);
                }
            });
        });

        // 监听提交按钮
        form.on('submit(saveBtn)', function (data) {
            var zt = $("#zt").val();
            var tjr = $("#tjr").val();
            var userId = $("#userId").val();
            if (userId != tjr)
                Message.error("您不是费用申请的提交人！", 1500);
            else if (zt == '数据不匹配')
                Message.error("数据不匹配，请联系管理员处理！", 1500);
            else {
                //基本信息
                layer.load(0, {shade: 0.1});
                AjaxUtil.post({
                    url: AjaxUtil.ctx + "prjApproverecord/doUpdateApproveFysq",
                    data: data.field,
                    success: function (res) {
                        //更新审批状态
                        var project = {
                            "id": xmApproval.xmid,
                            "spzt": '部门主任审批'
                        }

                        layer.load(0, {shade: 0.1});
                        AjaxUtil.post({
                            url: AjaxUtil.ctx + "staBudgetapproval/updateSpzt",
                            contentType: "application/json",
                            data: JSON.stringify(project),
                            success: function (res) {
                                parent.setUpdateFlag();

                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            },
                            error: function (error) {
                            }
                        });
                    },
                    error: function (error) {
                    }
                });
            }
        });

        // 监听取消按钮
        $("button[lay-filter='cancleBtn']").click(function () {
            var iframeIndex = parent.layer.getFrameIndex(window.name);
            parent.layer.close(iframeIndex);
        });
    });
    function getTravelExpense() {
        return travelExpense;
    }
    function getIntellectual() {
        return intellectual;
    }

    function getMember() {
        return tempMember;
    }

    function getDevExpense() {
        return devExpense;
    }
    function getInformation() {
        return information;
    }
    function getPrintln() {
        return println;
    }

    function getSoftExpense() {
        return softExpense;
    }

    function getMatCost() {
        return materialCost;
    }

    function getOutExpense() {
        return outExpense;
    }

    function getOutTesting() {
        return outTesting;
    }
    function stripHtmlTags(str) {
        return str.replace(/<\/?[^>]+(>|$)/g, "");
    }
</script>
</body>
</html>