var fullStartOfMonth = getFullDate( cloneNowDate.setDate(1) );
var fullEndOfMonth = getFullDate( cloneNowDate.setDate(endOfMonth) );
    var info =[];
    UrlSearch();
    function UrlSearch() {
        var name,value;
        var str=location.href;
        var num=str.indexOf("?");
        str=str.substr(num+1);
        var arr=str.split("&");
        for(var i=0;i < arr.length;i++){
            num=arr[i].indexOf("=");
            if(num>0){
                name=arr[i].substring(0,num);
                value=arr[i].substr(num+1);
                this[name]=value;
                info.push(value)
            }
        }
    }
var page = 1, pageSize = 10;

$('#J_List').infiniteScroll({
    pageSize: pageSize,
    initLoad: true,
    loadingHtml: '<strong>加载中...</strong>', /* 当然也可以<img src="../img/loading.gif" /> */
    loadListFn: function () {
        var def = $.Deferred();
        $.ajax({
            url:Url+'/record/v1/getPageRecordInstanceList',
            type:'get',
            data:{
                startTime:fullStartOfMonth,
                endTime:fullEndOfMonth,
                pageId:info[0],
                pageRecordParentId:info[1],
                pageNumber:page,
                pageSize:pageSize
            },
            success:function (res) {
                if (res.code === '200') {
                    for (var k = 0; k < res.data.length; k++) {
                        var html = ` <div class="card">
                                        <div class="card-content">
                                            <div class="card-content-inner card-content-inner${k}">
                                                <!-- 列表1 -->
                                                <a href="javascript:;" >
                                                    <div class="list">
                                                        <img class="more" src="./img/more.png">
                                                        <div class="items${k}">
                                                            
                                                        </div>
                                                    </div>
                                                </a>
                                            </div>
                                        </div>
                                    </div>`;
                        $('#J_ListContent').append(html);
                        for (var i = 0; i < res.data[k].length; i++) {
                            var str =`<div class="child-list">
                                            <img class="icon" src="./img/${res.data[k][i].statusFlag ==true?'ic_medicine_active':'ic_medicine_inactive'}.png">
                                            <div class="name">${res.data[k][i].createName}</div>
                                            <div class="time">${res.data[k][i].createDate}</div>
                                            <div class="status statusZ${res.data[k][i].recordParentId}">巡检状态：</div>
                                        </div>`;
                            $('.items'+k).append(str);
                            $('.card-content-inner'+k).attr("recordParentId",res.data[k][i].recordParentId);
                            for (var r = 0; r < res.data[k][i].recordStatusInstanceList.length; r++) {
                                var status = `<span>${res.data[k][i].recordStatusInstanceList[r].statusName}</span>`;
                                $('.statusZ'+res.data[k][i].recordParentId).append(status)
                            }
                        }
                    }
                    def.resolve(res.data);
                    ++page;
                }
            }
        });
        return def.promise();
    }
});
$('body').on('click','.card-content-inner',function () {
    var recordParentId = $(this).attr('recordParentId');
    location.href ='note-detail.html?recordParentId='+recordParentId;
});
