/*手机端通用获取商品列表*/
$(document).ready(function(){
    $('.add_goods_more').click(function(){
        page++;
        get_goods_list('','',page);
    });
});
var querydata = new Object;
var page = 1;
function get_goods_list(id,filter,page){
    page=parseInt(page);if(!page)page=1;
    querydata['page']=page;
    if(filter=='cat_id'&&id){querydata[filter]=id;}//分类
    if(filter=='order'&&id){querydata[filter]=id;}//排序
    $.ajax({
        url:queryurl,
        type: "post",
        data: querydata,
        dataType: "json",
        success: function (ret) {
            if (ret.status) {
                if(page==1){
                    $('#guessList').html(ret.data);
                }else{
                    $('#guessList').append(ret.data);
                }
                
                if(querydata['order_name']=="addtime"){
                    $("#addtime").addClass("on");
                }else{
                    $("#addtime").removeClass("on");
                }
                if(querydata['order_name']=="sell_count"){
                    $("#sell_count").addClass("on");
                }else{
                    $("#sell_count").removeClass("on");
                }
                if(querydata['order_name']=="shop_price"){
                    $("#shop_price").addClass("on");
                }else{
                    $("#shop_price").removeClass("on");
                }
            }else{
                if(page==1){
                    $('#no-content').html('暂无数据');
                }
                $.showSuccess('没有更多的数据了',1,'hc');
            }
        }
    });
}

/**
 *（商品、轮播图）加入我的小店
 * @param type 1：商品 0：轮播图
 * @param id 商品或轮播图id
 */
function add_myshop(id,type){
    var query=new Object();
    if(type==0){
        query.banner=id;
    }else{
        query.goods_id=id;
    }
    query.type=type;
    $.ajax({
        url:APP + "Mobile/LittleShop/add_myshop",
        data:query,
        type:"post",
        success:function(data){
            if(data.status==1) {
                $.showSuccess(data.msg,0,'hc');
                if(type==1){  //商品
                    $("#add_btn_"+id).addClass('over_add');
                    $("#add_btn_"+id).html("已添加");
                }
            }else{
                $.showErr(data.msg,0,'hc');
                if(data.url){
                    window.location.href=data.url;
                }
            }
        }
    })
}

/**
 *从我的小店中删除轮播图
 * @param 轮播图id
 */
function delete_myshop(banner_id){
    var query=new Object();
    query.id=banner_id;
    $.ajax({
        url:APP + "Mobile/LittleShop/delete_myshop",
        data:query,
        type:"post",
        success:function(data){
            if(data.status==1) {
                $.showSuccess(data.msg,0,'hc');
                $("#remove_"+banner_id).css('display','none');
            }else{
                $.showErr(data.msg,0,'hc');
                if(data.url){
                    window.location.href=data.url;
                }
            }
        }
    })
}

/**
 *从我的小店中修改商品
 * @param goods_id 商品id
 * @param shop_id 小店id
 * @param type 1：商品下架 2：是否首页推荐
 * @param status 用于我的精选下架 刷新页面
 */
function update_myshop(goods_id,shop_id,type,status){
    var query=new Object();
    query.goods_id=goods_id;
    query.shop_id=shop_id;
    query.type=type;
    $.ajax({
        url:APP + "Mobile/LittleShop/update_myshop",
        data:query,
        type:"post",
        success:function(data){
            if(data.status==1) {
                if(data.msg)$.showSuccess(data.msg,0,'hc');
                if(type==0){
                    $(".s_goodsj_ul").html('<a class="downxia" onClick="update_myshop('+goods_id+','+shop_id+',1)">商品下架</a>');
                }else if(type==1){
                    $("#remove_"+goods_id).css('display','none');
                    $(".s_goodsj_ul").html('<a class="upshang" onClick="update_myshop('+goods_id+','+shop_id+',0)">商品上架</a>');
                }else{
                    if(data.data.is_show==1){
                        $("#is_show_"+goods_id).addClass('on');
                        $("#htmlshow_"+goods_id).html('已推荐');
                    }else{
                        $("#is_show_"+goods_id).removeClass('on');
                        $("#htmlshow_"+goods_id).html('推荐');
                    }
                    
                }
                $("#up_num").html('出售中('+data.data.up_num+')');
                $("#down_num").html('已下架('+data.data.down_num+')');
                if(status){
                    // $.showSuccess('下架成功',0,'hc');
                    window.location.reload();
                }
                
            }else{
                if(data.msg)$.showErr(data.msg,0,'hc');
                if(data.url){
                    window.location.href=data.url;
                }
            }
        }
    })
}

