JLC_SHOP_TOOL

JLC_SHOP_TOOL_1.0

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