goodList.vue 8.1 KB

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