list.vue 7.1 KB

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