<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<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-card md-0 layui-form" lay-filter="layuiadmin-form-admin">
    <div class="layui-card-body">
            <div class="layui-form-item layui-col-xs12 ">
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">服务商名称：</label>
                        <div class="layui-input-block">
                            <input type="text" id="siteName" class="layui-input layui-bg-gray" value="${apply.siteName}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">申请人：</label>
                        <div class="layui-input-block">
                            <input type="text" id="applicantName" class="layui-input layui-bg-gray" value="${apply.applicantName}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">备件名称：</label>
                        <div class="layui-input-block">
                            <input type="text" id="fittingName" class="layui-input layui-bg-gray" value="${fitting.name}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">物料号：</label>
                        <div class="layui-input-block">
                            <input type="text" id="fittingCode" class="layui-input layui-bg-gray" value="${fitting.code}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">备件型号：</label>
                        <div class="layui-input-block">
                            <input type="text" id="fittingVersion" class="layui-input layui-bg-gray" value="${fitting.version}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">备件数量：</label>
                        <div class="layui-input-block">
                            <input type="text" lay-verify="ling" name="applyNum" id="applyNum" class="layui-input layui-bg-gray" value="<fmt:formatNumber type="number" value="${apply.applyNum}" maxFractionDigits="2"/>" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs12 mb-5">
                        <label class="layui-form-label">申请备注：</label>
                        <div class="layui-input-block">
                            <input type="text" id="applyMarks" class="layui-input layui-bg-gray" value="${apply.applyMarks}" disabled>
                        </div>
                    </div>
                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">当前库存：</label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input layui-bg-gray" value="${fitting.warning}" disabled>
                        </div>
                    </div>

                    <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label"><i class="mark ">*</i>审核数量：</label>
                        <div class="layui-input-block">
                            <input type="text" lay-verify="ling" name="fittingSuditNum" id="fittingSuditNum" class="layui-input " value="<fmt:formatNumber type="number" value="${apply.applyNum}" maxFractionDigits="2"/>" >
                        </div>
                    </div>
                   <%-- <div class="layui-col-xs4 mb-5">
                        <label class="layui-form-label">返回旧件：</label>
                        <div class="layui-input-block">
                            <select  name="oldFittingFlag" id="oldFittingFlag"  class="layui-bg-gray layui-disabled"  disabled>
                                <option value="">请选择</option>
                                <option value="0" <c:if test="${fitting.refundOldFlag eq 0}">selected</c:if> >无需返还</option>
                                <option value="1" <c:if test="${fitting.refundOldFlag eq 1}">selected</c:if> >需要返还</option>
                            </select>
                        </div>
                    </div>--%>
                    <div class="layui-col-xs12 mb-5">
                        <label class="layui-form-label">审核备注：</label>
                        <div class="layui-input-block">
                            <textarea placeholder="请输入内容" class="layui-textarea" id="factoryMarks" name="factoryMarks" ></textarea>

                        </div>
                    </div>
                </div>
    </div>
    <div class="operate-footer" >
        <input type="hidden" id="appplyId" name="id" value="${apply.id}" />
        <button class="layui-btn" onclick="adoptApply('${apply.id}')">同意</button>
        <button class="layui-btn" onclick="refuseFitting('${apply.id}')">驳回</button>
        <button class="layui-btn layui-btn-primary" onclick="cancels()">取消</button>
    </div>
</div>

<div class="layui-form  layui-card hide" id="Reasons">
    <div class="layui-card ">
        <div class="layui-card-body">
            <div class="layui-row">
                <div class="layui-col-xs12">
                    <label class="layui-form-label"><i class="mark">*</i>拒绝理由：</label>
                    <div class="layui-input-block">
                        <textarea name="refuseReason" id="refuseReason" class="layui-textarea" ></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
<script>
    var imgsCount;
    layui.use(['form', 'jquery','laydate','upload'], function () {
        $ = layui.$
            , element = layui.element
            , form = layui.form
            , laydate = layui.laydate;
        var upload = layui.upload;
        imgsCount = '${imgsCount}';


        $('.deliveryMsg').click(function () {
            var index = $(this).index();
            $(this).removeClass('layui-btn-primary').siblings().addClass('layui-btn-primary')
            if (index == '1') {
                $('.re-record').removeClass('layui-hide');
                $('.bj-msg').addClass('layui-hide');
            } else {
                $('.bj-msg').removeClass('layui-hide');
                $('.re-record').addClass('layui-hide');
            }
        })


    });

    function refuseFitting(id){

        var oldFittingFlag = $("#oldFittingFlag").val();  //返还旧件
        var factoryMarks = $("#factoryMarks").val();            //审核备注
        layer.open({
            type: 1,
            content: $("#Reasons")  //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
            ,title: "拒绝申请"
            ,btn:['确定', '取消']
            ,area:["600px","280px"]
            ,yes: function(index, layero){
                var refuseReason = $("#refuseReason").val();
                if(isBlank(refuseReason)){
                    layer.msg("请输入拒绝理由",{icon :2})
                    return
                }
                $.ajax({
                    url: '${ctx}/platform/fitting/refuseFitting',
                    type: 'post',
                    data: {
                        id: id,
                        oldFittingFlag: oldFittingFlag,
                        factoryMarks: factoryMarks,
                        refuseReason:refuseReason
                    },
                    success: function(data) {
                        if(data.code=="200"){
                            layer.msg("保存成功！",{time:1000},function(){
                                parent.layer.closeAll()
                                parent.window.location.reload();
                            });
                        }else if(data.code=='401'){
                            layer.msg("该备件申请不满足审核条件，已审核或者已取消");
                        }else{
                            layer.msg("保存失败！");
                        }
                    },
                    complete:function(){
                        noRepeatSub = false;
                    }
                });
            }
        })

    }

//通过申请
    var noRepeatSub = false;
    function adoptApply(id){
        if(noRepeatSub){
            return;
        }
        var fittingSuditNum = $("#fittingSuditNum").val();  //审核数量
        var oldFittingFlag = $("#oldFittingFlag").val();  //返还旧件
        var factoryMarks = $("#factoryMarks").val();            //审核备注

        var checkTe = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/
         if(isBlank(fittingSuditNum)){
            layer.msg("备件数量不可为空", {icon: 5, anim: 6});
            return;
        }else if (!checkTe.test(fittingSuditNum)) {
            layer.msg("备件数量格式不正确", {icon: 5, anim: 6});
            return;
        }else{
            $.ajax({
                url: '${ctx}/platform/fitting/adoptApply',
                type: 'post',
                data: {
                    id: id,
                    fittingSuditNum: fittingSuditNum,
                    oldFittingFlag: oldFittingFlag,
                    factoryMarks: factoryMarks
                },
                success: function(data) {
                    if(data.code=="200"){
                        layer.msg("保存成功！",{time:1000},function(){
                            parent.layer.closeAll()
                            parent.window.location.reload();
                        });
                    }else if(data.code="401"){
                        layer.msg(data.errMsg,{icon:2})
                    }else if(data.code="501"){
                        layer.msg(data.errMsg,{icon:2})
                    }else if(data.code="502"){
                        layer.msg(data.errMsg,{icon:2})
                    }else if(data.code="503"){
                        layer.msg(data.errMsg,{icon:2})
                    }else if(data.code="504"){
                        layer.msg(data.errMsg,{icon:2})
                    }else{
                        layer.msg("保存失败！");
                    }
                },
                complete:function(){

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