Detail.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. var purchaseQuantity = 1
  2. var areaId = 0
  3. function init(skuHistoricalPrice, skuPrice) {
  4. var priceInput = document.getElementById("irpc-input")
  5. priceInput.addEventListener("input", (e) => {
  6. purchaseQuantity = e.target.value
  7. if (purchaseQuantity <= 0) {
  8. purchaseQuantity = 1
  9. }
  10. if (purchaseQuantity > 999) {
  11. purchaseQuantity = 999
  12. }
  13. })
  14. var pchp = document.getElementById("price-calc-historical-price")
  15. var pcp = document.getElementById("price-calc-price")
  16. setInterval(() => {
  17. priceInput.value = purchaseQuantity
  18. //计算价格
  19. if (pchp) {
  20. pchp.innerText = (skuHistoricalPrice * purchaseQuantity).toFixed(2)
  21. }
  22. if (pcp) {
  23. pcp.innerText = (skuPrice * purchaseQuantity).toFixed(2)
  24. }
  25. }, 100)
  26. }
  27. // 购买数量减
  28. function purchaseQuantityAdd() {
  29. if (purchaseQuantity >= 999) {
  30. purchaseQuantity = 999
  31. return
  32. }
  33. purchaseQuantity++;
  34. }
  35. // 购买数量减
  36. function purchaseQuantityMinus() {
  37. if (purchaseQuantity <= 1) {
  38. purchaseQuantity = 1
  39. return
  40. }
  41. purchaseQuantity--;
  42. }
  43. function GetAreaById(areaId) {
  44. let areaEles = document.getElementsByClassName("info-left-select-btn")
  45. for (let i = 0; i < areaEles.length; i++) {
  46. if (areaEles[i].getAttribute("areaId") == areaId) {
  47. areaEles[i].style.backgroundColor = "rgb(199, 199, 199)"
  48. } else {
  49. areaEles[i].style.backgroundColor = ""
  50. }
  51. }
  52. console.log(areaId)
  53. let eles = document.getElementsByClassName("info-left-select-param-btn");
  54. for (let i = 0; i < eles.length; i++) {
  55. if (eles[i].getAttribute("areaId") == areaId) {
  56. eles[i].style = ""
  57. } else {
  58. eles[i].style.display = "none"
  59. }
  60. }
  61. return areaId
  62. }
  63. function RouterJumpId(id) {
  64. window.location.href = "?skuId=" + id
  65. }
  66. //TODO a
  67. function orderSubmit() {
  68. const data = {
  69. skuId: skuData.id,
  70. count: purchaseQuantity,
  71. //优惠券
  72. couponUserId: 0,
  73. //联系信息
  74. contactInformation: ""
  75. };
  76. fetch('/api/order/submit', {
  77. method: 'POST',
  78. headers: {
  79. 'Content-Type': 'application/json'
  80. },
  81. body: JSON.stringify(data)
  82. })
  83. .then(response => response.json())
  84. .then(data => {
  85. console.log('Success:', data);
  86. alert("假装购买成功");
  87. })
  88. .catch((error) => {
  89. console.error('Error:', error);
  90. alert("购买失败");
  91. });
  92. }
  93. let selectIndex = 0;
  94. let nowSku = { Price: 100, SkuImage: "path/to/image", SkuName: "SKU 名称", HistoricalPrices: 120 }; // Example data
  95. let count = 1;
  96. let goodsName = "商品名称"; // Example data
  97. function closeView() {
  98. document.querySelector(".order-buy-curtain").style.display = "none";
  99. }
  100. function selectPayMethod(index) {
  101. selectIndex = index;
  102. document.querySelectorAll(".order-buy-pay-item").forEach((item, idx) => {
  103. item.style.backgroundColor = idx === index ? "#cccccc" : "#dddddd";
  104. });
  105. updatePaySelectPosition();
  106. document.getElementById("test-purchase").style.display = index === 2 ? "flex" : "none";
  107. }
  108. function updatePaySelectPosition() {
  109. const select = document.getElementById("pay-select");
  110. const wxColor = "rgba(0, 168, 242, 1)";
  111. const zfbColor = "rgba(1, 183, 0, 1)";
  112. const pyColor = "rgba(234, 98, 0, 1)";
  113. let bc = "";
  114. switch (selectIndex) {
  115. case 0:
  116. bc = wxColor;
  117. break;
  118. case 1:
  119. bc = zfbColor;
  120. break;
  121. case 2:
  122. bc = pyColor;
  123. break;
  124. }
  125. select.style.left = 10 + (selectIndex * (10 + 340 / 3)) + "px";
  126. select.style.borderColor = bc;
  127. }
  128. function orderTest() {
  129. console.log("Test order submitted");
  130. alert("假装购买成功");
  131. }
  132. document.addEventListener("DOMContentLoaded", function() {
  133. selectPayMethod(0); // Set default selection
  134. });