classifyProductList.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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. <scroll-view :style="{'height':scrollHeight+'px'}" @scrolltolower="toLower" scroll-y v-if="listData.length > 0">
  5. <view v-for="(item,index) in listData" :key="index" :id="item.id" class="all-type-list-content commodity-list" @click.stop="navToDetailPage(item.productID)">
  6. <image mode='widthFix' :src="item.mainImage" class="list-img" alt="list-img"></image>
  7. <view class="list-details-info">
  8. <text class="list-details-title">{{item.name}}</text>
  9. <text class="list-details-specs">规格:{{item.unit}}</text>
  10. <view class="list-details-specs" v-if="item.productCode!=''&&item.productCode!=null">商品编码:{{item.productCode}}</view>
  11. <view class="list-details-price">
  12. <view v-if="hasLogin" class="list-price">
  13. <view v-if="userIdentity == 1">
  14. <text>¥<text class="price-larger">{{item.retailPrice ? item.retailPrice.toFixed(2) : '0.00'}}</text></text>
  15. </view>
  16. <view v-if="userIdentity == 4">
  17. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  18. <text class="txt">未公开价格</text>
  19. </view>
  20. <view v-else>
  21. <view class="price-larger" v-if="item.price1TextFlag == '2'">
  22. <text class="txt">价格仅会员可见</text>
  23. <text class="btn" @click.stop="this.$api.navigateTo(`/pages/login/apply?clubStatus=${clubStatus}`)">去升级</text>
  24. </view>
  25. <text v-else>¥<text class="price-larger">{{item.retailPrice ? item.retailPrice.toFixed(2) :'0.00'}}</text></text>
  26. </view>
  27. </view>
  28. <view v-if="userIdentity == 2">
  29. <view class="price-larger" v-if="item.price1TextFlag == '1'">
  30. <text class="txt">未公开价格</text>
  31. </view>
  32. <text>¥<text class="price-larger">{{item.retailPrice ? item.retailPrice.toFixed(2) :'0.00'}}</text></text>
  33. </view>
  34. </view>
  35. <view v-else class="list-login-now">
  36. <text class="p-no">价格:</text>
  37. <uni-stars :stars="parseInt(item.price1Grade)" :font-size='36' :width-info="180"></uni-stars>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <view v-if="showLoading && listData.length > 4">
  43. <view class="loading-wrapper loading-wrapper-now" v-if="loadingNow">{{loadingText}}<text v-if="loadingText === '已至底部'">‧ ‧ ‧</text></view>
  44. <view class="loading-wrapper loading-wrapper-btm" v-else>———<text class="btm-text">已至底部</text>———</view>
  45. </view>
  46. </scroll-view>
  47. <view class="empty-container" v-if="showEmpty">
  48. <image class="empty-container-image" src="https://img.caimei365.com/group1/M00/03/71/Cmis2F3wna6AY2ZjAABpmnBICH4247.png"></image>
  49. <text class="error-text">{{emptyText}}</text>
  50. </view>
  51. <!-- 透明模态层 -->
  52. <modal-layer v-if='isModallayer'></modal-layer>
  53. </view>
  54. </template>
  55. <script>
  56. import listSkeleton from '@/components/cm-module/listTemplate/listSkeleton'
  57. import modalLayer from "@/components/modal-layer"
  58. import uniStars from '@/components/uni-stars/uni-stars.vue'
  59. import { searchQueryTinyType} from "@/api/product.js"
  60. import { mapState,mapMutations } from 'vuex';
  61. export default{
  62. name:'CommodityList',
  63. components:{
  64. listSkeleton,
  65. modalLayer,
  66. uniStars
  67. },
  68. props: {
  69. emptyText: {
  70. type: String
  71. },
  72. serverUrl: {
  73. type: String
  74. },
  75. classifyID: {
  76. type:Number
  77. }
  78. },
  79. data(){
  80. return{
  81. clubStatus:'',
  82. isModallayer:false,
  83. windowHeight: '',
  84. showSkeleton: true,
  85. showEmpty: false,
  86. userID: '',
  87. userIdentity:'',
  88. scrollHeight: '',
  89. listData: [],
  90. showLoading: false,
  91. loadingNow: true,
  92. loadingText: '上拉加载更多',
  93. pageSize: 20,
  94. pageNum: 1,
  95. totalPage: 1,
  96. hasNextPage:false,
  97. pullFlag: true,
  98. cartNum: 0,
  99. }
  100. },
  101. created() {
  102. // console.log(this.typeId)
  103. this.setScrollHeight();
  104. this.$api.getComStorage('userInfo').then((resolve) =>{
  105. this.clubStatus = resolve.clubStatus
  106. this.userID = resolve.userID ? resolve.userID : '';
  107. this.userIdentity = resolve.userIdentity
  108. this.getListFromServer();
  109. }).catch(error =>{
  110. this.getListFromServer();
  111. })
  112. },
  113. computed: {
  114. ...mapState(['hasLogin','userInfo'])
  115. },
  116. methods:{
  117. toLower() {
  118. if(this.hasNextPage && this.pullFlag) {
  119. this.getListFromServer(true);
  120. }
  121. },
  122. setScrollHeight() {
  123. const {windowHeight, pixelRatio} = wx.getSystemInfoSync();
  124. this.windowHeight = windowHeight - 1;
  125. this.scrollHeight = windowHeight - 1;
  126. },
  127. getListFromServer(loadMore) {
  128. this.getQueryGoodslist(loadMore)
  129. },
  130. getQueryGoodslist(loadMore){
  131. this.showLoading = true;
  132. this.loadingNow = true;
  133. this.loadingText = '加载中';
  134. if(loadMore) { this.pageNum += 1; }
  135. let params ={
  136. classifyId:this.classifyID,
  137. userId:this.userID,
  138. pageNum:this.pageNum,
  139. pageSize:this.pageSize,
  140. }
  141. this.CommonService.GetHomeClassify(params).then(response =>{
  142. const resList = response.data.results;
  143. if(resList && resList.length > 0){
  144. this.showEmpty = false
  145. this.hasNextPage = response.data.hasNextPage;
  146. if(loadMore) {
  147. this.listData = [...this.listData,...resList];
  148. this.showSkeleton = false
  149. } else {
  150. this.listData = [...resList];
  151. this.showSkeleton = false
  152. }
  153. // 防上拉暴滑
  154. this.pullFlag = false;
  155. setTimeout(()=>{ this.pullFlag = true; },500)
  156. // 底部提示文案
  157. if(this.hasNextPage) {
  158. this.loadingText = '上拉加载更多';
  159. } else {
  160. this.showLoading = true;
  161. this.loadingNow = false;
  162. this.loadingText = '已至底部';
  163. }
  164. } else {
  165. if(!loadMore) { this.showEmpty = true; }
  166. }
  167. }).catch(error =>{
  168. this.$util.msg(error.msg,2000);
  169. })
  170. },
  171. navToDetailPage(id) {
  172. this.isModallayer = true;
  173. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  174. this.isModallayer = false;
  175. }
  176. }
  177. }
  178. </script>
  179. <style lang="scss">
  180. .commodity-list-wrapper {
  181. scroll-view {
  182. height: 100%;
  183. border-top: 2rpx solid rgba(0,0,0,0.07);
  184. }
  185. .empty-container-image {
  186. margin-top: -300rpx;
  187. }
  188. .toIndexPage {
  189. bottom: 390rpx;
  190. }
  191. .show-more-btn {
  192. width: 276rpx;
  193. height: 52rpx;
  194. line-height: 52rpx;
  195. border: 2rpx solid #D8D8D8;
  196. background: #F7F7F7;
  197. font-size: 26rpx;
  198. margin: 26rpx 0;
  199. position: absolute;
  200. left: 50%;
  201. margin-left: -138rpx;
  202. }
  203. }
  204. .all-type-list-content {
  205. height: 216rpx;
  206. padding: 24rpx;
  207. background: #fff;
  208. margin-bottom: 2rpx;
  209. display: flex;
  210. flex-direction: row;
  211. box-sizing: content-box;
  212. .list-img {
  213. width: 210rpx;
  214. height: 218rpx !important;
  215. margin-right: 26rpx;
  216. border-radius: 10rpx;
  217. border: 2rpx solid #f3f3f3;
  218. }
  219. }
  220. .list-details-info {
  221. width: 466rpx;
  222. display: flex;
  223. flex-direction: column;
  224. font-size: 26rpx;
  225. position: relative;
  226. .list-details-title {
  227. line-height: 38rpx;
  228. text-overflow: ellipsis;
  229. overflow: hidden;
  230. display: -webkit-box;
  231. -webkit-line-clamp: 2;
  232. line-clamp: 2;
  233. -webkit-box-orient: vertical;
  234. }
  235. .list-details-specs {
  236. margin-top: 8rpx;
  237. color: #666666;
  238. }
  239. .list-details-miniQuantity {
  240. margin-top: 7rpx;
  241. }
  242. }
  243. .list-details-price {
  244. width: 100%;
  245. display: flex;
  246. flex-direction: row;
  247. justify-content: space-between;
  248. position: absolute;
  249. bottom: 0;
  250. right: 0;
  251. .price-icon {
  252. width: 22rpx;
  253. height: 28rpx;
  254. vertical-align: middle;
  255. margin-right: 10rpx;
  256. }
  257. .price-icon + text {
  258. font-size: 25rpx;
  259. vertical-align: middle;
  260. }
  261. .list-login-now {
  262. width: 375rpx;
  263. color: #F8C499;
  264. position: absolute;
  265. bottom: 0;
  266. .p-no{
  267. float: left;
  268. font-size: $font-size-24;
  269. color: $color-system;
  270. margin-right: 10rpx;
  271. }
  272. }
  273. .login-now {
  274. padding: 10rpx 10rpx 10rpx 0;
  275. }
  276. .list-price {
  277. color: #FF2A2A;
  278. width: 100%;
  279. height: 44rpx;
  280. .price-larger {
  281. width: 100%;
  282. height: 44rpx;
  283. font-size: 32rpx;
  284. &.small{
  285. font-size: $font-size-24;
  286. }
  287. .txt{
  288. font-size: $font-size-24;
  289. display: inline-block;
  290. line-height: 44rpx;
  291. text-align: left;
  292. float: left;
  293. }
  294. .btn{
  295. width: 112rpx;
  296. height: 44rpx;
  297. display: inline-block;
  298. float: right;
  299. background: $btn-confirm;
  300. line-height: 44rpx;
  301. text-align: center;
  302. color: #FFFFFF;
  303. font-size: $font-size-24;
  304. border-radius: 22rpx;
  305. }
  306. }
  307. }
  308. .add-cart-btn {
  309. width: 156rpx;
  310. height: 64rpx;
  311. line-height: 64rpx;
  312. border-radius: 32rpx;
  313. color: #fff;
  314. font-size: 26rpx;
  315. margin-right: 0;
  316. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  317. }
  318. }
  319. .cart-icon {
  320. width: 92rpx;
  321. height: 92rpx;
  322. border-radius: 50%;
  323. background: rgba(255, 147, 0, 0.5);
  324. position: fixed;
  325. right: 24rpx;
  326. bottom: 30%;
  327. display: flex;
  328. align-items: center;
  329. justify-content: center;
  330. cursor: pointer;
  331. image {
  332. width: 58rpx;
  333. height: 58rpx;
  334. }
  335. text {
  336. font-size: 28rpx;
  337. position: absolute;
  338. top: -10rpx;
  339. right: 0;
  340. }
  341. }
  342. </style>