PageSourceSearch

https://www.meetion.com.cn/assets/js/unit/detail-button-buy.js

js meetion.com.cn collected 2026-10-04 20:37:05 UTC 7,425 bytes, 207 lines download raw bytes

1class ScriptDetailButtonBuy 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-buy`)
7    // 由于产品搭配与立即购买逻辑一样,所以把判断逻辑写在此处
8    this.$btn_together = this.$dom.querySelector(`.unit-detail-button-buytogether`)
9    this.$btn_inquiry = this.$dom.querySelector(`.unit-detail-match-product-inquiry`)
10    this.$btnlink = this.$btn.querySelector(`.btn`)
11    this.$btnlink_together = null
12    this.$priceDoms = null
13    this.isM = window.innerWidth < 768
14    this.isBuyTogether = false
15    // 暂无报价不能购买
16    this.buyOk = true
17  }
18  init() {
19    this.$priceDoms = document.querySelector('.unit-detail-product-match')
20    if (this.$btn_together) {
21      this.$btnlink_together = this.$btn_together.querySelector(`.btn`)
22    }
23    this.initBuy()
24  }
25  /**立即购买 */
26  async initBuy() {
27    // if (!this.$btn) return
28    // this.$btnlink.addEventListener('click', () => {
29    //   this.isBuyTogether = false
30    //   this.buy()
31    // })
32    if (this.$btn) {
33      this.$btnlink.addEventListener('click', () => {
34        this.isBuyTogether = false
35        this.buy()
36      })
37    }
38    if (this.$btn_together) {
39      this.$btnlink_together.addEventListener('click', () => {
40        this.isBuyTogether = true
41        this.buy()
42      })
43    }
44  }
45  buy(type = 'inner') {
46    if (!this.buyOk) return
47    if (!this.checkOrder(type)) return
48    this.utilts.setBtnLoadingStatus(this.$btnlink, true)
49    this.checkAvailabOnline().then(resCheck => {
50      if (resCheck.status === 0) {
51        this.utilts.setBtnLoadingStatus(this.$btnlink, false)
52        const price_id = window.app.info.productDetail.price_id
53        const quantity = window.app.info.productDetail.quantity
54        let href = ''
55        if (this.isBuyTogether) {
56          href = `/cart.html?isBuyTogether=1&price_id=${price_id}&quantity=${quantity}`
57        } else {
58          href = `/cart.html?isBuy=1&price_id=${price_id}&quantity=${quantity}`
59        }
60        window.location.href = globalThis.Server.getRinseHref(href, window.app.info.site)
61      } else {
62        this.utilts.setBtnLoadingStatus(this.$btnlink, false)
63        window.app.utilts.detailCheck(resCheck)
64      }
65    })
66  }
67  outerBuy() {
68    this.buy('outer')
69  }
70  checkOrder(type) {
71    let bool = true
72    if (!window.app.info.user.is_open) {
73      new Message().info(window.app.utilts.$t('The user center is out of service. Please contact customer service'))
74      bool = false
75    }
76    else if (!window.app.info.productDetail.price_id) {
77      if (this.isM && type === 'inner') this.$dom.querySelector('.unit-detail-pattern__modal-btn').click()
78      else new Message().error(window.app.utilts.$t('Please select attribute'))
79      bool = false
80    }
81    else if (window.app.info.productDetail.config.visitor_checkout) bool = true
82    else if (!window.app.info.user.is_login) {
83      bool = false
84      if (confirm('Please login in first')) window.location.href = globalThis.Server.getRinseHref('/login.html', window.app.info.site)
85    }
86    return bool
87  }
88  /**
89   * 购买时检查产品
90   *  异常状态:* 1-产品下架;2-款式存在;3-价格变化;4-有无库存;5-库存满足
91  **/
92  checkAvailabOnline() {
93    const detail = window.app.info.productDetail
94    const selling_price = detail.is_discount ? detail.discount_original_price : detail.min_price
95    let info = [{
96      product_id: detail.product_id,
97      price_id: detail.price_id,
98      quantity: detail.quantity,
99      selling_price: selling_price
100    }]
101    const params = detail.config.stock_available ? '1,2,3,4,5' : '1,2,3'
102    let match_price_ids = ''
103    let matchProducts = JSON.parse(sessionStorage.getItem('matchProducts') || '[]')
104    let ids = []
105    let matchProductsInfo = []
106    if (this.isBuyTogether && matchProducts.length) {
107      ids = matchProducts.map(el => el.price_id)
108      match_price_ids = ids.join(',')
109      matchProductsInfo = matchProducts.map(el => {
110        return {
111          product_id: el.product_id,
112          price_id: el.price_id,
113          quantity: detail.quantity,
114          selling_price: el.match_price / 100,
115          quantity: 1
116        }
117      })  
118      info = [...info, ...matchProductsInfo]
119    }
120    // if (this.isBuyTogether && ids.length) {
121    //   match_price_ids = ids.join(',')
122    // }
123    return this.utilts.checkoutAvailableHint(info, true, params,0, match_price_ids)
124  }
125
126  render() {
127    // this.$btn.style.display = 'block'
128    this.$btn.classList.add('show')
129    const isOrderOpen = window.app.info.productDetail.config.button_authority.includes('order')
130    const isInquiryOpen = window.app.info.productDetail.config.button_authority.includes('inquiry')
131    // const isB2B = window.app.info.site.site_type === 1
132    let showBuyTogether = isOrderOpen && window.app.info.productDetail.min_price > 0 && this.$btn_together
133    let showInquiry = isInquiryOpen && this.$btn_inquiry
134    if (showInquiry) {
135      this.$btn_inquiry.classList.add('show')
136      // this.$dom.querySelector('.unit-detail-product-match').classList.add('no-price')
137    }
138    if (this.hasBuyOn || !window.app.info.productDetail.status) {
139      this.$btn.classList.remove('show')
140      if (this.$priceDoms) {
141        this.$priceDoms.classList.add('no-price')
142      }
143    } else if (isOrderOpen && window.app.info.productDetail.min_price > 0) {
144      this.$btn.classList.add('show')
145      if (showBuyTogether) {
146        this.$btn_together.classList.add('show')
147      }
148      if (this.$priceDoms) {
149        this.$priceDoms.classList.remove('no-price')
150      }
151    } else if(!isOrderOpen) {
152      this.$btn.classList.remove('show')
153      if (this.$priceDoms) {
154        this.$priceDoms.classList.add('no-price')
155      }
156      return
157    }
158    if(window.app.info.productDetail&&window.app.info.productDetail.pattern&&window.app.info.productDetail.pattern.every(a=>a.selling_price===0)){
159      this.$btn.style.display = 'none'
160    }
161    if (window?.app?.info?.productDetail?.is_pattern) {
162      if (window?.app?.info?.productDetail?.min_price <= 0) {
163        this.setBtnDisable()
164      }else{
165        this.cancelBtnDisable()
166      }
167      if(window?.app?.info?.productDetail?.is_discount){
168        if (window?.app?.info?.productDetail?.discount_price <= 0) {
169          this.setBtnDisable()
170        }else{
171          this.cancelBtnDisable()
172        }
173      }
174      return
175    }
176    if (window.app.info.productDetail.min_price <= 0 || !window.app.info.productDetail.is_match_paramter) {
177      this.setBtnDisable()
178    } else {
179      this.cancelBtnDisable()
180    }
181  }
182  setBtnDisable(){
183    const $buy = this.$btn.querySelector('a.btn')
184    $buy.classList.add('button-disabled')
185    this.$btn.classList.add('d-none')
186    if (this.$btn_together) {
187      this.$btn_together.classList.remove('show')
188    }
189    if (this.$priceDoms) {
190      this.$priceDoms.classList.add('no-price')
191    }
192    this.buyOk = false
193  }
194  cancelBtnDisable() {
195    const $cart = this.$btn.querySelector('a.btn')
196    $cart.classList.remove('button-disabled')
197    this.$btn.classList.remove('d-none')
198    if (this.$btn_together) {
199      this.$btn_together.classList.add('show')
200    }
201    if (this.$priceDoms) {
202      this.$priceDoms.classList.remove('no-price')
203    }
204    this.buyOk = true
205  }
206}
207

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.