index.js 2.7 KB

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