﻿function snapSeatSubmit(index) {
    var item = findSnapRecord(index);
    if (item == null) {
        return false;
    }
    switch (item.st) {
        case 2: //竞拍开放
            {
                var currentT;
                //判断是否处于抢购时间内

                if (snaps.sysT >= item.sbti && snaps.sysT <= item.seti) {
                    if (!usersnapstatus) {
                        snapSeatActionInfo(index);
                    }
                }
                else if (snaps.sysT < item.sbti) {
                    xMsgBox.showMsgbox("商品未到开抢时间，请耐心等待！<br/>您可以参与其他即将开抢的其他商品。<br/><a href='" + GlobalHref.Default_R("DouZ") + "'>查看即将抢购的商品</a>", "info", true, 0);
                } else if (snaps.sysT > item.seti) {
                    xMsgBox.showMsgbox("本日抢购已结束！", "info", true, 0);
                }
            }
            break;
        case 3: //竞拍停拍
            {
                xMsgBox.showMsgbox("临时停拍！", "info", true, 0);
            }
            break;
        case 4: //抢购结束
            {
                xMsgBox.showMsgbox("已抢购结束！", "info", true, 0);
            }
            break;
        case 5:
            {
                xMsgBox.showMsgbox("已流拍！", "info", true, 0);
            }
            break;
        default:
            xMsgBox.showMsgbox("未知状态，请联系客服！", "info", true, 0);
            break;
    }
}

function snapSeatActionInfo(gid) {
    function seatSnapEvents_success(data) {
        if (!data || data == 'undefined') {
            return;
        }
        if (data.length == 0) {
            FailHandle();
        }
        else {
            if (data.action == "error") {
                xMsgBox.showMsgbox(data.reason, "error", true, 0);
            }
            else {

                if (data.snapRecords.length > 0) {

                    updateSnaps(data.snapRecords[0]);
                    updateShowDiv(data.snapRecords[0]);
                    if (pageArea == "list") {
                        
                    }
                    if (pageArea == "seat") {
                        updateSeatAccount(data.snapRecords[0].gid);
                        getSeatSnapRecordsList(data.snapRecords[0].gid);
                        xMsgBox.showMsgbox("完成一次订位抢购！", "info", false, 1000);
                    }
                }
            }
        }
        usersnapstatus = false;
        requeststatus = false;
    }

    function seatSnapEvents_error() {
        usersnapstatus = false;
        requeststatus = false;
        FailHandle();
    }

    function seatSnapEvents_before() {
        //状态控制
        usersnapstatus = true;
        requeststatus = true;
        //window.clearInterval(intervalID);
    }
    ajax_json_getV1('Services/AddSeatSnapActive.ashx?gid=' + gid + "&r=" + Math.random(), 10000, true, seatSnapEvents_success, seatSnapEvents_error, seatSnapEvents_before);
}

function updateSeatAccount(gid) {

    var seattemp = parseInt($("#u_g_rtimes_" + gid).html());
    if (seattemp > 0) {
        seattemp = seattemp - 1;
    }
    $("#u_g_rtimes_" + gid).html(seattemp);
}
