goodList.vue 5.9 KB

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