<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE HTML>
<html>
<head>
    <meta name="decorator" content="base" />
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${ctxPlugin}/static/css/reset.css">
    <style>
        .layui-form-select dl{
            max-height:200px;
            width: 80%;
        }
        html{background-color: #fff;padding-bottom: 50px;}
    </style>
</head>
<body>
<div class="layui-form">
    <div class="layui-card">
        <div class="layui-col-xs12 mb-10 pr-30">
            <label class="layui-form-label">申请原因：</label>
            <div class="layui-input-block">
                <select name="applyReasonId" id="applyReasonId" lay-filter="applyReasonId" >
                    <option value="">请选择</option>
                    <c:forEach items="${list}" var="ject">
                        <option value="${ject.columns.id}" title="${ject.columns.name}">${ject.columns.name}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
        <div class="layui-col-xs12 mb-10 pr-30 applyReasonName layui-hide" >
            <label class="layui-form-label">申请原因：</label>
            <div class="layui-input-block">
                <textarea id="applyReasonName" class="idea-text f-l layui-col-xs12" style="margin: 0px;height: 130px;padding: 10px"></textarea>
            </div>
        </div>
    </div>
    <div class="operate-footer">
        <input type="button"  id="refuseInDoc" class="layui-btn " value="退回">
        <input type="button" value="取消" class="layui-btn layui-btn-primary " onclick="closeSelf();">
    </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','laydate','jquery','layer'], function () {
        $ = layui.$
            , form = layui.form
            , layer = layui.layer
            ,laydate = layui.laydate;
        //执行实例

        var ids = "${ids}";
        var refuseFlag = true;
        $('#refuseInDoc').click(function(){
            if(!refuseFlag){
                return;
            }
            var applyReasonId = $('#applyReasonId').val();
            if(isBlank(applyReasonId)){
                layer.msg('请选择申请原因', {icon: 2});
                return;
            }
            var applyReasonName = $("#applyReasonId").find("option:selected").attr("title");
            var remarks = $("#applyReasonName").val();
            if(applyReasonId=='a'){
                if(isBlank(remarks)){
                    layer.msg('请输入申请重审原因', {icon: 2});
                    return;
                }
                applyReasonName = applyReasonName+":"+remarks;
            }
            refuseFlag = false;
            $.ajax({
                url:"${ctx}/customerEntry/saveRetrial",
                type:"POST",
                data:{
                    ids: ids,
                    applyReasonId: applyReasonId,
                    applyReasonName:applyReasonName
                }
                ,success:function (result) {
                    if (result.code == '200') {
                        parent.layer.msg('操作成功', {icon: 1});
                        closeSelf();
                        parent.searchOrder();
                    } else if (result.code == '501') {
                        layer.msg(data.errMsg, {icon: 2});
                    } else {
                        layer.msg('操作失败', {icon: 2});
                    }
                }
            })
        });


        form.on('select(applyReasonId)',function(data){
            $("#applyReasonName").val('');
            var id = $(data.elem).find("option:selected").val();
            if(id=='a'){

                $(".applyReasonName").removeClass("layui-hide");
            }else{
                var name = $(data.elem).find("option:selected").attr("title");
                $("#applyReasonName").val(name);
                $(".applyReasonName").addClass("layui-hide");
            }
        })


    });


    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>
