exchange.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. $(function () {
  2. //领取优惠券
  3. $(document).on('click', '.btn-exchange', function () {
  4. let id = $(this).data('id');
  5. let type = $(this).data('type');
  6. let html = $('#exchangetpl').html();
  7. layer.open({
  8. title: '兑换商品',
  9. type: 1,
  10. area: ['450px', type == 'reality' ? '300px' : '250px'], //宽高
  11. content: html,
  12. success: function () {
  13. $(document).on('click', '.btn-submit-exchange', function () {
  14. let form = $('#exchange-form').serializeArray();
  15. let data = {exchange_id:id};
  16. form.forEach(item => {
  17. data[item.name] = item.value;
  18. })
  19. SHOP.api.ajax({
  20. url: "/addons/shop/exchange/exchange",
  21. data: data
  22. }, function (res) {
  23. setTimeout(() => {
  24. window.location.reload();
  25. }, 1500)
  26. });
  27. })
  28. }
  29. })
  30. })
  31. // 增减数量
  32. $(document).on("click", ".quantity > div", function () {
  33. var input = $(this).siblings("input");
  34. var value = parseInt(input.val());
  35. var max = input.attr("max");
  36. var min = input.attr("min");
  37. var stocks = 0;
  38. value = $(this).text() == '-' ? value - 1 : value + 1;
  39. stocks = parseInt(input.data("stocks"));
  40. if (value >= stocks) {
  41. input.val(stocks);
  42. layer.msg("最多可以购买" + stocks + "件");
  43. return;
  44. }
  45. value = min != '' ? Math.max(min, value) : value;
  46. value = max != '' ? Math.min(max, value) : value;
  47. input.val(value);
  48. return false;
  49. });
  50. })