productList.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. <template>
  2. <view class="container commodity-list-wrapper" :style="{'overflow':(showSkeleton? 'hidden' : 'auto'),'height': (showSkeleton? windowHeight + 'px' : 'auto')}">
  3. <list-skeleton v-if="showSkeleton" :listType='0'></list-skeleton>
  4. <view class="product-container" v-if="!isShowEmpty">
  5. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="scrolltolower" scroll-y v-if="productList.length > 0">
  6. <view v-for="(item,index) in productList" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  7. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  8. <view class="list-details-info">
  9. <text class="list-details-title">{{item.name}}</text>
  10. <text class="list-details-specs">规格:{{item.unit}}</text>
  11. <text class="list-details-miniQuantity">起订量:{{ item.ladderPriceFlag == '1' ? item.maxBuyNumber : item.minBuyNumber}}</text>
  12. <view class="list-details-price" v-if="item.price1TextFlag == 1">
  13. <view class="list-none">
  14. <view class="price-small">未公开价格</view>
  15. </view>
  16. </view>
  17. <view class="list-details-price" v-else>
  18. <view class="list-shop">
  19. <view class="list-price" >
  20. <text class="price-view activity" v-if="item.isShowActFlg">活动价</text>
  21. <text class="price-view ladder" v-if="item.ladderPriceFlag == '1'">阶梯价</text>
  22. <text class="price-larger">¥{{item.retailPrice.toFixed(2)}}</text>
  23. </view>
  24. <view class="list-price-none" v-if="item.repurchasePriceState">
  25. <text class="price-none">¥{{item.discountPrice}}</text>
  26. <text class="iconfont icon-wenhao" @click.stop="repurchModel"></text>
  27. </view>
  28. </view>
  29. <button class="add-cart-btn" @click.stop="operationHanld(item)">数量</button>
  30. </view>
  31. </view>
  32. </view>
  33. <button class="show-more-btn" v-if="showRegularBtn" @click="getListFromServer(true)">查看更多</button>
  34. <view v-if="showLoading && productList.length > 4 && !showRegularBtn">
  35. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  36. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  37. </view>
  38. </scroll-view>
  39. </view>
  40. <view class="empty-container" v-else>
  41. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AWdWzAAGlgAP0das422.png" mode="aspectFit"></image>
  42. <text class="error-text">您还没有购买过任何商品哟~</text>
  43. <button class="submit-btn toIndexPage" @click="toIndexPage">去逛逛</button>
  44. </view>
  45. <!-- 可拖动悬浮按钮 -->
  46. <cm-drag v-if="!isShowEmpty"
  47. :cartNum="cartQuantity"
  48. :isDock="true"
  49. :existTabBar="true"
  50. @btnClick="btnClick"
  51. @btnTouchstart="btnTouchstart"
  52. @btnTouchend="btnTouchend">
  53. </cm-drag>
  54. <!-- 透明模态层 -->
  55. <modal-layer v-if='isModallayer'></modal-layer>
  56. </view>
  57. </template>
  58. <script>
  59. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  60. import modalLayer from "@/components/modal-layer"
  61. import uniStars from '@/components/uni-stars/uni-stars.vue'
  62. import cmDrag from '@/components/cm-custom/cm-drag.vue'
  63. import { queryAgaingoodslist } from "@/api/product.js"
  64. import { mapState,mapMutations } from 'vuex';
  65. export default{
  66. name:'productList',
  67. components:{
  68. listSkeleton,
  69. modalLayer,
  70. uniStars,
  71. cmDrag
  72. },
  73. props: {
  74. emptyText: {
  75. type: String
  76. },
  77. },
  78. data(){
  79. return{
  80. isModallayer:false,
  81. windowHeight: '',
  82. showSkeleton: true,
  83. isShowEmpty: false,
  84. userID: '',
  85. scrollHeight: '',
  86. productList: [],
  87. showLoading: false,
  88. loadingNow: true,
  89. loadingText: '上拉加载更多',
  90. pageSize: 10,
  91. pageNum: 1,
  92. hasNextPage: false,
  93. pullFlag: true,
  94. fromRegularPurchasePage: false,
  95. cartQuantity: 0,
  96. showRegularBtn: false,
  97. isPrecedence:false
  98. }
  99. },
  100. created() {
  101. this.setScrollHeight();
  102. this.$api.getStorage().then((resolve) =>{
  103. this.userID = resolve.userID
  104. this.getProductAgainInfo()
  105. })
  106. },
  107. computed: {
  108. ...mapState(['hasLogin','userInfo'])
  109. },
  110. methods:{
  111. scrolltolower() {
  112. if(this.hasNextPage && this.pullFlag) {
  113. this.getProductAgainInfo(true);
  114. }
  115. },
  116. setScrollHeight() {
  117. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  118. this.windowHeight = windowHeight - 1;
  119. this.scrollHeight = windowHeight - 1;
  120. },
  121. getProductAgainInfo(loadMore) {
  122. this.showLoading = true;
  123. this.loadingNow = true;
  124. this.loadingText = '加载中';
  125. this.isShowEmpty = false;
  126. if(loadMore) {this.pageNum += 1;}
  127. let params = {userId:this.userID,pageNum:this.pageNum,pageSize:this.pageSize}
  128. queryAgaingoodslist(params).then(response =>{
  129. this.isShowWrapper = true
  130. this.cartQuantity = response.data.cartQuantity
  131. const responseData = response.data.pageDate;
  132. if(responseData.results && responseData.results.length > 0){
  133. this.hasNextPage = responseData.hasNextPage;
  134. this.isShowEmpty = false;
  135. if(loadMore) {
  136. this.productList = [...this.productList,...responseData.results];
  137. } else {
  138. this.productList = [...responseData.results];
  139. this.showSkeleton = false;
  140. }
  141. //价格显示处理
  142. let isActFlg,newProductList=[];
  143. this.productList.map((item, index)=> {
  144. if(item.actStatus == 1){
  145. isActFlg = true
  146. }else if(item.actStatus == 1 && item.ladderPriceFlag == '1'){
  147. isActFlg = true
  148. }else{
  149. isActFlg = false
  150. }
  151. newProductList.push(Object.assign({},item,{isShowActFlg:isActFlg}))
  152. })
  153. this.productList = newProductList
  154. // 防上拉暴滑
  155. this.pullFlag = false;
  156. setTimeout(()=>{
  157. this.pullFlag = true;
  158. },500)
  159. // 底部提示文案
  160. if(this.hasNextPage) {
  161. this.loadingText = '上拉加载更多';
  162. } else {
  163. this.showLoading = true;
  164. this.loadingNow = false;
  165. }
  166. } else {
  167. if(!loadMore) {
  168. this.isShowEmpty = true;
  169. }
  170. }
  171. }).catch(response =>{
  172. this.$util.msg(response.msg,2000);
  173. })
  174. },
  175. operationHanld(prop){
  176. this.$emit('operationConfim',prop)
  177. },
  178. navToDetailPage(id) {
  179. this.isModallayer = true;
  180. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  181. this.isModallayer = false;
  182. },
  183. toIndexPage() {
  184. uni.switchTab({
  185. url: '/pages/tabBar/home/home'
  186. })
  187. },
  188. repurchModel(){
  189. this.$util.modal('','此商品的价格有变化,原来的购买价已不适用','知道了','',false,() =>{})
  190. },
  191. btnClick() {
  192. this.$api.navigateTo('/pages/goods/cart')
  193. },
  194. btnTouchstart() {
  195. // console.log('btnTouchstart');
  196. },
  197. btnTouchend() {
  198. // console.log('btnTouchend');
  199. }
  200. }
  201. }
  202. </script>
  203. <style lang="scss">
  204. .commodity-list-wrapper {
  205. scroll-view {
  206. height: 100%;
  207. border-top: 2rpx solid rgba(0,0,0,0.07);
  208. }
  209. .empty-container-image {
  210. margin-top: -300rpx;
  211. }
  212. .toIndexPage {
  213. bottom: 390rpx;
  214. }
  215. .show-more-btn {
  216. width: 276rpx;
  217. height: 52rpx;
  218. line-height: 52rpx;
  219. border: 2rpx solid #D8D8D8;
  220. background: #F7F7F7;
  221. font-size: 26rpx;
  222. margin: 26rpx 0;
  223. position: absolute;
  224. left: 50%;
  225. margin-left: -138rpx;
  226. }
  227. }
  228. .all-type-list-content {
  229. height: 240rpx;
  230. padding: 24rpx;
  231. background: #fff;
  232. margin-bottom: 2rpx;
  233. display: flex;
  234. flex-direction: row;
  235. box-sizing: content-box;
  236. .list-img {
  237. width: 240rpx;
  238. height: 240rpx !important;
  239. margin-right: 26rpx;
  240. border-radius: 10rpx;
  241. border: 2rpx solid #f3f3f3;
  242. }
  243. }
  244. .list-details-info {
  245. width: 442rpx;
  246. flex-direction: column;
  247. font-size: 26rpx;
  248. position: relative;
  249. .list-details-title {
  250. line-height: 38rpx;
  251. text-overflow: ellipsis;
  252. overflow: hidden;
  253. display: -webkit-box;
  254. -webkit-line-clamp: 2;
  255. line-clamp: 2;
  256. -webkit-box-orient: vertical;
  257. }
  258. .list-details-specs {
  259. width: 100%;
  260. display: inline-block;
  261. margin-top: 8rpx;
  262. color: #999999;
  263. }
  264. .list-details-miniQuantity {
  265. width: 100%;
  266. display: inline-block;
  267. margin-top: 7rpx;
  268. }
  269. }
  270. .list-details-price {
  271. width: 100%;
  272. display: flex;
  273. flex-direction: row;
  274. justify-content: space-between;
  275. .price-icon {
  276. width: 22rpx;
  277. height: 28rpx;
  278. vertical-align: middle;
  279. margin-right: 10rpx;
  280. }
  281. .price-icon + text {
  282. font-size: 25rpx;
  283. vertical-align: middle;
  284. }
  285. .list-login-now {
  286. width: 375rpx;
  287. color: #F8C499;
  288. position: absolute;
  289. bottom: 0;
  290. .p-no{
  291. float: left;
  292. font-size: $font-size-24;
  293. color: $color-system;
  294. margin-right: 10rpx;
  295. }
  296. }
  297. .login-now {
  298. padding: 10rpx 10rpx 10rpx 0;
  299. }
  300. .list-none{
  301. margin-top: 30rpx;
  302. .price-small{
  303. font-size:$font-size-24;
  304. line-height: 40rpx;
  305. color: #FF2A2A;
  306. }
  307. }
  308. .list-shop{
  309. width: 100%;
  310. height: auto;
  311. flex: 6;
  312. .list-price {
  313. width: 100%;
  314. color: #FF2A2A;
  315. float: left;
  316. line-height:36rpx ;
  317. align-items: center;
  318. justify-content: center;
  319. .price-larger {
  320. margin-top: 20rpx;
  321. font-size: $font-size-30;
  322. display: inline-block;
  323. }
  324. .price-view{
  325. display: inline-block;
  326. width: 78rpx;
  327. border-radius: 18rpx;
  328. font-size: $font-size-20;
  329. text-align: center;
  330. color: #FFFFFF;
  331. height: 36rpx;
  332. line-height: 36rpx;
  333. margin-right: 8rpx;
  334. &.ladder{
  335. background: linear-gradient(135deg,rgba(255,0,0,1) 0%,rgba(242,143,49,1) 100%);
  336. }
  337. &.activity{
  338. background: linear-gradient(135deg,rgba(128,0,255,1) 0%,rgba(242,49,153,1) 100%);
  339. }
  340. }
  341. }
  342. .list-price-none{
  343. width: 100%;
  344. .price-none{
  345. text-decoration: line-through;
  346. color: #999999;
  347. display: inline-block;
  348. }
  349. .icon-wenhao{
  350. font-size: $font-size-32;
  351. color: #0091FF;
  352. margin-left: 6rpx;
  353. }
  354. }
  355. }
  356. .add-cart-btn {
  357. flex: 4;
  358. width: 156rpx;
  359. height: 64rpx;
  360. line-height: 64rpx;
  361. border-radius: 32rpx;
  362. color: #fff;
  363. font-size: 26rpx;
  364. margin-right: 0;
  365. background:linear-gradient(135deg,rgba(242,143,49,1) 0%,rgba(225,86,22,1) 100%);
  366. }
  367. }
  368. </style>