productDetail.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <!-- 父组件使用 -->
  3. <view :class="['qn-page-' + theme]">
  4. <view v-if="flist.length" style="border-top: 1px solid #F5F5F5;">
  5. <u-tabs inactive-color="rgba(0, 0, 0, 0.5);" height="78" font-size="28" active-color="#000000"
  6. :bar-style="{ height: '4rpx', backgroundColor: primaryColor }" :list="flist" name="title"
  7. :current="tab_current" @change="tabtap"></u-tabs>
  8. </view>
  9. <scroll-view scroll-y class="goods-scroll" :class="[flist.length === 0 ? 'flist-no' : '']"
  10. lower-threshold="100px" @scrolltolower="lower">
  11. <Aempty text="暂无数据" src="https://onlineimg.qianniao.vip/search.png" v-if="shoppingList.length === 0">
  12. </Aempty>
  13. <!-- 循环item出来为对象 -->
  14. <block v-if="shoppingList.length > 0">
  15. <u-waterfall v-model="shoppingList" ref="uWaterfall">
  16. <template v-slot:left="{ leftList }">
  17. <block v-for="(item, index) in leftList" :key="index">
  18. <GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem>
  19. </block>
  20. </template>
  21. <template v-slot:right="{ rightList }">
  22. <block v-for="(item, index) in rightList" :key="index">
  23. <GoodsItem :isList="is_list" :item="item" @addCart="addCard(item.id)"></GoodsItem>
  24. </block>
  25. </template>
  26. </u-waterfall>
  27. </block>
  28. <u-loadmore margin-top="20" v-if="shoppingList.length" :status="loading_status" />
  29. </scroll-view>
  30. <CartFloat />
  31. <AddCardModel @close="is_add_show = false" :isShow="is_add_show" @change="cardModelPopChange"
  32. :goodsId="goods_id" />
  33. </view>
  34. </template>
  35. <script>
  36. import GoodsItem from '@/components/GoodsItem.vue';
  37. import CartFloat from '../components/CartFloat.vue';
  38. import AddCardModel from '@/components/AddCardModel';
  39. export default {
  40. components: {
  41. GoodsItem,
  42. CartFloat,
  43. AddCardModel
  44. },
  45. data() {
  46. return {
  47. tab_current: 0,
  48. is_list: false,
  49. is_add_show: false,
  50. goods_id: 0,
  51. flist: [],
  52. shoppingList: [],
  53. currentId: 1,
  54. cateId: 1,
  55. page: 1,
  56. pageSize: 10,
  57. loading_status: 'loadmore'
  58. };
  59. },
  60. // 下拉刷新
  61. onPullDownRefresh() {
  62. this.getGoodsByCategory();
  63. },
  64. async onLoad(options) {
  65. this.currentId = options.id;
  66. this.cateId = options.id;
  67. await this.getAllCategoryByPidid(this.currentId);
  68. await this.getGoodsByCategory();
  69. uni.setNavigationBarTitle({
  70. title: options.name || ''
  71. });
  72. },
  73. methods: {
  74. // 切换商品列表展示样式
  75. changeStyle() {
  76. this.is_list = !this.is_list;
  77. },
  78. cardModelPopChange(obj) {
  79. if (!obj.show) {
  80. this.is_add_show = false;
  81. }
  82. },
  83. addCard(id) {
  84. this.goods_id = id;
  85. this.is_add_show = true;
  86. },
  87. // 上拉加载
  88. lower() {
  89. if (this.pageTotal / this.pageSize > this.page) {
  90. this.page += 1;
  91. this.getGoodsByCategory();
  92. }
  93. },
  94. // 获取分类列表
  95. async getAllCategoryByPidid(currentId) {
  96. this.$u.api.getAllCategoryByPidid(currentId).then(res => {
  97. this.flist = res.data;
  98. if (this.flist.length) {
  99. this.flist.unshift({
  100. title: '全部',
  101. id: this.currentId
  102. });
  103. }
  104. });
  105. },
  106. // 获取商品列表
  107. getGoodsByCategory() {
  108. this.loading_status = 'loading';
  109. this.$u.api
  110. .getGoodsByCategory({
  111. categoryId: this.currentId,
  112. page: this.page,
  113. pageSize: this.pageSize
  114. })
  115. .then(data => {
  116. uni.stopPullDownRefresh();
  117. if (this.page === 1) {
  118. this.shoppingList = data.data;
  119. } else {
  120. this.shoppingList = this.shoppingList.concat(data.data);
  121. }
  122. this.pageTotal = data.pageTotal;
  123. this.loading_status = this.$_utils.loadStatus(this.page, this.pageSize, this.pageTotal);
  124. });
  125. },
  126. tabtap(current) {
  127. this.tab_current = current;
  128. // 获取的id
  129. this.currentId = this.flist[current].id;
  130. this.page = 1;
  131. // 调用商品详情
  132. this.shoppingList = []
  133. this.getGoodsByCategory();
  134. },
  135. leftList(dev) {
  136. console.log(dev);
  137. },
  138. rightList(dev) {
  139. console.log(dev);
  140. }
  141. }
  142. };
  143. </script>
  144. <style lang="scss" scoped>
  145. .goods-scroll {
  146. padding: 0;
  147. height: calc(100vh - 92rpx);
  148. }
  149. .flist-no {
  150. padding-top: 0;
  151. height: 100vh;
  152. }
  153. </style>