| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- var purchaseQuantity = 1
- var areaId = 0
- function init(skuHistoricalPrice, skuPrice) {
- var priceInput = document.getElementById("irpc-input")
- priceInput.addEventListener("input", (e) => {
- purchaseQuantity = e.target.value
- if (purchaseQuantity <= 0) {
- purchaseQuantity = 1
- }
- if (purchaseQuantity > 999) {
- purchaseQuantity = 999
- }
- })
- var pchp = document.getElementById("price-calc-historical-price")
- var pcp = document.getElementById("price-calc-price")
- setInterval(() => {
- priceInput.value = purchaseQuantity
- //计算价格
- if (pchp) {
- pchp.innerText = (skuHistoricalPrice * purchaseQuantity).toFixed(2)
- }
- if (pcp) {
- pcp.innerText = (skuPrice * purchaseQuantity).toFixed(2)
- }
- }, 100)
- }
- // 购买数量减
- function purchaseQuantityAdd() {
- if (purchaseQuantity >= 999) {
- purchaseQuantity = 999
- return
- }
- purchaseQuantity++;
- }
- // 购买数量减
- function purchaseQuantityMinus() {
- if (purchaseQuantity <= 1) {
- purchaseQuantity = 1
- return
- }
- purchaseQuantity--;
- }
- function GetAreaById(areaId) {
- let areaEles = document.getElementsByClassName("info-left-select-btn")
- for (let i = 0; i < areaEles.length; i++) {
- if (areaEles[i].getAttribute("areaId") == areaId) {
- areaEles[i].style.backgroundColor = "rgb(199, 199, 199)"
- } else {
- areaEles[i].style.backgroundColor = ""
- }
- }
- console.log(areaId)
- let eles = document.getElementsByClassName("info-left-select-param-btn");
- for (let i = 0; i < eles.length; i++) {
- if (eles[i].getAttribute("areaId") == areaId) {
- eles[i].style = ""
- } else {
- eles[i].style.display = "none"
- }
- }
- return areaId
- }
- function RouterJumpId(id) {
- window.location.href = "?skuId=" + id
- }
- //TODO a
- function orderSubmit() {
- const data = {
- skuId: skuData.id,
- count: purchaseQuantity,
- //优惠券
- couponUserId: 0,
- //联系信息
- contactInformation: ""
- };
- fetch('/api/order/submit', {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json'
- },
- body: JSON.stringify(data)
- })
- .then(response => response.json())
- .then(data => {
- console.log('Success:', data);
- alert("假装购买成功");
- })
- .catch((error) => {
- console.error('Error:', error);
- alert("购买失败");
- });
- }
- let selectIndex = 0;
- let nowSku = { Price: 100, SkuImage: "path/to/image", SkuName: "SKU 名称", HistoricalPrices: 120 }; // Example data
- let count = 1;
- let goodsName = "商品名称"; // Example data
- function closeView() {
- document.querySelector(".order-buy-curtain").style.display = "none";
- }
- function selectPayMethod(index) {
- selectIndex = index;
- document.querySelectorAll(".order-buy-pay-item").forEach((item, idx) => {
- item.style.backgroundColor = idx === index ? "#cccccc" : "#dddddd";
- });
- updatePaySelectPosition();
- document.getElementById("test-purchase").style.display = index === 2 ? "flex" : "none";
- }
- function updatePaySelectPosition() {
- const select = document.getElementById("pay-select");
- const wxColor = "rgba(0, 168, 242, 1)";
- const zfbColor = "rgba(1, 183, 0, 1)";
- const pyColor = "rgba(234, 98, 0, 1)";
- let bc = "";
- switch (selectIndex) {
- case 0:
- bc = wxColor;
- break;
- case 1:
- bc = zfbColor;
- break;
- case 2:
- bc = pyColor;
- break;
- }
- select.style.left = 10 + (selectIndex * (10 + 340 / 3)) + "px";
- select.style.borderColor = bc;
- }
- function orderTest() {
- console.log("Test order submitted");
- alert("假装购买成功");
- }
- document.addEventListener("DOMContentLoaded", function() {
- selectPayMethod(0); // Set default selection
- });
|