<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> 
<!DOCTYPE html>
<html>
<jsp:include page="../../common.jsp" />

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
	content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>消费记录</title>
</head>
<body class="pb100">
        <div class="positionf wp100 left0 top0 zindex100 bluebg h40 tcenter">
            <div>
                <a href="${ctx }/vip/myVIPCard?storeId=${sessionScope.sessionMerchantMenber.storeId}&phone=${sessionScope.sessionMerchantMenber.phone}" class="white f21 h40 left0 top0 positiona">
                    <span class="dblock w40 h40 icon icon-59 white f22"></span>
                </a>
                <span class="white">消费记录</span>
            </div>
        </div>
        <!-- 容器 -->
        <div class="weui-tab">
            <div class="mt60">
                <div id="data_content">
                <c:forEach items="${merchantMenberComsumeList }" var="mcs">
                    <div class="weui-flex pt10 pb10 bdbe">
                          <div class="ml10"><img src="https://www.shouyinbei.net/resources/wap/images/bg.png" class="dlblock fc radiusp50 vm" width="45" height="45"/></div>
                           <div class="weui-flex__item">
                                    <div class="mb10 f16 tleft ml10 f-black">${mcs.nickName }</div>
                                    <div class="f14 ml10"><fmt:formatDate value='${mcs.createDt }' pattern='yyyy-MM-dd HH:mm:ss' /></div>
                          </div>
                          <div class="mr10 f16 tright pt10 f-black">-${mcs.comsumeMoney }</div>
                    </div>
                </c:forEach>
                </div>      
            </div>
        </div>
    </body>
    <input type="hidden" id="memberCode" name="memberCode" value="${memberCode }" />
    <input type="hidden" id="storeId" name="storeId" value="${storeId }" />
    <!-- 定义分页的当前页码和总页码start -->
            <input type="hidden" id="currPage" value="1" />
            <input type="hidden" id="PageCount" value="0" />
    
    <script type="text/javascript">
    
    var pageIndex=1;
    $(document).ready(function(){
        //调用查询
        pageIndex=StringUtil.getQueryString('pageIndex');
        if(pageIndex==undefined||pageIndex==null){
            pageIndex=1;
        }
        queryConsumeLog(pageIndex);
    });
    
    var loading = false;  //状态标记
    $(document.body).infinite().on("infinite",function() {
      if(loading) return;
      loading = true;
      setTimeout(function() {
          if ($('#currPage').val()<=$('#PageCount').val()) {
              queryConsumeLog($('#currPage').val());
            } else {
                $.toast("已到底！", "text");
            }
        loading = false;
      }, 1500);   //模拟延迟
    });

    function queryConsumeLog(index){
        if(typeof(index)=='undefined'){
            index=1;
        }
         $.ajax({
             url:ctx+'/vip/goConsumeLog',
             data:{
                "currPage":index,
                "memberCode":$("#memberCode").val(),
                "storeId":$("#storeId").val(),
             },
             dataType:"json",
             type:"post",
             success:function(result){
            	 if(result.merchantMenberComsumeList.lenght==0){}else{
            		 var data='';
                     $.each(result.merchantMenberComsumeList,function(i){
                         var merchantMenberComsume=result.merchantMenberComsumeList[i];
                         var createDt='';
                         if(StringUtil.isNotBlank(merchantMenberComsume.createDt)){
                        	 createDt = myTime(merchantMenberComsume.createDt);
                         	createDt = formatDateTime(createDt);
                         }
                        data+='<div class="weui-flex pt10 pb10 bdbe">';
                        data+='<div class="ml10"><img src="'+ctx+'/resources/images/bg.png" class="dlblock fc radiusp50 vm" width="45" height="45"/></div>';
                        data+=' <div class="weui-flex__item">';
                        data+=' <div class="mb10 f16 tleft ml10 f-black">'+merchantMenberComsume.nickName+'</div>';
                        data+='<div class="f14 ml10">'+createDt+'</div>';
                        data+='</div>';
                        data+='<div class="mr10 f16 tright pt10 f-black">-'+merchantMenberComsume.comsumeMoney+'</div>';
                        data+='</div>';
                     });
                     $('#data_content').append(data);
                     $('#currPage').val(result.currPage + 1);
                     $('#PageCount').val(result.pageCount);
            	 }
                
                 
                 
                 
             }
          })
    }
    
    
    function myTime(date){
        var arr=date.split("T");
        var d=arr[0];
        var darr = d.split('-');

        var t=arr[1];
        var tarr = t.split('.000');
        var marr = tarr[0].split(':');

        var dd = parseInt(darr[0])+"/"+parseInt(darr[1])+"/"+parseInt(darr[2])+" "+parseInt(marr[0])+":"+parseInt(marr[1])+":"+parseInt(marr[2]);
        return dd;
    }

    function  addZero(num) {
        return num < 10 ? '0' + num : num;
    }

    function formatDateTime (date) {
        var time = new Date(Date.parse(date));
        time.setTime(time.setHours(time.getHours() + 8));
        var Y = time.getFullYear() + '/';
        var M = this.addZero(time.getMonth() + 1) + '/';
        var D = this.addZero(time.getDate()) + ' ';
        var h = this.addZero(time.getHours()) + ':';
        var m = this.addZero(time.getMinutes()) + ':';
        var s = this.addZero(time.getSeconds());
        return Y + M + D + h + m + s;
    }

    </script>
    
</html>