嘉立创购物车辅助工具

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

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

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