PageSourceSearch

https://www.wzxinyu.com/assets/js/unit/inquire-list.js

js wzxinyu.com collected 2026-10-04 04:54:32 UTC 12,609 bytes, 314 lines download raw bytes

1class ScriptInquireList extends Script {
2  constructor(params) {
3    super(params)
4    this.$dom = document.querySelector(`#${this.attrId}`)
5    this.$list_box = this.$dom.querySelector('.unit-inquire-lists')
6    this.$allSelect = this.$dom.querySelector('input[name="unit-select-all-product"]')
7    this.$nodata = this.$dom.querySelector('.unit-inquire-notdata')
8    this.attrId = params.attrId
9    this.utils = Utilts.ins()
10  }
11  /** 初始化,支持异步 */
12  async init() {
13    this.initContentHtml()
14  }
15
16  get list() {
17    return window.app.info.productInquireList
18  }
19  get productQuoteIdList() {
20    return window.app.info.productQuoteIdList
21  }
22  get productQuoteList() {
23    return window.app.info.productQuoteList
24  }
25  set productQuoteList(data) {
26    window.app.info.updateProductQuoteList(data)
27  }
28  initQuoteListTips() {
29    const $title = document.querySelector('.title')
30    const $desc = document.querySelector('.desc')
31    $title.innerText = window.app.utilts.$t(`Get in touch with us`)
32    $title.parentNode.parentNode.parentNode.parentNode.style.textAlign = 'left'
33    $desc.innerText = window.app.utilts.$t(`Just leave your email or phone number in the contact form so we can send you a free quote for our wide range of designs!`)
34    $desc.parentNode.parentNode.parentNode.parentNode.style.textAlign = 'left'
35    $desc.parentNode.parentNode.parentNode.parentNode.style.width = '100%'
36
37
38  }
39  async initQuoteList() {
40    this.productQuoteList = []
41    if (this.productQuoteIdList.length > 0) {
42      const res = await this.getProductData(this.productQuoteIdList.toString(),'title,price,thumb')
43      this.productQuoteList = res.data.map(i => {
44        return {
45          ...i,
46          page_url: location.origin + globalThis.Server.getRinseHref(i.page_url,window.app.info.site),
47          amount: 1
48        }
49      })
50
51      // updateProductQuoteList(this.productQuoteList)
52    }
53    const $header = document.querySelector('.unit-selet-all')
54    $header.style.display = 'flex'
55    const count = this.productQuoteList.length
56    $header.innerHTML = `<div style="width: 80%;flex: 1" class="product-quote-title">${window.app.utilts.$t('products')}(${count})</div><div style="width: 180px">${window.app.utilts.$t('quantity')}</div>`
57    if (this.productQuoteList.length === 0) {
58      this.$nodata.classList.add('show')
59      this.$list_box.classList.add('d-none')
60      // this.$allSelect.setAttribute('disabled', 'disabled')
61      return
62    }
63    const contentHtml = []
64
65    for (let index = 0; index < this.productQuoteList.length; index++) {
66      const item = this.productQuoteList[index]
67      if (!item) return
68      contentHtml.push(this.getQuoteContentHtml(item, index))
69    }
70    this.$list_box.innerHTML = contentHtml.join('')
71  }
72  initQuoteListEvent() {
73    const max_amount = 99999
74    const _this = this
75    const $quoteList = document.querySelector('.quote-list')
76    const items = $quoteList.querySelectorAll('.unit-inquire-list-items')
77    items.forEach(item => {
78      const contentId = item.getAttribute('content-id')
79      const $inputIncrease = item.querySelector('.input-number__increase')
80      const $inputDecrease = item.querySelector('.input-number__decrease')
81      const $input = item.querySelector('.input-number input')
82      function checkDisable() {
83        if ($input.value <= 1) {
84          $inputDecrease.classList.add('disabled')
85        } else {
86          $inputDecrease.classList.remove('disabled')
87        }
88      }
89      $inputDecrease.addEventListener('click',function (){
90        if($input.value <= 1) return
91        $input.value = $input.value - 0 - 1
92        const curr = _this.productQuoteList.find(i => i.id == contentId)
93        curr.amount = $input.value - 0
94        window.app.info.updateProductQuoteList(_this.productQuoteList)
95
96        checkDisable()
97      })
98      $inputIncrease.addEventListener('click',function (){
99        if ($input.value - 0 >= max_amount) return
100        $input.value = $input.value - 0 + 1
101        const curr = _this.productQuoteList.find(i => i.id == contentId)
102        curr.amount = $input.value - 0
103        window.app.info.updateProductQuoteList(_this.productQuoteList)
104        checkDisable()
105      })
106      $input.addEventListener('change',function (){
107        $input.value = Math.floor(Number($input.value))
108        if (Number.isNaN(Number($input.value))||$input.value<1) {
109          $input.value = 1
110        }
111        if ($input.value - 0 >= max_amount) {
112          $input.value = max_amount
113        }
114        const curr = _this.productQuoteList.find(i => i.id == contentId)
115        curr.amount = $input.value - 0
116        window.app.info.updateProductQuoteList(_this.productQuoteList)
117        checkDisable()
118      })
119      item.querySelector('.unit-inquire-list-remove').addEventListener('click',function (){
120        const contentId = item.getAttribute('content-id')
121        window.app.info.delProductQuote(contentId)
122        _this.productQuoteList = _this.productQuoteList.filter(i => i.id != contentId)
123        item.remove()
124        const items = $quoteList.querySelectorAll('.unit-inquire-list-items')
125        $quoteList.querySelector('.product-quote-title').innerHTML = `${window.app.utilts.$t(`products`)}(${items.length})`
126        if (items.length === 0) {
127          _this.$nodata.classList.add('show')
128        }
129      })
130    })
131  }
132
133  /** 获取产品数据 */
134  getProductData(ids, columns) {
135    return new Promise((resolve, reject) => {
136      const params = {
137        site_id: window.app.info.site.site_id,
138        language_code: window.app.info.site.language_code,
139        columns: columns,
140        ids: ids,
141        page_size: 50
142      }
143      // if (columns.indexOf('video') > -1) {
144      //   params['is_video'] = 1
145      // }
146      this.utilts.request({
147        url: '/product/get-list-by-filter',
148        method: 'GET',
149        params
150      }).then(res => {
151        resolve(res)
152      })
153          .catch(error => reject(error))
154    })
155  }
156
157  /**询盘列表内容初始化 */
158  async initContentHtml() {
159    const type = this.utils.urlParams.type
160    if (type==='quoteList') {
161      this.initQuoteListTips()
162      document.querySelector('.unit-inquire-list').classList.add('quote-list')
163      await this.initQuoteList()
164      this.initQuoteListEvent()
165      return
166    }
167    if (this.list.length === 0) {
168      this.$nodata.classList.add('show')
169      this.$list_box.classList.add('d-none')
170      this.$allSelect.setAttribute('disabled', 'disabled')
171      return
172    }
173    let contentHtml = []
174    for (let index = 0; index < this.list.length; index++) {
175      const item = this.list[index]
176      if (!item) return
177      contentHtml.push(this.getContentHtml(item, index))
178    }
179    
180    // 产品搭配的询盘,只显示选中的搭配产品
181    let matchProducts = JSON.parse(sessionStorage.getItem('matchProducts') || '[]')
182    let mainProduct = JSON.parse(sessionStorage.getItem('mainProduct') || '{}')
183    if (window.app.info.isMatchProducts && matchProducts.length) {
184      contentHtml = []
185      let matchInquires = matchProducts.map(el => {
186        return {
187          href: el.page_url,
188          detail_title: el.title,
189          detail_thumb: el.thumb_prefix,
190          selected: 1,
191          page_url: el.page_url,
192        }
193      })
194      matchInquires.unshift(mainProduct)
195      for (let index = 0; index < matchInquires.length; index++) {
196        const item = matchInquires[index]
197        if (!item) return
198        contentHtml.push(this.getContentHtml(item, index))
199      }
200    }
201    
202    this.$list_box.innerHTML = contentHtml.join('')
203    this.initDetailEvent()
204    this.delEvent()
205    this.selectAllEvent()
206
207  }
208  /**询盘列表数据绑定事件 */
209  initDetailEvent() {
210    let $inputList = this.$list_box.querySelectorAll('input[name="product"]')
211    for (let $input of $inputList) {
212      $input.onchange = () => {
213        window.app.info.toogleSelectProductInquire($input.value)
214        this.setCheckAllBox()
215      }
216    }
217  }
218
219  /**删除按钮事件绑定 */
220  delEvent() {
221    const $delBtnList = this.$list_box.querySelectorAll('.unit-icon-action-close')
222    for (let $delBtnItem of $delBtnList) {
223      $delBtnItem.onclick = () => {
224        new Modal().confirm(window.app.utilts.$t('Are you sure you want to delete it?'))
225          .then(() => {
226            const index = $delBtnItem.dataset.id
227            window.app.info.delProductInquire(index)
228            const $li = this.$list_box.querySelector(`[inquire-index="${index}"]`)
229            if ($li) $li.remove($li)
230            this.setCheckAllBox()
231            new Message().success(window.app.utilts.$t('Successfully delete'))
232          })
233          .catch(() => new Message().warn(window.app.utilts.$t('Not deleted')))
234      }
235    }
236  }
237
238  /**询盘列表数据全选 */
239  selectAllEvent() {
240    // 初始时,是否选中全选
241    this.setCheckAllBox()
242    // 全选事件
243    this.$allSelect.onchange = () => {
244      // 修改询盘全选或不全选
245      window.app.info.selectAllProductInquire(this.$allSelect.checked ? 1 : 0)
246      const $checkBoxs = this.$list_box.querySelectorAll('[type="checkbox"]')
247      $checkBoxs.forEach($checkBox => $checkBox.checked = this.$allSelect.checked)
248    }
249  }
250
251  /** 如果所有的数据是选中的,设置全选为选中,反之不选中 */
252  setCheckAllBox() {
253    this.$allSelect.checked = this.list.length >= 1 ? this.list.every(p => p.selected === 1) : false
254  }
255
256  /** 拼接的li html */
257  getContentHtml(item, index) {
258    let iopcmd = { convert: { quality: 100 }, thumbnail: { type: 4, width: 100 } }
259    let query_arr = item.detail_thumb.split('?')
260    if (query_arr.length > 1) {
261      let iopcmd_arr = query_arr[1].split('iopcmd=')
262      if (iopcmd_arr.length > 1) {
263        iopcmd_arr.shift()
264        iopcmd.query = 'iopcmd=' + iopcmd_arr.join('iopcmd=')
265      }
266    }
267
268    const liHtml = []
269    const href = globalThis.Server.getRinseHref(item.page_url, window.app.info.site)
270    liHtml.push(`<li class="unit-inquire-list-items" inquire-index="${item.page_id}">`)
271    liHtml.push(`    <div class="custom-control custom-checkbox">`)
272    liHtml.push(`      <input type="checkbox" class="custom-control-input" name="product" ${item.selected === 1 ? 'checked' : ''} value="${item.page_id}" id="${this.attrId}-${item.detail_title}">`)
273    liHtml.push(`      <label class="custom-control-label" for="${this.attrId}-${item.detail_title}"></label>`)
274    liHtml.push(`    </div>`)
275    liHtml.push(`    <a class="unit-inquire-list-a follow-font-family" text-style="3" href="${href}">`)
276    liHtml.push(`      <div class="unit-inquire-list-img"><img class="" src="${globalThis.Server.getTransferImgUrl(query_arr[0], iopcmd, 'webp', window.app.info.site)}" /></div>`)
277    liHtml.push(`      <div class="unit-inquire-list-title">${item.detail_title}</div>`)
278    liHtml.push(`    </a>`)
279    liHtml.push(`    <span class="iconfont unit_del_icon icon-action-close unit-icon-action-close" data-toggle="modal" data-target="#exampleModal" data-id="${item.page_id}"></span>`)
280    liHtml.push(`</li>`)
281    return liHtml.join('')
282  }
283  getQuoteContentHtml(item, index) {
284    let iopcmd = { convert: { quality: 100 }, thumbnail: { type: 4, width: 100 } }
285    let query_arr = item.thumb.split('?')
286    if (query_arr.length > 1) {
287      let iopcmd_arr = query_arr[1].split('iopcmd=')
288      if (iopcmd_arr.length > 1) {
289        iopcmd_arr.shift()
290        iopcmd.query = 'iopcmd=' + iopcmd_arr.join('iopcmd=')
291      }
292    }
293
294    const liHtml = []
295    const href = globalThis.Server.getRinseHref(item.page_url, window.app.info.site)
296    liHtml.push(`<li class="unit-inquire-list-items" content-id="${item.id}">`)
297    liHtml.push(`    <div class="unit-inquire-list-a follow-font-family" text-style="3" >`)
298    liHtml.push(`      <div class="unit-inquire-list-img"><img class="" src="${globalThis.Server.getTransferImgUrl(query_arr[0], iopcmd, 'webp', window.app.info.site)}" /></div>`)
299    liHtml.push(`      <div class="unit-inquire-list-product">`)
300    liHtml.push(`        <a href="${href}">`)
301    liHtml.push(`          <div class="unit-inquire-list-title">${item.title}</div>`)
302    liHtml.push(`        </a>`)
303    liHtml.push(`        <div class="unit-inquire-list-remove">${window.app.utilts.$t('Remove')}</div>`)
304    liHtml.push(`      </div>`)
305    liHtml.push(`    </div>`)
306    liHtml.push(`    <div class="input-number"><span class="input-number__decrease disabled">-</span><input type="text" value="1"><span class="input-number__increase">+</span></div>`)
307    liHtml.push(`</li>`)
308    return liHtml.join('')
309  }
310
311  render() {
312    this.initContentHtml()
313  }
314}

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.