立创商城辅助工具

立创商城辅助增强工具

当前为 2024-11-05 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name 立创商城辅助工具
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.3.1
  5. // @description 立创商城辅助增强工具
  6. // @author Lx
  7. // @match https://so.szlcsc.com/global.html**
  8. // @match https://bom.szlcsc.com/member/eda/search.html?**
  9. // @match https://bom.szlcsc.com/member/bom/upload/**.html
  10. // @match https://www.szlcsc.com/huodong.html?**
  11. // @match https://list.szlcsc.com/brand**
  12. // @match https://list.szlcsc.com/catalog**
  13. // @icon https://www.google.com/s2/favicons?sz=64&domain=szlcsc.com
  14. // @require https://update.greasyfork.org/scripts/446666/1389793/jQuery%20Core%20minified.js
  15. // @require https://update.greasyfork.org/scripts/455576/1122361/Qmsg.js
  16. // @resource customCSS https://gitee.com/snwjas/message.js/raw/master/dist/message.min.css
  17. // @grant GM_openInTab
  18. // @grant GM_xmlhttpRequest
  19. // @grant GM_setClipboard
  20. // @grant GM_addStyle
  21. // @grant GM_getResourceText
  22. // @license MIT
  23. // ==/UserScript==
  24.  
  25. (async function() {
  26. 'use strict';
  27. // 软件版本
  28. const __version = 'Version 2.3.1';
  29.  
  30. // 引入message的css文件并加入html中
  31. const css = GM_getResourceText("customCSS")
  32. GM_addStyle(css)
  33.  
  34. const webSiteShareData = {
  35. lcscCartUrl: "https://cart.szlcsc.com",
  36. lcscWwwUrl: "https://www.szlcsc.com",
  37. lcscSearchUrl: "https://so.szlcsc.com",
  38. };
  39.  
  40. /**
  41. * rgb颜色随机
  42. * @returns
  43. */
  44. const rgb = () => {
  45. var r = Math.floor(Math.random() * 256)
  46. var g = Math.floor(Math.random() * 256)
  47. var b = Math.floor(Math.random() * 256)
  48. var rgb = 'rgb(' + r + ',' + g + ',' + b + ')';
  49. return rgb;
  50. }
  51.  
  52. /**
  53. * rgba颜色随机
  54. * @param {*} a
  55. * @returns
  56. */
  57. const rgba = (a = 1) => {
  58. var r = Math.floor(Math.random() * 256)
  59. var g = Math.floor(Math.random() * 256)
  60. var b = Math.floor(Math.random() * 256)
  61. var rgb = 'rgba(' + r + ',' + g + ',' + b + ',' + a + ')';
  62. return rgb;
  63. }
  64.  
  65. /**
  66. * 深色 随机色
  67. * @returns
  68. */
  69. const srdmRgbColor = () => {
  70. //随机生成RGB颜色
  71. let arr = [];
  72. for (var i = 0; i < 3; i++) {
  73. // 暖色
  74. arr.push(Math.floor(Math.random() * 128 + 64));
  75. // 亮色
  76. // arr.push(Math.floor(Math.random() * 128 + 128));
  77. }
  78. let [r, g, b] = arr;
  79. // rgb颜色
  80. // var color=`rgb(${r},${g},${b})`;
  81. // 16进制颜色
  82. var color = `#${r.toString(16).length > 1 ? r.toString(16) : '0' + r.toString(16)}${g.toString(16).length > 1 ? g.toString(16) : '0' + g.toString(16)}${b.toString(16).length > 1 ? b.toString(16) : '0' + b.toString(16)}`;
  83. return color;
  84. }
  85.  
  86. /**
  87. * 十六进制颜色随机
  88. * @returns
  89. */
  90. const color16 = () => {
  91. var r = Math.floor(Math.random() * 256)
  92. var g = Math.floor(Math.random() * 256)
  93. var b = Math.floor(Math.random() * 256)
  94. var color = '#' + r.toString(16) + g.toString(16) + b.toString(16)
  95. return color;
  96. }
  97.  
  98. /**
  99. * 正则获取品牌名称,需要传入xxxx(品牌名称) 这样的字符
  100. * @param {*} text
  101. * @returns
  102. */
  103. const getBrandNameByRegex = (text) => {
  104. let res = text
  105. try {
  106. res = /\(.+\)/g.exec(text)[0].replace(/\((.*?)\)/, '$1')
  107. } catch (e) {
  108.  
  109. }
  110. return res
  111. }
  112.  
  113. /**
  114. * 正则获取品牌名称,优惠券的标题
  115. * @param {*} text
  116. * @returns
  117. */
  118. const getBrandNameByRegexInCouponTitle = (text) => {
  119. try {
  120. text = text.replaceAll(/.+元|品牌优惠/g, '')
  121. } catch (e) {
  122.  
  123. }
  124. return text
  125. }
  126.  
  127. /**
  128. * 等待
  129. * @param {*} timeout
  130. * @returns
  131. */
  132. const setAwait = (timeout) => {
  133. return new Promise((resolve, reject) => {
  134. setTimeout(() => {
  135. resolve(true)
  136. }, timeout);
  137. })
  138. }
  139.  
  140. /**
  141. * 等待 执行函数
  142. * @param {*} timeout
  143. * @returns
  144. */
  145. const setAwaitFunc = (timeout, func) => {
  146. return new Promise((resolve, reject) => {
  147. setTimeout(() => {
  148. func && func()
  149. }, timeout);
  150. })
  151. }
  152.  
  153. /**
  154. * 获取本地缓存
  155. * @param {*} key
  156. */
  157. const getLocalData = (k) => {
  158. return localStorage.getItem(k)
  159. }
  160.  
  161. /**
  162. * 设置本地缓存
  163. * @param {*} key
  164. */
  165. const setLocalData = (k, v) => {
  166. localStorage.setItem(k, v)
  167. }
  168.  
  169. /**
  170. * 判断插件是否已经加载切是显示状态
  171. * @returns
  172. */
  173. const plguinIsHavedAndShow = () => {
  174. return plguinIsHaved() && $('.bd').is(':visible');
  175. }
  176.  
  177. /**
  178. * 判断插件是否已经加载
  179. * @returns
  180. */
  181. const plguinIsHaved = () => {
  182. return $('.bd').length > 0;
  183. }
  184.  
  185. /**
  186. * 品牌名称加工
  187. * @param {*} name
  188. * @returns
  189. */
  190. const brandNameDataProcess = (name) => {
  191. return name.replace(/\//g, '_')
  192. }
  193.  
  194. // 后续支持强排序按钮
  195.  
  196. // 商品清单集合暂存
  197. const dataCartMp = new Map()
  198. // 品牌对应颜色,用于快速查找位置。
  199. const dataBrandColorMp = new Map()
  200. // 优惠券页面,数据暂存。只保存16-15的优惠券
  201. const all16_15CouponMp = new Map()
  202. // 自动领券的定时器
  203. let couponTimer = null;
  204. // 搜索页总条数
  205. var searchPageTotalCount = () => parseInt($('div.g01 span:eq(1)').text()) || parseInt($('#by-channel-total b').text());
  206. // 搜索页单页条数
  207. var searchPageSize = 30;
  208. // 搜索页需要显示多少条数据 自行修改
  209. var searchPageRealSize = 100;
  210. // 搜索页总页数
  211. var searchTotalPage = () => Math.min(((parseInt((searchPageTotalCount() / searchPageSize).toFixed(0)) + 1) || 34), 34);
  212. // 存储动态的function,用做数据处理
  213. var jsRules = [];
  214. // 搜索页数据预览定时器
  215. var searchTimer = null;
  216. // 搜索页数据暂存
  217. var searchTempList = [];
  218. // 品牌搜索结束标记
  219. var brandSearchEnd = false;
  220. // 搜索首页的结束标记
  221. var globalSearchEnd = false;
  222.  
  223. // 消息弹框全局参数配置
  224. Qmsg.config({
  225. showClose: true,
  226. timeout: 2800,
  227. maxNums: 50
  228. })
  229.  
  230. /**
  231. * 根据value排序Map
  232. * @param {*} map
  233. * @returns
  234. */
  235. const sortMapByValue = (map) => {
  236. var arrayObj = Array.from(map)
  237. //按照value值降序排序
  238. arrayObj.sort(function(a, b) { return a[1] - b[1] })
  239. return arrayObj
  240. }
  241.  
  242.  
  243. /**
  244. * GET请求封装
  245. * @param {} data
  246. */
  247. const getAjax = (url) => {
  248. return new Promise((resolve, reject) => {
  249. GM_xmlhttpRequest({
  250. url,
  251. method: 'GET',
  252. onload: (r) => {
  253. resolve(r.response)
  254. },
  255. onerror: (err) => {
  256. reject(err)
  257. }
  258. })
  259. })
  260. }
  261.  
  262. /**
  263. * POST请求封装
  264. * @param {} data
  265. */
  266. const postAjaxJSON = (url, data) => {
  267. return new Promise((resolve, reject) => {
  268. GM_xmlhttpRequest({
  269. url,
  270. method: 'POST',
  271. headers: { 'Content-Type': 'application/json' },
  272. data,
  273. onload: (r) => {
  274. resolve(r.response)
  275. },
  276. onerror: (err) => {
  277. reject(err)
  278. }
  279. })
  280. })
  281. }
  282.  
  283. function jsonToUrlParam(json, ignoreFields = '') {
  284. return Object.keys(json)
  285. .filter(key => ignoreFields.indexOf(key) === -1)
  286. .map(key => key + '=' + json[key]).join('&');
  287. }
  288.  
  289. /**
  290. * POST请求封装
  291. * @param {} data
  292. */
  293. const postFormAjax = (url, jsonData) => {
  294. return new Promise((resolve, reject) => {
  295. GM_xmlhttpRequest({
  296. url,
  297. data: jsonToUrlParam(jsonData),
  298. method: 'POST',
  299. headers: { 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' },
  300. onload: (r) => {
  301. resolve(r.response)
  302. },
  303. onerror: (err) => { reject(err) }
  304. })
  305. })
  306. }
  307.  
  308. /**
  309. * 有进度的等待所有异步任务的执行
  310. * @param {*} requests
  311. * @param {*} callback
  312. * @returns
  313. */
  314. const allWithProgress = (requests, callback) => {
  315. let index = 0;
  316. requests.forEach(item => {
  317. item.then(() => {
  318. index++;
  319. const progress = index * 100 / requests.length;
  320. callback({ total: requests.length, cur: index, progress });
  321. })
  322. });
  323. return Promise.all(requests);
  324. }
  325.  
  326. /**
  327. * 订购数量发生变化的时候
  328. */
  329. const onChangeCountHandler = () => {
  330. // 订购数量
  331. $('.product-item .cart-li input.input').on('change', () => {
  332. setTimeout(refresh, 1000);
  333. })
  334. // 加减数量
  335. $('.decrease,.increase').on('click', () => {
  336. setTimeout(refresh, 1000);
  337. })
  338. }
  339.  
  340. /**
  341. * 换仓按钮事件
  342. * 一键换仓专用
  343. *
  344. 换仓逻辑
  345. https://cart.szlcsc.com/cart/warehouse/deliverynum/update
  346.  
  347. cartKey规则:
  348. 标签id product-item-186525218
  349. 商品的跳转地址(商品id)20430799
  350.  
  351. cartKey: 186525218~0~20430799~RMB~CN
  352. gdDeliveryNum: 0
  353. jsDeliveryNum: 1
  354. */
  355. const onClickChangeDepotBtnHandler = () => {
  356.  
  357. /**
  358. *
  359. * @param {*} this 标签
  360. * @param {*} warehouseType 仓库类型 GUANG_DONG:广东,JIANG_SU
  361. * @returns
  362. */
  363.  
  364. // 换仓封装
  365. const _changeDepot = (that, warehouseType) => {
  366.  
  367. return new Promise((resolve, reject) => {
  368.  
  369. // 是否锁定样品
  370. let isLocked = (that.find('.warehouse-wrap .warehouse:contains(广东仓)').length +
  371. that.find('.warehouse-wrap .warehouse:contains(江苏仓)').length) == 0
  372.  
  373. // 查找商品的属性
  374. let infoElement = that.find('.cart-li:eq(1) a')
  375.  
  376. if (isLocked === true) {
  377. Qmsg.error(`物料编号:${infoElement.text()},处于锁定样品状态,无法换仓`)
  378. console.error(`物料编号:${infoElement.text()},处于锁定样品状态,无法换仓`)
  379. return
  380. }
  381.  
  382. // 订购数量
  383. let count = that.find('.cart-li:eq(-4) input').val()
  384.  
  385. // 物料ID1
  386. let productId1 = /\d+/g.exec(that.attr('id'))[0]
  387.  
  388. // 物料ID2
  389. let productId2 = /\d+/g.exec(infoElement.attr('href'))[0]
  390.  
  391. // 取最低起订量
  392. let sinpleCount = /\d+/g.exec(that.find('.price-area:eq(0)').text())[0]
  393.  
  394. // 订购套数
  395. let batchCount = count / sinpleCount
  396.  
  397. // 修改库存的参数体
  398. let params = ''
  399.  
  400. // 当前是广东仓
  401. if (warehouseType == 'GUANG_DONG') {
  402. params = `cartKey=${productId1}~0~${productId2}~RMB~CN&gdDeliveryNum=${batchCount}&jsDeliveryNum=${0}`
  403. }
  404. // 其他情况当成是江苏仓
  405. else if (warehouseType == 'JIANG_SU') {
  406. params = `cartKey=${productId1}~0~${productId2}~RMB~CN&gdDeliveryNum=${0}&jsDeliveryNum=${batchCount}`
  407. }
  408.  
  409. GM_xmlhttpRequest({
  410. url: `${webSiteShareData.lcscCartUrl}/cart/warehouse/deliverynum/update`,
  411. data: params,
  412. method: 'POST',
  413. headers: { 'Content-type': 'application/x-www-form-urlencoded; charset=UTF-8' },
  414. onload: (r) => {
  415. console.log(r.response)
  416. resolve(r.response)
  417. },
  418. onerror: (err) => { reject(err) }
  419. })
  420. })
  421. }
  422.  
  423.  
  424. /**
  425. * 动态刷新页面,不强制刷新
  426. * !!!暂时不能用,需要考虑订货商品还是现货
  427. */
  428. // const _reload = async () => {
  429.  
  430. // // 购物车URL
  431. // const cartDataUrl = `${webSiteShareData.lcscCartUrl}/cart/display?isInit=false&isOrderBack=${window.isOrderBack}&${Date.now()}`
  432. // const res = await getAjax(cartDataUrl)
  433. // const resObj = JSON.parse(res)
  434.  
  435. // // 合并订货和现货商品
  436. // const newArr = [...resObj.result.shoppingCartVO.rmbCnShoppingCart.currentlyProductList,
  437. // ...resObj.result.shoppingCartVO.rmbCnShoppingCart.isNeedProductList]
  438.  
  439. // // 遍历物料编号
  440. // newArr.forEach(function (item) {
  441.  
  442. // const {
  443. // jsDeliveryNum, // 江苏的订货量
  444. // gdDeliveryNum, // 广东的订货量
  445. // productCode, // 物料编码
  446. // isChecked, // 是否选中
  447. // jsValidStockNumber, // 江苏剩余库存
  448. // szValidStockNumber, // 广东剩余库存
  449. // jsDivideSplitDeliveryNum, // 江苏起订量的倍数
  450. // gdDivideSplitDeliveryNum, // 广东起订量的倍数
  451. // shopCarMapKey // 购物车主键
  452. // } = item
  453.  
  454. // // 查找到这个物料编号所在的行
  455. // const ele = getAllLineInfoByBrandName(productCode)
  456.  
  457. // // 计算出仓库名
  458. // const depotName = jsDeliveryNum > 0 ? '江苏仓' : (gdDeliveryNum > 0 ? '广东仓' : '')
  459.  
  460. // const depotEle = ele.find('.warehouse-wrap .warehouse')
  461.  
  462. // const newDepotName = (depotEle.html() || '').replace('江苏仓', depotName).replace('广东仓', depotName)
  463.  
  464. // // 重新设置仓库名称
  465. // depotEle.html(newDepotName)
  466.  
  467. // })
  468. // }
  469.  
  470. // 换仓-江苏
  471. $('.change-depot-btn-left_').on('click', function() {
  472.  
  473. let count = 0;
  474. const eles = getAllCheckedLineInfo()
  475. eles.each(async function() {
  476. count++
  477. await _changeDepot($(this), 'JIANG_SU').then(res => {
  478. Qmsg.success('切换【江苏仓】成功!')
  479. })
  480.  
  481. if (eles.length === count) {
  482. // setTimeout(_reload, 500);
  483. setTimeout(function() {
  484. location.reload()
  485. // 官方刷新购物车
  486. // cartModuleLoadCartList()
  487. }, 2500);
  488. }
  489. })
  490. })
  491.  
  492. // 换仓-广东
  493. $('.change-depot-btn-right_').on('click', function() {
  494.  
  495. let count = 0;
  496. const eles = getAllCheckedLineInfo()
  497. eles.each(async function() {
  498. count++
  499. await _changeDepot($(this), 'GUANG_DONG').then(res => {
  500. Qmsg.success('切换【广东仓】成功!')
  501. })
  502.  
  503. if (eles.length === count) {
  504. // setTimeout(_reload, 500);
  505. setTimeout(function() {
  506. location.reload()
  507. // 官方刷新购物车
  508. // cartModuleLoadCartList()
  509. }, 2500);
  510. }
  511. })
  512. })
  513. }
  514.  
  515. /**
  516. * 选中仓库事件
  517. * 一键选仓专用
  518. * 废弃:由于模拟点击,会导致小窗口频繁刷新,影响性能。下面重新换接口
  519. */
  520. const _checkDepotBtnHandler = () => {
  521.  
  522. const _clickFunc = (depotName, fn) => {
  523. const eles = fn()
  524.  
  525. // 先看看有没有指定仓
  526. const jsIsEmpty = getJsLineInfo().length === 0
  527. const gdIsEmpty = getGdLineInfo().length === 0
  528.  
  529. if (depotName === 'JIANG_SU' && jsIsEmpty) {
  530. Qmsg.error('购物车中并没有【江苏仓】的商品!')
  531. return
  532.  
  533. } else if (depotName === 'GUANG_DONG' && gdIsEmpty) {
  534. Qmsg.error('购物车中并没有【广东仓】的商品!')
  535. return
  536. }
  537.  
  538. // 是否有至少一个选中的
  539. const isHave = eles.parents('.product-item').find('input.check-box:checked').length > 0
  540.  
  541. if (isHave) {
  542. eles.each(function() {
  543. $(this).parents('.product-item').find('input.check-box:checked').click()
  544. })
  545. }
  546. // 都未选中,则执行仓库全选操作
  547. else {
  548. eles.each(function() {
  549. $(this).parents('.product-item').find('input.check-box').click()
  550. })
  551. }
  552. }
  553.  
  554. // 江苏仓
  555. $(".check-js-btn-left_").on('click', function() {
  556. _clickFunc('JIANG_SU', getJsLineInfo)
  557. })
  558.  
  559. // 广东仓
  560. $(".check-gd-btn-right_").on('click', function() {
  561. _clickFunc('GUANG_DONG', getGdLineInfo)
  562. })
  563. }
  564.  
  565.  
  566. /**
  567. * 选中仓库事件
  568. * 一键选仓专用
  569. */
  570. const checkDepotBtnHandlerNew = () => {
  571.  
  572. const _clickFunc = (depotName) => {
  573. // 广东仓选中
  574. const gdCheckedEles = getGdLineInfo()
  575. // 江苏仓选中
  576. const jsCheckedEles = getJsLineInfo()
  577.  
  578. // 先看看有没有指定仓
  579. const jsIsEmpty = jsCheckedEles.length === 0
  580. const gdIsEmpty = gdCheckedEles.length === 0
  581.  
  582. let isJs = depotName === 'JIANG_SU'
  583. let isGd = depotName === 'GUANG_DONG'
  584.  
  585. if (isJs && jsIsEmpty) {
  586. Qmsg.error('购物车中并没有【江苏仓】的商品!')
  587. return
  588.  
  589. } else if (isGd && gdIsEmpty) {
  590. Qmsg.error('购物车中并没有【广东仓】的商品!')
  591. return
  592. }
  593.  
  594. // 这里只需要操作多选框的选中状态就行
  595. if (isJs) {
  596. const jsInputCheckBox = jsCheckedEles.parents('.product-item').find('input.check-box')
  597. const jsInputCheckBoxCK = jsInputCheckBox.parents('.product-item').find('input.check-box:checked')
  598. const isHave = jsInputCheckBoxCK.length > 0
  599. jsInputCheckBox.prop('checked', !isHave)
  600.  
  601. } else if (isGd) {
  602. const gdInputCheckBox = gdCheckedEles.parents('.product-item').find('input.check-box')
  603. const gdInputCheckBoxCK = gdInputCheckBox.parents('.product-item').find('input.check-box:checked')
  604. const isHave = gdInputCheckBoxCK.length > 0
  605. gdInputCheckBox.prop('checked', !isHave)
  606. }
  607.  
  608. cartUpdateChecked().then(res => {
  609. if (res === 'true') {
  610. cartModuleLoadCartList()
  611. setTimeout(refresh(), 1000);
  612. }
  613. })
  614. }
  615.  
  616. // 江苏仓
  617. $(".check-js-btn-left_").on('click', function() {
  618. _clickFunc('JIANG_SU')
  619. })
  620.  
  621. // 广东仓
  622. $(".check-gd-btn-right_").on('click', function() {
  623. _clickFunc('GUANG_DONG')
  624. })
  625. }
  626.  
  627.  
  628. /**
  629. * 自动领取优惠券的定时器
  630. */
  631. const autoGetCouponTimerHandler = () => {
  632.  
  633. $('.auto-get-coupon').off('change')
  634. couponTimer = null
  635. // 自动领取优惠券开关
  636. $('.auto-get-coupon').on('change', function() {
  637. const isChecked = $(this).is(':checked')
  638. setLocalData('AUTO_GET_COUPON_BOOL', isChecked)
  639. autoGetCouponTimerHandler()
  640. })
  641.  
  642. couponTimer = setInterval(() => {
  643. const isChecked = $('.auto-get-coupon').is(':checked')
  644. if (isChecked) {
  645. console.log(`自动领取优惠券,后台运行中...`)
  646. dataCartMp.keys().forEach(item => {
  647. // 查找优惠券
  648. const $couponEle = $(`.couponModal .coupon-item:contains(${item}):contains(立即抢券) div[data-id]`)
  649.  
  650. if ($couponEle.length === 0) {
  651. return
  652. }
  653. //优惠券ID
  654. const couponId = $couponEle.data('id')
  655. // 优惠券名称
  656. const couponName = $couponEle.data('name')
  657.  
  658. getAjax(`${webSiteShareData.lcscWwwUrl}/getCoupon/${couponId}`).then(async res => {
  659. res = JSON.parse(res)
  660. if (res.result === 'success' || res.code == 200) {
  661. let msg = `${couponName}券,自动领取成功`;
  662. console.log(msg);
  663. Qmsg.success({
  664. content: msg,
  665. timeout: 4000
  666. })
  667. await setTimeout(5000);
  668. allRefresh()
  669. } else {
  670. console.error(`自动领取优惠券失败:${res.msg}`)
  671. }
  672. })
  673. })
  674. } else {
  675. clearInterval(couponTimer)
  676. couponTimer = null
  677. }
  678. }, 5000);
  679. }
  680.  
  681. /**
  682. * 一键分享 已经勾选的列表
  683. */
  684. const shareHandler = () => {
  685. // 产出数据并放在剪贴板中
  686. const _makeDataAndSetClipboard = () => {
  687. const $checkedEles = getAllCheckedLineInfo()
  688.  
  689. if ($checkedEles.length === 0) {
  690. Qmsg.error('购物车未勾选任何商品!')
  691. return
  692. }
  693.  
  694. // 获取所有已经勾选的商品,也包含订货商品
  695. const shareText = [...$checkedEles].map(function(item) {
  696. const $this = $(item)
  697. // 是否是江苏仓,如果是多个仓的话,只取一个
  698. const isJsDepot = $this.find('.warehouse-wrap .warehouse').text().includes('江苏仓')
  699. // 该商品订购的总量
  700. const count = $this.find('.cart-li:eq(4) input').val()
  701.  
  702. return $this.find('.cart-li:eq(1) a').text().trim() + '_' + (isJsDepot ? 'JS_' : 'GD_') + count
  703. }).join('~')
  704.  
  705. // navigator.clipboard.writeText(shareText)
  706. GM_setClipboard(shareText, "text", () => Qmsg.success('购物车一键分享的内容,已设置到剪贴板中!'))
  707. }
  708.  
  709. $('.share_').click(_makeDataAndSetClipboard)
  710. }
  711.  
  712.  
  713. /**
  714. * 一键解析
  715. */
  716. const shareParseHandler = () => {
  717. let _loading = null
  718. // 定义匿名函数
  719. const _shareParse = async() => {
  720. // 富文本框内容
  721. const text = $('.textarea').val().trim()
  722.  
  723. if (text.length === 0) {
  724. Qmsg.error('解析失败,富文本内容为空!')
  725. return
  726. }
  727.  
  728. _loading = Qmsg.loading("正在解析中...请耐心等待!")
  729.  
  730. // 成功条数计数
  731. let parseTaskSuccessCount = 0
  732. // 失败条数计数
  733. let parseTaskErrorCount = 0
  734. // 总条数
  735. let parseTaskTotalCount = 0
  736. // 首次处理出来的数组
  737. const firstparseArr = text.split('~')
  738.  
  739. parseTaskTotalCount = firstparseArr.length || 0
  740.  
  741. for (let item of firstparseArr) {
  742. // 二次处理出来的数组
  743. const secondParseArr = item.split('_')
  744.  
  745. // 物料编号
  746. const productNo = secondParseArr[0].trim().replace('\n', '')
  747. // 仓库编码
  748. const depotCode = secondParseArr[1].trim().replace('\n', '')
  749. // 数量
  750. const count = secondParseArr[2].trim().replace('\n', '')
  751.  
  752. if (productNo === undefined || count === undefined) {
  753. Qmsg.error('解析失败,文本解析异常!')
  754. _loading.close()
  755. return
  756. }
  757.  
  758. // 添加购物车
  759. await postFormAjax(`${webSiteShareData.lcscCartUrl}/cart/quick`, { productCode: productNo, productNumber: count }).then(res => {
  760.  
  761. res = JSON.parse(res)
  762. if (res.code === 200) {
  763. Qmsg.info(`正在疯狂解析中... 共:${parseTaskTotalCount}条,成功:${++parseTaskSuccessCount}条,失败:${parseTaskErrorCount}条。`);
  764. } else {
  765. Qmsg.error(`正在疯狂解析中... 共:${parseTaskTotalCount}条,成功:${parseTaskSuccessCount}条,失败:${++parseTaskErrorCount}条。`);
  766. }
  767. })
  768. }
  769.  
  770. Qmsg.success(`解析完成!共:${parseTaskTotalCount}条,成功:${parseTaskSuccessCount}条,失败:${parseTaskErrorCount}条。已自动加入购物车`)
  771.  
  772. _loading.close()
  773.  
  774. // 刷新购物车页面
  775. cartModuleLoadCartList()
  776. setTimeout(allRefresh, 100);
  777. }
  778.  
  779. $('.share-parse').click(_shareParse)
  780. }
  781.  
  782. /**
  783. * 一键锁定、释放商品
  784. */
  785. const lockProductHandler = () => {
  786. $(`.lock-product`).click(async function() {
  787. const $eles = getHavedCheckedLineInfo()
  788.  
  789. if ($eles.has(':contains("锁定样品")').length === 0) {
  790. Qmsg.error('没有要锁定的商品!')
  791. return;
  792. }
  793.  
  794. for (const that of $eles) {
  795. // 购物车商品的ID
  796. if (!$(that).has(':contains("锁定样品")').length) {
  797. continue;
  798. }
  799. const shoppingCartId = $(that).has(':contains("锁定样品")').attr('id').split('-')[2]
  800. // 接口限流延迟操作
  801. await postFormAjax(`${webSiteShareData.lcscCartUrl}/async/samplelock/locking`, { shoppingCartId }).then(res => {
  802. res = JSON.parse(res)
  803. if (res.code === 200) {
  804. Qmsg.success(res.msg || res.result || '商品锁定成功!')
  805. } else {
  806. Qmsg.error(res.msg || res.result || '商品锁定失败!请稍后再试')
  807. }
  808. })
  809. }
  810.  
  811. // 刷新购物车页面
  812. setTimeout(() => {
  813. cartModuleLoadCartList();
  814. setTimeout(allRefresh, 800);
  815. }, 1000);
  816.  
  817. })
  818.  
  819. $(`.unlock-product`).click(async function() {
  820.  
  821. const $eles = getHavedCheckedLineInfo()
  822.  
  823. if ($eles.has(':contains("释放样品")').length === 0) {
  824. Qmsg.error('没有要锁定的商品!')
  825. return;
  826. }
  827. for (const that of $eles) {
  828. // 购物车商品的ID
  829. if (!$(that).has(':contains("释放样品")').length) {
  830. continue;
  831. }
  832. const shoppingCartId = $(that).has(':contains("释放样品")').attr('id').split('-')[2]
  833. // 接口限流延迟操作
  834. await postFormAjax(`${webSiteShareData.lcscCartUrl}/async/samplelock/release/locking`, { shoppingCartId }).then(res => {
  835. res = JSON.parse(res)
  836. if (res.code === 200) {
  837. Qmsg.success(res.msg || res.result || '商品释放成功!')
  838. } else {
  839. Qmsg.error(res.msg || res.result || '商品释放失败!请稍后再试')
  840. }
  841. })
  842. }
  843.  
  844. // 刷新购物车页面
  845. setTimeout(() => {
  846. cartModuleLoadCartList();
  847. setTimeout(allRefresh, 800);
  848. }, 1000);
  849. })
  850. }
  851.  
  852. // 控制按钮的生成
  853. const buttonListFactory = () => {
  854.  
  855. let isBool = getAllCheckedLineInfo().length > 0
  856.  
  857. return `
  858. <div style="border: unset; position: relative; padding: 8px;">
  859. <div class='mb10 flex flex-sx-center'>
  860. <label style="font-size: 14px" class='ftw1000'>自动领取优惠券</label>
  861. <input style="margin: 0 8px;" type="checkbox" class="checkbox auto-get-coupon" ${getLocalData('AUTO_GET_COUPON_BOOL') === 'true' ? 'checked' : ''}/>
  862. </div>
  863.  
  864. <div class='mb10 flex flex-sx-center'>
  865. <label style="font-size: 14px; width: 105px; z-index: 2;" class='ftw1000 box_'>一键选仓
  866. <div class="circle_ tooltip_" data-msg='第一次点是选中,第二次点是取消选中' style="margin-left: 5px;">?</div>
  867. </label>
  868. <button class='check-js-btn-left_ btn-left_' type='button'>江苏</button>
  869. <button class='check-gd-btn-right_ btn-right_' type='button'>广东</button>
  870. </div>
  871.  
  872. <div class='mb10 flex flex-sx-center'>
  873. <label style="font-size: 14px; width: 105px; z-index: 2;" class='ftw1000 box_'>一键换仓
  874. <div class="circle_ tooltip_" data-msg='只操作多选框选中的商品,包含订货商品' style="margin-left: 5px;">?</div>
  875. </label>
  876. <button class='change-depot-btn-left_ btn-left_' type='button' ${!isBool ? "style='cursor: not-allowed; background-color: #b9b9b95e;color: unset;' disabled" : ""}>江苏</button>
  877. <button class='change-depot-btn-right_ btn-right_' type='button' ${!isBool ? "style='cursor: not-allowed; background-color: #b9b9b95e;color: unset;' disabled" : ""}>广东</button>
  878. </div>
  879.  
  880. <div class='mb10 flex flex-sx-center'>
  881. <label style="font-size: 14px; width: 105px; z-index: 2;" class='ftw1000 box_'>一键锁仓
  882. <div class="circle_ tooltip_" data-msg='只操作多选框选中的现货' style="margin-left: 5px;">?</div>
  883. </label>
  884. <button class='lock-product btn-left_' type='button'>锁定</button>
  885. <button class='unlock-product btn-right_' type='button'>释放</button>
  886. </div>
  887.  
  888.  
  889. <div class='flex flex-sx-center space-between'>
  890. <div class="flex flex-d-col">
  891. <p class='ftw1000 box_ small_btn_ share_' style="margin-bottom: 10px;">一键分享</p>
  892. <p class='ftw1000 box_ small_btn_ share-parse'>一键解析</p>
  893. </div>
  894. <div class="parse-text-box">
  895. <textarea class='textarea' placeholder="请将他人分享的购物车文本,粘贴在此处,之后点击一键解析"></textarea>
  896. </div>
  897. </div>
  898.  
  899. <!-- 查看平台优惠券列表 -->
  900. ${lookCouponListBtnFactory()}
  901. </div>
  902. `
  903. }
  904.  
  905. /**
  906. * 手动刷新按钮
  907. * @returns
  908. */
  909. const refreshBtnFactory = () => {
  910. const svg_ = `<svg t="1716342086339" style="position: absolute; top: 24px; left: 4px; cursor: pointer;" class="icon refresh_btn_" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2572" width="24" height="24"><path d="M981.314663 554.296783a681.276879 681.276879 0 0 1-46.986468 152.746388q-105.706098 230.734238-360.983096 242.19829a593.06288 593.06288 0 0 1-228.689008-33.853939v-1.022615l-31.808709 79.979258a55.759429 55.759429 0 0 1-20.506122 22.551352 40.043451 40.043451 0 0 1-21.04434 5.382184 51.076928 51.076928 0 0 1-19.483507-5.382184 95.210839 95.210839 0 0 1-13.347817-7.158305 52.314831 52.314831 0 0 1-5.382184-4.628679L71.671707 731.908862a57.427906 57.427906 0 0 1-7.158305-21.528737 46.932646 46.932646 0 0 1 1.022615-17.438277 35.952991 35.952991 0 0 1 7.158305-13.347816 74.435608 74.435608 0 0 1 10.279972-10.279972 60.495751 60.495751 0 0 1 11.248765-7.373593 50.431066 50.431066 0 0 1 8.18092-3.606063 6.189512 6.189512 0 0 0 3.067845-1.776121l281.003839-74.866183a91.497132 91.497132 0 0 1 35.899168-2.583448 122.337047 122.337047 0 0 1 22.174599 6.404799 21.528737 21.528737 0 0 1 12.325202 12.325202 76.157907 76.157907 0 0 1 4.628679 14.854829 47.63233 47.63233 0 0 1 0 14.370431 55.167388 55.167388 0 0 1-2.04523 10.764369 10.764368 10.764368 0 0 0-1.022615 3.606063l-32.831324 79.979258a677.50935 677.50935 0 0 0 164.264262 39.505232q77.395809 7.696523 131.809692-3.606063a358.507291 358.507291 0 0 0 101.023598-36.921784 381.27393 381.27393 0 0 0 73.951211-50.753997 352.64071 352.64071 0 0 0 48.708767-55.382676 410.391547 410.391547 0 0 0 26.910921-41.550462c3.767529-7.481236 6.673908-13.616926 8.719139-18.460892zM40.885614 449.667121a685.69027 685.69027 0 0 1 63.563595-176.427998q118.0313-212.273346 374.330913-207.160271a571.803252 571.803252 0 0 1 207.160271 39.989629l33.853939-78.956643A75.619688 75.619688 0 0 1 735.187378 9.189165a37.67529 37.67529 0 0 1 15.393047-8.234742 42.303968 42.303968 0 0 1 14.854829-0.538219 47.578509 47.578509 0 0 1 13.347817 3.606064 102.907362 102.907362 0 0 1 11.302586 6.13569 49.569917 49.569917 0 0 1 6.673909 4.628678l3.067845 3.067845 154.84544 276.913379a81.970666 81.970666 0 0 1 6.13569 22.712817 46.986468 46.986468 0 0 1-1.022615 17.438277 32.293105 32.293105 0 0 1-7.696523 13.347817 69.322533 69.322533 0 0 1-10.764369 9.741753 92.142994 92.142994 0 0 1-11.302587 6.673909l-8.18092 4.09046a7.104483 7.104483 0 0 1-3.067845 1.022615l-283.049068 67.546412a112.003254 112.003254 0 0 1-46.125319-1.022615c-11.571696-3.390776-19.160576-8.019454-22.551352-13.832214a41.173709 41.173709 0 0 1-5.382184-21.04434 97.256069 97.256069 0 0 1 1.291724-17.438277 24.381295 24.381295 0 0 1 3.067845-8.234742L600.632773 296.81309a663.730958 663.730958 0 0 0-164.102797-43.057474q-77.987849-9.203535-131.809692 0a348.227319 348.227319 0 0 0-101.292707 33.853938 368.571976 368.571976 0 0 0-75.350579 49.246986 383.31916 383.31916 0 0 0-50.269601 54.360061 408.507783 408.507783 0 0 0-28.740863 41.012244A113.025869 113.025869 0 0 0 40.885614 449.667121z m0 0" fill="#3498db" p-id="2573"></path></svg>`
  911. return svg_
  912. }
  913.  
  914. /**
  915. * 手动刷新按钮 点击事件
  916. */
  917. const refreshBtnHandler = () => {
  918. $('.refresh_btn_').click(function() {
  919. cartModuleLoadCartList()
  920. allRefresh()
  921. Qmsg.success(`静默刷新购物车成功!`)
  922. })
  923. }
  924.  
  925. /**
  926. * 版本号点击事件
  927. */
  928. const versionClickHandler = () => {
  929. $('#version__').on('click', function() {
  930. GM_setClipboard(
  931. 'https://greasyfork.org/zh-CN/scripts/491619-%E5%98%89%E7%AB%8B%E5%88%9B%E8%B4%AD%E7%89%A9%E8%BD%A6%E8%BE%85%E5%8A%A9%E5%B7%A5%E5%85%B7',
  932. "text",
  933. () => Qmsg.success('插件地址已设置到剪贴板中!'))
  934. })
  935. }
  936.  
  937. /**
  938. * 显示隐藏 小窗的的按钮展示
  939. */
  940. const showOrHideButtonFactory = () => {
  941.  
  942. $('.hideBtn,.showBtn').remove()
  943.  
  944. return `
  945. <div class="hideBtn" ${getLocalData('SHOW_BOOL') === 'false' ? 'hide_' : ''}>
  946. 收起助手 >
  947. </div>
  948. <div class="showBtn ${getLocalData('SHOW_BOOL') === 'true' ? 'hide_' : ''}" >
  949. < 展开助手
  950. </div>
  951. `
  952. }
  953.  
  954. /**
  955. * 查询购物车中的品牌数量总和(多选框选中)
  956. */
  957. const brandCountFactory = () => {
  958. return `
  959. <p class='small-sign small-sign-pos'>
  960. ${dataCartMp.size}
  961. </p>
  962. `
  963. }
  964.  
  965. /**
  966. * 计算总的金额
  967. */
  968. const totalMoneyFactory = () => {
  969.  
  970. let t = 0
  971.  
  972. if (dataCartMp.size > 0) {
  973. t = [...dataCartMp.values()].reduce((total, num) => total + num).toFixed(2)
  974. }
  975.  
  976. return `
  977. <p class='total-money_'>
  978. ${t}
  979. </p>
  980. `
  981. }
  982.  
  983. /**
  984. * 查询16-15优惠券列表
  985. */
  986. const lookCouponListBtnFactory = () => {
  987. return `
  988. <p class='look-coupon-btn'>
  989. 优惠券专区
  990. </p>
  991. `
  992. }
  993.  
  994. /**
  995. * 查看优惠券页面的扩展按钮,绑定事件
  996. */
  997. const lookCouponListExtendsBtnHandler = () => {
  998.  
  999. // 查看已领取的优惠券
  1000. $('.filter-haved').off('click').on('click', function() {
  1001. $('.coupon-item:visible:not(:contains(立即使用))').hide()
  1002. })
  1003.  
  1004. // 过滤16-15的优惠券
  1005. $('.filter-16-15').off('click').on('click', function() {
  1006. $('.coupon-item:visible:not(:contains(满16可用))').hide()
  1007. })
  1008.  
  1009. // 过滤20-15的优惠券
  1010. $('.filter-20-15').off('click').on('click', function() {
  1011. $('.coupon-item:visible:not(:contains(满20可用))').hide()
  1012. })
  1013.  
  1014. // 过滤新人优惠券
  1015. $('.filter-newone').off('click').on('click', function() {
  1016. $('.coupon-item:visible:not(:contains(新人专享))').hide()
  1017. })
  1018.  
  1019. // 过滤非新人优惠券
  1020. $('.filter-not-newone').off('click').on('click', function() {
  1021. $('.coupon-item:visible:contains(新人专享)').hide()
  1022. })
  1023.  
  1024.  
  1025. // 手动刷新优惠券页面
  1026. $('.refresh-coupon-page').off('click').on('click', function() {
  1027. setTimeout(() => {
  1028. Qmsg.info(`1秒后刷新优惠券页面...`)
  1029. setTimeout(() => lookCouponListModal(true), 500);
  1030. }, 500);
  1031.  
  1032. })
  1033.  
  1034.  
  1035.  
  1036. // 一键领取当前显示的所有优惠券
  1037. $('.get-all').click(function() {
  1038. const $couponEles = $('.coupon-item:visible div:contains(立即抢券)')
  1039.  
  1040. let totalCount = 0,
  1041. successCount = 0;
  1042. $couponEles.each(function() {
  1043.  
  1044. //优惠券ID
  1045. const couponId = $(this).data('id')
  1046.  
  1047. // 优惠券名称
  1048. const couponName = $(this).data('name')
  1049.  
  1050. getAjax(`${webSiteShareData.lcscWwwUrl}/getCoupon/${couponId}`).then(res => {
  1051. res = JSON.parse(res)
  1052. if (res.code === 200 && res.msg === '') {
  1053. successCount++
  1054. // console.log(`${couponName} 优惠券领取成功`)
  1055. } else {
  1056. // console.error(`${couponName} 优惠券领取失败,或者 已经没有可以领取的优惠券了!`)
  1057. }
  1058. })
  1059.  
  1060. totalCount++
  1061. })
  1062.  
  1063. if (successCount === 0) {
  1064. Qmsg.error(`优惠券领取失败,或者已经没有可以领取的优惠券了!`)
  1065. } else if ($couponEles.length === totalCount) {
  1066. Qmsg.success(`优惠券领取成功!成功:${successCount}条,失败:${totalCount - successCount}条。`)
  1067. setTimeout(() => {
  1068. Qmsg.info(`2秒后刷新优惠券页面...`)
  1069.  
  1070. // 由于调用接口领取,所以需要重新渲染优惠券页面
  1071. setTimeout(lookCouponListModal, 2000);
  1072. }, 2000);
  1073. }
  1074. })
  1075.  
  1076. // 过滤新人优惠券
  1077. $('.filter-clear').click(function() {
  1078. $('.coupon-item:hidden').show()
  1079. })
  1080. }
  1081.  
  1082. /**
  1083. * 查看优惠券列表的按钮
  1084. */
  1085. const lookCouponListHandler = () => {
  1086. const _lookCouponClick = () => {
  1087. if ($('#couponModal').is(':hidden')) {
  1088. $('#couponModal').show()
  1089. } else if ($('#couponModal').is(':visible')) {
  1090. $('#couponModal').hide()
  1091. }
  1092. }
  1093. $('.look-coupon-btn,.look-coupon-closebtn').on('click', _lookCouponClick)
  1094. }
  1095.  
  1096. // 优惠券模态框的锁
  1097. var lookCouponLock = false;
  1098. /**
  1099. * 优惠券模态框
  1100. */
  1101. const lookCouponListModal = async(clear = false) => {
  1102.  
  1103. if (lookCouponLock || !plguinIsHavedAndShow() || ($('.couponModal .all-coupon-page').length > 0 && clear === false)) {
  1104. return;
  1105. }
  1106. //上锁, 防止这次还没处理完, 下次定时任务就已经就绪了。
  1107. lookCouponLock = true;
  1108. let couponHTML = await getAjax(`${webSiteShareData.lcscWwwUrl}/huodong.html`);
  1109.  
  1110. const $couponHTML = $(couponHTML);
  1111.  
  1112. let $cssLink = [...$couponHTML].filter(item => item.localName == 'link' && item.href.includes('/public/css/page/activity/couponAllCoupons'))[0].outerHTML;
  1113. let $jsLink = [...$couponHTML].filter(item => item.localName == 'script' && item.src.includes('/public/js/chunk/page/activity/couponAllCoupons'))[0].outerHTML;
  1114.  
  1115. let $main_wraper = $couponHTML.find('.main_wraper');
  1116. let $navigation = $couponHTML.find('.navigation');
  1117.  
  1118. let ht = `
  1119. <div class="all-coupon-page"></div>
  1120. <div class="common-alert-success-tip-tmpl common-confirm-del">
  1121. <div class="common-confirm-del-title">
  1122. <h3>成功提示</h3>
  1123. <a style="cursor: pointer;" class="common-confirm-del-close"></a>
  1124. </div>
  1125. <div class="common-confirm-del-content">
  1126. <p class="common-confirm-del-content-txt success">content</p>
  1127. <div class="common-confirm-del-btn">
  1128. <input type="button" class="common-confirm-a" value="确定">
  1129. </div>
  1130. <div class="common-confirm-del-icon-success"></div>
  1131. </div>
  1132. </div>
  1133. <div class="mask">
  1134. </div>`;
  1135. const $couponEle = $('.couponModal');
  1136. $couponEle.empty().append(ht).append($cssLink).append($jsLink);
  1137.  
  1138. $('.couponModal .all-coupon-page').append($main_wraper).append($navigation);
  1139.  
  1140. couponGotoHandler();
  1141. // 解锁
  1142. lookCouponLock = false;
  1143. }
  1144.  
  1145. /**
  1146. * 品牌多选按钮监听处理事件
  1147. * 追加html、事件监听、模态框都放在这里写
  1148. */
  1149. const lookCouponCheckboxHandler = () => {
  1150. if ($('#batch-check-branch').length == 0 && $('.batch-del-btn').length > 0) {
  1151. $('.foot-tool-left div:eq(0)').append(`
  1152. <span id="batch-check-branch" style="margin-left: 10px;
  1153. margin-left: 6px;
  1154. padding: 10px 12px;
  1155. background: #0093e6;
  1156. border-radius: 2px;
  1157. cursor: pointer;
  1158. color: white;">批量选择现货品牌</span>
  1159. `);
  1160.  
  1161. // 动态刷新勾选框状态,商品下所有商品选中的状态才会打勾
  1162. setInterval(() => {
  1163. // 小模态框未显示的话,直接跳过
  1164. if ($('#batch-check-branch-box').length === 0 || $('#batch-check-branch-box').is(':hidden')) {
  1165. return;
  1166. }
  1167. // CHECKED选中、UNCHECKED未选中、INDETERMINATE不确定
  1168. var ckMap = checkboxStatusGroupByBrandName();
  1169. ckMap.forEach((checkStatus, brandName) => {
  1170. brandName = brandNameDataProcess(brandName);
  1171. // 判断状态
  1172. switch (checkStatus) {
  1173. case 'CHECKED':
  1174. $(`input#${brandName}-ckbox`).prop('checked', true);
  1175. $(`input#${brandName}-ckbox`)[0].indeterminate = false;
  1176. break;
  1177. case 'UNCHECKED':
  1178. $(`input#${brandName}-ckbox`).prop('checked', false);
  1179. $(`input#${brandName}-ckbox`)[0].indeterminate = false;
  1180. break;
  1181. case 'INDETERMINATE':
  1182. $(`input#${brandName}-ckbox`)[0].indeterminate = true;
  1183. break;
  1184. }
  1185. })
  1186. }, 1500);
  1187.  
  1188. // 点击事件监听
  1189. $('#batch-check-branch').on('click', function() {
  1190. const $box = $('#batch-check-branch-box');
  1191. if ($box.length == 0) {
  1192. $('body').append(`
  1193. <div id="batch-check-branch-box" style="
  1194. position: fixed;
  1195. flex-wrap: wrap;
  1196. display: flex;
  1197. bottom: 55px;
  1198. left: 25%;
  1199. z-index: 100;
  1200. overflow: auto;
  1201. width: 500px;
  1202. background-color: white;
  1203. border: 3px solid #3498db;
  1204. border-radius: 5px;
  1205. ">
  1206. ${[...dataBrandColorMp.keys()].reverse().map(brandName => {
  1207. var tempBname = brandName;
  1208. brandName = brandNameDataProcess(brandName);
  1209. return `<div class="hover-cs checkbox-branch-btn" style="background-color: ${dataBrandColorMp.get(tempBname)};
  1210. width: fit-content;
  1211. height: fit-content;
  1212. font-size: 14px;
  1213. margin: 5px 0px 5px 5px;
  1214. padding: 5px;
  1215. cursor: pointer;
  1216. color: white;">
  1217. <label id="${brandName}-ckbox" style="cursor: pointer;display: flex;">
  1218. <input id="${brandName}-ckbox" type="checkbox" style="margin-right: 5px; cursor: pointer;">${tempBname}</input>
  1219. </label>
  1220. </div>`
  1221. }).join('')}
  1222. </div>
  1223. `);
  1224. // 点击事件-选中指定品牌的所有商品
  1225. $('.checkbox-branch-btn').on('click', function() {
  1226. var brandName = $(this).find('label').text().replace(/[ \n]/g, '');
  1227. checkBoxByBrandName(brandName, $(this).find('input[type=checkbox]').is(':checked')?1:0);
  1228. })
  1229. }
  1230. $box.is(':visible') ? $box.hide() : $box.show();
  1231. })
  1232. }
  1233. }
  1234.  
  1235. // 暂存已经领取的优惠券列表
  1236. var havedCouponList = [];
  1237. /**
  1238. * 比较慢的定时,去尝试获取已经拥有的优惠券
  1239. * 遍历我的优惠券页面,这显然不是一个很好的方法
  1240. */
  1241. const lookHavedCouponList = () => {
  1242. // 清空集合
  1243. havedCouponList = [];
  1244. // 动态url
  1245. const renderUrl = (page) => `https://activity.szlcsc.com/member/couponList.html?currentPage=${page || 1}&couponUseStatus=no`;
  1246. // 当前页标记
  1247. var currentPage = 1;
  1248. // 定时取页面数据
  1249. var lookHavedCouponTimer = setInterval(async () => {
  1250. // http获取我都优惠券
  1251. let couponHTML = await getAjax(renderUrl(currentPage));
  1252. var $html = $(couponHTML);
  1253. // 查看当前页是否有优惠券
  1254. var isNull = $html.find('td:contains(没有相关优惠券记录)').length > 0;
  1255. // 没找到优惠券
  1256. if(isNull) {
  1257. // 清除定时
  1258. clearInterval(lookHavedCouponTimer);
  1259. lookHavedCouponTimer = null;
  1260. // 30秒后再次尝试看有没有领的优惠券
  1261. setTimeout(lookHavedCouponList, 30 * 1000);
  1262. return;
  1263. }
  1264. // 剩下的是有券的时候
  1265. else {
  1266. havedCouponList = [...new Set(
  1267. [
  1268. ...havedCouponList,
  1269. // 这里不关心 面板定制券、运费券 也不关心优惠券的金额。只要品牌名称对应上就算有券了。
  1270. ...($html.find('span.yhjmingchen').text().split(/品牌优惠券?/g).map(item => item.replace(/.+元/g, '')).filter(item => item && !item.includes('面板定制', '运费券')))
  1271. ])];
  1272. }
  1273. currentPage++;
  1274. // 追加显示优惠券的状态
  1275. if (plguinIsHavedAndShow()) {
  1276. $('.bd ul li .appendStatus').each(function() {
  1277. var isTrue = havedCouponList.includes($(this).attr('brandName'));
  1278. if(isTrue) {
  1279. $(this).off('click').removeClass('to_cou').css({
  1280. border: 'none',
  1281. background: 'transparent',
  1282. color: 'white',
  1283. fontSize: '12px'
  1284. }).text('已领取-优惠券');
  1285. }
  1286. });
  1287. }
  1288. }, 500);
  1289. }
  1290.  
  1291. /**
  1292. * 根据品牌名称分组多选框选中状态
  1293. * CHECKED选中、UNCHECKED未选中、INDETERMINATE不确定
  1294. * 只查现货的
  1295. */
  1296. const checkboxStatusGroupByBrandName = () => {
  1297. // 获取现货
  1298. var $ele = getHavedLineInfo();
  1299. // 品牌名是否全选
  1300. var ckMap = new Map();
  1301. [...$ele].forEach(function(that) {
  1302. var $this = $(that);
  1303. // 品牌名称
  1304. let brandName = $this.find('.cart-li-pro-info div:eq(2)').text().trim();
  1305. // 查找到品牌名称
  1306. brandName = getBrandNameByRegex(brandName.split('\n')[brandName.split('\n').length - 1].trim());
  1307. // 处理特殊字符
  1308. brandName = brandNameDataProcess(brandName);
  1309. var $checkedEle = $this.find('input.check-box');
  1310. // 当前元素的选中状态
  1311. var currentCheckStatus = $checkedEle.is(':checked') ? 'CHECKED' : 'UNCHECKED';
  1312. // 如果已经是未全选状态,直接跳出该品牌了
  1313. if(ckMap.get(brandName) === 'INDETERMINATE') {
  1314. return;
  1315. }
  1316. // 不确定的状态判断
  1317. if(ckMap.get(brandName) != null && ckMap.get(brandName) != currentCheckStatus) {
  1318. ckMap.set(brandName, 'INDETERMINATE');
  1319. return;
  1320. }
  1321. // 默认
  1322. ckMap.set(brandName, currentCheckStatus);
  1323. if (currentCheckStatus === 'UNCHECKED') {
  1324. ckMap.set(brandName, currentCheckStatus);
  1325. }
  1326. })
  1327.  
  1328. return ckMap;
  1329. }
  1330.  
  1331. /**
  1332. * 常规的多选框事件,指定品牌的
  1333. * @param {*} brandName
  1334. * @param {*} type 1选中、0移除选中
  1335. */
  1336. const checkBoxByBrandName = (brandName, type) => {
  1337. var $ele = getHavedLineInfoByBrandName(brandName);
  1338. var $checkedEle = $ele.find('input.check-box:checked');
  1339. var $notCheckedEle = $ele.find('input.check-box:not(:checked)');
  1340. if(type === 1) {
  1341. $notCheckedEle.click();
  1342. }
  1343. else if(type === 0) {
  1344. $checkedEle.click();
  1345. }
  1346. }
  1347.  
  1348. /**
  1349. * 获取勾选框选中的物料编号集合,波浪线分割
  1350. */
  1351. const myGetCK = () => {
  1352. return [...getAllCheckedLineInfo().map(function () {
  1353. return $(this).attr('id').split('-')[2]
  1354. })].join('~')
  1355. }
  1356.  
  1357.  
  1358. /**
  1359. * 更新购物车勾选
  1360. */
  1361. const cartUpdateChecked = () => {
  1362. return new Promise((resolve, reject) => {
  1363. try {
  1364. postFormAjax(`${webSiteShareData.lcscCartUrl}/page/home/cart/update/checked`, { ck: (myGetCK() || 'false') }).then(res => {
  1365. res = JSON.parse(res)
  1366. if (res.code === 200 && res.msg === null) {
  1367. resolve('true')
  1368. } else {
  1369. resolve('true')
  1370. }
  1371. })
  1372. } catch (error) {
  1373. console.error(error);
  1374. reject('false')
  1375. }
  1376. })
  1377. }
  1378.  
  1379. /**
  1380. * 根据品牌名称 查询是否多仓
  1381. * @returns true多仓,false 非多仓
  1382. */
  1383. const juageMultiDepotByBrandName = (brandName) => {
  1384. //这样是多仓 ['江苏', '广东', '']
  1385. return new Set($(`.product-item:contains("${brandName}")`).find('.warehouse:contains("仓")').text().replace(/[^广东江苏仓]+/g, '').split('仓')).size === 3
  1386. }
  1387.  
  1388. /**
  1389. * 追加的html
  1390. * @returns
  1391. */
  1392. const htmlFactory = () => {
  1393.  
  1394. let tempHtml = `
  1395. ${$('.couponModal').length === 0 ? `
  1396. <div id="couponModal" style="display: none;">
  1397. <div class="extend-btn-group_">
  1398. <p class="coupon-item-btn-text_ refresh-coupon-page">刷新领券页面</p>
  1399. <p class="coupon-item-btn-text_ filter-clear">清空筛选</p>
  1400. <p class="coupon-item-btn-text_ filter-haved">查看已领取</p>
  1401. <p class="coupon-item-btn-text_ filter-16-15">筛选16-15</p>
  1402. <p class="coupon-item-btn-text_ filter-20-15">筛选20-15</p>
  1403. <p class="coupon-item-btn-text_ filter-newone">筛选新人券</p>
  1404. <p class="coupon-item-btn-text_ filter-not-newone">筛选非新人券</p>
  1405.  
  1406. <p class="coupon-item-btn-text_ get-all" style="height: auto;">一键领取</br>当前展示优惠券</p>
  1407. </div>
  1408. <!-- <p class="look-coupon-closebtn" style=''>X</p> -->
  1409. <div class="couponModal">
  1410.  
  1411. </div>
  1412. </div>
  1413.  
  1414. ` : ''}
  1415.  
  1416. ${showOrHideButtonFactory()}
  1417. <div class="bd ${getLocalData('SHOW_BOOL') === 'true' ? '' : 'hide_'}">
  1418. ${buttonListFactory()}
  1419. <ul>`
  1420.  
  1421. const head = `
  1422. <li class='li-cs' style="position: sticky; top: 0px; background-color: white; z-index: 2;">
  1423. ${refreshBtnFactory()}
  1424. <div>
  1425. <!-- 勾选的品牌数量 -->
  1426. ${brandCountFactory()}
  1427.  
  1428. <!-- 计算所有的总金额 -->
  1429. ${totalMoneyFactory()}
  1430.  
  1431. <span style='font-weight: 1000; color: black;width: 165px; line-height: 24px;' class="flex flex-zy-center">品牌名称
  1432. </br>(现货)</span>
  1433. <span style='font-weight: 1000; color: black; width: 90px;line-height: 24px;' class="flex flex-zy-center">总金额</span>
  1434. <span style='font-weight: 1000; color: black; width: 80px;line-height: 24px;' class="flex flex-zy-center">差额</span>
  1435. <span style='font-weight: 1000; color: black; line-height: 24px;' class="flex flex-zy-center">优惠券</br>(16-15) </span>
  1436. </div>
  1437. </li>
  1438. `
  1439.  
  1440. tempHtml += head
  1441.  
  1442. for (var [key, val] of sortMapByValue(dataCartMp)) {
  1443. tempHtml += `
  1444. <li class='li-cs click-hv ftw500'>
  1445. <div>
  1446. <p class="small-sign ${juageMultiDepotByBrandName(key) ? 'multi_' : 'multi_default'} multi_pos_" style="font-size: 12px; line-height: 100%;">多仓库</p>
  1447. <span class='key sort_' style="width: 155px; text-overflow: ellipsis;overflow: hidden;white-space: nowrap;">${key}</span>
  1448. <span class='val sort_' style="width: 90px;">${val}</span>
  1449. <span class='val sort_' style="width: 80px;">${(16 - val).toFixed(2)}</span>
  1450. ${couponHTMLFactory(key)}
  1451. </div>
  1452. </li>
  1453. `
  1454. }
  1455.  
  1456. return tempHtml + `</ul>
  1457. <div style="display: flex;
  1458. justify-content: space-between;
  1459. padding: 4px 5px 4px;
  1460. background: #fff;
  1461. box-sizing: border-box;
  1462. position: sticky;
  1463. user-select:none;
  1464. bottom: 0px;">
  1465. <span id="version__" title="点击版本,可以复制插件地址~" style="color: #3498dbe7; font-size: 14px; font-family: fantasy; cursor: pointer;">${__version}</span>
  1466. <span style="color: #777;">如果觉得插件有用,请分享给你身边的朋友~</span>
  1467. </div>
  1468. </div>`;
  1469. }
  1470.  
  1471. /**
  1472. * 优惠券按钮的html生成
  1473. * @param {*} brandName 品牌名称
  1474. */
  1475. const couponHTMLFactory = (brandName) => {
  1476.  
  1477. // 优惠券实体
  1478. const couponEntity = all16_15CouponMp.get(brandName)
  1479.  
  1480. let buttonLine = ''
  1481.  
  1482. if (!$.isEmptyObject(couponEntity)) {
  1483.  
  1484. // 是否已经领取
  1485. if (couponEntity.isHaved === true) {
  1486. buttonLine = `<span class='val' style="text-align: center; ">
  1487. <span style="font-size: 12px;">已领取-${couponEntity.isNew === false ? '普通券' : '新人券'}</span>
  1488. </span> `
  1489. }
  1490. else if (couponEntity.isUsed === true) {
  1491. buttonLine = `<span class='val' style="text-align: center; ">
  1492. <span style="font-size: 12px;">本月已使用</span>
  1493. </span> `
  1494. }
  1495. else {
  1496. buttonLine = `<span class='flex-sx-center flex-zy-center flex' style="padding: 0; width: 195px; text-align: center; ">
  1497. <button type="button" class="to_cou appendStatus" brandName="${brandName}">${couponEntity.isNew === false ? '普通券' : '新人券'}</button>
  1498. </span> `
  1499. }
  1500. }
  1501. // 这里会查一遍我的优惠券,如果有的话,就证明有券。
  1502. return $.isEmptyObject(buttonLine) ? `<span class='val' style="text-align: center; ">
  1503. <span class="appendStatus" brandName="${brandName}">${havedCouponList.includes(brandName) ? '优惠券已领取' : '' }</span>
  1504. </span> ` : buttonLine
  1505. }
  1506.  
  1507.  
  1508. /**
  1509. * 追加的css
  1510. * @returns
  1511. */
  1512. const cssFactory = () => `
  1513. <style id="myCss">
  1514. .hover-cs:hover {
  1515. color: #e1e1e1 !important;
  1516. cursor: pointer;
  1517. }
  1518.  
  1519. #couponModal {
  1520. height: 85vh;
  1521. position: fixed;
  1522. top: 40px;
  1523. right: 440px;
  1524. z-index: 9999;
  1525. overflow: auto;
  1526. background-color: white;
  1527. border: 3px solid #3498db;
  1528. border-radius: 5px;
  1529. padding: 5px 150px 0 10px;
  1530. margin-left: 40px;
  1531. }
  1532.  
  1533. .look-coupon-closebtn {
  1534. position: fixed;
  1535. top: 20px;
  1536. right: 210px;
  1537. border: 2px solid #3498db !important;
  1538. background-color: white;
  1539. padding: 5px 20px;
  1540. width: min-content !important;
  1541. border-radius: 5px;
  1542. zoom: 200%;
  1543. }
  1544.  
  1545. .bd {
  1546. position: fixed;
  1547. top: 40px;
  1548. right: 33px;
  1549. background-color: white;
  1550. border: 2px solid #3498db;
  1551. width: 380px;
  1552. padding: 3px 3px 0px 3px;
  1553. border-radius: 5px;
  1554. z-index: 99;
  1555. overflow: auto;
  1556. }
  1557.  
  1558. .ftw400 {
  1559. font-weight: 400;
  1560. }
  1561.  
  1562. .ftw500 {
  1563. font-weight: 500;
  1564. }
  1565.  
  1566. .ftw1000 {
  1567. font-weight: 1000;
  1568. }
  1569.  
  1570. .hideBtn,
  1571. .showBtn {
  1572. position: fixed;
  1573. top: 20px;
  1574. right: 10px;
  1575. background-color: white;
  1576. border: 2px solid #3498db;
  1577. width: 85px;
  1578. line-height: 30px;
  1579. text-align: center;
  1580. padding: 3px;
  1581. font-weight: 800;
  1582. border-radius: 5px;
  1583. z-index: 1501;
  1584. font-size: 16px;
  1585. cursor: pointer;
  1586. user-select:none;
  1587. }
  1588.  
  1589. .hide_ {
  1590. display: none;
  1591. }
  1592.  
  1593. .m10 {
  1594. margin: 10px;
  1595. }
  1596. .mb10 {
  1597. margin-bottom: 10px;
  1598. }
  1599. .mt10 {
  1600. margin-top: 10px;
  1601. }
  1602. .ml10 {
  1603. margin-left: 10px;
  1604. }
  1605. .mr10 {
  1606. margin-right: 10px;
  1607. }
  1608.  
  1609. .flex {
  1610. display: flex;
  1611. }
  1612.  
  1613. .flex-sx-center {
  1614. /*上下居中*/
  1615. align-items: center;
  1616. }
  1617.  
  1618. .space-between {
  1619. justify-content: space-between;
  1620. }
  1621.  
  1622. .flex-zy-center {
  1623. /*左右居中*/
  1624. justify-content: center;
  1625. }
  1626.  
  1627. .flex-d-col {
  1628. flex-direction: column;
  1629. }
  1630.  
  1631. .flex-d-row {
  1632. flex-direction: row;
  1633. }
  1634.  
  1635. .li-cs {
  1636. margin: 5px;
  1637. font-size: 14px;
  1638. box-sizing: border-box;
  1639. user-select:none;
  1640. position: relative;
  1641. }
  1642.  
  1643. .box_ {
  1644. box-sizing: border-box;
  1645. }
  1646.  
  1647. .click-hv:hover span {
  1648. color: #e1e1e1 !important;
  1649. cursor: pointer;
  1650. }
  1651.  
  1652. .li-cs div, .li-cs p {
  1653. display: flex;
  1654. width: 100%;
  1655. border: 2px solid #3498db;
  1656. border-radius: 5px;
  1657. }
  1658.  
  1659. .li-cs span {
  1660. padding: 10px;
  1661. width: 50%;
  1662. color: white;
  1663. box-sizing: border-box;
  1664. }
  1665.  
  1666. .li-cs .to_cou {
  1667. border: 1px solid white;
  1668. border-radius: 3px;
  1669. background-color: rgba(255, 255, 255, 0.6);
  1670. padding: 5px 15px;
  1671. color: #2c4985;
  1672. }
  1673.  
  1674. .cart-li-pro-info div:hover {
  1675. color: rgba(57, 46, 74, 0.9) !important;
  1676. }
  1677.  
  1678. .checkbox {
  1679. appearance: none;
  1680. width: 64px;
  1681. height: 32px;
  1682. position: relative;
  1683. border-radius: 16px;
  1684. cursor: pointer;
  1685. background-color: #777;
  1686. zoom: 90%;
  1687. }
  1688.  
  1689. .checkbox:before {
  1690. content: "";
  1691. position: absolute;
  1692. width: 28px;
  1693. height: 28px;
  1694. background: white;
  1695. left: 2px;
  1696. top: 2px;
  1697. border-radius: 50%;
  1698. transition: left cubic-bezier(0.3, 1.5, 0.7, 1) 0.3s;
  1699. }
  1700.  
  1701. .checkbox:after {
  1702. content: "开 关";
  1703. text-indent: 12px;
  1704. word-spacing: 4px;
  1705. display: inline-block;
  1706. white-space: nowrap;
  1707. color: white;
  1708. font: 14px/30px monospace;
  1709. font-weight: bold;
  1710. }
  1711.  
  1712. .checkbox:hover:before {
  1713. box-shadow: inset 0px 0px 5px 0px #3498db;
  1714. }
  1715.  
  1716. .checkbox:checked {
  1717. background-color: #3498db;
  1718. }
  1719.  
  1720. .checkbox:checked:before {
  1721. left: 34px;
  1722. }
  1723.  
  1724. .checkbox:checked:after {
  1725. color: #fff;
  1726. }
  1727.  
  1728. .small-sign {
  1729. padding: 2px 3px;
  1730. width: min-content !important;
  1731. font-weight: bold;
  1732. }
  1733.  
  1734. .small-sign-pos {
  1735. position: absolute;
  1736. top: 35px;
  1737. left: 70px;
  1738. }
  1739.  
  1740. .multi_ {
  1741. background: white;
  1742. color: #013d72 !important;
  1743. width: min-content !important;
  1744. font-weight: 200 !important;
  1745. border-radius: 2px !important;
  1746. padding: unset !important;
  1747. height: fit-content;
  1748. border: none !important;
  1749. font-size: 11px;
  1750. }
  1751.  
  1752. .multi_default {
  1753. width: min-content !important;
  1754. font-weight: 200 !important;
  1755. border-radius: 2px !important;
  1756. padding: unset !important;
  1757. height: fit-content;
  1758. border: none !important;
  1759. font-size: 11px;
  1760. color: #00000000;
  1761. }
  1762.  
  1763. .multi_pos {
  1764. position: absolute;
  1765. top: -3px;
  1766. left: 83px;
  1767. }
  1768.  
  1769. .total-money_ {
  1770. position: absolute;
  1771. top: 35px;
  1772. left: 123px;
  1773. padding: 2px 3px;
  1774. width: min-content !important;
  1775. font-weight: bold;
  1776. }
  1777.  
  1778.  
  1779. .look-coupon-btn {
  1780. font-weight: bold;
  1781. width: 110px !important;
  1782. height: 135px;
  1783. text-align: center;
  1784. line-height: 130px;
  1785. display: block !important;
  1786. background-color: #3498db;
  1787. position: absolute;
  1788. top: 20px;
  1789. right: 4px;
  1790. color: white;
  1791. font-size: 18px;
  1792. border-radius: 5px;
  1793. border: 2px solid #3498db;
  1794. user-select:none;
  1795. }
  1796.  
  1797. .btn-group_ {
  1798. border: 2px solid #3498db;
  1799. }
  1800.  
  1801. button.btn-left_,
  1802. button.btn-right_ {
  1803. width: 60px;
  1804. height: 30px;
  1805. border: unset;
  1806. background-color: white;
  1807. }
  1808.  
  1809. button.btn-right_:hover,
  1810. button.btn-left_:hover,
  1811. .to_cou:hover,
  1812. .showBtn:hover,
  1813. .look-coupon-closebtn:hover,
  1814. .look-coupon-btn:hover,
  1815. .share_:hover,
  1816. .coupon-item-btn-text_:hover
  1817. {
  1818. background-color: #53a3d6 !important;
  1819. color: white !important;
  1820. cursor: pointer;
  1821. }
  1822.  
  1823. button.btn-left_ {
  1824. border-left: 2px solid #3498db;
  1825. border-block: 2px solid #3498db;
  1826. border-radius: 5px 0 0 5px;
  1827. border-right: 2px solid #3498db;
  1828. }
  1829.  
  1830. button.btn-right_ {
  1831. border-right: 2px solid #3498db;
  1832. border-block: 2px solid #3498db;
  1833. border-radius: 0 5px 5px 0;
  1834. }
  1835.  
  1836. .circle_ {
  1837. display: inline-block;
  1838. width: 16px;
  1839. height: 16px;
  1840. border-radius: 50%;
  1841. background-color: #77b0e2;
  1842. color: #fff;
  1843. font-size: 12px;
  1844. text-align: center;
  1845. line-height: 15px;
  1846. position: relative;
  1847. }
  1848.  
  1849. .circle_::before {
  1850. content: "?";
  1851. font-size: 16px;
  1852. position: absolute;
  1853. top: 50%;
  1854. left: 50%;
  1855. transform: translate(-50%, -50%);
  1856. }
  1857.  
  1858. .tooltip_ {
  1859. position: relative;
  1860. font-size: 14px;
  1861. cursor: pointer;
  1862. }
  1863.  
  1864. .tooltip_:hover::before {
  1865. word-break: keep-all;
  1866. white-space: nowrap;
  1867. content: attr(data-msg);
  1868. position: absolute;
  1869. padding: 8px 10px;
  1870. display: block;
  1871. color: #424343;
  1872. border: 2px solid #3498db;
  1873. border-radius: 5px;
  1874. font-size: 14px;
  1875. line-height: 20px;
  1876. top: -47px;
  1877. left: 50%;
  1878. transform: translateX(-25%);
  1879. background-color: white;
  1880. }
  1881.  
  1882. .tooltip_:hover::after {
  1883. content: "﹀";
  1884. position: absolute;
  1885. top: -10px;
  1886. left: 50%;
  1887. -webkit-transform: translateX(-50%);
  1888. -ms-transform: translateX(-50%);
  1889. transform: translateX(-50%);
  1890. background: #fff;
  1891. color: #3498db;
  1892. height: 7px;
  1893. line-height: 10px;
  1894. background-color: white;
  1895. }
  1896.  
  1897.  
  1898. .all-coupon-page .navigation {
  1899. position: fixed;
  1900. left: unset !important;
  1901. right: 505px !important;
  1902. top: 470px !important;
  1903. z-index: 1000;
  1904. }
  1905.  
  1906. .all-coupon-page .main_wraper {
  1907. background: #fff;
  1908. zoom: 0.9;
  1909. width: unset !important;
  1910. }
  1911.  
  1912. .extend-btn-group_ {
  1913. position: fixed;
  1914. right: 480px;
  1915. top: 100px;
  1916. z-index: 888;
  1917. margin-left: -720px;
  1918. }
  1919.  
  1920. .extend-btn-group_ .coupon-item-btn-text_ {
  1921. box-sizing: border-box;
  1922. width: 100px;
  1923. height: 30px;
  1924. text-align: center;
  1925. background: #199fe9;
  1926. font-size: 14px;
  1927. font-weight: 400;
  1928. color: #fff;
  1929. line-height: 30px;
  1930. cursor: pointer;
  1931. border-radius: 4px;
  1932. margin-top: 9px;
  1933. }
  1934.  
  1935. .extend-btn-group_ .filter-clear {
  1936. color: #3498db;
  1937. background: white;
  1938. border: 1px solid #3498db;
  1939. font-weight: bolder;
  1940. }
  1941.  
  1942. .coupon-item {
  1943. margin: 0 7px 10px 7px !important;
  1944. }
  1945.  
  1946. .parse-text-box {
  1947. margin-right: 7px;
  1948. width: 100%;
  1949. }
  1950.  
  1951. .textarea {
  1952. width: 100%;
  1953. min-width: 230px !important;
  1954. min-height: 85px !important;
  1955. border: 1px solid #3498db;
  1956. border-radius: 3px;
  1957. }
  1958.  
  1959. .small_btn_ {
  1960. font-size: 14px;
  1961. width: 80px;
  1962. margin-right: 22px;
  1963. z-index: 2;
  1964. border: 2px;
  1965. background-color: #3498db;
  1966. cursor: pointer;
  1967. color: white;
  1968. text-align: center;
  1969. border-radius: 5px;
  1970. padding: 6px;
  1971. }
  1972.  
  1973. ::-webkit-scrollbar {
  1974. width:14px !important;
  1975. height:unset !important;
  1976. }
  1977.  
  1978. ::-webkit-scrollbar-thumb {
  1979. background: #e1e1e1 !important;
  1980. }
  1981.  
  1982. /* 选中任意的状态不确定的 <input> */
  1983. input:indeterminate {
  1984. background: lime;
  1985. }
  1986. </style>
  1987. `;
  1988.  
  1989. // /*滚动条整体样式*/
  1990. // .bd::-webkit-scrollbar {
  1991. // width: 10px;
  1992. // height: 1px;
  1993. // }
  1994. // /*滚动条里面小方块*/
  1995. // .bd::-webkit-scrollbar-thumb {
  1996. // border-radius: 10px;
  1997. // background-color: #b4b7ba;
  1998. // background-image:
  1999. // -webkit-linear-gradient(
  2000. // 45deg,
  2001. // rgba(255, 255, 255, .2) 25%,
  2002. // transparent 25%,
  2003. // transparent 50%,
  2004. // rgba(255, 255, 255, .2) 50%,
  2005. // rgba(255, 255, 255, .2) 75%,
  2006. // transparent 75%,
  2007. // transparent
  2008. // );
  2009. // }
  2010. // /*滚动条里面轨道*/
  2011. // .bd::-webkit-scrollbar-track {
  2012. // -webkit-box-shadow: inset 0 0 5px rgba(0,0,0,0.2);
  2013. // /*border-radius: 10px;*/
  2014. // background: #EDEDED;
  2015. // }
  2016.  
  2017. /**
  2018. * 追加到body
  2019. */
  2020. const appendHtml = () => {
  2021.  
  2022. // console.time('appendHtml')
  2023.  
  2024. if ($('#myCss').length === 0) {
  2025. $('body').append(cssFactory())
  2026. }
  2027.  
  2028. $('.bd').remove()
  2029. $('body').append(htmlFactory())
  2030.  
  2031. // =========== 事件 ==============
  2032. clickBrandHandler()
  2033. getCouponClickHandler()
  2034. showOrHideModalHandler()
  2035. onClickChangeDepotBtnHandler()
  2036. checkDepotBtnHandlerNew()
  2037. lookCouponListExtendsBtnHandler()
  2038. lookCouponListHandler()
  2039. shareHandler()
  2040. shareParseHandler()
  2041. lockProductHandler()
  2042. refreshBtnHandler()
  2043. versionClickHandler()
  2044. // =============================
  2045. resizeHeight()
  2046.  
  2047. // console.timeEnd('appendHtml')
  2048. }
  2049.  
  2050. /**
  2051. * 基础配置优化
  2052. */
  2053. const basicSettings = () => {
  2054. // 多选框放大
  2055. $('input.check-box:not([style*=zoom])').css('zoom', '150%')
  2056.  
  2057. // 点击物料图片,操作多选框
  2058. $('.product-img:not([class*=click_do_])').addClass('click_do_')
  2059. .on('click', function () {
  2060. $(this).addClass('click_do_').prev('.check-box').click();
  2061. })
  2062.  
  2063. // 购物车列表 点击品牌跳转到该品牌下的商品
  2064. $('.product-item li.cart-li-pro-info:not(:has([class*=open_do_]))').find('div:eq(2)')
  2065. .css({ cursor: 'pointer' }).addClass('open_do_').click(function () {
  2066. GM_openInTab(`${webSiteShareData.lcscSearchUrl}/global.html?k=${getBrandNameByRegex(this.innerText)}`, { active: true, insert: true, setParent: true })
  2067. })
  2068. }
  2069.  
  2070.  
  2071. /**
  2072. * 遍历购物车清单,并计算品牌总金额
  2073. */
  2074. const eachCartList = () => {
  2075. dataCartMp.clear()
  2076.  
  2077. getHavedCheckedLineInfo().each(function (i) {
  2078.  
  2079. let $this = $(this)
  2080.  
  2081. // 物料编号
  2082. // let productNo = $this.find('ul li:eq(1) a').text().trim()
  2083.  
  2084. // 品牌名称
  2085. let brandName = $this.find('.cart-li-pro-info div:eq(2)').text().trim()
  2086.  
  2087. // 查找到品牌名称
  2088. brandName = getBrandNameByRegex(brandName.split('\n')[brandName.split('\n').length - 1].trim())
  2089.  
  2090. // if ($this.find('input:checked').length === 0) {
  2091. // return
  2092. // }
  2093.  
  2094. // 品牌下的单个商品总价
  2095. let linePrice = parseFloat($this.find('.line-total-price').text().trim().replace('¥', ''))
  2096.  
  2097. // 日志打印控制台
  2098. // console.log(productId, brandName, linePrice)
  2099.  
  2100. let mpVal = $.isEmptyObject(dataCartMp.get(brandName)) ? 0 : dataCartMp.get(brandName)
  2101.  
  2102. // 保存到Map中
  2103. dataCartMp.set(brandName, parseFloat((mpVal + linePrice).toFixed(2)))
  2104.  
  2105.  
  2106. if ($.isEmptyObject(dataBrandColorMp.get(brandName))) {
  2107. // 对品牌进行随机色设置
  2108. dataBrandColorMp.set(brandName, srdmRgbColor())
  2109. }
  2110. })
  2111. }
  2112.  
  2113. /**
  2114. * 对品牌进行随机色设置
  2115. */
  2116. const setBrandColor = () => {
  2117.  
  2118. //弹框 对品牌进行随机色设置
  2119. $('.li-cs').each(function (i) {
  2120. $(this).css('background', dataBrandColorMp.get($(this).find('span:eq(0)').text().trim()))
  2121. })
  2122.  
  2123. // 购物车列表 品牌颜色设置
  2124. dataBrandColorMp.forEach((v, k) => {
  2125. let brandElement = getHavedLineInfoByBrandName(k).find('ul li.cart-li-pro-info div:eq(2)')
  2126. brandElement.css({
  2127. 'background-color': v,
  2128. 'width': 'min-content',
  2129. 'color': 'white'
  2130. })
  2131.  
  2132. brandElement.find('a').css({
  2133. 'color': 'white'
  2134. })
  2135. })
  2136. }
  2137.  
  2138. /**
  2139. * 查找购物车中所有选中的行的元素(包含现货、订货)
  2140. *
  2141. */
  2142. const getAllCheckedLineInfo = () => {
  2143. return $('.product-list .product-item input:checked').parents('.product-item')
  2144. }
  2145.  
  2146. /**
  2147. * 查找购物车中所有选中的行的元素(包含现货、订货)指定:江苏仓
  2148. *
  2149. */
  2150. const getJsLineInfo = () => {
  2151. return $('.product-list .product-item .warehouse-wrap .warehouse:contains(江苏仓)')
  2152. }
  2153.  
  2154. /**
  2155. * 查找购物车中所有选中的行的元素(包含现货、订货)指定:广东仓
  2156. *
  2157. */
  2158. const getGdLineInfo = () => {
  2159. return $('.product-list .product-item .warehouse-wrap .warehouse:contains(广东仓)')
  2160. }
  2161.  
  2162. /**
  2163. * 通过品牌名称,查找购物车中所在行的元素(包含现货、订货)
  2164. */
  2165. const getAllLineInfoByBrandName = (brandName) => {
  2166. return $('.product-list .product-item:contains(' + brandName + ')')
  2167. }
  2168.  
  2169. /**
  2170. * 购物车中所在行的元素(包含现货、订货)
  2171. */
  2172. const getAllLineInfo = () => {
  2173. return $('.product-list .product-item')
  2174. }
  2175.  
  2176. /**
  2177. * 通过品牌名称,查找购物车中的行元素(只获取现货商品)
  2178. */
  2179. const getHavedLineInfoByBrandName = (brandName) => {
  2180. return $('.product-list .product-list-dl:eq(0) .product-item:contains(' + brandName + ')')
  2181. }
  2182.  
  2183. /**
  2184. * 购物车中的行元素(只获取现货商品)
  2185. */
  2186. const getHavedLineInfo = () => {
  2187. return $('.product-list .product-list-dl:eq(0) .product-item')
  2188. }
  2189.  
  2190. /**
  2191. * 通过品牌列表名称,购物车中的行的元素(只获取现货商品)
  2192. */
  2193. const getHavedLineInfoByBrandNameList = (brandNameList) => {
  2194. return $(
  2195. [...getHavedLineInfo()].filter(item => {
  2196. const brandName = getBrandNameByRegex($(item).find(`.cart-li:eq(2) div:eq(2)`).text().trim())
  2197. return brandNameList.includes(brandName)
  2198. })
  2199. )
  2200. }
  2201.  
  2202. /**
  2203. * 查找购物车中选中的行元素(只获取现货商品、选中的)
  2204. * product-list-dl eq 0 是现货
  2205. * product-list-dl eq 1 是订货
  2206. *
  2207. */
  2208. const getHavedCheckedLineInfo = () => {
  2209. return $('.product-list .product-list-dl:eq(0) .product-item input:checked').parents('.product-item')
  2210. }
  2211.  
  2212. /**
  2213. * 查找购物车中没有选中的行元素(只获取现货商品、选中的)
  2214. * product-list-dl eq 0 是现货
  2215. * product-list-dl eq 1 是订货
  2216. *
  2217. */
  2218. const getHavedNotCheckedLineInfo = () => {
  2219. return $('.product-list .product-list-dl:eq(0) .product-item input:not(:checked)').parents('.product-item')
  2220. }
  2221.  
  2222. /**
  2223. * 点击小窗口的品牌按钮,实现该品牌下的单选
  2224. * 且该品牌下的物料,会自动排到购物车的前面几条
  2225. */
  2226. const clickBrandHandler = () => {
  2227. $('.click-hv .sort_').on('click', function (target) {
  2228. let brandName = $(this).text().trim()
  2229.  
  2230. let cutHtmlElement = []
  2231.  
  2232. // 查找购物车 现货商品
  2233. getHavedLineInfoByBrandName(brandName).each(function (i) {
  2234. cutHtmlElement.push($(this))
  2235. })
  2236.  
  2237. cutHtmlElement.forEach(item => {
  2238. $('.product-list .product-list-dl:eq(0) .product-item').insertAfter(item)
  2239. })
  2240. })
  2241.  
  2242. /**
  2243. * 小窗口品牌列表的双击事件
  2244. * 双击全选品牌
  2245. */
  2246. $('.click-hv .sort_').on('dblclick', function () {
  2247.  
  2248. let brandName = $(this).text().trim()
  2249.  
  2250. // 当前品牌行
  2251. const $brandEle = $(`.product-item:contains("${brandName}")`)
  2252. // 当前品牌选中的
  2253. const $brandCheckedEle = $(`.product-item:contains("${brandName}") li.cart-li .check-box:checked`)
  2254. // 当前品牌没有选中的
  2255. const $brandNotCheckedEle = $(`.product-item:contains("${brandName}") li.cart-li .check-box:not(:checked)`)
  2256.  
  2257. // 当前品牌全选
  2258. if ($brandCheckedEle.length != $brandEle.length) {
  2259. setAwaitFunc(10, function () {
  2260. $brandNotCheckedEle.click();
  2261. })
  2262. return;
  2263. }
  2264.  
  2265. /**
  2266. * 过滤封装
  2267. * @param {*} eles
  2268. * @returns
  2269. */
  2270. const _filterNotSelf = (eles, brandName_, finder) => {
  2271. return $([...eles].filter(item => {
  2272. return $(item).find(`li.cart-li:eq(2):not(:contains(${brandName_}))`).length > 0
  2273. })).find(finder)
  2274. }
  2275.  
  2276. // 获取选中的现货
  2277. const $havedEles = getHavedCheckedLineInfo()
  2278.  
  2279.  
  2280. // 看看有没有选中除自己之外,其他品牌的商品
  2281. const isNckOtherPdtsBool = _filterNotSelf($havedEles, brandName, `li.cart-li:eq(2):not(:contains(${brandName}))`).length > 0
  2282.  
  2283. if (isNckOtherPdtsBool) {
  2284. // 获取现货
  2285. setAwaitFunc(10, function () {
  2286. _filterNotSelf($havedEles, brandName, `li.cart-li .check-box:checked`).click()
  2287. })
  2288. }
  2289. else {
  2290. // 全选
  2291. setAwaitFunc(10, function () {
  2292. _filterNotSelf(getHavedNotCheckedLineInfo(), brandName, `li.cart-li .check-box:not(:checked)`).click()
  2293. })
  2294. }
  2295. })
  2296. }
  2297.  
  2298. /**
  2299. * 多选框变化,刷新小窗口的计算结果
  2300. */
  2301. const checkStatusChangeHandler = () => {
  2302. // $(".check-box,.check-box-checked-all").change(refresh)
  2303.  
  2304. $(".check-box,.check-box-checked-all").change(() => {
  2305. setTimeout(refresh, 1000);
  2306. })
  2307. }
  2308.  
  2309. /**
  2310. * 获取优惠券列表信息,并暂存在变量集合中
  2311. */
  2312. const getCouponHTML = async () => {
  2313. // http获取优惠券信息
  2314. let couponHTML = await getAjax(`${webSiteShareData.lcscWwwUrl}/huodong.html`)
  2315. // 遍历优惠券
  2316. $(couponHTML).find('.coupon-item:contains(满16可用) div[data-id]').each(function () {
  2317. // 获取当前元素
  2318. let $this = $(this);
  2319. // 优惠券id
  2320. let couponId = $this.data('id');
  2321. // 是否已经领取
  2322. let isHaved = $this.find(':contains(立即使用)').length > 0;
  2323. // 优惠券名称
  2324. let couponName = $this.data('name');
  2325. // 对应的品牌主页地址
  2326. let brandIndexHref = $this.data('href');
  2327. // 优惠券金额
  2328. let couponPrice = couponName.replace(/^.*?\>(.*?)元.*$/, '$1');
  2329. // 品牌名称
  2330. let brandName = couponName.replace(/^.*?元(.*?)品牌.*$/, '$1');
  2331. // 是否新人优惠券
  2332. let isNew = couponName.split('新人专享').length >= 2;
  2333. // 是否已经使用过
  2334. let isUsed = $this.find(':contains(已使用)').length > 0;
  2335.  
  2336. // 一些优惠券特殊处理
  2337. if(brandName === 'MDD') {
  2338. // 存到变量Map中
  2339. all16_15CouponMp.set('辰达半导体', {
  2340. couponName, // 优惠券名称
  2341. isNew, // 是否新人专享
  2342. couponPrice, //优惠券金额减免
  2343. brandName: '辰达半导体', // 品牌名称
  2344. couponId, // 优惠券id
  2345. isHaved, // 是否已经领取
  2346. isUsed, // 是否已经使用过
  2347. brandIndexHref, // 对应的品牌主页地址
  2348. couponLink: `${webSiteShareData.lcscWwwUrl}/getCoupon/${couponId}`, // 领券接口地址
  2349. });
  2350. }
  2351.  
  2352. // 存到变量Map中
  2353. all16_15CouponMp.set(brandName, {
  2354. couponName, // 优惠券名称
  2355. isNew, // 是否新人专享
  2356. couponPrice, //优惠券金额减免
  2357. brandName, // 品牌名称
  2358. couponId, // 优惠券id
  2359. isHaved, // 是否已经领取
  2360. isUsed, // 是否已经使用过
  2361. brandIndexHref, // 对应的品牌主页地址
  2362. couponLink: `${webSiteShareData.lcscWwwUrl}/getCoupon/${couponId}`, // 领券接口地址
  2363. });
  2364. });
  2365. }
  2366.  
  2367. /**
  2368. * 优惠券领取按钮的绑定事件
  2369. */
  2370. const getCouponClickHandler = () => {
  2371. $('.to_cou').click(async function (target) {
  2372. let brandName = $(this).parents('span').siblings('.key').text()
  2373.  
  2374. // 优惠券实体
  2375. let couponEntity = all16_15CouponMp.get(brandName)
  2376.  
  2377. if (!$.isEmptyObject(couponEntity)) {
  2378. let res = await getAjax(couponEntity.couponLink)
  2379. // console.log(res)
  2380.  
  2381. let resParseData = JSON.parse(res)
  2382. if (resParseData.result === 'success') {
  2383. Qmsg.success(`${couponEntity.couponName},领取成功!`)
  2384. refresh(true)
  2385. } else {
  2386. Qmsg.error(resParseData.msg)
  2387. }
  2388. }
  2389. })
  2390. }
  2391.  
  2392. // 隐藏/显示 小窗
  2393. const showOrHideModalHandler = () => {
  2394. $('.showBtn,.hideBtn').click(function (target) {
  2395. let $bd = $('.bd')
  2396.  
  2397. if ($bd.is(':hidden')) {
  2398. $('.hideBtn').show()
  2399. $('.showBtn').hide()
  2400. setLocalData('SHOW_BOOL', true)
  2401. refresh()
  2402. } else if ($bd.is(':visible')) {
  2403. $('.showBtn').show()
  2404. $('.hideBtn').hide()
  2405. $('#couponModal').hide()
  2406. setLocalData('SHOW_BOOL', false)
  2407. }
  2408.  
  2409. $bd.fadeToggle()
  2410. })
  2411. }
  2412.  
  2413. /**
  2414. * 优惠券快速入口
  2415. */
  2416. const couponGotoHandler = () => {
  2417.  
  2418. if ($('.coupon-item-goto').length > 0) {
  2419. return;
  2420. }
  2421.  
  2422. if ($('#conponCss_').length === 0)
  2423. $('body').append(`
  2424. <style id="conponCss_">
  2425. .coupon-item-goto {
  2426. user-select:none;
  2427. right: 6% !important;
  2428. left: unset !important;
  2429. width: 43% !important;
  2430. position: absolute;
  2431. bottom: 12px;
  2432. margin-left: -96px;
  2433. box-sizing: border-box;
  2434. height: 30px;
  2435. text-align: center;
  2436. font-size: 14px;
  2437. font-weight: 400;
  2438. color: #fff;
  2439. line-height: 30px;
  2440. cursor: pointer;
  2441. border-radius: 4px;
  2442. background: #53a3d6;
  2443. }
  2444. .watch-category-btn:hover,.coupon-item-goto:hover
  2445. {
  2446. opacity: 0.9;
  2447. color: white !important;
  2448. cursor: pointer;
  2449. }
  2450. .open-tab-search:hover
  2451. {
  2452. opacity: 0.9;
  2453. background-color: #e0e0e0;
  2454. cursor: pointer;
  2455. }
  2456. .coupon-item-btn {
  2457. width: 43% !important;
  2458. }
  2459. .watch-category-btn {
  2460. user-select:none;
  2461. right: 13px !important;
  2462. top: 10px !important;
  2463. width: 33% !important;
  2464. position: absolute;
  2465. margin-left: -96px;
  2466. box-sizing: border-box;
  2467. height: 30px;
  2468. text-align: center;
  2469. font-size: 14px;
  2470. font-weight: 400;
  2471. color: #fff;
  2472. line-height: 30px;
  2473. cursor: pointer;
  2474. border-radius: 4px;
  2475. background: #e9a719;
  2476. }
  2477. .qmsg.qmsg-wrapper {
  2478. z-index: 1000000 !important;
  2479. }
  2480. </style>
  2481. `)
  2482.  
  2483. const append_ = `<a class='coupon-item-goto' href="" target="_blank">快速入口</a>`;
  2484. $('.coupon-item').each(function () {
  2485. const $this = $(this)
  2486. const btnBackgound = $this.hasClass('coupon-item-plus') ? '#61679e' : ($this.hasClass('receive') ? 'linear-gradient(90deg,#f4e6d6,#ffd9a8)' : '#199fe9')
  2487.  
  2488. $this.append(append_)
  2489.  
  2490. const dataUrl = $this.find('div.coupon-item-btn').data('url');
  2491. const dataName = $this.find('div.coupon-item-btn').data('name');
  2492. if (dataUrl.includes('/brand')) {
  2493. $this.append(`<p class='watch-category-btn' data-url="${dataUrl}" data-name="${dataName}">查看类目</p>`)
  2494. }
  2495. if ($this.hasClass('receive')) {
  2496. $this.find('.coupon-item-goto').css({ color: 'unset' })
  2497. }
  2498.  
  2499. $this.find('.coupon-item-goto').css({ background: btnBackgound })
  2500. $this.find('.coupon-item-goto').attr('href', $this.find('div[data-id]').data('url'))
  2501. });
  2502.  
  2503. $(`p.watch-category-btn`).off('click').on('click', function() {
  2504. const brandNameTitle = $(this).data('name');
  2505. const brandDataUrl = $(this).data('url');
  2506. const brandName = getBrandNameByRegexInCouponTitle(brandNameTitle);
  2507. searchGlobalBOM(brandName, brandNameTitle, brandDataUrl);
  2508. });
  2509. }
  2510.  
  2511. const searchGlobalBOM = async (k, title, brandDataUrl) => {
  2512. const brandId = brandDataUrl.replaceAll(/[^\d]+/g, '');
  2513. const url = `https://bom.szlcsc.com/global?k=${k}&pageSize=1&pageNumber=1`;
  2514. const res = await getAjax(url);
  2515.  
  2516. const resJsonObject = JSON.parse(res)
  2517.  
  2518. if(resJsonObject.code === 200) {
  2519. const renderCatelogHtml = JSON.parse(resJsonObject.result.catalogGroupJson)
  2520. .map(e => `<span data-search-k="${e.label}" data-brand-id="${brandId}"
  2521. class="open-tab-search" style="cursor: pointer; border: 1px solid black;padding: 5px 10px;margin-left: 10px; margin-bottom: 10px; height: min-content;">
  2522. ${e.label}(${e.count})</span>`).join(``);
  2523. Qmsg.info({
  2524. content: `
  2525. <h1 style="padding: 20px 10px 10px; color: #199fe9db;">${title}</h1>
  2526. <div style="color: black;flex-flow: wrap; padding: 20px 0;
  2527. width: 46vw;flex-flow: wrap;
  2528. display: flex;
  2529. max-height: 55vh;
  2530. overflow-y: auto;
  2531. align-content: flex-start;
  2532. ">
  2533. ${renderCatelogHtml}
  2534. </div>
  2535. `,
  2536. autoClose: false,
  2537. html: true,
  2538. });
  2539.  
  2540. $('.qmsg.qmsg-wrapper').css('top', '18%');
  2541. $('i.qmsg-icon:not(.qmsg-icon-close)').remove();
  2542. $('i.qmsg-icon-close').css('zoom', '200%');
  2543.  
  2544. // 跳转到对应的分类下查询
  2545. $('span.open-tab-search').off('click').on('click', function() {
  2546. const searchK = $(this).data('search-k');
  2547. const brandId = $(this).data('brand-id');
  2548. GM_openInTab(`${webSiteShareData.lcscSearchUrl}/global.html?k=${searchK}&gp=${brandId||''}`, { active: true, insert: true, setParent: true })
  2549. });
  2550. }
  2551. }
  2552.  
  2553. /**
  2554. * 页面加载的时候,控制小窗显示隐藏
  2555. */
  2556. const onLoadSet = () => {
  2557. // if (getLocalData('SHOW_BOOL') === 'false') {
  2558. // $('#bd').hide()
  2559. // $('.hideBtn').click()
  2560. // }
  2561.  
  2562. // if (getLocalData('AUTO_GET_COUPON_BOOL') === 'true') {
  2563. // $('.auto-get-coupon').attr('checked', true)
  2564. // }
  2565.  
  2566. // $('textarea').css('min-width', `${$('textarea').css('width')} !important`)
  2567. }
  2568.  
  2569. /**
  2570. * 刷新小窗口数据
  2571. * @param {*} notRefreshCouponHtml 是否更新优惠券集合数据
  2572. */
  2573. const refresh = async (notRefreshCouponHtml) => {
  2574.  
  2575. // console.time('refresh')
  2576.  
  2577. if (getLocalData('SHOW_BOOL') === 'false') {
  2578. return
  2579. }
  2580.  
  2581. // 是否更新优惠券集合数据,主要更新是否领取的状态
  2582. if (notRefreshCouponHtml === true) {
  2583. await getCouponHTML()
  2584. }
  2585.  
  2586. eachCartList()
  2587. appendHtml()
  2588.  
  2589. setBrandColor()
  2590.  
  2591. // console.timeEnd('refresh')
  2592. }
  2593.  
  2594. /**
  2595. * 全部刷新重置
  2596. */
  2597. const allRefresh = async () => {
  2598.  
  2599. await getCouponHTML()
  2600.  
  2601. refresh(true)
  2602.  
  2603. checkStatusChangeHandler()
  2604. onChangeCountHandler()
  2605. autoGetCouponTimerHandler()
  2606.  
  2607.  
  2608. lookCouponListModal()
  2609.  
  2610. // await setAwait(1000)
  2611. // onLoadSet()
  2612. }
  2613.  
  2614. /**
  2615. * 重置小窗口的高度
  2616. *
  2617. */
  2618. const resizeHeight = () => {
  2619.  
  2620. if (((window.innerHeight - 120) < $('.bd').height())) {
  2621. $('.bd').height('82vh')
  2622. } else {
  2623. $('.bd').height('auto')
  2624. }
  2625. }
  2626.  
  2627. /**
  2628. * 购物车页面 初始化(只执行一次)
  2629. */
  2630. const cartStart = async () => {
  2631.  
  2632. // 判断是否已经处理完成,否则会有性能问题
  2633. basicSettings()
  2634.  
  2635. // 插件只执行一次
  2636. if (plguinIsHaved()) { return; }
  2637.  
  2638. window.addEventListener('resize', resizeHeight)
  2639.  
  2640. eachCartList()
  2641. await getCouponHTML()
  2642. appendHtml()
  2643. setBrandColor()
  2644.  
  2645. checkStatusChangeHandler()
  2646. onChangeCountHandler()
  2647. autoGetCouponTimerHandler()
  2648.  
  2649. // onLoadSet()
  2650. lookCouponListModal()
  2651. lookCouponCheckboxHandler()
  2652. lookHavedCouponList()
  2653. }
  2654.  
  2655. /**
  2656. * 搜索页
  2657. * @param {*} isNew 是否新人 true/false
  2658. * @param {*} type 单选多选 ONE/MORE
  2659. */
  2660. const searchStart = async () => {
  2661. /**
  2662. * 搜索列表中,对品牌颜色进行上色
  2663. * list.szlcsc.com/catalog
  2664. */
  2665. const catalogListRenderBrandColor = () => {
  2666. for (let [brandName, brandDetail] of all16_15CouponMp) {
  2667. // 获取页面元素
  2668. const $brandEle = $(`li[title*="${brandName}"]:not([style*=background-color]),span[title*="${brandName}"]:not([style*=background-color]),a.brand-name[title*="${brandName}"]:not([style*=background-color])`);
  2669. // && $brandEle.css('background-color') === "rgba(0, 0, 0, 0)"
  2670. if ($brandEle.length > 0) {
  2671. $brandEle.css({
  2672. "background-color": brandDetail.isNew ? '#00bfffb8' : '#7fffd4b8'
  2673. })
  2674. }
  2675. }
  2676. }
  2677.  
  2678. catalogListRenderBrandColor()
  2679.  
  2680. // 回到顶部 嘉立创的返回顶部,在展开客服里。
  2681. // if ($('div.logo-wrap').hasClass('active')) {
  2682. // if ($('#scrollTo_').length === 0) {
  2683. // $('#productListFixedHeader:visible').parents('body').after(`
  2684. // <a id="scrollTo_" style="border-radius: 5px;
  2685. // z-index: 10000;
  2686. // position: fixed;
  2687. // right: 45px;
  2688. // bottom: 45px;
  2689. // padding: 10px 10px 5px 10px;
  2690. // background: white;
  2691. // border: 2px solid #199fe9;
  2692. // font-size: 20px;
  2693. // font-weight: 600;" href="javascript:scrollTo(0,0)">
  2694. // <svg t="1716543304931" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4240" width="40" height="40"><path d="M0 96V0h1024v96z" fill="#3498db" p-id="4241"></path><path d="M384 1022.72V606.4H255.488a64 64 0 0 1-46.336-108.16l256.448-269.312a64 64 0 0 1 92.8 0l255.744 269.44a64 64 0 0 1-46.4 108.032h-120.32v416.32H384z" fill="#3498db" p-id="4242"></path></svg>
  2695. // </a>
  2696. // `);
  2697. // }
  2698. // } else {
  2699. // $('#scrollTo_').remove();
  2700. // }
  2701.  
  2702. if ($('span[class*=select-spec-]').length === 0) {
  2703. // 查询封装规格
  2704. const selectSpecHandler = () => {
  2705. /**
  2706. * 模糊查
  2707. * 如果多选中没有查找到规格,则做一些小小的递归数据处理
  2708. * @param {*} specName
  2709. * @returns
  2710. */
  2711. const _MHCEachClick = (specName) => {
  2712. if ($(`.det-screen:contains("封装:") label.fuxuanku-lable:contains("${specName}")`).length > 0) {
  2713. $(`.det-screen:contains("封装:") label.fuxuanku-lable:contains("${specName}")`).click();
  2714. } else {
  2715. if (specName.includes('-')) {
  2716. _MHCEachClick(specName.split('-').slice(0, -1).join('-'));
  2717. }
  2718. }
  2719. }
  2720. /**
  2721. * 精确查
  2722. * 如果多选中没有查找到规格,则做一些小小的递归数据处理
  2723. * @param {*} specName
  2724. * @returns
  2725. */
  2726. const _JQCEachClick = (specName) => {
  2727. if ($(`.det-screen:contains("封装:") label.fuxuanku-lable[title="${specName}"]`).length > 0) {
  2728. $(`.det-screen:contains("封装:") label.fuxuanku-lable[title="${specName}"]`).click();
  2729. } else {
  2730. if (specName.includes('-')) {
  2731. _JQCEachClick(specName.split('-').slice(0, -1).join('-'));
  2732. }
  2733. }
  2734. }
  2735.  
  2736. /**
  2737. * 封装查询-多选框点击
  2738. * @param specName 规格封装名称
  2739. * @param selectType 模糊查:MHC,精确查:JQC
  2740. */
  2741. const _clickSpecFunc = async (specName, selectType) => {
  2742. // 统一文字
  2743. $(`.det-screen:contains("规格:") .det-screen-title`).text('封装:');
  2744. // 展开规格
  2745. $(`.det-screen:contains("封装:") #more-standard`).click();
  2746.  
  2747. switch (selectType) {
  2748. // 模糊查
  2749. case "MHC":
  2750. _MHCEachClick(specName);
  2751. break;
  2752. // 精确查
  2753. case "JQC":
  2754. _JQCEachClick(specName);
  2755. break;
  2756. }
  2757.  
  2758. // 查找规格对应的选项
  2759. $(`.det-screen:contains("封装:") input[value="确定"]`).click();
  2760. }
  2761.  
  2762. $('.li-ellipsis:contains("封装:")').each(function () {
  2763. // 查询到点击追加的规格名称
  2764. let specName = $(this).find('span:eq(1)').attr('title');
  2765. // 页面追加按钮元素
  2766. $(this).after(`
  2767. <li class="li-el">
  2768. <span class="select-spec-mh" style="border-radius: 2px; display: inline-flex; padding: 3px 8px; color: white; cursor: pointer; user-select: none; background: #199fe9;"
  2769. specName="${specName}" selectType="MHC">封装模糊匹配</span>
  2770. <span class="select-spec-jq" style="border-radius: 2px; display: inline-flex; padding: 3px 8px; color: white; cursor: pointer; user-select: none; background: #199fe9; margin-left: 3px;"
  2771. specName="${specName}" selectType="JQC">封装精确匹配</span>
  2772. </li>
  2773. `);
  2774. });
  2775.  
  2776. // $('.li-el + li').css('height', '10px')
  2777. // 查询封装-按钮事件
  2778. $('span[class*=select-spec-]').on('click', function () {
  2779. _clickSpecFunc($(this).attr('specName'), $(this).attr('selectType'))
  2780. })
  2781. }
  2782. // 查询规格快捷按钮
  2783. selectSpecHandler()
  2784. }
  2785.  
  2786. if ($('.searchTaobao_').length === 0) {
  2787. // 预售拼团 不处理,其他的都追加按钮
  2788. $('.line-box:not(:contains("预售拼团")) li.pan-list').append(`
  2789. <button type="button" class="pan-list-btn searchTaobao_" style="margin-top: 5px; background: #199fe9;">一键搜淘宝</button>
  2790. `)
  2791. } else
  2792. // 搜索页的 一键搜淘宝
  2793. if ($('.searchTaobao_:not([addedClickHandler])').length > 0) {
  2794. /**
  2795. * 非阻容,其他数据处理
  2796. * @param {*} parents 行级标签
  2797. * @param {*} resArr 数据存放的数组
  2798. */
  2799. function other(parents, resArr) {
  2800. let productName = parents.find('li.li-ellipsis a:eq(0)').attr('title') || '';
  2801.  
  2802. if (productName.length === 0 || resArr.length > 0) {
  2803. return;
  2804. }
  2805.  
  2806. let footprint = parents.find('li.li-ellipsis:contains("封装:") span:eq(1)').attr('title') || '';
  2807. resArr.push(productName); resArr.push(footprint);
  2808. }
  2809. /**
  2810. * 电阻数据处理
  2811. * @param {*} parents 行级标签
  2812. * @param {*} resArr 数据存放的数组
  2813. */
  2814. function R(parents, resArr) {
  2815. const r = parents.find('li.li-ellipsis:contains("阻值:")').text().replace(/(阻值:|Ω)+/g, '').trim()
  2816.  
  2817. if (r.length === 0 || resArr.length > 0) {
  2818. return;
  2819. }
  2820. const f = parents.find('li.li-ellipsis:contains("封装:")').text().replace('封装:', '').trim()
  2821. const j = parents.find('li.li-ellipsis:contains("精度:")').text().replace(/(精度:|\±)+/g, '').trim()
  2822.  
  2823. resArr.push(r); resArr.push(f); resArr.push(j);
  2824. }
  2825.  
  2826. /**
  2827. * 电容数据处理
  2828. * @param {*} parents 行级标签
  2829. * @param {*} resArr 数据存放的数组
  2830. */
  2831. function C(parents, resArr) {
  2832. const c = parents.find('li.li-ellipsis:contains("容值:")').text().replace('容值:', '').trim()
  2833.  
  2834. if (c.length === 0 || resArr.length > 0) {
  2835. return;
  2836. }
  2837.  
  2838. const v = parents.find('li.li-ellipsis:contains("额定电压:")').text().replace('额定电压:', '').trim()
  2839. const j = parents.find('li.li-ellipsis:contains("精度:")').text().replace(/(精度:|\±)+/g, '').trim()
  2840. const f = parents.find('li.li-ellipsis:contains("封装:")').text().replace('封装:', '').trim()
  2841.  
  2842. resArr.push(c); resArr.push(v); resArr.push(j); resArr.push(f);
  2843. }
  2844. $('.searchTaobao_:not([addedClickHandler])').attr('addedClickHandler', true).on('click', function (params) {
  2845. let searchArrVals = [];
  2846.  
  2847. const $parents = $(this).parents('td.line-box');
  2848. // 阻容处理、其他元件处理
  2849. R($parents, searchArrVals); C($parents, searchArrVals); other($parents, searchArrVals);
  2850.  
  2851. GM_openInTab(`https://s.taobao.com/search?q=${searchArrVals.join('/')}`, { active: true, insert: true, setParent: true })
  2852. })
  2853. }
  2854.  
  2855. /**
  2856. * 设置单选的背景颜色
  2857. */
  2858. const _setOneCssByBrandName = (brandName, bgColor = '#00bfffb8') => {
  2859. // 查找某个品牌
  2860. const searchBrandItemList = $(`#brandList div`).find(`span:eq(0):contains(${brandName})`)
  2861. searchBrandItemList.css({ 'background-color': bgColor, 'border-radius': '30px' })
  2862. }
  2863.  
  2864. /**
  2865. * 设置多选的背景颜色
  2866. */
  2867. const _setMultiCssByBrandName = (brandName, bgColor = '#00bfffb8') => {
  2868. // 查找某个品牌
  2869. const searchBrandItemList = $(`.pick-txt.det-screen1 div`).find(`label:contains(${brandName})`)
  2870. searchBrandItemList.css({ 'background-color': bgColor, 'border-radius': '30px' })
  2871. }
  2872.  
  2873. /**
  2874. * 筛选条件:单选品牌-颜色
  2875. */
  2876. const _renderFilterBrandColor = async () => {
  2877.  
  2878. await setAwait(200)
  2879.  
  2880. $(`#brandList div`).find(`span:eq(0)`).each(function () {
  2881. const text = $(this).text().trim()
  2882.  
  2883. let findBrandName = text
  2884. if (text.includes('(')) {
  2885. findBrandName = getBrandNameByRegex(text)
  2886. }
  2887.  
  2888. if (all16_15CouponMp.has(findBrandName)) {
  2889. if (all16_15CouponMp.get(findBrandName).isNew) {
  2890. _setOneCssByBrandName(findBrandName)
  2891. } else {
  2892. _setOneCssByBrandName(findBrandName, '#7fffd4b8')
  2893. }
  2894. }
  2895. })
  2896. // 省略号去掉,方便查看
  2897. $('.det-screen1 span').css({ 'display': 'unset' })
  2898. }
  2899.  
  2900. /**
  2901. * 筛选条件:单选品牌-颜色
  2902. */
  2903. const _renderMulitFilterBrandColor = async () => {
  2904.  
  2905. await setAwait(200)
  2906.  
  2907. $(`.pick-txt.det-screen1 div`).each(function () {
  2908. const text = $(this).find('label').attr('title').trim()
  2909.  
  2910. let findBrandName = text
  2911. if (text.includes('(')) {
  2912. findBrandName = getBrandNameByRegex(text)
  2913. }
  2914.  
  2915. if (all16_15CouponMp.has(findBrandName)) {
  2916. if (all16_15CouponMp.get(findBrandName).isNew) {
  2917. _setMultiCssByBrandName(findBrandName)
  2918. } else {
  2919. _setMultiCssByBrandName(findBrandName, '#7fffd4b8')
  2920. }
  2921. }
  2922. })
  2923. // 省略号去掉,方便查看
  2924. $('.det-screen1 span').css({ 'display': 'unset' })
  2925. }
  2926. /**
  2927. * 筛选条件:多选品牌
  2928. * @param {*} isNew 是否新人券 true/false
  2929. */
  2930. const multiFilterBrand = async (isNew) => {
  2931. $('#more-brand').click()
  2932. // $('.pick-txt.det-screen1 label.active').removeClass('active');
  2933. $('.pick-txt.det-screen1 div').each(function () {
  2934. const $labelEle = $(this).find('label.fuxuanku-lable')
  2935. // 品牌名称
  2936. const text = $labelEle.attr('title').trim()
  2937.  
  2938. let findBrandName = text
  2939. if (text.includes('(')) {
  2940. findBrandName = getBrandNameByRegex(text)
  2941. }
  2942.  
  2943. if (all16_15CouponMp.has(findBrandName)) {
  2944. if (all16_15CouponMp.get(findBrandName).isNew === isNew) {
  2945. // 多选框选中
  2946. $labelEle.click()
  2947. }
  2948. }
  2949. })
  2950.  
  2951. $('.hoice-ys .more-input02').click()
  2952. }
  2953.  
  2954. if ($('#_remind').length === 0) {
  2955. $('.det-screen:contains("品牌:")').append(`
  2956. <div id='_remind'>
  2957. <span class='row_center get_new_coupon'><p class='new_'></p>新人券</span>
  2958. <span class='row_center get_notnew_coupon'><p class='not_new_'></p>非新人券</span>
  2959. </div>
  2960.  
  2961. <style>
  2962. #_remind {
  2963. display: inline-block;
  2964. position: absolute;
  2965. top: 0px;
  2966. right: 100px;
  2967. width: 100px;
  2968. }
  2969. .row_center {
  2970. display: inline-flex;
  2971. align-items: center;
  2972. }
  2973. .new_ {
  2974. background-color: #00bfffb8;
  2975. margin-right: 10px;
  2976. width: 20px;
  2977. height: 10px;
  2978. }
  2979. .not_new_ {
  2980. background-color: #7fffd4b8;
  2981. margin-right: 10px;
  2982. width: 20px;
  2983. height: 10px;
  2984. }
  2985. .get_new_coupon,
  2986. .get_notnew_coupon {
  2987. cursor: pointer;
  2988. }
  2989.  
  2990. .get_new_coupon:hover,
  2991. .get_notnew_coupon:hover {
  2992. background: #e1e1e1;
  2993. }
  2994. </style>
  2995. `)
  2996.  
  2997. // 更新优惠券列表到集合中
  2998. await getCouponHTML()
  2999.  
  3000. _renderFilterBrandColor()
  3001.  
  3002. // 多选展开按钮
  3003. $('#more-brand').click(_renderMulitFilterBrandColor)
  3004. // 品牌单选
  3005. $('.screen-more .more-brand').click(_renderFilterBrandColor)
  3006. // 多选新人券
  3007. $('.get_new_coupon').click(() => multiFilterBrand(true))
  3008. // 多选非新人券
  3009. $('.get_notnew_coupon').click(() => multiFilterBrand(false))
  3010.  
  3011. }
  3012.  
  3013. /**
  3014. * 显示最低购入价
  3015. * @param {*} params
  3016. */
  3017. function minBuyMoney(params) {
  3018. $('.three-nr').find('.three-nr-item:eq(0) .price-warp p').each(function () {
  3019. let minMum = parseInt($(this).attr('minordernum'));
  3020. let orderPrice = parseFloat($(this).attr('orderprice'));
  3021.  
  3022. $(this).parents('.three-nr-item').before(`
  3023. <p class="minBuyMoney_" style="
  3024. width: fit-content;
  3025. padding: 2px 3px;
  3026. font-weight: 600;
  3027. color: #0094e7;">最低购入价: ${parseFloat((minMum * orderPrice).toFixed(6))}</p>
  3028. `)
  3029. })
  3030. }
  3031.  
  3032. //
  3033. if ($('.minBuyMoney_').length === 0) {
  3034. minBuyMoney()
  3035. }
  3036.  
  3037. /**
  3038. * html追加到页面中
  3039. */
  3040. const appendProductListBox = (html) => {
  3041. $('.wait-h2').hide(); $('.nodata-h2').hide();
  3042. $('#product-list-box div#data-box—').html(html);
  3043.  
  3044. if (html.length === 0 || $('#product-list-box div#data-box— table').length === 0) {
  3045. $('.nodata-h2').show();
  3046. $('.wait-h2').hide();
  3047. return;
  3048. }
  3049. }
  3050.  
  3051.  
  3052. /**
  3053. * 分类搜索页的凑单逻辑
  3054. */
  3055. const renderCatalogPageMinPriceSearch = () => {
  3056. // 持续请求 && 定时器未初始化 && 未查询到结果的时候
  3057. if(!globalSearchEnd) {
  3058. // 总页数。默认:30页
  3059. const totalPage = searchTotalPage();
  3060. const promiseList = [];
  3061. var searchData_ = null;
  3062.  
  3063. // 取一遍值 如果没有定义,则取默认值
  3064. try {
  3065. searchData_ = searchData;
  3066. } catch (error) {
  3067. searchData_ = {
  3068. catalogNodeId: /\d+/g.exec(location.pathname)[0],
  3069. pageNumber: 1,
  3070. querySortBySign: 0,
  3071. showOutSockProduct: 1,
  3072. showDiscountProduct: 1
  3073. }
  3074. }
  3075. for (let pn = 1; pn <= totalPage; pn++) {
  3076. searchData_['pageNumber'] = pn;
  3077. var settings = {
  3078. "url": "https://list.szlcsc.com/products/list",
  3079. "method": "POST",
  3080. "data": searchData_
  3081. };
  3082. promiseList.push($.ajax(settings));
  3083. }
  3084. globalSearchEnd = true;
  3085. allWithProgress(promiseList, ({total, cur, progress}) => {
  3086. $('.wait-h2').html(`数据加载中...</br>(共${total}页,正在加载第${cur}页。或只查询前1000条记录)...`);
  3087. }).then(function (result) {
  3088. result.forEach(data => {
  3089. if(data.success === true && data.productRecordList) {
  3090. searchTempList = [...searchTempList, ...data.productRecordList];
  3091. }
  3092. });
  3093. }).finally(() => {
  3094. renderMinPriceSearch();
  3095. setTimeout(() => { $('#js-filter-btn').click() }, 100);
  3096. });
  3097. }
  3098. }
  3099.  
  3100. /**
  3101. * 搜索主页的凑单逻辑
  3102. */
  3103. const renderMainPageMinPriceSearch = () => {
  3104. // 持续请求 && 定时器未初始化 && 未查询到结果的时候
  3105. if(!globalSearchEnd) {
  3106. var val = $('#search-input').val();
  3107. if (val == null || val.length === 0) {
  3108. searchTempList = [];
  3109. return;
  3110. }
  3111. // 总页数。默认:30页
  3112. const totalPage = searchTotalPage();
  3113. const promiseList = [];
  3114. for (let pn = 1; pn <= totalPage; pn++) {
  3115. const data = {};
  3116. [...$('form#allProjectFrom>input[type="hidden"]:not([id*=SloganVal]):not([id*=LinkUrlVal])')].forEach(item => {
  3117. const name = $(item).attr('name');
  3118. const val = $(item).val();
  3119. data[name] = val;
  3120. });
  3121. data['pageNumber'] = pn;
  3122. data['k'] = val;
  3123. data['sk'] = val;
  3124. data['localQueryKeyword'] = $('input[name="localQueryKeyword"]').val() || '';
  3125. data['bp'] = $('input[name="bpTemp"]').val() || '';
  3126. data['ep'] = $('input[name="epTemp"]').val() || '';
  3127.  
  3128. var settings = {
  3129. "url": "https://so.szlcsc.com/search",
  3130. "method": "POST",
  3131. // "data": { "pn": searchPageNum, "k": val, "sk": val }
  3132. "data": data
  3133. };
  3134.  
  3135. // console.log('品牌搜索页参数:', settings);
  3136. promiseList.push($.ajax(settings));
  3137. }
  3138.  
  3139. globalSearchEnd = true;
  3140. allWithProgress(promiseList, ({total, cur, progress}) => {
  3141. $('.wait-h2').html(`数据加载中...</br>(共${total}页,正在加载第${cur}页。或只查询前1000条记录)...`);
  3142. }).then(function (result) {
  3143. console.time('搜索首页凑单渲染速度');
  3144. result.forEach(data => {
  3145. if(data.code === 200 && data.result != null) {
  3146. if (data.result.productRecordList != null) {
  3147. searchTempList = [...searchTempList, ...data.result.productRecordList];
  3148. }
  3149. }
  3150. });
  3151. }).finally(() => {
  3152. renderMinPriceSearch();
  3153. console.timeEnd('搜索首页凑单渲染速度');
  3154. setTimeout(() => { $('#js-filter-btn').click() }, 100);
  3155. });
  3156. }
  3157. }
  3158.  
  3159. /**
  3160. * 品牌搜索主页的凑单逻辑
  3161. */
  3162. const renderBrandPageMinPriceSearch = async () => {
  3163. if (!brandSearchEnd) {
  3164. const totalPage = searchTotalPage();
  3165. // 延迟任务集合
  3166. const promiseList = [];
  3167. for (let pn = 1; pn <= totalPage; pn++) {
  3168. // 取品牌id
  3169. const brandId = /\d+/g.exec(location.href)[0];
  3170. if (brandId != null) {
  3171. const data = {};
  3172. [...$('form#allProjectFrom>input[type="hidden"]')].forEach(item => {
  3173. const name = $(item).attr('name');
  3174. const val = $(item).val();
  3175. data[name] = val;
  3176. });
  3177.  
  3178. data['pageNumber'] = pn;
  3179. data['queryProductGradePlateId'] = brandId;
  3180. data['localQueryKeyword'] = $('input[name="localQueryKeyword"]').val() || '';
  3181. data['queryBeginPrice'] = $('input[name="queryBeginPrice"]').val() || '';
  3182. data['queryEndPrice'] = $('input[name="queryEndPrice"]').val() || '';
  3183. data['queryBeginPriceTemp'] = $('input[name="queryBeginPriceTemp"]').val() || '';
  3184. data['queryEndPriceTemp'] = $('input[name="queryEndPriceTemp"]').val() || '';
  3185.  
  3186. var settings = {
  3187. "url": `https://list.szlcsc.com/brand_page/${brandId}.html`,
  3188. "method": "POST",
  3189. "data": data
  3190. }
  3191. // console.log('搜索首页参数:', settings);
  3192. promiseList.push($.ajax(settings));
  3193. }
  3194. }
  3195.  
  3196. brandSearchEnd = true;
  3197. allWithProgress(promiseList, ({total, cur, progress}) => {
  3198. $('.wait-h2').html(`数据加载中...</br>(共${total}页,正在加载第${cur}页。或只查询前1000条记录)...`);
  3199. }).then((result) => {
  3200. const dataArray = result.reduce((arr, cur)=> {
  3201. const $tables = $(cur).find('#shop-list table');
  3202. return arr.concat([...$tables]);
  3203. }, []);
  3204.  
  3205. const _buildMapData = ($table) => {
  3206. const map = {};
  3207. $table.each((i, e) => {
  3208. map[$(e).find('span:eq(0)').text().trim()] = $(e).find('span:eq(1)').text().trim();
  3209. });
  3210. return map;
  3211. }
  3212. console.time('品牌页凑单渲染速度');
  3213. searchTempList = dataArray.map(h => {
  3214. const $table = $(h);
  3215. return {
  3216. productId: $table.data('productid'),
  3217. lightStandard: $table.data('encapstandard'),
  3218. lightProductCode: $table.data('productcode'),
  3219. productMinEncapsulationNumber: $table.data('productminencapsulationnumber'),
  3220. productMinEncapsulationUnit: $table.data('productminencapsulationunit'),
  3221. productName: $table.data('productname'),
  3222. productModel: $table.data('productmodel'),
  3223. lightProductModel: $table.data('productmodel-unlight'),
  3224. productGradePlateId: $table.data('brandid'),
  3225. productPriceList: [...$table.find('li.three-nr-item span.ccd-ppbbz')].map(e => ({
  3226. "startPurchasedNumber": parseInt($(e).data('startpurchasednumber')),
  3227. "endPurchasedNumber": parseInt($(e).data('endpurchasednumber')),
  3228. "productPrice": parseFloat($(e).data('productprice'))
  3229. })),
  3230. listProductDiscount: $table.find('div.three-box-top ul.three-nr > li.three-nr-01').find('span:eq(0)').text().replace(/[ 折\n]+/g, '') || null,
  3231. productGradePlateName: $table.data('brandname'),
  3232. hkConvesionRatio: $table.data('hkconvesionratio'),
  3233. convesionRatio: $table.data('convesionratio'),
  3234. theRatio: $table.data('theratio'),
  3235. smtStockNumber: parseInt($table.find('table div.smt-stock').text() || 0),
  3236. smtLabel: $table.find('div.smt-flag.common-label').text() || '',
  3237. productStockStatus: $table.data('productstockstatus'),
  3238. isPlusDiscount: $table.data('isplusdiscount'),
  3239. productUnit: $table.data('productunit'),
  3240. isPresent: $table.data('ispresent'),
  3241. isGuidePrice: $table.data('isguideprice'),
  3242. minBuyNumber: $table.data('minbuynumber'),
  3243. hasSampleRule: $table.data('hassamplerule'),
  3244. breviaryImageUrl: $table.find('a.one-to-item-link img').data('urls').split('<$>')[0],
  3245. luceneBreviaryImageUrls: $table.find('a.one-to-item-link img').data('urls') || '',
  3246. productType: $table.find('li.li-ellipsis a.catalog').attr('title') || '',
  3247. productTypeCode: /\d+/g.exec($table.find('li.li-ellipsis a.catalog').attr('href') || '')[0],
  3248. pdfDESProductId: $table.find('li.li-ellipsis a.sjsc').attr('param-click'),
  3249. gdWarehouseStockNumber: parseInt($table.find('div.stock-nums-gd span').text() || 0),
  3250. jsWarehouseStockNumber: parseInt($table.find('div.stock-nums-js span').text() || 0),
  3251. paramLinkedMap: _buildMapData($table.find('ul.params-list li.li-ellipsis')),
  3252. recentlySalesCount: /\d+/g.exec($table.find('div.stocks span').text() || '0')[0],
  3253. batchStockLimit: $table.data('batchstocklimit'),
  3254. };
  3255. });
  3256.  
  3257. }).finally(() => {
  3258. renderMinPriceSearch();
  3259. console.timeEnd('品牌页凑单渲染速度');
  3260. setTimeout(() => { $('#js-filter-btn').click() }, 100);
  3261. });
  3262. }
  3263. }
  3264.  
  3265. /**
  3266. * 搜索页-查找最低价 列表渲染方法
  3267. */
  3268. const renderMinPriceSearch = () => {
  3269. // 如果广东仓和江苏仓同时没有货的话,那么就属于订货商品,不需要显示
  3270. // 如果没有价格区间,证明是停售商品
  3271. var newList = searchTempList.filter(item =>!(parseInt(item.jsWarehouseStockNumber||0) <= 0 && parseInt(item.gdWarehouseStockNumber||0) <= 0) && item.productPriceList.length > 0);
  3272. // 去重
  3273. const map = new Map();
  3274. newList.forEach(item => {
  3275. map.set(item.productId, item);
  3276. });
  3277. newList = [...map.values()];
  3278. // 列表自动正序,方便凑单
  3279. newList.sort((o1, o2) =>{
  3280. return (o1.theRatio * o1.productPriceList[0].productPrice * (o1.listProductDiscount || 10) / 10).toFixed(6) - (o2.theRatio * o2.productPriceList[0].productPrice * (o2.listProductDiscount || 10) / 10).toFixed(6);
  3281. });
  3282. // 外部动态js规则组
  3283. if (jsRules.length > 0) {
  3284. jsRules.forEach(jsr => { newList = newList.filter(jsr); });
  3285. }
  3286.  
  3287. // 取指定条数的数据。默认50个
  3288. const html = newList.slice(0, (searchPageRealSize || 50)).map(item => {
  3289. const {
  3290. productId ,
  3291. lightStandard ,
  3292. lightProductCode ,
  3293. productMinEncapsulationNumber ,
  3294. productMinEncapsulationUnit ,
  3295. productName ,
  3296. productModel ,
  3297. lightProductModel ,
  3298. productGradePlateId ,
  3299. productPriceList ,
  3300. listProductDiscount ,
  3301. productGradePlateName ,
  3302. hkConvesionRatio ,
  3303. convesionRatio ,
  3304. theRatio ,
  3305. smtStockNumber ,
  3306. smtLabel ,
  3307. productStockStatus ,
  3308. isPlusDiscount ,
  3309. productUnit ,
  3310. isPresent ,
  3311. isGuidePrice ,
  3312. minBuyNumber ,
  3313. hasSampleRule ,
  3314. breviaryImageUrl ,
  3315. luceneBreviaryImageUrls ,
  3316. productType ,
  3317. productTypeCode ,
  3318. pdfDESProductId ,
  3319. gdWarehouseStockNumber ,
  3320. jsWarehouseStockNumber ,
  3321. paramLinkedMap ,
  3322. recentlySalesCount ,
  3323. batchStockLimit
  3324. } = item;
  3325.  
  3326. return `<table class="inside inside-page tab-data no-one-hk list-items"
  3327. id="product-tbody-line-${productId}" width="100%" border="0"
  3328. cellspacing="0" cellpadding="0" data-curpage="1" data-mainproductindex="0"
  3329. pid="${productId}" psid
  3330. data-batchstocklimit="${batchStockLimit}" data-encapstandard="${lightStandard}"
  3331. data-hassamplerule="${hasSampleRule}" data-productcode="${lightProductCode}"
  3332. data-productminencapsulationnumber="${productMinEncapsulationNumber}"
  3333. data-productminencapsulationunit="${productMinEncapsulationUnit}" data-productmodel="${productModel}"
  3334. data-productname="${productName}"
  3335. data-productstockstatus="${productStockStatus}"
  3336. data-convesionratio="${convesionRatio}" data-theratio="${theRatio}" data-hkconvesionratio="${hkConvesionRatio}"
  3337. data-productunit="${productUnit}" data-isplusdiscount="${isPlusDiscount}"
  3338. data-isguideprice="${isGuidePrice}" data-ispresent="${isPresent}" data-brandid="${productGradePlateId}"
  3339. data-brandname="${productGradePlateName}"
  3340. data-productmodel-unlight="${lightProductModel}" data-istiprovider data-isptoc
  3341. data-firstprice="${productPriceList[0].discountPrice || productPriceList[0].productPrice}" data-minbuynumber="${minBuyNumber}"
  3342. data-provider data-reposition data-productid="${productId}">
  3343. <tbody>
  3344. <tr class="no-tj-tr add-cart-tr" data-inventory-type="local" pid="${productId}">
  3345. <td class="line-box">
  3346. <div class="one line-box-left">
  3347. <a class="one-to-item-link"
  3348. href="https://item.szlcsc.com/${productId}.html?fromZone=s_s__%2522123%2522"
  3349. target="_blank" data-trackzone="s_s__&quot;123&quot;"
  3350. onclick="goItemDetailBuriedPoint('${productId}', this, 'picture', 's_s__&quot;${$("#search-input").val()}&quot;', null, '0')">
  3351. <img
  3352. src="${breviaryImageUrl}"
  3353. productid="${productId}" alt="${productName}"
  3354. xpath="${breviaryImageUrl}"
  3355. data-urls="${luceneBreviaryImageUrls}"
  3356. showflag="yes"
  3357. onerror="javascript:this.src='//static.szlcsc.com/ecp/assets/web/static/images/default_pic.gif'">
  3358. </a>
  3359. <span>
  3360. <input type="button" class="db" data-add-compare="${productId}"
  3361. title="对比后该商品会添加到对比栏中" value>
  3362. <input type="button" class="sc common-sc productId-${productId} "
  3363. title="收藏后该商品会保存到[会员中心]下的[我的收藏]中"
  3364. data-productid="${productId}">
  3365. </span>
  3366. </div>
  3367. <div class="line-box-right">
  3368. <div class="line-box-right-bottom">
  3369. <div class="two">
  3370. <div class="two-01 two-top">
  3371. <ul class="l02-zb">
  3372. <li class="li-ellipsis">
  3373. <a title="${productName}"
  3374. class="ellipsis product-name-link item-go-detail"
  3375. href="https://item.szlcsc.com/${productId}.html?fromZone=s_s__%2522123%2522"
  3376. target="_blank"
  3377. data-trackzone="s_s__&quot;123&quot;"
  3378. onclick="goItemDetailBuriedPoint('${productId}', this, 'name', 's_s__&quot;${$("#search-input").val()}&quot;', null, '0')">
  3379. ${productName}</a>
  3380. </li>
  3381. <li class="band li-ellipsis"
  3382. onclick="commonBuriedPoint(this, 'go_brand')">
  3383. <span class="c9a9a9a" title="品牌:${productGradePlateName}">品牌:</span>
  3384. <a class="brand-name" title="点击查看${productGradePlateName}的品牌信息"
  3385. href="https://list.szlcsc.com/brand/${productGradePlateId}.html"
  3386. target="_blank">
  3387. ${productGradePlateName}
  3388. </a>
  3389. </li>
  3390. <li class="li-ellipsis">
  3391. <span class="c9a9a9a" title="封装:${lightStandard}">封装:</span>
  3392. <span title="${lightStandard}">${lightStandard}</span>
  3393. </li>
  3394. <!--<li class="li-el">
  3395. <span class="select-spec-mh"
  3396. style="border-radius: 2px; display: inline-flex; padding: 3px 8px; color: white; cursor: pointer; user-select: none; background: #199fe9;"
  3397. specname="${lightStandard}" selecttype="MHC">封装模糊匹配</span>
  3398. <span class="select-spec-jq"
  3399. style="border-radius: 2px; display: inline-flex; padding: 3px 8px; color: white; cursor: pointer; user-select: none; background: #199fe9; margin-left: 3px;"
  3400. specname="${lightStandard}" selecttype="JQC">封装精确匹配</span>
  3401. </li>-->
  3402. <li>
  3403. </li>
  3404. </ul>
  3405. <ul class="l02-zb params-list">
  3406. ${Object.keys(paramLinkedMap).map(key => {
  3407. return `<li class="li-ellipsis">
  3408. <span class="c9a9a9a">${key}</span>:
  3409. <span title="${paramLinkedMap[key]}">${paramLinkedMap[key]}</span>
  3410. </li>`
  3411. }).join('')}
  3412. </ul>
  3413. <ul class="l02-zb">
  3414. <li class="li-ellipsis"
  3415. onclick="commonBuriedPoint(this, 'go_catalog')">
  3416. <span class="c9a9a9a">类目:</span>
  3417. <a title="${productType}" target="_blank"
  3418. class="catalog ellipsis underLine"
  3419. href="https://list.szlcsc.com/catalog/${productTypeCode}.html">
  3420. ${productType}
  3421. </a>
  3422. </li>
  3423. <li class="li-ellipsis">
  3424. <span class="c9a9a9a">编号:</span>
  3425. <span>${lightProductCode}</span>
  3426. </li>
  3427. <li class="li-ellipsis">
  3428. <span class="c9a9a9a">详细:</span>
  3429. <a class="sjsc underLine" productid="${productId}"
  3430. param-click="${pdfDESProductId}">
  3431. 数据手册
  3432. </a>
  3433. </li>
  3434. </ul>
  3435. </div>
  3436. <div class="two-bottom">
  3437. <!-- <li class="tag-wrapper">-->
  3438. <!--</li>-->
  3439. <!--<div class="three-box-bottom common-label common-useless-label">-->
  3440. <!--<section class="smt-price" id="SP-LIST">-->
  3441. <!-- <a target="_blank" data-pc="${lightProductCode}" class="to-jlc-smt-list"-->
  3442. <!-- href="https://www.jlcsmt.com/lcsc/detail?componentCode=${lightProductCode}&amp;stockNumber=10&amp;presaleOrderSource=shop">嘉立创贴片惊喜价格(库存<span-->
  3443. <!-- class="smtStockNumber">${smtStockNumber}</span>)</a>-->
  3444. <!--</section>-->
  3445. <!--</div>-->
  3446. <!-- SMT 基础库、扩展库 -->
  3447. <!--<div class="smt-flag common-label">${smtLabel}</div> -->
  3448. </div>
  3449. </div>
  3450. <div class="three-box hasSMT">
  3451. <div class="three-box-top">
  3452. <div class="three">
  3453. <ul class="three-nr">
  3454. ${listProductDiscount != null && listProductDiscount < 10 ? `
  3455. <li class="three-nr-01">
  3456. <span>${listProductDiscount}折</span>
  3457. <span class="show-discount-icon">
  3458. <div class="common-float-dialog">
  3459. <div class="common-float-content">
  3460. <ul class="cel-item num-cel">
  3461. <li></li>
  3462. ${productPriceList.map(item => {
  3463. return `<li>${item.startPurchasedNumber * theRatio}+:&nbsp;</li>`;
  3464. }).join('')}
  3465. </ul>
  3466. <ul class="cel-item mr5">
  3467. <li class="text-align-center">折后价</li>
  3468. ${productPriceList.map(item => {
  3469. return `<li>¥${parseFloat((item.productPrice * (listProductDiscount || 10) / 10).toFixed(6))}</li>`;
  3470. }).join('')}
  3471. </ul>
  3472. <ul class="cel-item not-plus-o-price-cel">
  3473. <li class="text-align-center">原价</li>
  3474. ${productPriceList.map(item => {
  3475. return `<li class="o-price">¥${item.productPrice}</li>`;
  3476. }).join('')}
  3477. </ul>
  3478. </div>
  3479. <s class="f-s"><i class="f-i"></i></s>
  3480. </div>
  3481. </span>
  3482. </li>
  3483. `:''}
  3484. <p class="minBuyMoney_" style="
  3485. width: fit-content;
  3486. padding: 2px 3px;
  3487. font-weight: 600;
  3488. color: #0094e7;">最低购入价: ${parseFloat((theRatio * productPriceList[0].productPrice * (listProductDiscount || 10) / 10).toFixed(6))}</p>
  3489. ${
  3490. productPriceList.map(item => {
  3491. const discountPrice = parseFloat((item.productPrice * (listProductDiscount || 10) / 10).toFixed(6));
  3492. return `<li class="three-nr-item">
  3493. <div class="price-warp price-warp-local">
  3494. <p class="ppbbz-p no-special " minordernum="${item.startPurchasedNumber * theRatio}"
  3495. originalprice="${item.productPrice}" discountprice="${discountPrice}"
  3496. orderprice="${discountPrice}">
  3497. ${item.startPurchasedNumber * theRatio}+:&nbsp;
  3498. </p>
  3499. <span class="ccd ccd-ppbbz show-price-span"
  3500. minordernum="${item.startPurchasedNumber * theRatio}" data-endpurchasednumber="${item.endPurchasedNumber}"
  3501. data-productprice="${item.productPrice}" data-productprice-discount
  3502. orderprice="${item.productPrice}"
  3503. data-startpurchasednumber="${item.startPurchasedNumber}">
  3504. ${discountPrice}
  3505. </span>
  3506. </div>
  3507. </li>`;
  3508. }).join('')}
  3509. </ul>
  3510. </div>
  3511. <div class="three three-hk">
  3512. </div>
  3513. </div>
  3514. </div>
  3515. <div class="conformity-box">
  3516. <div class="conformity-box-top">
  3517. <div class="three-change">
  3518. <span class="three-nr-01 three-nr-long">现货最快4H发</span>
  3519. <ul class="finput">
  3520. <li class="stocks stocks-change stocks-style"
  3521. local-show="yes" hk-usd-show="no">
  3522. <div class="stock-nums-gd">广东仓:<span style="font-weight:bold">${gdWarehouseStockNumber}</span></div>
  3523. <div class="stock-nums-js">江苏仓:<span style="font-weight:bold">${jsWarehouseStockNumber}</span></div>
  3524. </li>
  3525. <li class="display-none">
  3526. <div local-show="no" hk-usd-show="yes">
  3527. </div>
  3528. </li>
  3529. </ul>
  3530. <!--
  3531. <div class="smt-stock">广东SMT仓: <span style="font-weight:bold">
  3532. ${smtStockNumber}
  3533. </span></div>
  3534. -->
  3535. </div>
  3536. <div class="ffour">
  3537. <ul class="finput">
  3538. <li class="price-input price-input-gd local-input">
  3539. <input type="text" maxlength="9" unit-type="single"
  3540. class="cartnumbers " pluszk="false"
  3541. unitnum="${productMinEncapsulationNumber}" placeholder="广东仓" defaultwarehouse="sz"
  3542. data-type="gd" gdstock="${gdWarehouseStockNumber}" value>
  3543. <div class="unit ">
  3544. <span class="cur-unit ">个</span>
  3545. <i class="xl"></i>
  3546. <div class="unit-contain" style="display: none;">
  3547. <div class="unit-type">
  3548. <span class="unit-one">个</span>
  3549. <span class="unit-two">${productMinEncapsulationUnit}</span>
  3550. </div>
  3551. <i class="sl"></i>
  3552. </div>
  3553. </div>
  3554. </li>
  3555. <li class="price-input price-input-js local-input">
  3556. <input type="text" maxlength="9" unit-type="single"
  3557. class="cartnumbers " pluszk="false"
  3558. unitnum="${productMinEncapsulationNumber}" placeholder="江苏仓" defaultwarehouse="sz"
  3559. data-type="js" jsstock="${jsWarehouseStockNumber}" value>
  3560. <div class="unit ">
  3561. <span class="cur-unit ">个</span>
  3562. <i class="xl"></i>
  3563. <div class="unit-contain" style="display: none;">
  3564. <div class="unit-type">
  3565. <span class="unit-one">个</span>
  3566. <span class="unit-two">${productMinEncapsulationUnit}</span>
  3567. </div>
  3568. <i class="sl"></i>
  3569. </div>
  3570. </div>
  3571. </li>
  3572. <li class="price-input price-input-hk">
  3573. <input type="text" maxlength="9" unit-type="single"
  3574. class="cartnumbers " pluszk="false"
  3575. unitnum="${productMinEncapsulationNumber}" placeholder="香港仓" data-type="hk"
  3576. value="${hkConvesionRatio}">
  3577. <div class="unit ">
  3578. <span class="cur-unit ">个</span>
  3579. <i class="xl"></i>
  3580. <div class="unit-contain" style="display: none;">
  3581. <div class="unit-type">
  3582. <span class="unit-one">个</span>
  3583. <span class="unit-two">${productMinEncapsulationUnit}</span>
  3584. </div>
  3585. <i class="sl"></i>
  3586. </div>
  3587. </div>
  3588. </li>
  3589. <li>${productMinEncapsulationNumber}个/${productMinEncapsulationUnit}</li>
  3590. <li class="totalPrice-li">总额:<span class="goldenrod totalPrice">¥0</span>
  3591. <div class="plus_mj">
  3592. <div class="plus-flag">
  3593. <span><span class="mj-name"></span>已优惠<span
  3594. class="mj-money">0</span>元!</span>
  3595. <s><i></i></s>
  3596. </div>
  3597. </div>
  3598. </li>
  3599. </ul>
  3600. <ul class="pan">
  3601. <li class="pan-list">
  3602. <button type="button" class="pan-list-btn addCartBtn "
  3603. kind="cart" local-show="yes"
  3604. hk-usd-show="no" id="addcart-so" productcode="${lightProductCode}"
  3605. data-curpage="1"
  3606. data-mainproductindex="0" param-product-id="${productId}"
  3607. data-agl-cvt="15"
  3608. data-trackzone="s_s__&quot;123&quot;">加入购物车</button>
  3609. <button type="button"
  3610. class="pan-list-btn addCartBtn display-none"
  3611. kind="order" local-show="no"
  3612. hk-usd-show="yes" productcode="${lightProductCode}" data-curpage="1"
  3613. data-mainproductindex="0"
  3614. param-product-id="${productId}" data-agl-cvt="15"
  3615. data-trackzone="s_s__&quot;123&quot;">我要订货</button>
  3616. <div class="stocks">
  3617. <span>近期成交${recentlySalesCount}单</span>
  3618. </div>
  3619. <span class="add-cart-tip">
  3620. <i class="add-cart"></i><span
  3621. class="c999 cursor-default lh">已加购</span>
  3622. </span>
  3623. <button onclick="commonBuriedPoint(this, 'purchase_plan')"
  3624. type="button" class="stock-btn"
  3625. data-productmodel="${productName}"
  3626. data-brandname="${productGradePlateName}"
  3627. data-trackzone="s_s__&quot;123&quot;">
  3628. 我要备货
  3629. </button>
  3630. <button type="button" class="pan-list-btn searchTaobao_"
  3631. style="margin-top: 5px; background: #199fe9;">一键搜淘宝</button>
  3632. </li>
  3633. </ul>
  3634. </div>
  3635. </div>
  3636. </div>
  3637. </div>
  3638. </div>
  3639. </td>
  3640. </tr>
  3641. <tr
  3642. class="more-channel-products items-overseas-products display-none hide-tr">
  3643. <td colspan="6" id="overseasList" oldbatchproductlist
  3644. isgroupproduct="false" listlength="30" productid="${productId}">
  3645. </td>
  3646. </tr>
  3647. <tr class="more-channel-products items-hk-products display-none hide-tr">
  3648. <td colspan="6" id="hkProductList" oldbatchproductlist
  3649. isgroupproduct="false" listlength="30" productid="${productId}">
  3650. </td>
  3651. </tr>
  3652. </tbody>
  3653. </table>`;
  3654. }).join('');
  3655.  
  3656. appendProductListBox(html);
  3657.  
  3658. }
  3659.  
  3660. // 哪些需要显示凑单按钮
  3661. const productListIsShowBool = location.href.includes('so.szlcsc.com/global.html') || location.href.includes('list.szlcsc.com/brand') || location.href.includes('list.szlcsc.com/catalog');
  3662. // 在搜索首页
  3663. if(productListIsShowBool && $('#product-list-show-btn').length === 0) {
  3664. $('body').append( `<div id="product-list-show-btn" style="
  3665. border-radius: 5px;
  3666. z-index: 10000;
  3667. position: fixed;
  3668. right: 45px;
  3669. bottom: 45px;
  3670. padding: 5px 10px;
  3671. color: white;
  3672. background: #199fe9;
  3673. border: 2px solid #199fe9;
  3674. font-size: 20px;
  3675. cursor: pointer;
  3676. user-select:none;
  3677. font-weight: 600;"><p>凑单</p><span style="font-size: 12px;">页面加载慢,请耐心等待!</span></div>`);
  3678.  
  3679. $('#product-list-show-btn').on('click', function() {
  3680. if ($('#product-list-box').is(":hidden")) {
  3681. globalSearchEnd = false;
  3682. searchTempList = [];
  3683. }
  3684. $('#product-list-box').fadeToggle();
  3685. });
  3686. }
  3687.  
  3688. if(productListIsShowBool && $('#product-list-box').length === 0) {
  3689. // 这里处理前10页的最低购入价的排序
  3690. $('body').append(`<div id='product-list-box' style="display: none; position: fixed; bottom: 35px; right: 100px; width: min-content; min-height: 30vh; max-height: 75vh; overflow: auto; border: 2px solid #199fe9; z-index: 9999; padding: 5px; background: white;">
  3691. <div style="display: flex; justify-content: space-around;height: 60px; position: sticky; top: 0px;z-index: 99999;">
  3692. <div style="border: 2px solid #199fe9; display: flex; padding: 5px; width: 100%;">
  3693. <button id="gd-filter-btn" style="white-space:nowrap; border-radius: 4px; display: inline-flex; padding: 3px 8px; color: white; width: 100%; border: none; justify-content: center; align-items: center;font-size: 16px; font-weight: bold;margin-left: 0px;cursor: pointer;user-select: none;background: #aaaeb0;">广东仓</button>
  3694. <button id="js-filter-btn" style="white-space:nowrap; border-radius: 4px; display: inline-flex; padding: 3px 8px; color: white; width: 100%; border: none; justify-content: center; align-items: center;font-size: 16px; font-weight: bold;margin-left: 10px;cursor: pointer;user-select: none;background: #aaaeb0;">江苏仓</button>
  3695. </div>
  3696. <div style="margin-left: 10px; border: 2px solid #199fe9; display: flex; padding: 5px; width: 100%;">
  3697. <button id="new-filter-coupon-btn" style="white-space:nowrap; border-radius: 4px; display: inline-flex; padding: 3px 8px; color: white; width: 100%; border: none; justify-content: center; align-items: center;font-size: 16px; font-weight: bold;margin-left: 0px;cursor: pointer;user-select: none;background: #aaaeb0;">新人券</button>
  3698. <button id="unnew-filter-coupon-btn" style="white-space:nowrap; border-radius: 4px; display: inline-flex; padding: 3px 8px; color: white; width: 100%; border: none; justify-content: center; align-items: center;font-size: 16px; font-weight: bold;margin-left: 10px;cursor: pointer;user-select: none;background: #aaaeb0;">非新人券</button>
  3699. <button id="other-filter-coupon-btn" style="white-space:nowrap; border-radius: 4px; display: inline-flex; padding: 3px 8px; color: white; width: 100%; border: none; justify-content: center; align-items: center;font-size: 16px; font-weight: bold;margin-left: 10px;cursor: pointer;user-select: none;background: #aaaeb0;">其他券</button>
  3700. </div>
  3701. </div>
  3702. <h2 class="wait-h2" style="height: 200px; width: 500px; display: flex;justify-content: center;align-items: center;">数据正在加载中...</h2>
  3703. <h2 class="nodata-h2" style="height: 200px; width: 500px; display: flex; justify-content: center;align-items: center;">暂无数据,请稍后刷新页面再试!</h2>
  3704. <div id="data-box—"></div>
  3705. </div>`);
  3706. $('.nodata-h2').hide();
  3707. // 广东仓过滤
  3708. $('#gd-filter-btn').on('click', function() {
  3709. $('button[id*=-filter-btn]').css('background', '#aaaeb0');
  3710. $('#gd-filter-btn').css('background', '#199fe9');
  3711. jsRules[0] = (item) => parseInt(item.gdWarehouseStockNumber||0) > 0;
  3712. renderMinPriceSearch();
  3713. });
  3714. // 江苏仓过滤
  3715. $('#js-filter-btn').on('click', function() {
  3716. $('button[id*=-filter-btn]').css('background', '#aaaeb0');
  3717. $('#js-filter-btn').css('background', '#199fe9')
  3718. jsRules[0] = (item) => parseInt(item.jsWarehouseStockNumber||0) > 0;
  3719. renderMinPriceSearch();
  3720. });
  3721. // 新人券过滤
  3722. $('#new-filter-coupon-btn').on('click', function() {
  3723. $('button[id*=-filter-coupon-btn]').css('background', '#aaaeb0');
  3724. $('#new-filter-coupon-btn').css('background', '#199fe9');
  3725. jsRules[1] = (item) => {
  3726. try {
  3727. return all16_15CouponMp.get(getBrandNameByRegex(item.productGradePlateName)).isNew === true;
  3728. } catch (error) {
  3729. return false;
  3730. }
  3731. };
  3732. renderMinPriceSearch();
  3733. });
  3734. // 非新人券过滤
  3735. $('#unnew-filter-coupon-btn').on('click', function() {
  3736. $('button[id*=-filter-coupon-btn]').css('background', '#aaaeb0');
  3737. $('#unnew-filter-coupon-btn').css('background-color', '#199fe9');
  3738. jsRules[1] = (item) => {
  3739. try {
  3740. return all16_15CouponMp.get(getBrandNameByRegex(item.productGradePlateName)).isNew === false;
  3741. } catch (error) {
  3742. return false;
  3743. }
  3744. };;
  3745. renderMinPriceSearch();
  3746. });
  3747. // 其他券过滤
  3748. $('#other-filter-coupon-btn').on('click', function() {
  3749. $('button[id*=-filter-coupon-btn]').css('background', '#aaaeb0');
  3750. $('#other-filter-coupon-btn').css('background-color', '#199fe9');
  3751. jsRules[1] = (item) => {
  3752. try {
  3753. // 这里不返回,就看领券中心有没有这个品牌的券,不太准确反正
  3754. all16_15CouponMp.get(getBrandNameByRegex(item.productGradePlateName)).isNew;
  3755. } catch (error) {
  3756. // 不在领券中心的商品
  3757. return true;
  3758. }
  3759. };;
  3760. renderMinPriceSearch();
  3761. });
  3762. } else if($('#product-list-box').is(':visible')) {
  3763. // 搜索首页
  3764. if (location.href.includes('so.szlcsc.com/global.html')) {
  3765. renderMainPageMinPriceSearch();
  3766. }
  3767. // 品牌首页
  3768. else if(location.href.includes('list.szlcsc.com/brand')) {
  3769. renderBrandPageMinPriceSearch();
  3770. }
  3771. // 分类搜索
  3772. else if(location.href.includes('list.szlcsc.com/catalog')) {
  3773. renderCatalogPageMinPriceSearch();
  3774. }
  3775. }
  3776. }
  3777.  
  3778.  
  3779. // 排序记录 desc降序,asc升序
  3780.  
  3781. /**
  3782. * 配单页 增加价格排序按钮
  3783. */
  3784. const bomStart = () => {
  3785.  
  3786. if ($('div.bom-result-progess .progess-box .progess-line-blue').text() !== '0%') {
  3787. $('#new-box_').attr('disabled', true)
  3788. } else {
  3789. $('#new-box_').attr('disabled', false)
  3790. }
  3791. if ($('button#new-box_').length > 0) {
  3792. return
  3793. }
  3794. const sortHt = `<button id='new-box_' class="new-box_" onclick="(function () {
  3795. const $eles = $('.el-table__row.perfect').get();
  3796. $eles.sort((next, prev) => {
  3797. let nextPrice = $(next).find('div.dfc:contains(¥)').text().replace(/[¥ ]+/g, '')
  3798. let prevPrice = $(prev).find('div.dfc:contains(¥)').text().replace(/[¥ ]+/g, '')
  3799. if(localStorage.getItem('sortSign') === 'desc') {
  3800. if (parseFloat(nextPrice) > parseFloat(prevPrice)) return -1;
  3801. if (parseFloat(nextPrice) < parseFloat(prevPrice)) return 1;
  3802. }
  3803. else if(localStorage.getItem('sortSign') === 'asc') {
  3804. if (parseFloat(nextPrice) > parseFloat(prevPrice)) return 1;
  3805. if (parseFloat(nextPrice) < parseFloat(prevPrice)) return -1;
  3806. }
  3807. return 0;
  3808. })
  3809. localStorage.setItem('sortSign', (localStorage.getItem('sortSign') === 'desc') ? 'asc' : 'desc');
  3810. $('.el-table__body-wrapper tbody').html($eles)
  3811. })()"
  3812. style="color: #315af8; width: 100px; height: 35px; line-height: 35px;background-color: #fff;border-radius: 3px;border: 1px solid #cdf; margin-left: 10px;">
  3813. <div data-v-1b5f1317="" class="sg vg" style="height: 35px; display: none;">
  3814. <svg data-v-1b5f1317="" viewBox="25 25 50 50" class="bom-circular blue" style="width: 16px; height: 16px;">
  3815. <circle data-v-1b5f1317="" cx="50" cy="50" r="20" fill="none" class="path"></circle>
  3816. </svg>
  3817. </div>
  3818. <div class="">
  3819. 小计 升/降序
  3820. </div>
  3821. </button>
  3822. <style>
  3823. .new-box_:hover {
  3824. color: #315af8;
  3825. border: 1px solid #315af8 !important;
  3826. }
  3827. .new-box_:disabled {
  3828. border: 1px solid #dcdcdc !important;
  3829. cursor: not-allowed;
  3830. color: rgba(0, 0, 0, .3) !important;
  3831. }
  3832. </style>`;
  3833.  
  3834. $('div.bom-top-result.dfb div.flex-al-c:eq(2)').append(sortHt)
  3835. }
  3836.  
  3837. // 搜索页
  3838. let isSearchPage = () => location.href.includes('so.szlcsc.com/global.html') || location.href.includes('list.szlcsc.com/brand') || location.href.includes('list.szlcsc.com/catalog');
  3839. // 购物车页
  3840. let isCartPage = () => location.href.includes('cart.szlcsc.com/cart/display.html');
  3841. // BOM配单页
  3842. let isBomPage = () => location.href.includes('bom.szlcsc.com/member/eda/search.html') || location.href.includes('bom.szlcsc.com/member/bom/upload/');
  3843. // 优惠券页
  3844. let isCouponPage = () => location.href.includes('www.szlcsc.com/huodong.html');
  3845.  
  3846. setInterval(function () {
  3847.  
  3848. // if (isCartPage()) {
  3849. // cartStart()
  3850. // }
  3851.  
  3852. if (isSearchPage()) {
  3853. searchStart()
  3854. }
  3855.  
  3856. if (isBomPage()) {
  3857. bomStart()
  3858. }
  3859.  
  3860. if (isCouponPage()) {
  3861. couponGotoHandler()
  3862. }
  3863. }, 500)
  3864. })()