goodList.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" :defaultText="goodName" clearButton="auto" cancelButton="none"
  5. bgColor="#ffffff" @confirm="search" class="search-bar" />
  6. </view>
  7. <k-scroll-view @onPullDown="handlePullDown" @onPullUp="handleLoadMore" class="goods-box">
  8. <view class="goods-row" v-for="item in goodsList" @click="goToGoodDetails(item)">
  9. <cover-image class="goods-img" :src="item.imgPath"></cover-image>
  10. <view class="goods-info">
  11. <view class="goods-name">{{item.productName}}</view>
  12. <view class="goods-details">{{item.details}}</view>
  13. <view class="goods-number">
  14. <text class="goods-icon">¥</text>
  15. <text class="goods-spec">{{item.bizPrice}}/{{item.spec}}</text>
  16. <text class="goods-sales">{{item.sellCount}}人付款</text>
  17. </view>
  18. </view>
  19. <view class="goods-cart">
  20. <view class="cart-button">
  21. <view class="iconfont icongouwuche"></view>
  22. </view>
  23. </view>
  24. </view>
  25. </k-scroll-view>
  26. </view>
  27. </template>
  28. <script>
  29. const NET = require('@/utils/request')
  30. const API = require('@/config/api')
  31. export default {
  32. data() {
  33. return {
  34. goodType: '',
  35. pageIndex: 1,
  36. isOver: false,
  37. goodName: '',
  38. goodsList: [],
  39. }
  40. },
  41. onLoad(options) {
  42. this.goodName = options.goodName ? options.goodName : ''
  43. this.goodType = options.goodType
  44. switch (this.goodType) {
  45. case 0:
  46. break;
  47. default:
  48. }
  49. uni.setNavigationBarTitle({
  50. title: this.goodType == 0 ? '商品列表' : (this.goodType == 1 ? '自助采摘' : (this.goodType == 2 ? '共享种植' : '拍卖'))
  51. });
  52. this.getGoodsList()
  53. },
  54. onReady(options) {
  55. if (this.goodName) {
  56. this.$refs.searchBar.show = true
  57. this.$refs.searchBar.showSync = true
  58. this.$refs.searchBar.searchVal = this.goodName
  59. }
  60. },
  61. methods: {
  62. // 搜索商品
  63. search(data) {
  64. this.goodName = data.value
  65. this.goodsList = []
  66. this.pageIndex = 1
  67. this.getGoodsList()
  68. },
  69. // 下拉刷新
  70. handlePullDown(stopLoad) {
  71. this.pageIndex = 1
  72. this.goodsList = []
  73. this.getGoodsList(stopLoad)
  74. stopLoad ? stopLoad() : '';
  75. },
  76. // 懒加载
  77. handleLoadMore(stopLoad) {
  78. if (!this.isOver) {
  79. this.pageIndex++
  80. this.getGoodsList()
  81. } else {
  82. stopLoad ? stopLoad({
  83. isEnd: true
  84. }) : '';
  85. }
  86. },
  87. // 获取商品
  88. getGoodsList(stopLoad) {
  89. NET.request(API.getGoodsBySort, {
  90. name: this.goodName,
  91. oneId: '',
  92. twoId: '',
  93. pageIndex: this.pageIndex,
  94. pageSize: 10,
  95. }, 'POST').then(res => {
  96. if (res.code == 0) {
  97. this.isOver = res.data.list.length != 10
  98. this.goodsList = this.goodsList.concat(res.data.list)
  99. } else {
  100. uni.showToast({
  101. title: "获取商品列表失败",
  102. icon: "none"
  103. })
  104. }
  105. }).catch(res => {})
  106. },
  107. // 跳转商品详情
  108. goToGoodDetails(item) {
  109. uni.navigateTo({
  110. url: '/pagesGood/goodDetails?goodId=' + item.productId
  111. });
  112. }
  113. },
  114. }
  115. </script>
  116. <style lang="less" scoped>
  117. page {
  118. width: 100%;
  119. height: 100%;
  120. }
  121. .container {
  122. width: 100%;
  123. height: 100%;
  124. background-color: #f7f7f7;
  125. .search-box {
  126. width: 100%;
  127. height: 58px;
  128. box-sizing: border-box;
  129. padding: 2px 12px 1px 12px;
  130. /deep/.uni-searchbar {
  131. background-color: #f7f7f7;
  132. }
  133. }
  134. .goods-box {
  135. width: 100%;
  136. height: calc(100% - 58px) !important;
  137. padding: 6px 0 0px 0;
  138. box-sizing: border-box;
  139. overflow-y: auto;
  140. .goods-row {
  141. width: calc(100% - 24px);
  142. height: 104px;
  143. padding: 11px 11px 11px 7px;
  144. box-sizing: border-box;
  145. margin: 4px 0 12px 12px;
  146. background: #FFFFFF;
  147. box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
  148. border-radius: 15px;
  149. .goods-img {
  150. width: 84px;
  151. height: 84px;
  152. float: left;
  153. }
  154. .goods-info {
  155. width: calc(100% - 108px);
  156. height: 84px;
  157. float: left;
  158. .goods-name {
  159. height: 18px;
  160. font-size: 15px;
  161. font-family: PingFang SC;
  162. color: #333333;
  163. line-height: 18px;
  164. white-space: nowrap;
  165. text-overflow: ellipsis;
  166. overflow: hidden;
  167. }
  168. .goods-details {
  169. height: 28px;
  170. font-size: 12px;
  171. font-family: PingFang SC;
  172. color: #999999;
  173. line-height: 14px;
  174. overflow: hidden;
  175. text-overflow: ellipsis;
  176. display: -webkit-box;
  177. -webkit-line-clamp: 2;
  178. -webkit-box-orient: vertical;
  179. word-wrap: break-word;
  180. margin: 4px 0 12px 0;
  181. }
  182. .goods-number {
  183. height: 16px;
  184. font-family: PingFang SC;
  185. line-height: 16px;
  186. .goods-icon {
  187. font-size: 12px;
  188. color: #52A63A;
  189. }
  190. .goods-spec {
  191. font-size: 15px;
  192. color: #52A63A;
  193. margin-right: 15px;
  194. }
  195. .goods-sales {
  196. font-size: 12px;
  197. color: #999999;
  198. }
  199. }
  200. }
  201. .goods-cart {
  202. width: 24px;
  203. height: 84px;
  204. float: left;
  205. .cart-button {
  206. width: 24px;
  207. height: 24px;
  208. margin-top: 30px;
  209. background-color: #52A63A;
  210. border-radius: 50%;
  211. text-align: center;
  212. .iconfont {
  213. color: #FFFFFF;
  214. font-size: 18px;
  215. line-height: 24px;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. </style>