list.vue 6.9 KB

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