goods.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <view class="container all-type-list-wrapper">
  3. <commodity-list ref="childList" :empty-text="emptyText" :serverUrl="serverUrl" :typeId="typeId" v-if="isRequest"></commodity-list>
  4. </view>
  5. </template>
  6. <script>
  7. import commodityList from '@/components/cm-module/listTemplate/commodityList'
  8. export default{
  9. components:{
  10. commodityList
  11. },
  12. data(){
  13. return{
  14. serverUrl: '',
  15. emptyText: '',
  16. lastPageType: '',
  17. lastPageVal: '',
  18. isRequest:false,
  19. typeId:null
  20. }
  21. },
  22. onLoad(option) {
  23. this.setServerUrl(option);
  24. },
  25. methods:{
  26. setServerUrl(option) {
  27. let self = this;
  28. const {type, from: value} = option;
  29. this.lastPageType = type;
  30. this.lastPageVal = value;
  31. uni.setNavigationBarTitle({title:value});
  32. uni.getStorage({
  33. key: 'commodity_id',
  34. success: function (res) {
  35. const emptyTxt = '正在上架中,敬请期待~';
  36. /**
  37. *@商品分类列表传参类型
  38. *@type 首页分类:0,首页商品模块1:1,首页商品模块2:2,首页商品模块3:3,底部导航分类:4
  39. **/
  40. switch(type){
  41. case '0':
  42. console.log(res)
  43. self.typeId = res.data;
  44. self.serverUrl = '/home/classify';
  45. self.emptyText = '该分类暂时还没有商品哟,去逛逛别的吧~';
  46. break;
  47. case '1':
  48. self.typeId = 1;
  49. self.serverUrl = '/search/query/product/preferred';
  50. self.emptyText = `${self.lastPageVal}商品${emptyTxt}`;
  51. break;
  52. case '2':
  53. self.typeId = 10;
  54. self.serverUrl = '/search/query/product/preferred';
  55. self.emptyText = `${self.lastPageVal}商品${emptyTxt}`;
  56. break;
  57. case '3':
  58. self.typeId = 100;
  59. self.serverUrl = '/search/query/product/preferred';
  60. self.emptyText = `${self.lastPageVal}${emptyTxt}`;
  61. break;
  62. case '4':
  63. self.typeId = res.data;
  64. self.serverUrl = '/search/query/product/tinyType';
  65. self.emptyText = '该分类暂时还没有商品哟,去逛逛别的吧~';
  66. break;
  67. }
  68. self.isRequest = true
  69. }
  70. })
  71. }
  72. },
  73. onShow() {
  74. let pages = getCurrentPages(),
  75. thisPage = pages[pages.length - 1];
  76. if(thisPage.refresh) {
  77. this.setServerUrl(thisPage.listData);
  78. }
  79. }
  80. }
  81. </script>
  82. <style lang="scss">
  83. page {
  84. background: $sub-bg-color;
  85. .all-type-list-wrapper {
  86. display: flex;
  87. flex-direction: column;
  88. }
  89. }
  90. </style>