index.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. var app = getApp();
  2. Component({
  3. properties: {
  4. value: {
  5. type: Object,
  6. value: {}
  7. },
  8. idx: {
  9. type: Number,
  10. value: 0
  11. }
  12. },
  13. data: {
  14. // list: [],
  15. _lock: false,
  16. current: 0
  17. },
  18. attached: function() {
  19. this.setData({_lock: true },()=>{
  20. this.getGoodsList();
  21. })
  22. },
  23. pageLifetimes: {
  24. show: function () {
  25. this.data._lock || this.getGoodsList();
  26. }
  27. },
  28. methods: {
  29. getGoodsList() {
  30. var token = wx.getStorageSync('token');
  31. var that = this;
  32. var cur_community = wx.getStorageSync('community');
  33. let { current, value } = this.data;
  34. let vlist = value.list;
  35. let sources = vlist[current].sources;
  36. let params = {};
  37. if(sources=='category') {
  38. params.gid = vlist[current].categoryId;
  39. params.is_random = 0;
  40. } else {
  41. params.is_random = 1;
  42. }
  43. app.util.request({
  44. url: 'entry/wxapp/index',
  45. data: {
  46. controller: 'index.load_gps_goodslist',
  47. token,
  48. pageNum: 1,
  49. head_id: cur_community.communityId || '',
  50. per_page: 20 || value.goodsCount,
  51. ...params
  52. },
  53. dataType: 'json',
  54. success: function (res) {
  55. console.log('many_goods_list')
  56. that.setData({ _lock: false })
  57. that.triggerEvent('diyGoodsList', { id: that.data.idx, data: res.data });
  58. }
  59. })
  60. },
  61. changeCate(e) {
  62. let idx = e.currentTarget.dataset.idx;
  63. this.setData({
  64. current: idx
  65. },()=>{
  66. this.getGoodsList();
  67. })
  68. }
  69. }
  70. })