嘉立创购物车辅助工具

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

当前为 2024-10-18 提交的版本,查看 最新版本

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