list.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <template>
  2. <view>
  3. <u-navbar title="商品列表" :border="true" :placeholder="true" :autoBack="true" bgColor="#fff" />
  4. <!-- 固定nav -->
  5. <view class="fixed-top">
  6. <!-- 搜索 -->
  7. <view class="fixed-top-search flex">
  8. <u--input v-model="title" @blur="pageList()" placeholder="请输入商品名称" border="none" prefixIcon="search" prefixIconStyle="font-size: 22px;color: #909399" />
  9. </view>
  10. <!-- 选择 -->
  11. <view class="fixed-top-choice flex">
  12. <view class="fixed-top-choice-item" :class="{ 'action': choiceIndex == 1 }" @click="changeChice(1)">
  13. <text>综合</text>
  14. </view>
  15. <view class="fixed-top-choice-item" :class="{ 'action': choiceIndex == 2 }" @click="changeChice(2)">
  16. <text>销量</text>
  17. </view>
  18. <view class="fixed-top-choice-item flex" :class="{ 'action': choiceIndex == 3 }" @click="changeChice(3)">
  19. <text>价格</text>
  20. <view class="icon flex" v-if="choiceIndex == 3">
  21. <image src="../static/list_up.png" mode="" v-if="priceShow" />
  22. <image src="../static/list_down.png" mode="" v-else />
  23. </view>
  24. <view class="icon flex" v-else>
  25. <image src="../static/list_null.png" mode="" />
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="none"></view>
  31. <!-- 列表 -->
  32. <view class="goods">
  33. <view class="goods-list flex">
  34. <view class="goods-list-item flex" v-for="(item, index) in list" :key="index" @click="toGoodsDetail(item)">
  35. <view class="image-wrap flex">
  36. <image :src="item.picUrl" mode="aspectFit"></image>
  37. </view>
  38. <view class="content">
  39. <view class="content-title ells-one">{{ item.title }}</view>
  40. <view class="content-coin flex">
  41. <view class="content-coin__left flex">
  42. <image src="../../static/public/goods_coin.png" mode=""></image>
  43. <view class="num">×{{ item.exchangePrice }}</view>
  44. </view>
  45. <view class="content-coin__right" v-if="item.originPrice">原价:{{ item.originPrice }}</view>
  46. </view>
  47. <view class="content-price">¥{{ $numberFormat(item.value) }}</view>
  48. </view>
  49. </view>
  50. <view class="goods-list-item"></view>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script>
  56. import env from '../../config/env.js'
  57. import $http from '@/utils/request.js'
  58. export default {
  59. data() {
  60. return {
  61. pageNum: 1,
  62. total: 0,
  63. list: [],
  64. title: '',
  65. choiceIndex: 1,
  66. priceSort: null,
  67. saleSort: null,
  68. priceShow: false
  69. };
  70. },
  71. onLoad(opthios) {
  72. console.log(opthios);
  73. this.title = opthios.title
  74. },
  75. onShow() {
  76. this.pageList()
  77. },
  78. methods: {
  79. pageList() {
  80. this.pageNum = 1
  81. this.total = 0
  82. this.list = []
  83. this.getList()
  84. },
  85. // 商品列表
  86. getList() {
  87. uni.showLoading({
  88. title: '加载中'
  89. });
  90. let data = {
  91. goodsName: this.title,
  92. priceSort: this.priceSort,
  93. saleSort: this.saleSort,
  94. noToken: true
  95. }
  96. $http.post(`/api/v1/mp/user/exchange/goods/list?pageNum=${this.pageNum}&pageSize=20`,data).then(
  97. res => {
  98. uni.hideLoading();
  99. if (res.code == 0) {
  100. console.log("res: ",res);
  101. res.rows.forEach(item => {
  102. item.picUrl = env.filePublic + item.picUrl.split(',')[0] + '?imageView2/2/w/340'
  103. })
  104. this.total = res.total
  105. this.list = this.list.concat(res.rows)
  106. }
  107. }).catch(() => {
  108. uni.hideLoading();
  109. })
  110. },
  111. // 商品详情
  112. toGoodsDetail(item) {
  113. uni.navigateTo({
  114. url: `/packageGoods/goods/detail?id=${ item.goodsId }`
  115. })
  116. },
  117. // 筛选
  118. changeChice(num) {
  119. this.choiceIndex = num
  120. if(num == 1) {
  121. this.priceSort = null
  122. this.saleSort = null
  123. } else if (num == 2) {
  124. this.saleSort = 2
  125. this.priceSort = null
  126. } else if (num == 3) {
  127. this.saleSort = null
  128. this.priceShow = !this.priceShow
  129. this.priceSort = this.priceShow ? 1 : 2
  130. }
  131. this.pageList()
  132. },
  133. },
  134. onReachBottom() {
  135. // 判断是否有数据
  136. if (this.total > this.pageNum * 20) {
  137. setTimeout(() => {
  138. ++this.pageNum
  139. this.getList()
  140. }, 500)
  141. } else {
  142. uni.$u.toast('已经到底了')
  143. }
  144. },
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. // 固定
  149. .fixed-top {
  150. position: fixed;
  151. width: 100%;
  152. background-color: #fff;
  153. padding: 34rpx;
  154. z-index: 100;
  155. box-shadow: 0 5rpx 5rpx #ececec;
  156. // 搜索
  157. &-search {
  158. height: 72rpx;
  159. background: #F7F7F7;
  160. border-radius: 34px;
  161. padding-left: 24rpx;
  162. margin-bottom: 32rpx;
  163. }
  164. // 选择
  165. &-choice {
  166. justify-content: space-around;
  167. &-item {
  168. color: #666;
  169. .icon {
  170. flex-direction: column;
  171. image {
  172. width: 18rpx;
  173. height: 20rpx;
  174. margin-left: 6rpx;
  175. }
  176. }
  177. }
  178. .action {
  179. color: #FA822C;
  180. }
  181. }
  182. }
  183. .none {
  184. height: 240rpx;
  185. }
  186. // 列表
  187. .goods {
  188. padding: 0 34rpx;
  189. &-list {
  190. width: 100%;
  191. justify-content: space-between;
  192. flex-wrap: wrap;
  193. &-item {
  194. flex-direction: column;
  195. justify-content: flex-start;
  196. width: 48%;
  197. padding-bottom: 36rpx;
  198. background: #FFFFFF;
  199. box-shadow: 0px 0px 3px 0px rgba(100, 100, 100, 0.1);
  200. border-radius: 16rpx;
  201. margin-bottom: 30rpx;
  202. .image-wrap {
  203. width: 100%;
  204. height: 320rpx;
  205. margin-bottom: 18rpx;
  206. image {
  207. width: 100%;
  208. height: 100%;
  209. border-radius: 16rpx 16rpx 0 0;
  210. }
  211. }
  212. .content {
  213. width: 100%;
  214. padding: 0 22rpx;
  215. &-title {
  216. height: 28rpx;
  217. font-size: 28rpx;
  218. line-height: 28rpx;
  219. font-weight: bold;
  220. margin-bottom: 40rpx;
  221. }
  222. &-coin {
  223. height: 30rpx;
  224. font-size: 24rpx;
  225. justify-content: flex-start;
  226. margin-bottom: 34rpx;
  227. &__left {
  228. margin-right: 24rpx;
  229. image {
  230. width: 34rpx;
  231. height: 30rpx;
  232. }
  233. }
  234. &__right {
  235. color: #666666;
  236. text-decoration: line-through;
  237. }
  238. }
  239. &-price {
  240. font-size: 24rpx;
  241. color: #666666;
  242. }
  243. }
  244. }
  245. &-item:last-child {
  246. box-shadow: none;
  247. background: none;
  248. }
  249. }
  250. }
  251. </style>