<%@ page import="com.alibaba.fastjson.JSON" %>
<%@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_query.js"></script>
<script type="text/javascript" src="<%=webpath%>/js/DatePicker/WdatePicker.js"></script>
<style>

    table.searchTable td:nth-last-child(1) {
        width: 25%;
    }

    table.searchTable td {
        width: auto;
    }
    table.searchTable td input {
        width:60%;
    }
</style>
<%
    LoginUserVo vo = (LoginUserVo) request.getSession().getAttribute("logininfo");
%>
<script type="text/javascript">

    function query() {
        var path = $("#paths").val();
        var uri = path + "/coupon/consume_querys.do";
        var queryParams = {};
        queryParams['vininput'] = $("#vininput").val();
        queryParams['electronicAccounts'] = $("#electronicAccounts").val();
        queryParams['license'] = $("#license").val();
        queryParams['phone'] = $("#phone").val();
        queryParams['rescueCompanyName'] = $("#rescueCompanyName").val();
        queryParams['queryDate1'] = $("#queryDate1").val();
        queryParams['queryDate2'] = $("#queryDate2").val();
        queryParams['checkState'] = $("#checkState").val();
        queryCouponList(uri, queryParams);
    }
    function clearVal() {
        $("#vininput").val("");
        $("#electronicAccounts").val("");
        $("#license").val("");
        $("#phone").val("");
        $("#rescueCompanyName").val("");
        $("#queryDate1").val("");
        $("#queryDate2").val("");
        $("#checkState").val("");
    }

    function updateSettle(states) {
        var data = $("#datatable").datagrid('getSelections');
        if (data.length > 0) {
        	var title="同意付款";
        	if(states==100){
        	 title="已付款";
        	}
            if (!confirm("即将"+title + data.length + "条记录")) {
                return;
            }
        } else {
            return;
        }
        var updateIds = "";
        for (var i = 0; i < data.length; i++) {
            if (data.length - 1 == i) {
                updateIds += data[i].ID;
            } else {
                updateIds += data[i].ID + ",";
            }
        }

        var path = $("#paths").val();
        $.post(path + "/coupon/consume_update.do", {
            ids: updateIds,
            state: states
        }, function (data) {
            query();
        });
    }

    function updateRevert() {
        var data = $("#datatable").datagrid('getSelections');
        if (data.length > 0) {
            if (!confirm("即将撤回" + data.length + "条记录")) {
                return;
            }
        } else {
            return;
        }
        var updateIds = "";
        for (var i = 0; i < data.length; i++) {
            if (data.length - 1 == i) {
                updateIds += data[i].ID;
            } else {
                updateIds += data[i].ID + ",";
            }
        }
        var path = $("#paths").val();
        $.post(path + "/coupon/consume_update.do", {
            ids: updateIds,
            state: 101
        }, function (data) {
            query();
        });
    }

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

    });

    $(document).on('click', '.cancel', function () {
        $(".order_undo").hide();
    });

    //导出数据
    function expordata() {
        var queryParams = {};
        queryParams['vininput'] = $("#vininput").val();
        queryParams['electronicAccounts'] = $("#electronicAccounts").val();
        queryParams['license'] = $("#license").val();
        queryParams['phone'] = $("#phone").val();
        queryParams['rescueCompanyName'] = $("#rescueCompanyName").val();
        queryParams['queryDate1'] = $("#queryDate1").val();
        queryParams['queryDate2'] = $("#queryDate2").val();
        queryParams['checkState'] = $("#checkState").val();

        var checkurl = $("#paths").val() + "/coupon/exportData.do";

        //刷新列表
        var data = ajaxgetresultpost(checkurl, queryParams);
        // alert(data.webUrl);
        if (data.result == 1) {
            $.messager.alert("提示", "导出数据失败");
        } else {
            //$("#dataexport_div").hide();
            window.open(data.webUrl);
        }

    }

    $(document).ready(function () {

        var path = $("#paths").val();
        var uri = path + "/coupon/consume_querys.do";
        queryCouponList(uri, {});
    })
</script>
<input type="hidden" id="paths" value="<%=path%>"/>
<div id="main">
    <div class="search">
        <table class="searchTable">
            <tbody>
            <tr>
                <td>
                    <span class="inputTitle">VIN码:</span>
                    <input id="vininput" name="vininput" type="text" value=""
                           class="mc-ipt-text hasDatepicker" style=""/>
                </td>

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

                <td>
                    <span class="inputTitle">车牌号:</span>
                    <input id="license" name="license" type="text" value=""
                           class="mc-ipt-text hasDatepicker" style=""/>
                </td>

                <td>
                    <span class="inputTitle">电话号码:</span>
                    <input id="phone" name="phone" type="text" value=""
                           class="mc-ipt-text hasDatepicker" style=""/>
                </td>


                <td>
                    <button class="t-button searchBtn" style="margin-left:10px;" type="button" onclick="expordata();">
                        导出报表
                    </button>
                    <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>


                </td>
            </tr>
            <tr>
                <td style="position:relative;">
                    <span class="inputTitle">经销商:</span>
                    <input id="rescueCompanyName" name="rescueCompanyName" type="text" value=""
                           class="mc-ipt-text hasDatepicker" style=""/>
                </td>
                <td>
                    <span class="inputTitle"> 开始日期: </span>
                    <input type="text" id="queryDate1" class="Wdate" readonly="readonly"
                           onfocus="WdatePicker({errDealMode:2,readOnly:true,startDate:'%y-%M-%d %H:%m:%s',dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'queryDate2\')||\'%y-%M-%d\'}'})"
                           style="cursor:pointer;"/>
                </td>

                <td>
                    <span class="inputTitle"> 结束日期: </span>
                    <input type="text" id="queryDate2" class="Wdate" readonly="readonly"
                           onfocus="WdatePicker({errDealMode:2,readOnly:true,startDate:'%y-%M-%d %H:%m:%s',dateFmt:'yyyy-MM-dd',maxDate:'%y-%M-%d',minDate:'#F{$dp.$D(\'queryDate1\')}'})"
                           style="cursor:pointer;"/>
                </td>

                <td>
                    <span class="inputTitle">审核状态:</span>
                    <select id="checkState"
                            style="width: 61%;height:30px;border-radius: 5px;
                           border: 1px solid #D2D2D2;
                           text-indent: 1em;color: #AFAFAF;"
                            class="finalChoice" tabindex="-1"
                            aria-hidden="true"
                            name="checkState">
                        <option value="" selected>-全部-
                        </option>
                        <option value="0">未结算</option>
                        <option value="10">同意付款</option>
                        <option value="100">已付款</option>
                        <option value="101">已撤销</option>
                    </select>
                </td>
                <td></td>
            </tr>
            </tbody>
        </table>
    </div>
    <div id="edit-tb" style="height:auto!important;padding-left:20px">
        <c:if test="${state == '0'}">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="updateSettle(10)">同意付款</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="updateSettle(100)">已付款</a>
        </c:if>
        <c:if test="${state == '1'}">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true"
           onclick="updateRevert()">撤销</a>
        </c:if>
    </div>
    <table id="datatable"></table>
</div>


<div class="order_undo" id="cosume_windowContent" style="display: none;">
    <div class="dialog_default" style="width: 1000px">
        <div class="dialog_title">
            代金券消费明细
        </div>
        <div class="dialog_con">
            <div id="moduleCtId">
                <div class="ng-scope">
                    <div ng-switch="v">
                        <div class="ng-scope" style="padding-top:30px;">
                            <span class="ng-binding" id="caseInfoEdit20MsgCtBackMsg"></span>
                            <table class="infoTable">
                                <tr>
                                    <td class="ng-binding" style="position:relative;">电子账户:
                                        <span class="mc-ipt" id="i-ELECTRONIC_ACCOUNTS"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">VIN:
                                        <span class="mc-ipt" id="i-VIN_CODE"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">车牌号:
                                        <span class="mc-ipt" id="i-LICENSE"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">客户电话:
                                        <span class="mc-ipt" id="i-USER_PHONE"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">经销商:
                                        <span class="mc-ipt" id="i-NAME"></span>
                                    </td>

                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">消费日期:
                                        <span class="mc-ipt" id="i-CONSUME_TIME"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">消费金额:
                                        <span class="mc-ipt" id="i-CONSUME_COUNT"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">故障信息:
                                        <span class="mc-ipt" id="i-HITCH_INFO"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">维修情况:
                                        <span class="mc-ipt" id="i-REPARIE_INFO"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">录入时间:
                                        <span class="mc-ipt" id="i-CREATE_TIME"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">审核时间:
                                        <span class="mc-ipt" id="i-SETTLE_TIME"></span>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2">
                                        <hr/>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="ng-binding" style="position:relative;">审批状态:
                                        <span class="mc-ipt" id="i-SETTLEMENT_STATE"></span>
                                    </td>
                                    <td class="ng-binding" style="position:relative;">DMS工单号:
                                        <span class="mc-ipt" id="i-REMARK"></span>
                                    </td>
                                </tr>

                            </table>
                        </div>
                    </div>
                </div>
            </div>
            <div class="confirm_cancel clearfix">
                <a onclick="$('#cosume_windowContent').hide();" id="caseInfoEdit20SelCtshow_OK" class="btn2">确&nbsp;&nbsp;定</a>
            </div>
        </div>
    </div>
</div>
<%@ include file="footer.jsp" %>