goodList.vue 7.0 KB

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