<%@page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8" %>
<%@ include file="header.jsp" %>
<script type="text/javascript" src="<%=webpath%>/js/business/coupon.js"></script>
<script type="text/javascript" src="<%=webpath%>/js/DatePicker/WdatePicker.js"></script>
<script type="text/javascript">
	var gobalFlag = true;
    function query() {
        var vin = $("#vininput").val();
        var electronicAccounts = $("#electronicAccounts").val();
        if ((vin == null || vin == '') && (electronicAccounts == null || electronicAccounts == '')) {
            alert("查询条件不能为空");
            return;
        }
        var path = $("#paths").val();
        var url = path + "/coupon/get_coupon.do";
        var queryParams = {};
        queryParams['vin'] = vin;
        queryParams['electronicAccounts'] = electronicAccounts;
        queryCouponList(url, queryParams);

    }
    function clearVal() {
        $("#vininput").val("");
    }

	 function toggleClick(){
		if(gobalFlag){
			$("#submitBtn").attr("disabled",true); 
			submitconsume();
		}
		else {
			return false;
		} 
	} 
	
    function submitconsume() {
        var vinCode = $("#vinCode").val();
        var consumeCount = $("#consumeCount").val();
        var remark = $("#remark").val();
        var epassword = $("#epassword").val();

        var consumeTime = $("#consumeTime").val();

        var balance = $("#balance").val();
        /* 	var reparieInfo=$("#reparieInfo").val();
         var hitchInfo=$("#hitchInfo").val();
         */
        if (vinCode != null && vinCode != '' && consumeCount != null && consumeCount != '' && remark != null && remark != '' && epassword != null && epassword != '' && consumeTime != null && consumeTime != '') {
            if (parseFloat(balance)  <  parseFloat(consumeCount)) {
                alert("消费金额过大，请重新输入消费金额");
                $("#consumeCount").val("");
                gobalFlag = true;
                $('#submitBtn').removeAttr('disabled');
                return;
            }
            var params = {};
            params['vinCode'] = vinCode;
            params['consumeCount'] = consumeCount;
            params['remark'] = remark;
            params['epassword'] = epassword;
            params['consumeTime'] = consumeTime;
			gobalFlag = false;	
            var result = ajaxgetresultpost($("#paths").val()
                + '/coupon/consume.do', params);     
            if(result){
            	//$("#submitBtn").unbind("click");
            	if (result.flag == 0) {
	                alert(result.msg);
	                $('#submitBtn').removeAttr('disabled');
	            } else if(result.flag == 1){
	                alert(result.msg);
	                $("#consume_dialog").hide();
	                query();
	                $('#submitBtn').removeAttr('disabled');
	            }else {
	            	 alert(result.msg);
	                $("#consume_dialog").hide();
	                query();
	                $('#submitBtn').removeAttr('disabled');
	            }
	    
	            gobalFlag = true;
            }else{
            	alert("服务器出错");
            	gobalFlag = true;
            	$('#submitBtn').removeAttr('disabled');
            	
            }
        } else {
            alert("提交数据不能为空");
            gobalFlag = true;
            $('#submitBtn').removeAttr('disabled');
        }
        //console.log(gobalFlag);

    }

    $(".opera").bind("click", function () {
        $(".order_undo").show();
    });

    $(document).on('click', '.cancel', function () {
        $("#consumeCount").val("");
        $("#consumeTime").val("");
        $("#epassword").val("");
        $("#remark").val("");
        $('#submitBtn').removeAttr('disabled');
        $(".order_undo").hide();
    });


    /*   $(document).on('click','.datagrid-row',function(){
     showConsumePanel(this.vinCode);
     }); */


    /* $(".cancel").bind("click",function(){
     alert(1);
     $(".order_undo").hide();
     }) */
    $(document).ready(function () {
        queryCouponList("", "");
    })
</script>
<input type="hidden" id="paths" value="<%=path%>"/>
<div id="main">
    <div class="search">
        <table class="searchTable">
            <tbody>

            <tr>


                <td style="position:relative;">
                    VIN码:&nbsp;&nbsp;
                    <span id="input34Wrap">
							<input id="vininput" name="endSubmitDate"
                                   type="text" value="" class="mc-ipt-text hasDatepicker" style=""/>
							<span class="mc-ipt" style="width:90%;"> <span
                                    id="input33Tip" class="mc-ipt-tip-query"
                                    style="font-size: 11px; line-height: 40px; height: 40px;">
									<font></td>

                <td>
                    <span class="inputTitle">电子账户:</span>
                    <input id="electronicAccounts" name="electronicAccounts" type="text" value=""
                           class="mc-ipt-text hasDatepicker" style=""/>
                </td>

                <td>
                    <button class="t-button searchBtn" id="CaseInfoList2btnCtClear"
                            type="button" onclick="clearVal();">
                        <img class="searchIcon" src="../images/clear.png">清空
                    </button>
                    <button class="t-button searchBtn" style="margin-right:10px;"
                            id="CaseInfoList2btnCtSearch" type="button" onclick="query();">
                        <img class="searchIcon" src="../images/search.png">搜索
                    </button>
                    <!-- <button class="searchBtn"><img class="searchIcon" src="../images/clear.png">清空</button> -->
                    <!-- &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
     <button class="t-button" id="CaseInfoList2btnCtSearch" type="button" onclick="query();">
     <font>
     <font>&nbsp;&nbsp;搜 索&nbsp;&nbsp;</font>
     </font>
     </button> -->
                </td>

                <td></td>
            </tr>
            </tbody>
        </table>
    </div>

    <table id="datatable"></table>
</div>


<div class="order_undo" id="consume_dialog" style="display: none;">
    <input type="hidden" value="" id="vinCode">
    <input type="hidden" value="" id="balance">
    <div class="dialog_default">
        <div class="dialog_title">代金券消费</div>
        <div class="dialog_con">
            <div class="result_input">
                <span class="line">&nbsp;</span><span id="balancetext">余额</span>
            </div>
            <div class="result_input">
                <span class="line">&nbsp;</span>消费金额
            </div>
            <input class="money_con" onkeyup="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')" id="consumeCount">

            <div class="result_input">
                <span class="line">&nbsp;</span>消费时间
            </div>
            <input type="text" id="consumeTime" name="consumeTime" class="Wdate money_con" readonly="readonly"
                   onfocus="WdatePicker({errDealMode:2,readOnly:true,startDate:'%y-%M-%d %H:%m:%s',dateFmt:'yyyy-MM-dd'})"
                   style="cursor:pointer;height:40px;"/>

            <div class="result_input">
                <span class="line">&nbsp;</span>消费密码:
            </div>
            <input class="money_con" id="epassword" type="password">

            <div class="result_input">
                <span class="line">&nbsp;</span>DMS单号:
            </div>
            <input class="money_con" id="remark" type="text">


            <br>

            <!-- <div class="result_input">
                <span class="line">&nbsp;</span>维修信息
            </div>
            <input class="money_con" id="reparieInfo" type="text">

            <div class="result_input">
                <span class="line">&nbsp;</span>故障信息
            </div>
            <input class="money_con" id="hitchInfo" type="text">
            -->
            <div class="confirm_cancel clearfix">
                <input class="btn2" type="button" onclick="toggleClick();" id="submitBtn" value="提&nbsp;&nbsp;交" /> 
                <input type="button" class="btn1 cancel" value="取&nbsp;&nbsp;消" />
            </div>
        </div>
    </div>
</div>


<!-- <div id="consume_dialog" style="padding:10px;display: none;" >
<input type="hidden" value="" id="vinCode">
消费金额 <input type="text" id="consumeCount" style="width:215px;"></br>
维修信息 <input type="text" id="reparieInfo" style="width:215px;"></br>
故障信息 <input type="text" id="hitchInfo" style="width:215px;"></br>
<input type="button" value="提交" onclick="submitconsume();">
</div> -->
<%@ include file="footer.jsp" %>