list.vue 7.4 KB

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