嘉立创购物车辅助工具

嘉立创购物车辅助增强工具 包含:手动领券、自动领券、小窗显示优惠券领取状态、一键分享BOM、一键锁定/释放商品、一键换仓、一键选仓、搜索页优惠券新老用户高亮。

当前为 2024-08-13 提交的版本,查看 最新版本

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