list.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view>
  3. <u-navbar :title="name" :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 class="flex empty" v-if="!list.length && !loading">
  54. <u-empty text="暂无商品" mode="order" />
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import env from '../../config/env.js'
  60. import $http from '@/utils/request.js'
  61. export default {
  62. data() {
  63. return {
  64. pageNum: 1,
  65. total: 0,
  66. list: [],
  67. title: '',
  68. name: '商品列表',
  69. tagIds: null,
  70. categoryId: null,
  71. choiceIndex: 1,
  72. priceSort: null,
  73. saleSort: null,
  74. priceShow: false
  75. };
  76. },
  77. onLoad(opthios) {
  78. this.title = opthios.title
  79. if(opthios.name) {
  80. this.name = opthios.name
  81. this.tagIds = opthios.tagIds
  82. this.categoryId = opthios.categoryId
  83. }
  84. },
  85. onShow() {
  86. this.pageList()
  87. },
  88. methods: {
  89. pageList() {
  90. this.pageNum = 1
  91. this.total = 0
  92. this.list = []
  93. this.getList()
  94. },
  95. // 商品列表
  96. getList() {
  97. uni.showLoading({
  98. title: '加载中'
  99. });
  100. let data = {
  101. goodsName: this.title,
  102. priceSort: this.priceSort,
  103. saleSort: this.saleSort,
  104. tagIds: this.tagIds,
  105. categoryId: this.categoryId,
  106. noToken: true
  107. }
  108. $http.post(`/api/v1/mp/user/exchange/goods/list?pageNum=${this.pageNum}&pageSize=20`,data).then(
  109. res => {
  110. uni.hideLoading();
  111. if (res.code == 0) {
  112. res.rows.forEach(item => {
  113. item.picUrl = env.filePublic + item.picUrl.split(',')[0] + '?imageView2/2/w/340'
  114. })
  115. this.total = res.total
  116. this.list = this.list.concat(res.rows)
  117. }
  118. }).catch(() => {
  119. uni.hideLoading();
  120. })
  121. },
  122. // 商品详情
  123. toGoodsDetail(item) {
  124. uni.navigateTo({
  125. url: `/packageGoods/goods/detail?id=${ item.goodsId }`
  126. })
  127. },
  128. // 筛选
  129. changeChice(num) {
  130. this.choiceIndex = num
  131. if(num == 1) {
  132. this.priceSort = null
  133. this.saleSort = null
  134. } else if (num == 2) {
  135. this.saleSort = 2
  136. this.priceSort = null
  137. } else if (num == 3) {
  138. this.saleSort = null
  139. this.priceShow = !this.priceShow
  140. this.priceSort = this.priceShow ? 1 : 2
  141. }
  142. this.pageList()
  143. },
  144. },
  145. onReachBottom() {
  146. // 判断是否有数据
  147. if (this.total > this.pageNum * 20) {
  148. setTimeout(() => {
  149. ++this.pageNum
  150. this.getList()
  151. }, 500)
  152. } else {
  153. uni.$u.toast('已经到底了')
  154. }
  155. },
  156. }
  157. </script>
  158. <style lang="scss" scoped>
  159. // 固定
  160. .fixed-top {
  161. position: fixed;
  162. width: 100%;
  163. background-color: #fff;
  164. padding: 34rpx;
  165. z-index: 100;
  166. box-shadow: 0 5rpx 5rpx #ececec;
  167. // 搜索
  168. &-search {
  169. height: 72rpx;
  170. background: #F7F7F7;
  171. border-radius: 34px;
  172. padding-left: 24rpx;
  173. margin-bottom: 32rpx;
  174. }
  175. // 选择
  176. &-choice {
  177. justify-content: space-around;
  178. &-item {
  179. color: #666;
  180. .icon {
  181. flex-direction: column;
  182. image {
  183. width: 18rpx;
  184. height: 20rpx;
  185. margin-left: 6rpx;
  186. }
  187. }
  188. }
  189. .action {
  190. color: #FA822C;
  191. }
  192. }
  193. }
  194. .none {
  195. height: 240rpx;
  196. }
  197. // 列表
  198. .goods {
  199. padding: 0 34rpx;
  200. &-list {
  201. width: 100%;
  202. justify-content: space-between;
  203. flex-wrap: wrap;
  204. &-item {
  205. flex-direction: column;
  206. justify-content: flex-start;
  207. width: 48%;
  208. padding-bottom: 36rpx;
  209. background: #FFFFFF;
  210. box-shadow: 0px 0px 3px 0px rgba(100, 100, 100, 0.1);
  211. border-radius: 16rpx;
  212. margin-bottom: 30rpx;
  213. .image-wrap {
  214. width: 100%;
  215. height: 320rpx;
  216. margin-bottom: 18rpx;
  217. image {
  218. width: 100%;
  219. height: 100%;
  220. border-radius: 16rpx 16rpx 0 0;
  221. }
  222. }
  223. .content {
  224. width: 100%;
  225. padding: 0 22rpx;
  226. &-title {
  227. height: 28rpx;
  228. font-size: 28rpx;
  229. line-height: 28rpx;
  230. font-weight: bold;
  231. margin-bottom: 40rpx;
  232. }
  233. &-coin {
  234. height: 30rpx;
  235. font-size: 24rpx;
  236. justify-content: flex-start;
  237. margin-bottom: 34rpx;
  238. &__left {
  239. margin-right: 24rpx;
  240. image {
  241. width: 34rpx;
  242. height: 30rpx;
  243. }
  244. }
  245. &__right {
  246. color: #666666;
  247. text-decoration: line-through;
  248. }
  249. }
  250. &-price {
  251. font-size: 24rpx;
  252. color: #666666;
  253. }
  254. }
  255. }
  256. &-item:last-child {
  257. box-shadow: none;
  258. background: none;
  259. }
  260. }
  261. }
  262. .empty {
  263. height: 50vh;
  264. }
  265. </style>