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.p_id)">
  6. <image mode='widthFix' :src="item.p_image" class="list-img" alt="list-img"></image>
  7. <view class="list-details-info">
  8. <text class="list-details-title">{{item.p_name}}</text>
  9. <text class="list-details-specs">规格:{{item.p_unit}}</text>
  10. <view class="list-details-specs" v-if="item.p_code!=''&&item.p_code!=null">商品编码:{{item.p_code}}</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.p_price_flag == '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.p_price_flag == '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.p_price_flag == '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.p_price_grade)" :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: 20,
  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. this.getListFromServer();
  120. })
  121. },
  122. computed: {
  123. ...mapState(['hasLogin','userInfo'])
  124. },
  125. methods:{
  126. toLower() {
  127. if(this.totalPage>this.listData.length && 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.listData.length) {
  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. productIdArr.push(item.p_id)
  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.p_id == priceList[i].productId ){
  206. Object.assign(item,priceObj)
  207. }
  208. }
  209. });
  210. }
  211. this.priceLoading = false;
  212. }).catch(error =>{
  213. this.$util.msg(error.msg,2000)
  214. })
  215. },
  216. navToDetailPage(id) {
  217. this.isModallayer = true;
  218. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  219. this.isModallayer = false;
  220. }
  221. }
  222. }
  223. </script>
  224. <style lang="scss">
  225. .commodity-list-wrapper {
  226. scroll-view {
  227. height: 100%;
  228. border-top: 2rpx solid rgba(0,0,0,0.07);
  229. }
  230. .empty-container-image {
  231. margin-top: -300rpx;
  232. }
  233. .toIndexPage {
  234. bottom: 390rpx;
  235. }
  236. .show-more-btn {
  237. width: 276rpx;
  238. height: 52rpx;
  239. line-height: 52rpx;
  240. border: 2rpx solid #D8D8D8;
  241. background: #F7F7F7;
  242. font-size: 26rpx;
  243. margin: 26rpx 0;
  244. position: absolute;
  245. left: 50%;
  246. margin-left: -138rpx;
  247. }
  248. }
  249. .all-type-list-content {
  250. height: 216rpx;
  251. padding: 24rpx;
  252. background: #fff;
  253. margin-bottom: 2rpx;
  254. display: flex;
  255. flex-direction: row;
  256. box-sizing: content-box;
  257. .list-img {
  258. width: 210rpx;
  259. height: 218rpx !important;
  260. margin-right: 26rpx;
  261. border-radius: 10rpx;
  262. border: 2rpx solid #f3f3f3;
  263. }
  264. }
  265. .list-details-info {
  266. width: 466rpx;
  267. display: flex;
  268. flex-direction: column;
  269. font-size: 26rpx;
  270. position: relative;
  271. .list-details-title {
  272. line-height: 38rpx;
  273. text-overflow: ellipsis;
  274. overflow: hidden;
  275. display: -webkit-box;
  276. -webkit-line-clamp: 2;
  277. line-clamp: 2;
  278. -webkit-box-orient: vertical;
  279. }
  280. .list-details-specs {
  281. margin-top: 8rpx;
  282. color: #666666;
  283. }
  284. .list-details-miniQuantity {
  285. margin-top: 7rpx;
  286. }
  287. }
  288. .list-details-price {
  289. width: 100%;
  290. display: flex;
  291. flex-direction: row;
  292. justify-content: space-between;
  293. position: absolute;
  294. bottom: 0;
  295. right: 0;
  296. .price-icon {
  297. width: 22rpx;
  298. height: 28rpx;
  299. vertical-align: middle;
  300. margin-right: 10rpx;
  301. }
  302. .price-icon + text {
  303. font-size: 25rpx;
  304. vertical-align: middle;
  305. }
  306. .list-login-now {
  307. width: 375rpx;
  308. color: #F8C499;
  309. position: absolute;
  310. bottom: 0;
  311. .p-no{
  312. float: left;
  313. font-size: $font-size-24;
  314. color: $color-system;
  315. margin-right: 10rpx;
  316. }
  317. }
  318. .login-now {
  319. padding: 10rpx 10rpx 10rpx 0;
  320. }
  321. .list-price {
  322. color: #FF2A2A;
  323. width: 100%;
  324. height: 44rpx;
  325. .price-larger {
  326. width: 100%;
  327. height: 44rpx;
  328. font-size: 32rpx;
  329. &.small{
  330. font-size: $font-size-24;
  331. }
  332. .txt{
  333. font-size: $font-size-24;
  334. display: inline-block;
  335. line-height: 44rpx;
  336. text-align: left;
  337. float: left;
  338. }
  339. .btn{
  340. width: 112rpx;
  341. height: 44rpx;
  342. display: inline-block;
  343. float: right;
  344. background: $btn-confirm;
  345. line-height: 44rpx;
  346. text-align: center;
  347. color: #FFFFFF;
  348. font-size: $font-size-24;
  349. border-radius: 22rpx;
  350. }
  351. }
  352. }
  353. .add-cart-btn {
  354. width: 156rpx;
  355. height: 64rpx;
  356. line-height: 64rpx;
  357. border-radius: 32rpx;
  358. color: #fff;
  359. font-size: 26rpx;
  360. margin-right: 0;
  361. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  362. }
  363. }
  364. .cart-icon {
  365. width: 92rpx;
  366. height: 92rpx;
  367. border-radius: 50%;
  368. background: rgba(255, 147, 0, 0.5);
  369. position: fixed;
  370. right: 24rpx;
  371. bottom: 30%;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. cursor: pointer;
  376. image {
  377. width: 58rpx;
  378. height: 58rpx;
  379. }
  380. text {
  381. font-size: 28rpx;
  382. position: absolute;
  383. top: -10rpx;
  384. right: 0;
  385. }
  386. }
  387. </style>