goodList.vue 6.8 KB

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