index.js 26 KB

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