goodList.vue 7.4 KB

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