$(document).ready(function () {
  $(".jiajian").on("click", "button", function (e) {
    var on = $(this).attr("dota");
    var val = parseInt($(this).siblings("#itemjiajian").val());
    val ? "" : (val = 1);
    if (on == 1) {
      val += 1;
    } else {
      val -= 1;
    }
    val <= 0 ? (val = 1) : "";

    $(this).siblings("#itemjiajian").val(val);
  });

  /* 加入购物车 */
  var type = true;
  $(".tijiao").on("click", "button", function () {
    var num = $("#itemjiajian").val();
    var count = parseInt(num); //商品数量
    if (!num || count <= 0) {
      body_frame("", ichilang.JSLANG24);
      return false;
    }
    if (type == true) {
      type = false;
      var url = "/shoppingCart/addShoppingCart";
      var scode = $("#scode").val(); //商品id
      const name = $("#cdescript").val();
      const img = $("#img").val();
      const price = $("#price").val();
      const cat = $("#cat").val();
      var data = { scode: scode, count: count, name, img, price, cat };
      //改变当前相应商品购物车数量价钱
      // editShoppingCartList(scode, 1, count);
      //谷歌统计
      var items = [
        {
          id: scode,
          name: $("#cdescript").val(),
          list_name: "添加购物车", //列表名称
          price: $("#price").val(),
        },
      ];
      gtag_funs(ichilang.JSLANG25, "", "add_to_cart", items);
      //

      var that = this;
      $.post(
        "/Public/js_api_login",
        { url: url, data: data },
        function (result) {
          if (result["success"]) {
            if ($(that).hasClass("submit1")) {
              body_frame("", result.msg, 1);
              if (result["data"] != null) {
                addShoppingCartDom(result['data'])
              }
            } else {
              //body_frame('',result.msg,1);
              location.href = getComputedUrl("/user/shopping.html");
            }
          } else {
            body_frame("", result.msg);
          }
          type = true;
        },
        "json"
      );
    }
  });
});
