• 最小库存单元


    <h2>Detail</h2>

    <table>
    <tr>
    <td>
    <img id="img1" src="" alt="" width="300" height="400"/>
    </td>
    <td>
    <table>
    <tr>
    <td id="td1"> </td>
    </tr>
    <tr>
    <td id="td2"> </td>
    </tr>
    <tr>
    <td id="td3"> </td>
    </tr>
    <tr>
    <td id="td4">

    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>

    <script>
    var sku = [];
    var OldPrice = "";
    var currentSku = {};

    function load() {
    var id = @ViewBag.Id;
    $.ajax({
    url: 'http://localhost:56334/api/Default/GetONe/'+id,
    type: 'get',
    dataType: 'json',
    success: function (data) {
    $("#img1").attr("src", data.Imgs[0].ImageUrl);
    $("#td1").text(data.Goods.Name);
    $("#td2").text(data.Goods.Price);
    OldPrice = data.Goods.Price;
    sku = data.Sku;

    $(data.Attr).each(function () {
    $("#td3").append( this.AName +":"+this.Value +"<br/>");
    });


    $(data.SKUAttr).each(function () {
    var str = "";
    var check = "checked";
    var values = $(this.AValue).each(function () {
    str += "<input " + check + " type='radio' name='AA" + this.AttributeId + "' value='" + this.Value + "' onclick='changePrice()'> " + this.Value
    check = "";
    });
    $("#td4").append(
    ' <div>'+ this.AName+
    ' :'+ str+
    '</div>')
    });
    }
    });


    }
    load();

    function changePrice() {
    var price = "";

    var s = [];
    $(":radio:checked").each(function () {
    s.push( $(this).val());
    });

    $(sku).each(function () {
    var sign = 1;
    for (var i = 0; i < s.length; i++) {
    if (this.AttrStr.indexOf(s[i]) == -1) {
    sign = 0;
    }
    }
    if (sign == 1) {
    price = this.Price + "";
    currentSku = this;
    }
    });

    if (price != "")
    $("#td2").text(price);
    else
    $("#td2").text(OldPrice);
    }
    </script>

    ----------------------------------------------------------------------------------------------

    <h2>Index</h2>

    <div id="dv">
    <table style="float:left">
    <tr>
    <td>
    <img src="" width="80" height="120" />
    </td>
    <tr />

    <tr>

    <td>
    <span></span>
    <span></span>
    </td>
    </tr>
    </table>
    </div>
    <div style="clear:both"></div>

    <script>
    function load()
    {
    $.ajax({
    url: 'http://localhost:56334/api/Default/GetAll',
    type: 'get',
    dataType: 'json',
    success: function (data) {
    $("#dv").empty();
    $(data).each(function () {
    $("#dv").append(
    '<table style="float:left">'+
    ' <tr>'+
    ' <td>'+
    ' <a href="/Default/Detail/'+this.Goods.Id+'"> <img src="'+this.Img+'" width="80" height="120" /></a>'+
    ' </td></tr><tr>'+
    ' <td>'+
    ' <span>'+this.Goods.Name+'</span>'+
    ' <span>'+this.Goods.Price+'</span>'+
    ' </td>'+
    ' </tr>'+
    '</table>'
    );
    });
    }
    });
    }
    load();
    </script>

    --------------------------------------------------------------------------------------------------------------------

    MyShopDB db = new MyShopDB();
    public object GetAll()
    {
    var list = db.Goods_SPU.ToList();
    var data = list.Select(p => new { Goods = p, Img = db.Image.Where(k => k.SPUID == p.Id ).FirstOrDefault().ImageUrl });
    return data;
    }

    public object GetOne(int Id)
    {
    // 获取商品
    Goods_SPU goods = db.Goods_SPU.Find(Id);
    // 获取商品的SPU属性
    var goods_Attribute = (from S in db.SPUAttribute
    join A in db.Attribute
    on S.AID equals A.Id
    where A.AttributeType == 0
    select new
    {
    Id = S.SPID, // 商品ID
    AId = S.AID, // 属性ID
    AType = A.InputType ,// 属性的输入类型
    AName = A.AttributeName, //属性名
    AValue = db.AttributeValue.Where(p => p.AttributeId == S.AID).ToList(),// 属性值列表
    Value = S.Value // 实际值
    }).ToList();
    // 获取商品的SKU属性
    var goods_SKU_Attribute = (from S in db.SPUAttribute
    join A in db.Attribute
    on S.AID equals A.Id
    where A.AttributeType == 1
    select new
    {
    Id = S.SPID, // 商品ID
    AId = S.AID, // 属性ID
    AType = A.InputType,// 属性的输入类型
    AName = A.AttributeName, //属性名
    AValue = db.AttributeValue.Where(p => p.AttributeId == S.AID).ToList(),// 属性值列表
    Value = S.Value // 实际值
    }).ToList();

    var imgs = db.Image.Where(p => p.SPUID == Id).ToList();
    var sku = db.Goods_SKU.Where(p => p.SPUID == Id).ToList();

    return new {
    Goods=goods, // 商品本身
    Attr=goods_Attribute, // 商品属性
    SKUAttr = goods_SKU_Attribute, // 商品库存属性
    Imgs =imgs, // 商品图片
    Sku=sku // 商品规格列表
    };
    }

    -------------------------------------------------

  • 相关阅读:
    1300 · 巴什博弈
    1 · A + B 问题
    37 · 反转一个3位整数
    145 · 大小写转换
    Spring-Boot整合freemarker引入静态资源css、js等
    Monkey API学习与脚本编写小记
    Mac终端快速启动uiautomatorviewer
    Mac解决使用uiautomatorviewer会报错:./uiautomatorviewer 03:56:07 E/Screenshot: Unsupported protocol: 2
    charles抓包https乱码问题解决-转载
    mac解决adb devices命令找不到真机设备
  • 原文地址:https://www.cnblogs.com/gc1229/p/13381655.html
Copyright © 2020-2023  润新知