<%@ 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" 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">
</head>
<body>
<div class="layui-form  layui-card mb-0 pr-30">
    <div class="layui-card mb-0 pr-30">
        <div class="layui-card-body">
            <div class="layui-row">
                <input class="layui-hide" name="orderId" value="${orderId}" id="orderId">
                <div class="layui-col-xs12">
                    <label class="layui-form-label"><i class="mark">*</i>无效理由：</label>
                    <div class="layui-input-block">
                        <textarea name="description" id="description" lay-filter="description" class="layui-textarea" lay-verify="required"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-form-item " style="text-align: center;">
            <div class="layui-input-block">
                <button class="layui-btn"  id="sureSubmit">确认</button>
                <button  class="layui-btn " lay-filter="cancel" id="cancel">取消</button>
            </div>

        </div>
    </div>
</div>

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

        var saveFlag=false;
        $("#sureSubmit").on('click',function(data){
            if(saveFlag){
                return;
            }
            var orderId=$("#orderId").val();
            var description=$("#description").val();
            if(isBlank(description)){
                layer.msg("请输入无效理由！");
                return;
            }
            saveFlag=true;
            $.ajax({
                type:"POST",
                url:"${ctx}/order/siteInvalidOrder",
                data:{
                    orderId:orderId,
                    description:description
                },
                success:function(result){
                    var index = parent.layer.getFrameIndex(window.name);
                    if(result.code == "200"){
                        layer.msg("保存成功",{icon:1,time:1000},function(){
                            parent.layer.closeAll();
                            if (where == '1') {
                                parent.parent.location.reload();
                            } else {
                                parent.location.reload(); //刷新父页面
                            }
                        })

                    }else if(result.code =="400"){
                        layer.msg('该工单已派工不可操作无效！', {icon:2},function(){
                            parent.layer.close(index);
                        });
                    }else if(result.code =="402"){
                        layer.msg('该工单有申请备件，不能操作无效！', {icon:2},function(){
                            parent.layer.close(index);
                        });
                    }else if(result.code =="403"){
                        layer.msg('该工单有收款记录，不能操作无效！', {icon:2},function(){
                            parent.layer.close(index);
                        });
                    } else{
                        layer.msg('操作失败！', {icon:2},function(){
                            parent.layer.close(index);
                        });
                    }
                }
            });
        })
        $("#cancel").on('click',function(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })

    });
    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }
</script>
</body>
</html>
