list.vue 7.0 KB

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