嘉立创购物车辅助工具

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

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

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