index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  1. const app = getApp();
  2. import wxh from '../../utils/wxh.js';
  3. import {
  4. getIndexData,
  5. getCoupons,
  6. getTemlIds,
  7. getLiveList,
  8. getNotifications
  9. } from '../../api/api.js';
  10. import {
  11. CACHE_SUBSCRIBE_MESSAGE
  12. } from '../../config.js';
  13. import {
  14. getCategoryList,
  15. getProductHot,
  16. getProductslist
  17. } from '../../api/store.js';
  18. import {
  19. getCouponReceive
  20. } from '../../api/user.js';
  21. import {
  22. getSeckillIndexTime,
  23. getSeckillList
  24. } from '../../api/activity.js';
  25. import Util from '../../utils/util.js';
  26. const CATE_BLACKHOLE_ID = 199
  27. const PAGE_LIMIT = 20
  28. const THROTTLE_TIME = 100
  29. const HEIGHT_OF_ROW = 500 // 摘抄自 css, 商品高度,包含图片文字 margin.
  30. const ITEM_NUM_OF_ROW = 2 // 设计为一行 2 个元素
  31. Page({
  32. /**
  33. * 页面的初始数据
  34. */
  35. data: {
  36. CATE_BLACKHOLE_ID: CATE_BLACKHOLE_ID,
  37. logoUrl: '', // 左上方 logo
  38. prodCates: [], // 分类列表/活动列表 (目前只有一个,就是“活动”)
  39. banner: [], // 顶部 banner
  40. itemNew: [], // 跑马灯列表
  41. menus: [],
  42. getCouponList: [], //@deprecated
  43. activity: [],
  44. timeList: [], //@deprecated
  45. killIndex: 0, //@deprecated 点击当前index值;
  46. seckillTimeIndex: 0, //@deprecated 当前秒杀index;
  47. killIndexTime: 0, //@deprecated 点击当前index值所对应的秒杀时间;
  48. killIndexLen: 0, //@deprecated 当前秒杀的产品列表长度
  49. seckillList: [], //@deprecated
  50. scrollLeft: 0, //@deprecated
  51. status: 1, //@deprecated
  52. lovely: [], //@deprecated
  53. info: {
  54. fastList: [],
  55. bastBanner: [], // 精品推荐 banner
  56. firstList: [], // 首发新品
  57. bastList: [] // 精品推荐
  58. },
  59. avtiveIndex: 0, // 轮播图索引
  60. likeInfo: [], // 热门榜单
  61. benefit: [], // 促销单品
  62. hotProducts: [], // 海量精品 ?
  63. indicatorDots: false, // 跑马灯轮播图不带点
  64. circular: true, // 轮播图圆点
  65. autoplay: true, // 跑马灯轮播图自动播放
  66. intervalNew: 3500, // 轮播图自动播放间隔
  67. durationNew: 700, // 轮播图自动播放时长
  68. parameter: {
  69. 'navbar': '0',
  70. 'return': '0',
  71. 'class': '5'
  72. },
  73. window: false, // 是否显示优惠券窗口
  74. iShiddenTip: false, // 是否显示提示
  75. isAuto: true, // 是否自动授权;
  76. iShidden: true, // 是否隐藏;
  77. isGoIndex: false, // 是否返回首页;
  78. recommend: {
  79. loadend: false,
  80. loading: false,
  81. loadTitle: '加载更多',
  82. page: 1,
  83. limit: 20,
  84. },
  85. /// 以下为拉洋片算法参数
  86. navH: 0, // 标题栏高度
  87. navPxH: 0, //
  88. rowHeight: HEIGHT_OF_ROW,
  89. rowPxHeight: HEIGHT_OF_ROW,
  90. rowProdNum: ITEM_NUM_OF_ROW,
  91. rowCacheNum: 5, // 拉洋片缓冲商品: 3 行
  92. ///
  93. activeTabIndex: 0,
  94. countDownHour: "00",
  95. countDownMinute: "00",
  96. countDownSecond: "00",
  97. seckillCont: true, //@deprecated
  98. interval: null,
  99. timerNotification: null,
  100. newGoodsBananr: '', //@deprecated
  101. cpnMine: null, // 挖礦組件
  102. liveList: [], // 直播列表
  103. liveInfo: {}
  104. },
  105. closeTip: function () {
  106. wx.setStorageSync('msg_key', true);
  107. this.setData({
  108. iShiddenTip: true
  109. })
  110. },
  111. // 挖矿组件绑定
  112. onNeedLogin: function () {
  113. this.setData({
  114. iShidden: false
  115. })
  116. },
  117. /**
  118. * 生命周期函数--监听页面加载
  119. */
  120. onLoad: function (options) {
  121. if (options.a && options.a == 'share' && options.id && options.spid) {
  122. wx.navigateTo({
  123. url: '/pages/goods_details/index?id=' + options.id + '&spid=' + options.spid,
  124. })
  125. }
  126. let query = wx.createSelectorQuery()
  127. query.select('.indexs').boundingClientRect((rect) => {
  128. let width = rect.width
  129. let ratio = 750 / width
  130. this.setData({
  131. rowPxHeight: Math.floor(this.data.rowHeight / ratio),
  132. navH: app.globalData.navHeight,
  133. navPxH: Math.floor(app.globalData.navHeight / ratio),
  134. })
  135. }).exec()
  136. wxh.selfLocation(1);
  137. this.getCategoryData();
  138. // this.getCoupon();
  139. this.get_hot_product();
  140. // this.get_product_list();
  141. this.setData({
  142. navH: app.globalData.navHeight
  143. });
  144. if (options.spid) {
  145. app.globalData.spid = options.spid;
  146. }
  147. if (options.scene) {
  148. app.globalData.code = decodeURIComponent(options.scene);
  149. }
  150. if (wx.getStorageSync('msg_key')) {
  151. this.setData({
  152. iShiddenTip: true
  153. });
  154. }
  155. this.getTemlIds();
  156. this.getLiveList();
  157. },
  158. getTemlIds() {
  159. let messageTmplIds = wx.getStorageSync(CACHE_SUBSCRIBE_MESSAGE);
  160. if (!messageTmplIds) {
  161. getTemlIds().then(res => {
  162. if (res.data) {
  163. wx.setStorageSync(CACHE_SUBSCRIBE_MESSAGE, JSON.stringify(res.data));
  164. }
  165. }).catch(() => {})
  166. }
  167. },
  168. //授权
  169. onLoadFun: function () {
  170. // 挖矿组件认证回调
  171. if (this.data.cpnMine != null) {
  172. this.data.cpnMine.onLoadFun();
  173. }
  174. },
  175. catchTouchMove: function (res) {
  176. return false
  177. },
  178. /** 关闭优惠券窗口 */
  179. onClose: function () {
  180. this.setData({
  181. window: false
  182. });
  183. },
  184. /**
  185. * 生命周期函数--监听页面初次渲染完成
  186. */
  187. onReady: function () {},
  188. /**
  189. * 轮播监听
  190. */
  191. bindchange(e) {
  192. var index = e.detail.current;
  193. this.setData({
  194. avtiveIndex: index
  195. });
  196. },
  197. /**
  198. * 生命周期函数--监听页面显示
  199. */
  200. onShow: function () {
  201. // this.getCoupon();
  202. this.getIndexConfig();
  203. // this.getSeckillTime();
  204. var that = this
  205. this.setData({
  206. timerNotification: setInterval(function () {
  207. that.loadNotifications()
  208. }, 1000 * 60 * 3)
  209. })
  210. app.updateUnread()
  211. },
  212. // 加载通知,目前只有跑马灯
  213. loadNotifications: function () {
  214. var that = this
  215. getNotifications().then(res => {
  216. if (res.data.carousel.length > 0) {
  217. that.setData({
  218. itemNew: res.data.carousel
  219. })
  220. }
  221. })
  222. },
  223. getIndexConfig: function () {
  224. var that = this;
  225. getIndexData().then(res => {
  226. that.setData({
  227. banner: res.data.banner,
  228. menus: res.data.menus,
  229. activity: res.data.activity,
  230. lovely: res.data.lovely,
  231. info: res.data.info,
  232. itemNew: res.data.roll,
  233. likeInfo: res.data.likeInfo,
  234. benefit: res.data.benefit,
  235. logoUrl: res.data.logoUrl,
  236. couponList: res.data.couponList,
  237. });
  238. app.setUnread(res.data.notice);
  239. })
  240. },
  241. getLiveList: function () {
  242. let that = this
  243. getLiveList(1, 20).then(res => {
  244. if (res.data.length == 1) {
  245. that.setData({
  246. liveInfo: res.data[0]
  247. });
  248. } else {
  249. that.setData({
  250. liveList: res.data
  251. });
  252. }
  253. }).catch(res => {
  254. })
  255. },
  256. /**
  257. * 商品详情跳转
  258. */
  259. goDetailType: function (e) {
  260. let item = e.currentTarget.dataset.items
  261. if (item.activity && item.activity.type === "1") {
  262. wx.navigateTo({
  263. url: `/pages/activity/goods_seckill_details/index?id=${item.activity.id}&time=${item.activity.time}&status=1`
  264. });
  265. } else if (item.activity && item.activity.type === "2") {
  266. wx.navigateTo({
  267. url: `/pages/activity/goods_bargain_details/index?id=${item.activity.id}`
  268. });
  269. } else if (item.activity && item.activity.type === "3") {
  270. wx.navigateTo({
  271. url: `/pages/activity/goods_combination_details/index?id=${item.activity.id}`
  272. });
  273. } else {
  274. wx.navigateTo({
  275. url: `/pages/goods_details/index?id=${item.id}`
  276. });
  277. }
  278. },
  279. /**
  280. * 获取我的推荐
  281. */
  282. get_hot_product: function (isReload) {
  283. if (this.data.recommend.loadend) return;
  284. if (this.data.recommend.loading) return;
  285. if (isReload) {
  286. this.setData({
  287. hotProducts: []
  288. });
  289. }
  290. this.setData({
  291. 'recommend.loading': true,
  292. 'recommend.loadTitle': ''
  293. });
  294. let that = this;
  295. getProductHot(this.data.recommend.page, this.data.recommend.limit).then(res => {
  296. let list = res.data;
  297. let hotProducts = app.SplitArray(list, that.data.hotProducts);
  298. let loadend = list.length < that.data.recommend.limit;
  299. that.setData({
  300. 'recommend.loadend': loadend,
  301. 'recommend.loading': false,
  302. 'recommend.loadTitle': loadend ? '已全部加载' : '加载更多',
  303. hotProducts: hotProducts,
  304. ['recommend.page']: that.data.recommend.page + 1,
  305. });
  306. }).catch(err => {
  307. that.setData({
  308. 'recommend.loading': false,
  309. 'recommend.loadTitle': '加载更多'
  310. });
  311. });
  312. },
  313. /** 点击上方活动标签按钮 */
  314. onTapCategoryTabItem: function (event) {
  315. let tabIndex = event.detail.index;
  316. if (tabIndex <= 0 || tabIndex > this.data.prodCates.children.length) {
  317. this.setData({
  318. activeTabIndex: tabIndex
  319. })
  320. return
  321. }
  322. if (this.data.prodCates.children[tabIndex - 1].id === CATE_BLACKHOLE_ID) {
  323. // 黑洞
  324. let mine = null
  325. if (this.data.cpnMine == null) {
  326. mine = this.selectComponent('#mine')
  327. }
  328. this.setData({
  329. activeTabIndex: tabIndex,
  330. cpnMine: mine,
  331. })
  332. var _ = this.data.cpnMine && this.data.cpnMine.show()
  333. return
  334. } else {
  335. var _ = this.data.cpnMine && this.data.cpnMine.hide()
  336. }
  337. this.setData({
  338. activeTabIndex: tabIndex
  339. })
  340. // 首屏
  341. if (this.data.prodCates.children[tabIndex - 1].page <= 1) {
  342. this.get_product_list(tabIndex);
  343. }
  344. wx.pageScrollTo({
  345. scrollTop: this.data.prodCates.children[tabIndex - 1].scrollPos
  346. })
  347. },
  348. // productTap: function (e) {
  349. // let index = e.currentTarget.dataset.indexn;
  350. // this.setData({
  351. // 'where.page': 1,
  352. // loadend: false,
  353. // loading: false,
  354. // 'where.sid': this.data.prodCates[this.data.activeTabIndex - 1].children[index].id
  355. // })
  356. // this.get_product_list(true);
  357. // },
  358. get_product_list: function (tabIndex, isReload) {
  359. if (tabIndex <= 0 || tabIndex > this.data.prodCates.children.length) {
  360. return
  361. }
  362. let cid = this.data.prodCates.id
  363. let act = this.data.prodCates.children[tabIndex - 1]
  364. if (act.loading) return
  365. if (act.loaded && !isReload) return
  366. let cindex = tabIndex - 1
  367. if (isReload) {
  368. act.products = []
  369. act.page = 1
  370. this.setData({
  371. [`prodCates.children[${cindex}].page`]: 1,
  372. [`prodCates.children[${cindex}].products`]: []
  373. })
  374. }
  375. this.setData({
  376. [`prodCates.children[${cindex}].loading`]: true,
  377. [`prodCates.children[${cindex}].loadTitle`]: ''
  378. });
  379. act.loading = true
  380. act.loadTitle = ''
  381. var that = this;
  382. getProductslist({
  383. page: act.page,
  384. limit: PAGE_LIMIT,
  385. cid: cid,
  386. sid: act.id,
  387. }).then(res => {
  388. let list = [] // res.data
  389. // 过滤产品列表, 只保留本页用的字段
  390. let counter = act.products.length
  391. res.data.forEach((item) => {
  392. counter += 1
  393. list.push({
  394. id: item.id,
  395. image: item.image,
  396. activity: item.activity,
  397. store_name: item.store_name,
  398. price: item.price,
  399. vip_price: item.vip_price,
  400. sales: item.sales,
  401. isShow: counter / 2 - act.aboveShowRowIndex <= 2 * this.data.rowCacheNum, // 是否显示
  402. })
  403. })
  404. let firstPage = act.products.length <= 0
  405. act.products = app.SplitArray(list, act.products)
  406. act.loaded = list.length < PAGE_LIMIT
  407. act.loading = false
  408. act.loadTitle = act.loaded ? '已全部加载' : '加载更多'
  409. act.page += 1
  410. that.setData({
  411. [`prodCates.children[${cindex}].loaded`]: act.loaded,
  412. [`prodCates.children[${cindex}].loading`]: false,
  413. [`prodCates.children[${cindex}].loadTitle`]: act.loaded ? '已全部加载' : '加载更多',
  414. [`prodCates.children[${cindex}].products`]: act.products,
  415. [`prodCates.children[${cindex}].page`]: act.page + 1
  416. });
  417. }).catch(err => {
  418. console.log(err)
  419. that.setData({
  420. [`prodCates.children[${cindex}].loading`]: false,
  421. [`prodCates.children[${cindex}].loadTitle`]: '加载更多'
  422. });
  423. });
  424. },
  425. // getSeckillTime: function () {
  426. // let that = this;
  427. // getSeckillIndexTime().then(res => {
  428. // let timeList = res.data.seckillTime, seckillTimeIndex = res.data.seckillTimeIndex;
  429. // that.setData({
  430. // timeList: timeList,
  431. // seckillCont: res.data.seckillCont,
  432. // killIndex: seckillTimeIndex,
  433. // seckillTimeIndex: seckillTimeIndex,
  434. // killIndexTime: timeList[that.data.killIndex].stop,
  435. // status: timeList[seckillTimeIndex].status
  436. // })
  437. // wxh.time(timeList[that.data.killIndex].stop, that,false);
  438. // that.getSeckillLists();
  439. // }).catch(()=>{
  440. // });
  441. // },
  442. // 页面事件, 不再使用
  443. // setTime: function (e) {
  444. // let index = e.currentTarget.dataset.index;
  445. // this.setData({
  446. // killIndex: index,
  447. // status: that.data.timeList[index].status
  448. // })
  449. // // that.getSeckillLists();
  450. // },
  451. // 不再触发
  452. // getSeckillLists: function () {
  453. // let that = this;
  454. // let timeId = that.data.timeList[that.data.killIndex].id;
  455. // getSeckillList(timeId, {
  456. // page: 1,
  457. // limit: 20
  458. // }).then(res => {
  459. // that.setData({
  460. // seckillList: res.data
  461. // })
  462. // if (this.data.timeList.length) {
  463. // let query = wx.createSelectorQuery().in(this);
  464. // query.select('.timeLen').boundingClientRect(function (res) {
  465. // if (res) {
  466. // that.setData({
  467. // scrollLeft: (that.data.killIndex - 1.8) * res.width
  468. // });
  469. // }
  470. // }).exec();
  471. // if (that.data.killIndex === that.data.seckillTimeIndex) {
  472. // that.setData({
  473. // killIndexLen: res.data.length
  474. // })
  475. // }
  476. // }
  477. // }).catch(() => {});
  478. // },
  479. /** 获取分类列表 */
  480. getCategoryData: function () {
  481. let that = this;
  482. getCategoryList().then(res => {
  483. let cates = res.data.length > 0 ? res.data[0] : {}
  484. that.setData({
  485. prodCates: that._rebuildProdCates(cates)
  486. })
  487. });
  488. },
  489. // 整理 this.data.prodCates
  490. _rebuildProdCates: function (cates) {
  491. cates.children.forEach(cate => {
  492. // 不处理黑洞星球
  493. if (cate.id == CATE_BLACKHOLE_ID) {
  494. return
  495. }
  496. // 增加属性
  497. cate.loading = false
  498. cate.loaded = false
  499. cate.loadTitle = '加载更多'
  500. cate.products = []
  501. cate.page = 1 // 当前第几页
  502. cate.scrollPos = 0 // 上次滚动条位置
  503. cate.aboveShowRowIndex = 0 // 可见区域上部行索引
  504. cate.belowShowRowNum = 0 // 底部隐藏行数
  505. })
  506. return cates;
  507. },
  508. /** 获取优惠券列表 不再触发*/
  509. // getCoupon: function () {
  510. // var that = this;
  511. // getCoupons({
  512. // page: 1,
  513. // limit: 6
  514. // }).then(res => {
  515. // that.setData({
  516. // getCouponList: res.data
  517. // })
  518. // }).catch(err => {
  519. // // app.Tips({
  520. // // title: err
  521. // // });
  522. // });
  523. // },
  524. // 页面回调,不再触发
  525. // receiveCoupon: function (e) {
  526. // if (!app.globalData.isLog) {
  527. // this.setData({
  528. // iShidden: false
  529. // });
  530. // } else {
  531. // var that = this;
  532. // var list = that.data.getCouponList;
  533. // var index = e.currentTarget.dataset.index;
  534. // var id = that.data.getCouponList[index].id;
  535. // getCouponReceive({
  536. // couponId: id
  537. // })
  538. // .then(function () {
  539. // list[index].is_use = true;
  540. // that.setData({
  541. // getCouponList: that.data.getCouponList
  542. // })
  543. // app.Tips({
  544. // title: "领取成功"
  545. // });
  546. // })
  547. // .catch(function (err) {
  548. // // app.Tips({
  549. // // title: err
  550. // // });
  551. // });
  552. // }
  553. // },
  554. /**
  555. * 生命周期函数--监听页面隐藏
  556. */
  557. onHide: function () {
  558. this.setData({
  559. window: false
  560. });
  561. this.data.interval !== null && clearInterval(this.data.interval);
  562. if (this.data.timerNotification != null) {
  563. clearInterval(this.data.timerNotification);
  564. this.setData({
  565. timerNotification: null,
  566. })
  567. }
  568. var _ = this.data.cpnMine && this.data.cpnMine.hide()
  569. },
  570. /**
  571. * 生命周期函数--监听页面卸载
  572. */
  573. onUnload: function () {
  574. this.data.interval !== null && clearInterval(this.data.interval);
  575. },
  576. /**
  577. * 页面相关事件处理函数--监听用户下拉动作
  578. */
  579. onPullDownRefresh: function () {
  580. let tabIndex = this.data.activeTabIndex
  581. if (tabIndex == 0) {
  582. this.getIndexConfig();
  583. } else if (tabIndex == this.data.prodCates.children.length) { // 黑洞星球不处理
  584. } else {
  585. this.get_product_list(tabIndex, true)
  586. }
  587. wx.stopPullDownRefresh();
  588. },
  589. /**
  590. * 页面上拉触底事件的处理函数
  591. */
  592. onReachBottom: function () {
  593. this.get_hot_product();
  594. this.get_product_list(this.data.activeTabIndex);
  595. },
  596. onPageScroll: throttle(function (obj) {
  597. if (this.data.activeTabIndex <= 0 || this.data.activeTabIndex >= this.data.prodCates.children.length) {
  598. return
  599. }
  600. let pos = obj[0].scrollTop
  601. let calcPos = pos //- this.data.navPxH
  602. calcPos = calcPos > 0 ? calcPos : 0
  603. let rowNum = Math.floor(calcPos / this.data.rowPxHeight) // 滚动过去的总行数, 也是当前 viewport 的开始索引位置
  604. let clearRowNum = rowNum - this.data.rowCacheNum// 隐藏总行数
  605. let cindex = this.data.activeTabIndex - 1
  606. let tabData = this.data.prodCates.children[cindex]
  607. // console.log('pos:', pos, 'rowPxHeight', this.data.rowPxHeight,
  608. // 'rowNum:', rowNum, 'clearRowNum:', clearRowNum, 'aboveShowRowIndex:', tabData.aboveShowRowIndex)
  609. let changingData = {}
  610. if (pos - tabData.scrollPos > 0) { // 向下
  611. if (clearRowNum > 0) {
  612. // aboveShowRowIndex 索引的行之前都不显示
  613. for (let i = tabData.aboveShowRowIndex; i < clearRowNum; i++) {
  614. let leftIndex = i * 2
  615. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  616. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  617. let belowShowRowIndex = i + 2 * this.data.rowCacheNum
  618. if (belowShowRowIndex < Math.floor(tabData.products.length / 2)) {
  619. leftIndex = belowShowRowIndex * 2
  620. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = true
  621. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = true
  622. }
  623. }
  624. }
  625. } else { // 向上
  626. if (clearRowNum >= 0) {
  627. for (let i = tabData.aboveShowRowIndex - 1; i >= clearRowNum; i--) {
  628. let leftIndex = i * 2
  629. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = true
  630. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = true
  631. let belowShowRowIndex = i + 2 * this.data.rowCacheNum
  632. if (belowShowRowIndex < tabData.products.length / 2) {
  633. leftIndex = belowShowRowIndex * 2
  634. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  635. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  636. }
  637. }
  638. } else {
  639. if (tabData.aboveShowRowIndex > 0) {
  640. for (let i = 0; i < tabData.aboveShowRowIndex; i++) {
  641. this.setData({
  642. [`prodCates.children[${cindex}].products[${i * 2}].isShow`]: true,
  643. [`prodCates.children[${cindex}].products[${i * 2 + 1}].isShow`]: true,
  644. })
  645. // changingData[[`prodCates.children[${cindex}].products[${i * 2}].isShow`]] = true
  646. // changingData[[`prodCates.children[${cindex}].products[${i * 2 + 1}].isShow`]] = true
  647. }
  648. }
  649. }
  650. } //
  651. clearRowNum = clearRowNum > 0 ? clearRowNum : 0;
  652. if (clearRowNum >= 0 && !(clearRowNum > 0 && clearRowNum == tabData.aboveShowRowIndex)) {
  653. changingData[[`prodCates.children[${cindex}].aboveShowRowIndex`]] = clearRowNum
  654. let belowShowRowNum = tabData.products.length / 2 - (2 * this.data.rowCacheNum + clearRowNum)
  655. belowShowRowNum = belowShowRowNum > 0 ? belowShowRowNum : 0
  656. // console.log('belowShowRowNum:', belowShowRowNum, 'tabData.products.length:', tabData.products.length, 'clearRowNum:', clearRowNum)
  657. if (belowShowRowNum >= 0) {
  658. changingData[[`prodCates.children[${cindex}].belowShowRowNum`]] = belowShowRowNum
  659. // for (let i = 0; i < belowShowRowNum; i++) {
  660. // let leftIndex = (tabData.products.length / 2 - i - 1) * 2;
  661. // changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  662. // changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  663. // }
  664. }
  665. this.setData(changingData)
  666. }
  667. if (cindex >= 0 && cindex < this.data.prodCates.children.length - 1) {
  668. this.setData({
  669. ['prodCates.children[' + cindex + '].scrollPos']: pos
  670. })
  671. }
  672. // this._debugProducts()
  673. }),
  674. _debugProducts: function () {
  675. let all = [],
  676. display = [],
  677. tabIndex = this.data.activeTabIndex
  678. if (tabIndex <= 0 || tabIndex > this.data.prodCates.children.length) {
  679. return
  680. }
  681. let tabData = this.data.prodCates.children[tabIndex - 1]
  682. for (let i = 0; i < tabData.products.length; i++) {
  683. if (tabData.products[i].isShow) {
  684. display.push(i)
  685. }
  686. all.push(i)
  687. }
  688. console.debug('all:', all)
  689. console.debug('display:', display)
  690. },
  691. /**
  692. * 用户点击右上角分享
  693. */
  694. onShareAppMessage: function () {
  695. }
  696. })
  697. function throttle(fn) {
  698. let valid = true
  699. return function () {
  700. if (!valid) {
  701. return false
  702. }
  703. valid = false
  704. return setTimeout(() => {
  705. fn.call(this, arguments)
  706. valid = true
  707. }, THROTTLE_TIME)
  708. }
  709. }