list.vue 7.4 KB

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