goodList.vue 6.9 KB

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