index.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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. this.setData({
  369. [`prodCates.children[${cindex}].page`]: 1,
  370. [`prodCates.children[${cindex}].products`]: []
  371. })
  372. }
  373. this.setData({
  374. [`prodCates.children[${cindex}].loading`]: true,
  375. [`prodCates.children[${cindex}].loadTitle`]: ''
  376. });
  377. var that = this;
  378. getProductslist({
  379. page: act.page,
  380. limit: PAGE_LIMIT,
  381. cid: cid,
  382. sid: act.id,
  383. }).then(res => {
  384. let list = [] // res.data
  385. // 过滤产品列表, 只保留本页用的字段
  386. let counter = act.products.length
  387. res.data.forEach((item) => {
  388. counter += 1
  389. list.push({
  390. id: item.id,
  391. image: item.image,
  392. activity: item.activity,
  393. store_name: item.store_name,
  394. price: item.price,
  395. vip_price: item.vip_price,
  396. sales: item.sales,
  397. isShow: (counter / 2 - act.aboveShowRowIndex) <= 2 * this.data.rowCacheNum, // 是否显示
  398. })
  399. })
  400. // console.log('list.length:', list.length, 'res.data.length:', res.data.length)
  401. let products = app.SplitArray(list, act.products)
  402. let loaded = list.length < PAGE_LIMIT
  403. that.setData({
  404. [`prodCates.children[${cindex}].loaded`]: loaded,
  405. [`prodCates.children[${cindex}].loading`]: false,
  406. [`prodCates.children[${cindex}].loadTitle`]: loaded ? '已全部加载' : '加载更多',
  407. [`prodCates.children[${cindex}].products`]: products,
  408. [`prodCates.children[${cindex}].page`]: act.page + 1
  409. });
  410. }).catch(err => {
  411. console.log(err)
  412. that.setData({
  413. [`prodCates.children[${cindex}].loading`]: false,
  414. [`prodCates.children[${cindex}].loadTitle`]: '加载更多'
  415. });
  416. });
  417. },
  418. // getSeckillTime: function () {
  419. // let that = this;
  420. // getSeckillIndexTime().then(res => {
  421. // let timeList = res.data.seckillTime, seckillTimeIndex = res.data.seckillTimeIndex;
  422. // that.setData({
  423. // timeList: timeList,
  424. // seckillCont: res.data.seckillCont,
  425. // killIndex: seckillTimeIndex,
  426. // seckillTimeIndex: seckillTimeIndex,
  427. // killIndexTime: timeList[that.data.killIndex].stop,
  428. // status: timeList[seckillTimeIndex].status
  429. // })
  430. // wxh.time(timeList[that.data.killIndex].stop, that,false);
  431. // that.getSeckillLists();
  432. // }).catch(()=>{
  433. // });
  434. // },
  435. // 页面事件, 不再使用
  436. // setTime: function (e) {
  437. // let index = e.currentTarget.dataset.index;
  438. // this.setData({
  439. // killIndex: index,
  440. // status: that.data.timeList[index].status
  441. // })
  442. // // that.getSeckillLists();
  443. // },
  444. // 不再触发
  445. // getSeckillLists: function () {
  446. // let that = this;
  447. // let timeId = that.data.timeList[that.data.killIndex].id;
  448. // getSeckillList(timeId, {
  449. // page: 1,
  450. // limit: 20
  451. // }).then(res => {
  452. // that.setData({
  453. // seckillList: res.data
  454. // })
  455. // if (this.data.timeList.length) {
  456. // let query = wx.createSelectorQuery().in(this);
  457. // query.select('.timeLen').boundingClientRect(function (res) {
  458. // if (res) {
  459. // that.setData({
  460. // scrollLeft: (that.data.killIndex - 1.8) * res.width
  461. // });
  462. // }
  463. // }).exec();
  464. // if (that.data.killIndex === that.data.seckillTimeIndex) {
  465. // that.setData({
  466. // killIndexLen: res.data.length
  467. // })
  468. // }
  469. // }
  470. // }).catch(() => {});
  471. // },
  472. /** 获取分类列表 */
  473. getCategoryData: function () {
  474. let that = this;
  475. getCategoryList().then(res => {
  476. let cates = res.data.length > 0 ? res.data[0] : {}
  477. that.setData({
  478. prodCates: that._rebuildProdCates(cates)
  479. })
  480. });
  481. },
  482. // 整理 this.data.prodCates
  483. _rebuildProdCates: function (cates) {
  484. cates.children.forEach(cate => {
  485. // 不处理黑洞星球
  486. if (cate.id == CATE_BLACKHOLE_ID) {
  487. return
  488. }
  489. // 增加属性
  490. cate.loading = false
  491. cate.loaded = false
  492. cate.loadTitle = '加载更多'
  493. cate.products = []
  494. cate.page = 1 // 当前第几页
  495. cate.scrollPos = 0 // 上次滚动条位置
  496. cate.aboveShowRowIndex = 0 // 可见区域上部行索引
  497. cate.belowShowRowNum = 0 // 底部隐藏行数
  498. })
  499. return cates;
  500. },
  501. /** 获取优惠券列表 不再触发*/
  502. // getCoupon: function () {
  503. // var that = this;
  504. // getCoupons({
  505. // page: 1,
  506. // limit: 6
  507. // }).then(res => {
  508. // that.setData({
  509. // getCouponList: res.data
  510. // })
  511. // }).catch(err => {
  512. // // app.Tips({
  513. // // title: err
  514. // // });
  515. // });
  516. // },
  517. // 页面回调,不再触发
  518. // receiveCoupon: function (e) {
  519. // if (!app.globalData.isLog) {
  520. // this.setData({
  521. // iShidden: false
  522. // });
  523. // } else {
  524. // var that = this;
  525. // var list = that.data.getCouponList;
  526. // var index = e.currentTarget.dataset.index;
  527. // var id = that.data.getCouponList[index].id;
  528. // getCouponReceive({
  529. // couponId: id
  530. // })
  531. // .then(function () {
  532. // list[index].is_use = true;
  533. // that.setData({
  534. // getCouponList: that.data.getCouponList
  535. // })
  536. // app.Tips({
  537. // title: "领取成功"
  538. // });
  539. // })
  540. // .catch(function (err) {
  541. // // app.Tips({
  542. // // title: err
  543. // // });
  544. // });
  545. // }
  546. // },
  547. /**
  548. * 生命周期函数--监听页面隐藏
  549. */
  550. onHide: function () {
  551. this.setData({
  552. window: false
  553. });
  554. this.data.interval !== null && clearInterval(this.data.interval);
  555. if (this.data.timerNotification != null) {
  556. clearInterval(this.data.timerNotification);
  557. this.setData({
  558. timerNotification: null,
  559. })
  560. }
  561. var _ = this.data.cpnMine && this.data.cpnMine.hide()
  562. },
  563. /**
  564. * 生命周期函数--监听页面卸载
  565. */
  566. onUnload: function () {
  567. this.data.interval !== null && clearInterval(this.data.interval);
  568. },
  569. /**
  570. * 页面相关事件处理函数--监听用户下拉动作
  571. */
  572. onPullDownRefresh: function () {
  573. let tabIndex = this.data.activeTabIndex
  574. if (tabIndex == 0) {
  575. this.getIndexConfig();
  576. } else if (tabIndex == this.data.prodCates.children.length) { // 黑洞星球不处理
  577. } else {
  578. this.get_product_list(tabIndex, true)
  579. }
  580. wx.stopPullDownRefresh();
  581. },
  582. /**
  583. * 页面上拉触底事件的处理函数
  584. */
  585. onReachBottom: function () {
  586. this.get_hot_product();
  587. this.get_product_list(this.data.activeTabIndex);
  588. },
  589. onPageScroll: throttle(function (obj) {
  590. if (this.data.activeTabIndex <= 0 || this.data.activeTabIndex > this.data.prodCates.children.length) {
  591. return
  592. }
  593. let pos = obj[0].scrollTop
  594. let calcPos = pos //- this.data.navPxH
  595. calcPos = calcPos > 0 ? calcPos : 0
  596. let rowNum = Math.floor(calcPos / this.data.rowPxHeight) // 滚动过去的总行数, 也是当前 viewport 的开始索引位置
  597. let clearRowNum = rowNum - this.data.rowCacheNum// 隐藏总行数
  598. let cindex = this.data.activeTabIndex - 1
  599. let tabData = this.data.prodCates.children[cindex]
  600. // console.log('pos:', pos, 'rowPxHeight', this.data.rowPxHeight,
  601. // 'rowNum:', rowNum, 'clearRowNum:', clearRowNum, 'aboveShowRowIndex:', tabData.aboveShowRowIndex)
  602. let changingData = {}
  603. if (pos - tabData.scrollPos > 0) { // 向下
  604. if (clearRowNum > 0) {
  605. // aboveShowRowIndex 索引的行之前都不显示
  606. for (let i = tabData.aboveShowRowIndex; i < clearRowNum; i++) {
  607. let leftIndex = i * 2
  608. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  609. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  610. let belowShowRowIndex = i + 2 * this.data.rowCacheNum
  611. if (belowShowRowIndex < Math.floor(tabData.products.length / 2)) {
  612. leftIndex = belowShowRowIndex * 2
  613. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = true
  614. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = true
  615. }
  616. }
  617. }
  618. } else { // 向上
  619. if (clearRowNum >= 0) {
  620. for (let i = tabData.aboveShowRowIndex - 1; i >= clearRowNum; i--) {
  621. let leftIndex = i * 2
  622. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = true
  623. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = true
  624. let belowShowRowIndex = i + 2 * this.data.rowCacheNum
  625. if (belowShowRowIndex < tabData.products.length / 2) {
  626. leftIndex = belowShowRowIndex * 2
  627. changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  628. changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  629. }
  630. }
  631. } else {
  632. if (tabData.aboveShowRowIndex > 0) {
  633. for (let i = 0; i < tabData.aboveShowRowIndex; i++) {
  634. this.setData({
  635. [`prodCates.children[${cindex}].products[${i * 2}].isShow`]: true,
  636. [`prodCates.children[${cindex}].products[${i * 2 + 1}].isShow`]: true,
  637. })
  638. // changingData[[`prodCates.children[${cindex}].products[${i * 2}].isShow`]] = true
  639. // changingData[[`prodCates.children[${cindex}].products[${i * 2 + 1}].isShow`]] = true
  640. }
  641. }
  642. }
  643. } //
  644. clearRowNum = clearRowNum > 0 ? clearRowNum : 0;
  645. if (clearRowNum >= 0 && !(clearRowNum > 0 && clearRowNum == tabData.aboveShowRowIndex)) {
  646. changingData[[`prodCates.children[${cindex}].aboveShowRowIndex`]] = clearRowNum
  647. let belowShowRowNum = tabData.products.length / 2 - (2 * this.data.rowCacheNum + clearRowNum)
  648. belowShowRowNum = belowShowRowNum > 0 ? belowShowRowNum : 0
  649. // console.log('belowShowRowNum:', belowShowRowNum, 'tabData.products.length:', tabData.products.length, 'clearRowNum:', clearRowNum)
  650. if (belowShowRowNum >= 0) {
  651. changingData[[`prodCates.children[${cindex}].belowShowRowNum`]] = belowShowRowNum
  652. // for (let i = 0; i < belowShowRowNum; i++) {
  653. // let leftIndex = (tabData.products.length / 2 - i - 1) * 2;
  654. // changingData[[`prodCates.children[${cindex}].products[${leftIndex}].isShow`]] = false
  655. // changingData[[`prodCates.children[${cindex}].products[${leftIndex + 1}].isShow`]] = false
  656. // }
  657. }
  658. this.setData(changingData)
  659. }
  660. if (cindex >= 0 && cindex < this.data.prodCates.children.length - 1) {
  661. this.setData({
  662. ['prodCates.children[' + cindex + '].scrollPos']: pos
  663. })
  664. }
  665. // this._debugProducts()
  666. }),
  667. _debugProducts: function () {
  668. let all = [],
  669. display = [],
  670. tabIndex = this.data.activeTabIndex
  671. if (tabIndex <= 0 || tabIndex > this.data.prodCates.children.length) {
  672. return
  673. }
  674. let tabData = this.data.prodCates.children[tabIndex - 1]
  675. for (let i = 0; i < tabData.products.length; i++) {
  676. if (tabData.products[i].isShow) {
  677. display.push(i)
  678. }
  679. all.push(i)
  680. }
  681. console.debug('all:', all)
  682. console.debug('display:', display)
  683. },
  684. /**
  685. * 用户点击右上角分享
  686. */
  687. onShareAppMessage: function () {
  688. }
  689. })
  690. function throttle(fn) {
  691. let valid = true
  692. return function () {
  693. if (!valid) {
  694. return false
  695. }
  696. valid = false
  697. return setTimeout(() => {
  698. fn.call(this, arguments)
  699. valid = true
  700. }, THROTTLE_TIME)
  701. }
  702. }