index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. async request () {
  39. try {
  40. let { value: _value } = this.data;
  41. let { page, totalPage, value } = _value;
  42. if (page > totalPage) return false;
  43. let res = await wx.$request({ method: "get", url: "/order/productList/", data: { limit: 10, page } });
  44. ++page;
  45. totalPage = res.totalPage;
  46. value = res.data.map(item => ({ img: item.mail_image, id: item.id, month: item.month, title: item.name, details: item.details_image }));
  47. this.setData({ value: { page, totalPage, value } });
  48. } catch (err) { wx.$err(err) }
  49. },
  50. timer: null,
  51. onLoad: async function (options) {
  52. // 微信小程序生命周期执行 不友好
  53. this.timer = setInterval(() => {
  54. if (app.globalData._initState) {
  55. clearInterval(this.timer);
  56. this.setData({ isLoad: false })
  57. }
  58. }, 100);
  59. this.request();
  60. try {
  61. let resB = await wx.$request({ method: "get", url: "/notices/list/" });
  62. 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 }));
  63. this.setData({ tips: resB.data });
  64. wx.stopPullDownRefresh();
  65. } catch (err) { wx.$err(err) }
  66. },
  67. onReady: function () {
  68. },
  69. onShow: function () {
  70. },
  71. onHide: function () {
  72. },
  73. onUnload: function () {
  74. clearInterval(this.timer);
  75. },
  76. onPullDownRefresh: function () {
  77. this.request();
  78. },
  79. onReachBottom: function () {
  80. },
  81. onShareAppMessage: function () {
  82. }
  83. })