<%@ 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"/>
	<style>
		.mark {
			color: #ff5151 !important;
		}

		html {
			background-color: #fff;
		}
	</style>
</head>
<body>
<div class="layui-form" lay-filter="layuiadmin-form-useradmin">
	<div class="layui-card">
		<div class="layui-card-body pt-20" style="margin-left:70px;" id="layuiadmin-form-useradmin">
			<div class=" layui-form-item layui-form-text">
				<label class="layui-form-label">
					<span class="mark">*</span>
					支付凭证：
				</label>
				<div class="layui-input-block">
					<div class="upload-container" id="uploader">
						<img src="" alt="img placeholder" style="width: 80px; height: 80px;" id="pic">
					</div>
				</div>
				<input type="hidden" name="imgs" id="imgs" lay-verify="imgsCheck">
			</div>
			<input type="hidden" name="id" id="id" value="${id}"/>
			<div class="layui-form-item" style="margin-top: 40px;">
				<div class="layui-input-block" style="margin-left: 10px;">
					您确定需要给
					<span style="color: #FFB800;"> ${out!=null ? out.siteName : '' } </span>
					结账了吗？
				</div>
			</div>

		</div>
	</div>
	<div class="operate-footer">
		<input type="button" class="layui-btn" lay-submit lay-filter="sureSubmit" id="sureSubmit" value="确认">
	</div>
</div>

<script src="${ctxPlugin}/lib/layuiAdmin/dist/layuiadmin/layui/layui.js"></script>
	<script>
    function complaintType() {
        return $("#complaintType").val();
    }
    var imgs="";
    //Demo
    layui.use(['form', 'upload'], function () {
        var form = layui.form,
        $ = layui.$;

        var checkOrder = false;
        form.on('submit(sureSubmit)', function (data) {
            $("#sureSubmit").attr("disabled","true");
            if(checkOrder){
                return false;
            }
            var dat = data.field;
            var imgs = dat.imgs;
            var id = dat.id;
            if(isBlank(imgs)){
                layer.msg('请上传支付凭证！', {icon:2});
                return false
            }
            checkOrder = true;
            $.ajax({
                type:"POST",
                url:"${ctx}/siteReceipt/CashSettlement",
                data:{
                    id:id,
                    imgs:imgs
                },
                success:function(result){
                    checkOrder = false;
                    if(result.code ==200){
                        layer.closeAll()
                        parent.layer.closeAll();
                        parent.layer.msg('结账成功！', {icon:1,time:1000},function(){
                            console.log("sdjkhshdhs")
						//parent.layui.table.reload('settlementList');
                        });
                    }else if(result.code == "505"){
                        layer.msg('保存失败!', {icon:2,time:1000},function(){
                            layer.closeAll()
                        });
                    }else if(result.code == '402'){
                        layer.msg("请款金额大于钱包金额",{icon:2})
					}else{
                        layer.msg('保存失败,数据有误', {icon:2,time:1000});
                    }
                }
            });
            return false;
        })

        
        function isBlank(val){
        	if(val==null || $.trim(val)=='' || val==undefined){
        		return true;
        	}
        	return false;
        }
        
        form.verify({
            imgsCheck: function(value, item){ //value：表单的值、item：表单的DOM对象
                if(isBlank(value)){
                	return "请上传支付凭证！";
                }
            }
        });

        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#uploader' //绑定元素
            , url: '${ctx}/common/uploadFile' //上传接口
            ,size:5*1024
            ,number:1
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                	
                });
            }
            , done: function (res) {
            	if(res.code > 0){
            		return layer.msg("上传失败！",{icon:2});
            	}
            	var imgPath = res.path;
            	$('#pic').attr('src', '${commonStaticImgPath}'+imgPath); //图片链接（base64）
                $("#pic").show();
            	$("#imgs").val(imgPath);
            }
            , error: function () {
                //请求异常回调 演示失败状态
            }
        });

    });
</script>
</body>
</html>
