index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { tabberFunc } from "../../utils/util";
  2. const app = getApp();
  3. Page({
  4. data: {
  5. isLoad: true,
  6. loadProgress: 100,
  7. CustomBar: app.globalData.CustomBar,
  8. // 通知栏
  9. tips: [
  10. // { key: 1, value: "一二三111122221112211222111222111122221112211222111222" },
  11. ],
  12. // 商品
  13. value: {
  14. page: 1,
  15. totalPage: 1,
  16. value: [
  17. // { img: "https://ossweb-img.qq.com/images/lol/web201310/skin/big10006.jpg", title: "钢铁之翼", detail: "Only the guilty need fear me." },
  18. ]
  19. }
  20. },
  21. // 跳转详情页
  22. onClickFunc (e) {
  23. let { index } = e.currentTarget.dataset, { value } = this.data;
  24. wx.navigateTo({ url: "/pages/detail/index?data=" + JSON.stringify(value['value'][index]) });
  25. },
  26. // tabber
  27. NavChange (e) {
  28. if (this.data.isLoad) return false;
  29. let { active, path } = e.currentTarget.dataset;
  30. tabberFunc(active, path)
  31. },
  32. // 通知栏
  33. tipsFunc (e) {
  34. let { index } = e.currentTarget.dataset, { tips } = this.data;
  35. console.log(tips[index])
  36. },
  37. // 请求
  38. request_lock: false,
  39. async request () {
  40. try {
  41. let { value: _value } = this.data;
  42. let { page, totalPage, value } = _value;
  43. if (page > totalPage || this.request_lock) return false;
  44. this.request_lock = true;
  45. let res = await wx.$request({ method: "get", url: "/order/productList/", data: { limit: 10, page } });
  46. ++page;
  47. totalPage = res.totalPage;
  48. value = res.data.map(item => ({ img: item.mail_image, id: item.id, month: item.month, title: item.name, details: item.details_image }));
  49. this.setData({ value: { page, totalPage, value } });
  50. this.request_lock = false;
  51. } catch (err) { wx.$err(err); this.request_lock = false; }
  52. },
  53. timer: null,
  54. onLoad: async function (options) {
  55. // 微信小程序生命周期执行 不友好
  56. this.timer = setInterval(() => {
  57. if (app.globalData._initState) {
  58. clearInterval(this.timer);
  59. this.setData({ isLoad: false })
  60. }
  61. }, 100);
  62. this.request();
  63. try {
  64. let resB = await wx.$request({ method: "get", url: "/notices/list/" });
  65. resB.data = resB.data.map(item => ({ key: item.id, value: item.title, detail: item.content, create_time: item.create_time, create_user: item.create_user }));
  66. this.setData({ tips: resB.data });
  67. } catch (err) { wx.$err(err) }
  68. },
  69. onReady: function () {
  70. },
  71. onShow: function () {
  72. },
  73. onHide: function () {
  74. },
  75. onUnload: function () {
  76. clearInterval(this.timer);
  77. },
  78. onPullDownRefresh: function () {
  79. },
  80. onReachBottom: function () {
  81. this.request();
  82. },
  83. onShareAppMessage: function () {
  84. }
  85. })