/**
 * Created by Administrator on 2017/7/25.
 */
var pageNumber = 0,pageSize=5;
var shareId = getParam("shareId");
mui.ready(function() {
    ++pageNumber;
    mui.ajax(base_path + '/qrcode/select_admin_machine?dates=' + new Date().getTime(), {
        data: {
            "pageNO":pageNumber,"pageSize":pageSize
        },
        dataType: 'json',
        type: 'post',
        timeout: 15000,
        success: function(dt) {
            if(dt.isRedirect) {
                location.href = dt.redirectURL;
            } else {
                if(dt.status) {
                    var data = dt.data;
                    var table = document.body.querySelector('.my-eq-list');
                    if(data.length>0){
                        $(".middle-div").css("padding-top","0");
                    }
                    mui(data).each(function(index) {
                        var li = document.createElement('li');
                        li.className='mui-table-view-cell';
                        li.innerHTML = '<a class="mui-navigate-right" href="update_personal_information.html?id=' + this.numberId + '">'
                            + '<div class="my-table">'
                            + '<div>'
                            + '<span class="iconfont icon-chanpintiyan"></span>'
                            + '<div class="number">' + subStr(this.numberBarcode) + '</div>'
                            + '</div>'
                            + '<div>购买日期<br><span class="time">' + dateFormat(this.numberSalesTime) + '</span></div>'
                            + '<div>录入日期<br><span class="time">' + dateFormat(this.numberCreateTime) + '</span></div>'
                            + '</div>'
                            + '</a>'
                        table.appendChild(li);
                    });
                } else {
                    mui.alert(dt.message);
                }
            }
        },
        error: function(xhr, type, errorThrown) {
            //异常处理；
            console.log(xhr);
        }
    });
    document.querySelector('.loading-bg').style.display = 'none';
});

function subStr(str) {
    var value = '';
    if (str.length > 6) {
        value = str.substring(str.length-6,str.length);
    } else {
        value = str;
    }
    return value;
}


mui('body').on('tap', '.bind-img', function() {
    location.href="personal_information.html"
    //不带机器id的有扫描二维码
});
mui('body').on('tap', '.my-eq-list>li>a', function() {
    location.href=this.getAttribute("href");
    //把机器id带到下个页面去判断，有机器id就隐藏二维码扫描功能
});

function dateFormat(now) {
    if (now == null || now == '') {
        return '暂无';
    } else {
        now = new Date(now);
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        return year + "-" + month + "-" + date
    }
};

/*
mui('body').on('tap', '.mui-navigate-right', function() {
    mui.openWindow({
        /!*url: '/tooth/view/personal_information.html'*!/
        url: '/tooth/view/update_personal_information.html'
    })
});*/
