嘉立创购物车辅助工具

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

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

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