<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>电站详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="decorator" content="base"/>
    <link rel="stylesheet" type="text/css" href="${ctxPlugin}/static/css/reset.css"/>
    <style>html {background-color: #fff;}</style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-card-body ">
            <div class="layui-col-xs11 mb-10">
                <label class="layui-form-label"><i class="mark">*</i>变更类型：</label>
                <div class="layui-input-block ">
                    <select id="rectification" name="rectification" lay-filter="rectification" required>
                        <option value="" rel=""></option>
                        <c:forEach items="${list}" var="ins">
                            <option value="${ins.columns.id}" rel="${ins.columns.status}" <c:if test="${ins.columns.id eq customerEntry.rectificationSetId}">selected</c:if>>${ins.columns.name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
            <div class="layui-col-xs11 mb-10">
                <label class="layui-form-label">变更后状态：</label>
                <div class="layui-input-block">
                    <input type="text" id="status" name="name" value="" autocomplete="off" class="layui-input layui-bg-gray" disabled="disabled">
                </div>
            </div>
            <div class="layui-col-xs11 mb-10" >
                <label class="layui-form-label">申请原因：</label>
                <div class="layui-input-block">
                    <textarea id="applyReasonName" class="idea-text f-l layui-col-xs12" style="height: 100px;padding: 10px" disabled>${customerEntry.changeReason}</textarea>
                </div>
            </div>
            <div class="layui-col-xs11 mb-10" >
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-block">
                    <textarea id="auditComments" class="idea-text f-l layui-col-xs12" style="height: 100px;padding: 10px">${customerEntry.auditComments}</textarea>
                </div>
            </div>
        </div>
    </div>

    <div class="operate-footer">
        <button type="button" class="layui-btn" id="refuseInDoc">同意</button>
        <button type="button" class="layui-btn" id="refuseNotRetaial">驳回</button>
        <button class="layui-btn layui-btn-primary" onclick="closeSelf()">取消</button>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layedit', 'laydate','jquery','upload','layer'], function () {

        $ = layui.$;
        layer = layui.layer;
        form = layui.form;
        var id = "${customerEntry.id}";
        var refuseFlag = true;
        $('#refuseInDoc').click(function(){

            if(!refuseFlag){
                return;
            }
            var index= layer.load(2, {shade: [0.5,'#fff'], content:''});

            var rectificationId = $('#rectification').val();
            var auditComments = $('#auditComments').val();

            if (isBlank(rectificationId)) {
                layer.msg('请选择变更类型', {icon: 2});
                return;
            }

            refuseFlag = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/rectificationAudit',
                data: {
                    id: id,
                    type:'1',
                    rectificationId: rectificationId,
                    auditComments: auditComments
                },
                success: function(data){
                    if (data.code == '200') {
                        parent.layer.msg('操作成功', {icon: 1});
                        closeSelf();
                        parent.searchOrder();
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                complete: function(){
                    refuseFlag = true;
                    layer.close(index);
                }
            });
        });

        var refuseNotFlag = true;
        $('#refuseNotRetaial').click(function(){
            if(!refuseNotFlag){
                return;
            }

            var auditComments = $('#auditComments').val();

            if (isBlank(auditComments)) {
                layer.msg('请填写备注', {icon: 2});
                return;
            }

            refuseNotFlag = false;
            $.ajax({
                type: 'post',
                url: '${ctx}/customerEntry/rectificationAudit',
                data: {
                    id: id,
                    type: "2",
                    auditComments: auditComments
                },
                success: function(data){
                    if (data.code == '200') {
                        parent.layer.msg('操作成功', {icon: 1});
                        closeSelf();
                        parent.searchOrder();
                    } else {
                        layer.msg(data.msg, {icon: 2});
                    }
                },
                complete: function(){
                    refuseNotFlag = true;
                }
            });
        });

        $("#status").val(changeStatus($("#rectification").find("option:selected").attr("rel")));

        form.on('select(rectification)',function(data){
            var status = $(data.elem).find("option:selected").attr("rel");
            $("#status").val(changeStatus(status));
        })
    })

    function changeStatus(status) {
        if (status == "0") {
            return "暂存";
        } else if (status == "1") {
            return "设计审核"
        } else if (status == "2") {
            return "待安装"
        } else if (status == "3") {
            return "待安装验收"
        } else if (status == "4") {
            return "待并网"
        } else if (status == "5") {
            return "待上传发票"
        } else if (status == "6") {
            return "待签署合同"
        } else if (status == "7") {
            return "待并网验收"
        } else {
            return "";
        }
    }

    window.closeSelf = function () {
        var index = parent.layer.getFrameIndex(window.name);
        // window.parent.location.reload();//刷新父级页面
        parent.layer.close(index);//关闭当前页
    }
    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>

