list.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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">{{ 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. <u-loadmore :line="true" v-if="list.length>5" :status="status" :loading-text="'努力加载中'" :nomore-text="'已经到低了'" />
  62. </view>
  63. </view>
  64. <view class="flex empty" v-if="!list.length">
  65. <view class="center">
  66. <image class="center-img" src="https://mp-public-1310078123.cos.ap-shanghai.myqcloud.com/v2/nodata_3.png" mode="scaleToFill"></image>
  67. <view class="center-font">还没有商品</view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. import env from '../../config/env.js'
  74. import $http from '@/utils/request.js'
  75. export default {
  76. data() {
  77. return {
  78. status: 'nomore',//上拉刷新状态
  79. pageNum: 1,
  80. total: 0,
  81. list: [],
  82. title: '',
  83. name: '商品列表',
  84. tagIds: null,
  85. categoryId: null,
  86. choiceIndex: 1,
  87. priceSort: null,
  88. saleSort: null,
  89. priceShow: false
  90. };
  91. },
  92. onLoad(opthios) {
  93. this.title = opthios.title
  94. if(opthios.name) {
  95. this.name = opthios.name
  96. this.tagIds = opthios.tagIds
  97. this.categoryId = Number(opthios.categoryId)
  98. }
  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. if(this.total < this.pageNum * 20) return ;
  160. this.status = 'loading';
  161. // setTimeout(() => {
  162. ++this.pageNum
  163. if(this.total < this.pageNum * 20) this.status = 'nomore';
  164. else this.status = 'loading';
  165. this.getList()
  166. // }, 2000)
  167. },
  168. }
  169. </script>
  170. <style lang="scss" scoped>
  171. // 固定
  172. .fixed-top {
  173. position: fixed;
  174. width: 100%;
  175. background-color: #fff;
  176. padding: 34rpx;
  177. z-index: 100;
  178. box-shadow: 0 5rpx 5rpx #ececec;
  179. // 搜索
  180. &-search {
  181. height: 72rpx;
  182. background: #F7F7F7;
  183. border-radius: 34px;
  184. padding-left: 24rpx;
  185. margin-bottom: 32rpx;
  186. }
  187. // 选择
  188. &-choice {
  189. justify-content: space-around;
  190. &-item {
  191. color: #666;
  192. .icon {
  193. flex-direction: column;
  194. image {
  195. width: 18rpx;
  196. height: 20rpx;
  197. margin-left: 6rpx;
  198. }
  199. }
  200. }
  201. .action {
  202. color: #FA822C;
  203. }
  204. }
  205. }
  206. .none {
  207. height: 240rpx;
  208. }
  209. // 列表
  210. .goods {
  211. padding: 0 34rpx;
  212. &-list {
  213. width: 100%;
  214. justify-content: space-between;
  215. flex-wrap: wrap;
  216. &-item {
  217. flex-direction: column;
  218. justify-content: flex-start;
  219. width: 48%;
  220. padding-bottom: 36rpx;
  221. background: #FFFFFF;
  222. box-shadow: 0px 0px 3px 0px rgba(100, 100, 100, 0.1);
  223. border-radius: 16rpx;
  224. margin-bottom: 32rpx;
  225. .image-wrap {
  226. width: 100%;
  227. height: 320rpx;
  228. margin-bottom: 16rpx;
  229. image {
  230. width: 100%;
  231. height: 100%;
  232. border-radius: 16rpx 16rpx 0 0;
  233. }
  234. }
  235. .content {
  236. width: 100%;
  237. padding: 0 22rpx;
  238. &-title {
  239. height: 28rpx;
  240. font-size: 28rpx;
  241. line-height: 28rpx;
  242. font-weight: bold;
  243. }
  244. &-titletwo {
  245. height: 28rpx;
  246. font-size: 28rpx;
  247. line-height: 32rpx;
  248. font-weight: bold;
  249. white-space: nowrap;
  250. overflow: hidden;
  251. text-overflow: ellipsis;
  252. }
  253. &-coin {
  254. height: 34rpx;
  255. font-size: 24rpx;
  256. justify-content: space-between;
  257. margin-top: 30rpx;
  258. margin-bottom: 24rpx;
  259. &__left {
  260. margin-right: 24rpx;
  261. font-size: 28rpx;
  262. font-weight: bold;
  263. text {
  264. font-weight: normal;
  265. }
  266. image {
  267. width: 34rpx;
  268. height: 34rpx;
  269. }
  270. }
  271. &__right {
  272. color: #666666;
  273. text-decoration: line-through;
  274. }
  275. }
  276. &-price {
  277. font-size: 24rpx;
  278. line-height: 24rpx;
  279. color: #666666;
  280. }
  281. }
  282. }
  283. &-item:last-child {
  284. box-shadow: none;
  285. background: none;
  286. }
  287. }
  288. }
  289. .empty {
  290. height: 50vh;
  291. .center {
  292. text-align: center;
  293. &-img {
  294. width: 228rpx;
  295. height: 320rpx;
  296. }
  297. &-font {
  298. font-size: 30rpx;
  299. font-weight: 400;
  300. color: #999999;
  301. margin-bottom: 250rpx;
  302. }
  303. }
  304. }
  305. </style>