commodityList.vue 11 KB

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