<%@ 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-card md-0">
    <%--   <div class="layui-card-body">--%>
    <form class="layui-form"  lay-filter="component-form-element" >
        <div class="layui-form-item layui-col-xs12 mt-20">
            <div class="layui-col-lg2 layui-col-sm4">
                <label class="layui-form-label">服务时长：</label>
                接单-完工：${hour} 小时
            </div>
            <div class="layui-col-lg2 layui-col-sm4">
                <label class="layui-form-label">里程参考：</label>
                ${map.address}
                <input type="hidden"  id="mileageHide" value="${map.address}" >
            </div>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">服务态度：</label>
                    <div class="layui-input-block">
                        <c:if test="${call.serviceAttitude == 5}">
                            <input type="text"   class="layui-input layui-bg-gray" value="十分满意" disabled>
                        </c:if>
                        <c:if test="${call.serviceAttitude == 4}">
                            <input type="text"   class="layui-input layui-bg-gray" value="满意" disabled>
                        </c:if>
                        <c:if  test="${call.serviceAttitude == 3}">
                            <input type="text"   class="layui-input layui-bg-gray" value="一般" disabled>
                        </c:if>
                        <c:if  test="${call.serviceAttitude == 2}">
                            <input type="text"   class="layui-input layui-bg-gray" value="不满意" disabled>
                        </c:if>
                        <c:if  test="${call.serviceAttitude == 1}">
                            <input type="text"   class="layui-input layui-bg-gray" value="十分不满意" disabled>
                        </c:if>
                        <c:if  test="${call.serviceAttitude == 6}">
                            <input type="text"   class="layui-input layui-bg-gray" value="无效回访" disabled>
                        </c:if>
                        <c:if  test="${call.serviceAttitude == 7}">
                            <input type="text"   class="layui-input layui-bg-gray" value="回访未成功" disabled>
                        </c:if>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">收款金额：</label>
                    <div class="layui-input-block">
                        <input type="text"   class="layui-input layui-bg-gray" value="${order.totalCollections}" disabled>
                    </div>
                </div>

                <label class="ml-10" style="color: blue" id="showImage">收款凭证</label>

            </div>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">保修类型：</label>
                    <div class="layui-input-block">

                        <c:if test="${order.warrantyType eq 1}">
                            <input type="text"   class="layui-input layui-bg-gray" value="保内" disabled>
                        </c:if>
                        <c:if test="${order.warrantyType eq 2}">
                            <input type="text"   class="layui-input layui-bg-gray" value="保外" disabled>
                        </c:if>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">结算总额：</label>
                    <div class="layui-input-block">
                        <input type="text" id="total"  class="layui-input layui-bg-gray" value="" disabled>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">服务措施：</label>
                    <div class="layui-input-block">
                        <input type="text" name="" id="serviceStep" value="${siteSet.serviceStep}"  class="layui-input layui-bg-gray" id="" disabled >
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">维修费用：</label>
                    <div class="layui-input-block">
                        <input type="text" id="serviceCosts" name="serviceCosts" value="${siteSet.serviceCosts}"  class="layui-input layui-bg-gray changeCost"  disabled>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">快速奖励费： </label>
                    <div class="layui-input-block ">
                        <input type="radio" name="sex" value="1" title="有" <c:if test="${siteSet.rewardCosts gt 0.00}">checked</c:if> lay-filter="reward">
                        <input type="radio" name="sex" value="0" title="无" <c:if test="${siteSet.rewardCosts le 0.00}">checked</c:if> lay-filter="reward">
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm4 fee <c:if test="${siteSet.rewardCosts le 0.00}">layui-hide</c:if>">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="text" id="rewardCosts" name="rewardCosts" value="${siteSet.rewardCosts}" class="layui-input layui-bg-gray changeCost" disabled>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">差旅费用：</label>
                    <div class="layui-input-block">
                        <input type="text"  id="mileageCost" name="mileageCost" value="${siteSet.mileageCost}"  class="layui-input layui-bg-gray changeCost" disabled>
                    </div>
                </div>
                <div class="layui-col-lg2 layui-col-sm4">
                    <label class="layui-form-label">其他费用：</label>
                    <div class="layui-input-block">
                        <input type="text" onkeyup="change()" id="otherCost" name="otherCost" value="${siteSet.otherCost}"  class="layui-input changeCost"  >
                    </div>
                </div>
            </div>

            <div class="layui-col-xs8">
                <label class="layui-form-label">备注：</label>
                <div class="layui-input-block">
                    <textarea name="remarks" id="remarks" placeholder="" class="layui-textarea" >${siteSet.remarks}</textarea>
                </div>
            </div>
            <div class="layui-col-xs12 text-c mt-20">
                <button class="layui-btn layui-hide"  lay-submit="callOrder" id="setSubmit" lay-filter="setSubmit">结算完成</button>
            </div>
        </div>

        <div class="layui-form-item text-c"  >
            <button class="layui-btn" lay-submit="callOrder" id="callOrder" lay-filter="callOrder">保存</button>
            <button class="layui-btn" onclick="cancel()">取消</button>
        </div>

    </form>
    <%--  </div>--%>
</div>

<div id="lookImg" class="hide pos-r">
    <div style="position:relative;">
        <div class="w-500 lookImg" style="line-height: 300px">
            <img src="" id="image">
        </div>
        <i class="layui-icon xuanZhuan" style="position:absolute;bottom:9px;left:50%;">&#xe9aa;</i>
    </div>
</div>

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

        change();


        form.on("radio(reward)",function(data){
            var a = data.value;
            if(a== 1){
                $("#rewardCosts").val(60);
                $(".fee").removeClass("layui-hide");

            }else{
                $("#rewardCosts").val(0.00);
                $(".fee").addClass("layui-hide");
            }
            change();
        })

        var images="${collectionVoucher.columns.imgs}";
      /*  var images="sfimg02/M00/00/33/wKgCF1z3GruAUCswAALp7tlm2WY29..jpg,sfimg02/M00/00/3F/wKgCF11KJ4CAGjysAAKQF2GgG6g23..jpg,sfimg02/M00/00/33/wKgCF1z9p3GASP6mAAcBCt7Lur883..jpg";*/
        $("#showImage").click(function(){
            if(isBlank(images)){
                layer.msg("暂无数据!");
                return;
            }
            var arr=images.split(",");
            var number=0;
            $("#lookImg img").attr('src', "${commonStaticImgPath}" + arr[number]);
            layer.open({
                type: 1,
                title:false,
                area:['500px','400px'],
                btn:['上一张','下一张'],
                content: $('#lookImg'),
                scrollbar:false,
                yes:function(){
                    if(number<=0){
                        number=0;
                    }else{
                        number-=1;
                    }
                    $("#lookImg img").attr('src', "${commonStaticImgPath}" + arr[number]);
                },btn2:function(){
                    if(number>=arr.length-1){
                        number=arr.length-1;
                    }else{
                        number+=1;
                    }
                    $("#lookImg img").attr('src', "${commonStaticImgPath}" + arr[number]);
                    return false;
                }
            });
        })

        //旋转
        var deg = 0;
        $(".xuanZhuan").click(function(){
            deg += 90;
            document.getElementById("image").style.transform = "rotate(" + deg + "deg)";
        })

        var sameFlag=false;
        form.on('submit(callOrder)',function(){
            if(sameFlag){
                return false;
            }
          var serviceStep=$("#serviceStep").val();    //服务措施
            var serviceCosts=$("#serviceCosts").val();  //维修费用
            var rewardCosts=$("#rewardCosts").val();// 奖励费用
          var mileageCost=$("#mileageCost").val(); //里程费用
            var otherCost=$("#otherCost").val(); //其他费用
            var remarks =$("#remarks").val();//故障描述
            if(isBlank(otherCost)){
                otherCost=0.00;
            }
            sameFlag=true;
            $.ajax({
                type:"POST",
                url:"${ctx}/settlement/site/stat/saveAgainSettlementOrder",
                data:{
                    id:settleId,
//                    serviceStep:serviceStep,
                    serviceCosts:serviceCosts,
                    rewardCosts:rewardCosts,
                  mileageCost:mileageCost,
                    otherCost:otherCost,
                    remarks:remarks,
                },
                success:function(result){
                    if(result.code =="200"){
                        //先得到当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //再执行关闭
                        layer.msg('结算成功！', {icon:1,time:1000},function(){
                            parent.layer.close(index);
                            parent.location.reload(); //刷新父页面
                        })
                    }else if(result.code =="409"){
                        layer.msg('该工单不在待结算状态下，结算失败！', {icon:2,time:1000});
                    }else if(result.code =="500"){
                        layer.msg('服务商已结账，不可重新结算！', {icon:2,time:1000});
                    }else{
                        layer.msg('结算失败,数据有误', {icon:2,time:1000});
                    }
                    sameFlag=false;
                }
            })
            return false;
        })


    });


    function isBlank(val) {
        if (val == null || val == '' || val == undefined) {
            return true;
        }
        return false;
    }

    function change(){
        var total=0.00;
        $(".changeCost").each(function(index, el){
            var Fee = ($(el).val()).trim();
            if (!isNaN(parseFloat(Fee))){
                total+=parseFloat(Fee);
            }
        })
        $("#total").val(total.toFixed(2));

    }
    function cancel(){
        var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
        parent.layer.close(index);//关闭弹出层
    }

</script>
</body>
</html>