list.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <!-- #ifdef H5 -->
  3. <zj-page-layout
  4. :hasFooter="false"
  5. :isScroll="true"
  6. :refresherTriggered="refresherTriggered"
  7. @refresherrefresh="refresherrefresh"
  8. @scrolltolower="scrolltolower">
  9. <template slot="header">
  10. <view class="header-container">
  11. <u-tabs
  12. :list="categoryList"
  13. :current="categoryCurrent"
  14. @click="clickCategory"
  15. keyName="categoryName"
  16. :scrollable="categoryList.length === 4 ? false : true"
  17. lineColor="#01C30B">
  18. </u-tabs>
  19. <u-search
  20. placeholder="输入商品名称搜索"
  21. :showAction="false"
  22. clearabled
  23. v-model="keyword"
  24. @search="refreshList"
  25. @clear="refreshList">
  26. </u-search>
  27. <u-tabs
  28. :list="tabList"
  29. :current="tabCurrent"
  30. @click="clickTab"
  31. :scrollable="false"
  32. lineColor="#01C30B">
  33. </u-tabs>
  34. </view>
  35. </template>
  36. <view class="common-goods-list">
  37. <view class="item" v-for="(item, index) in dataList" :key="index" @tap="toGoodsDetail(item.id)">
  38. <view class="top">
  39. <image src="@/static/common/logo.png"></image>
  40. <view class="user">
  41. <view class="name">{{item.userName}}</view>
  42. <view class="time">{{item.createTime}}</view>
  43. </view>
  44. <view class="price">{{item.amount | priceFilter2}}</view>
  45. </view>
  46. <view class="title">{{item.title}}</view>
  47. <view class="des">{{item.content}}</view>
  48. <view class="imgs">
  49. <image :src="imgUrl + it.imgUrl" v-for="(it, idx) in item.goodsFiles" :key="idx"></image>
  50. </view>
  51. <view class="bottom">
  52. <view class="left-location"><text class="iconfont icon-dingwei"></text>{{item.address}}</view>
  53. <view class="right-stats">
  54. <view class="it">
  55. <text class="iconfont icon-dianzan"></text>
  56. <text class="text">2</text>
  57. </view>
  58. <view class="it">
  59. <text class="iconfont icon-pinglun"></text>
  60. <text class="text">2</text>
  61. </view>
  62. <view class="it">
  63. <text class="iconfont icon-liulan"></text>
  64. <text class="text">2</text>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. <Loading :loadStatus="loadStatus" :dataList="dataList" />
  71. </zj-page-layout>
  72. <!-- #endif -->
  73. <!-- #ifndef H5 -->
  74. <web-view :src="webViewHref('/pages/goods/list')"></web-view>
  75. <!-- #endif -->
  76. </template>
  77. <script>
  78. // #ifdef H5
  79. export default {
  80. data() {
  81. return {
  82. imgUrl: this.$imageUrl,
  83. categoryList: [],
  84. categoryId: '',
  85. tabList: [
  86. {name: '默认顺序', value: 0},
  87. {name: '在售商品', value: 1},
  88. {name: '离我最近', value: 2},
  89. {name: '人气最高', value: 3},
  90. ],
  91. tabCurrent: 0,
  92. keyword: '',
  93. dataList: [],
  94. pageNum: 1,
  95. loadStatus: 0,
  96. refresherTriggered: false,
  97. }
  98. },
  99. computed:{
  100. categoryCurrent() {
  101. if(this.categoryId) {
  102. return this.categoryList.map(item => item.categoryId).indexOf(this.categoryId)
  103. }else {
  104. return 0
  105. }
  106. }
  107. },
  108. async onLoad({categoryId, keyword}) {
  109. console.log(categoryId);
  110. console.log(keyword);
  111. this.categoryId = categoryId;
  112. this.keyword = keyword;
  113. await this.getCategory();
  114. await this.getList();
  115. },
  116. methods: {
  117. async getCategory() {
  118. return new Promise((resolve, reject) => {
  119. this.$api.get('/goods/category/list')
  120. .then(res => {
  121. this.categoryList = res.data || [];
  122. }).finally(res => {
  123. resolve(1);
  124. })
  125. })
  126. },
  127. //获取列表数据
  128. async getList() {
  129. let params = {};
  130. if(this.tabCurrent === 1) {
  131. params.status = '1';
  132. }else if(this.tabCurrent === 2) {
  133. params.lng = this.lng;
  134. params.lat = this.lat;
  135. }else if(this.tabCurrent === 3) {
  136. params.visitOrderBy = 'YES';
  137. }
  138. this.$api.get('/goods/list', {
  139. pageNum: this.pageNum,
  140. pageSize: 10,
  141. categoryId: this.categoryId,
  142. title: this.keyword,
  143. ...params
  144. }).then(res => {
  145. this.loadStatus = 0;
  146. let list = res.data.records;
  147. if (list.length < 10) {
  148. this.loadStatus = 2;
  149. }
  150. this.dataList = this.dataList.concat(list);
  151. }).catch(() => {
  152. this.loadStatus = 2;
  153. })
  154. },
  155. clickCategory(item) {
  156. this.categoryId = item.categoryId;
  157. this.refreshList();
  158. },
  159. clickTab(item) {
  160. this.tabCurrent = item.value;
  161. this.refreshList();
  162. },
  163. // 滚动到底部
  164. scrolltolower(e) {
  165. if (this.loadStatus === 0) {
  166. this.pageNum++;
  167. this.getList();
  168. }
  169. },
  170. // 触发下拉刷新
  171. async refresherrefresh(e) {
  172. this.refresherTriggered = true;
  173. // await this.getCategory();
  174. this.refreshList();
  175. this.refresherTriggered = false;
  176. },
  177. refreshList() {
  178. this.dataList = [];
  179. this.pageNum = 1;
  180. this.getList();
  181. },
  182. toGoodsDetail(id) {
  183. this.$navToPage({
  184. url: `/pages/goods/detail?${id}`
  185. })
  186. },
  187. }
  188. }
  189. // #endif
  190. // #ifndef H5
  191. // #endif
  192. </script>
  193. <style lang="scss" scoped>
  194. .header-container {
  195. background: #ffffff;
  196. padding: 0 30rpx;
  197. ::v-deep .u-search {
  198. margin-top: 20rpx !important;
  199. }
  200. }
  201. .common-goods-list {
  202. padding: 0 30rpx;
  203. .item {
  204. @include zj-card;
  205. }
  206. }
  207. </style>