goodList.vue 8.4 KB

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