goodList.vue 9.0 KB

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