PageSourceSearch

https://www.ctechigroup.com/assets/js/unit/detail-button-cart.js

js ctechigroup.com collected 2026-10-08 16:10:41 UTC 5,447 bytes, 146 lines download raw bytes

1class ScriptDetailButtonCart extends Script {
2  constructor(params) {
3    super(params)
4    this.hasBuyOn = params.hasBuyOn
5    this.$dom = document.querySelector(`#${this.attrId}`)
6    this.$btn = this.$dom.querySelector(`.unit-detail-button-cart`)
7    this.$btnLink = this.$btn.querySelector(`.btn`)
8    this.isM = window.innerWidth < 768
9    // 暂无报价不能购买
10    this.addCartOk = true
11  }
12  init() {
13    this.initCart()
14  }
15  /**加入购物车 */
16  initCart() {
17    if (!this.$btn) return
18    this.$btnLink.addEventListener('click', () => {
19      this.addCart()
20    })
21  }
22  addCart(type = 'inner') {
23    if (!this.addCartOk) return
24    if (!this.checkOrder(type)) return
25    this.utilts.setBtnLoadingStatus(this.$btnLink, true)
26    this.checkAvailabOnline().then(resCheck => {
27      if (resCheck.status === 0) {
28        this.utilts.request({
29          url: '/shopping-cart/update-or-insert',
30          method: 'POST',
31          params: {
32            site_id: window.app.info.site.site_id,
33            visitor_code: window.app.info.user.visitor_code,
34            product_id: window.app.info.page.content_id,
35            price_id: window.app.info.productDetail.price_id,
36            quantity: window.app.info.productDetail.quantity,
37            append: 1
38          }
39        }).then(_res => {
40          this.utilts.setBtnLoadingStatus(this.$btnLink, false)
41          document.querySelector('[package-type="header"]').classList.remove('header-hide')
42          this.utilts.getCartQuantity()
43          const modal = new Modal().init({
44            title: window.app.utilts.$t('Add to Cart'),
45            content: `<span class="iconfont icon-base-success-fill mr-1" style="color: rgb(140, 213, 0);"></span>${window.app.utilts.$t('A new item has been added to your Shopping Cart')}`,
46            submitText: window.app.utilts.$t('View Cart & Checkout'),
47            cancelText: window.app.utilts.$t('Continue Shopping'),
48            className: 'unit-detail-button-cart__modal',
49            onSubmit: () => {
50              location.href = globalThis.Server.getRinseHref('/cart.html', window.app.info.site)
51              modal.destroy()
52            },
53            onCancel: () => modal.destroy()
54          }).open()
55        }).catch(err => {
56          this.utilts.setBtnLoadingStatus(this.$btnLink, false)
57          console.error(err)
58        })
59      } else {
60        this.utilts.setBtnLoadingStatus(this.$btnLink, false)
61        window.app.utilts.detailCheck(resCheck)
62      }
63    })
64  }
65  checkOrder(type) {
66    let bool = true
67    if (!window.app.info.user.is_open) {
68      new Message().info(window.app.utilts.$t('The user center is out of service. Please contact customer service'))
69      bool = false
70    }
71    else if (!window.app.info.productDetail.price_id) {
72      if (this.isM && type === 'inner') this.$dom.querySelector('.unit-detail-pattern__modal-btn').click()
73      else new Message().error(window.app.utilts.$t('Please select attribute'))
74      bool = false
75    }
76    return bool
77  }
78
79  /**
80   * 购买时检查产品
81   *  异常状态:* 1-产品下架;2-款式存在;3-价格变化;4-有无库存;5-库存满足
82  **/
83  checkAvailabOnline() {
84    const detail = window.app.info.productDetail
85    const selling_price = detail.is_discount ? detail.discount_original_price : detail.min_price
86    const info = [{
87      product_id: detail.product_id,
88      price_id: detail.price_id,
89      quantity: detail.quantity,
90      selling_price: selling_price
91    }]
92    const params = detail.config.stock_available ? '1,2,3,4,5' : '1,2,3'
93    return this.utilts.checkoutAvailableHint(info, true, params)
94  }
95
96  render() {
97    // this.$btn.style.display = 'block'
98    this.$btn.classList.add('show')
99    const isCartOpen = window.app.info.productDetail.config.button_authority.includes('cart')
100    if (this.hasBuyOn || !window.app.info.productDetail.status) this.$btn.classList.remove('show')
101    else if (isCartOpen && window.app.info.productDetail.min_price > 0) this.$btn.classList.add('show')
102    else if(!isCartOpen) return this.$btn.classList.remove('show')
103    if(window.app.info.productDetail&&window.app.info.productDetail.pattern&&window.app.info.productDetail.pattern.every(a=>a.selling_price===0)){
104      this.$btn.style.display = 'none'
105    }
106    if (window?.app?.info?.productDetail?.is_pattern) {
107      if (window?.app?.info?.productDetail?.min_price <= 0) {
108        this.setBtnDisable()
109      }else{
110        this.cancelBtnDisable()
111      }
112      if(window?.app?.info?.productDetail?.is_discount){
113        if (window?.app?.info?.productDetail?.discount_price <= 0) {
114          this.setBtnDisable()
115        }else{
116          this.cancelBtnDisable()
117        }
118      }
119      return
120    }
121    if (window.app.info.productDetail.min_price <= 0 || !window.app.info.productDetail.is_match_paramter) {
122      this.setBtnDisable()
123    } else {
124      this.cancelBtnDisable()
125    }
126  }
127  setBtnDisable(){
128    console.log('!fsgsdfgdsfgdsf!')
129    const $cart = this.$btn.querySelector('a.btn')
130    $cart.classList.add('button-disabled')
131    this.$btn.classList.add('d-none')
132    // $cart.removeAttribute('href')
133    // $cart.removeAttribute('target')
134    this.addCartOk = false
135  }
136  cancelBtnDisable() {
137    const $cart = this.$btn.querySelector('a.btn')
138    $cart.classList.remove('button-disabled')
139    this.$btn.classList.remove('d-none')
140    this.addCartOk = true
141  }
142  outerAddCart() {
143    this.addCart('outer')
144  }
145}
146

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.