commodityList.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. console.log(this.listData)
  168. // 防上拉暴滑
  169. this.pullFlag = false;
  170. setTimeout(()=>{ this.pullFlag = true; },500)
  171. // 底部提示文案
  172. if(this.totalPage>this.listData.length) {
  173. this.loadingText = '上拉加载更多';
  174. } else {
  175. this.showLoading = true;
  176. this.loadingNow = false;
  177. }
  178. } else {
  179. if(!loadMore) { this.showEmpty = true; }
  180. }
  181. }).catch(error =>{
  182. this.$util.msg(error.msg,2000);
  183. })
  184. },
  185. setProductPrice(){//获取价格
  186. if (!this.userID) {return false;}
  187. let productIdArr = [];
  188. this.listData.map(item=>{// 0公开价格 1不公开价格 2仅对会员机构公开
  189. productIdArr.push(item.p_id)
  190. })
  191. this.productIds = productIdArr.join(",");
  192. querySearchProductPrice({userId: this.userID,productIds:this.productIds}).then(response =>{
  193. if (response.data) {
  194. let priceList = response.data
  195. this.listData.map(item=>{
  196. for (let i = 0; i < priceList.length; i++) {
  197. let priceObj ={
  198. actStatus:priceList[i].actStatus,
  199. costCheckFlag:priceList[i].costCheckFlag,
  200. costPrice:priceList[i].costPrice,
  201. costProportional:priceList[i].costProportional,
  202. ladderPriceFlag:priceList[i].ladderPriceFlag,
  203. price:Number(priceList[i].price).toFixed(2),
  204. minBuyNumber:priceList[i].minBuyNumber
  205. }
  206. if( item.p_id == priceList[i].productId ){
  207. Object.assign(item,priceObj)
  208. }
  209. }
  210. });
  211. console.log(this.listData)
  212. }
  213. this.priceLoading = false;
  214. }).catch(error =>{
  215. this.$util.msg(error.msg,2000)
  216. })
  217. },
  218. navToDetailPage(id) {
  219. this.isModallayer = true;
  220. this.$api.navigateTo(`/pages/goods/product?id=${id}`);
  221. this.isModallayer = false;
  222. }
  223. }
  224. }
  225. </script>
  226. <style lang="scss">
  227. .commodity-list-wrapper {
  228. scroll-view {
  229. height: 100%;
  230. border-top: 2rpx solid rgba(0,0,0,0.07);
  231. }
  232. .empty-container-image {
  233. margin-top: -300rpx;
  234. }
  235. .toIndexPage {
  236. bottom: 390rpx;
  237. }
  238. .show-more-btn {
  239. width: 276rpx;
  240. height: 52rpx;
  241. line-height: 52rpx;
  242. border: 2rpx solid #D8D8D8;
  243. background: #F7F7F7;
  244. font-size: 26rpx;
  245. margin: 26rpx 0;
  246. position: absolute;
  247. left: 50%;
  248. margin-left: -138rpx;
  249. }
  250. }
  251. .all-type-list-content {
  252. height: 216rpx;
  253. padding: 24rpx;
  254. background: #fff;
  255. margin-bottom: 2rpx;
  256. display: flex;
  257. flex-direction: row;
  258. box-sizing: content-box;
  259. .list-img {
  260. width: 210rpx;
  261. height: 218rpx !important;
  262. margin-right: 26rpx;
  263. border-radius: 10rpx;
  264. border: 2rpx solid #f3f3f3;
  265. }
  266. }
  267. .list-details-info {
  268. width: 466rpx;
  269. display: flex;
  270. flex-direction: column;
  271. font-size: 26rpx;
  272. position: relative;
  273. .list-details-title {
  274. line-height: 38rpx;
  275. text-overflow: ellipsis;
  276. overflow: hidden;
  277. display: -webkit-box;
  278. -webkit-line-clamp: 2;
  279. line-clamp: 2;
  280. -webkit-box-orient: vertical;
  281. }
  282. .list-details-specs {
  283. margin-top: 8rpx;
  284. color: #666666;
  285. }
  286. .list-details-miniQuantity {
  287. margin-top: 7rpx;
  288. }
  289. }
  290. .list-details-price {
  291. width: 100%;
  292. display: flex;
  293. flex-direction: row;
  294. justify-content: space-between;
  295. position: absolute;
  296. bottom: 0;
  297. right: 0;
  298. .price-icon {
  299. width: 22rpx;
  300. height: 28rpx;
  301. vertical-align: middle;
  302. margin-right: 10rpx;
  303. }
  304. .price-icon + text {
  305. font-size: 25rpx;
  306. vertical-align: middle;
  307. }
  308. .list-login-now {
  309. width: 375rpx;
  310. color: #F8C499;
  311. position: absolute;
  312. bottom: 0;
  313. .p-no{
  314. float: left;
  315. font-size: $font-size-24;
  316. color: $color-system;
  317. margin-right: 10rpx;
  318. }
  319. }
  320. .login-now {
  321. padding: 10rpx 10rpx 10rpx 0;
  322. }
  323. .list-price {
  324. color: #FF2A2A;
  325. width: 100%;
  326. height: 44rpx;
  327. .price-larger {
  328. width: 100%;
  329. height: 44rpx;
  330. font-size: 32rpx;
  331. &.small{
  332. font-size: $font-size-24;
  333. }
  334. .txt{
  335. font-size: $font-size-24;
  336. display: inline-block;
  337. line-height: 44rpx;
  338. text-align: left;
  339. float: left;
  340. }
  341. .btn{
  342. width: 112rpx;
  343. height: 44rpx;
  344. display: inline-block;
  345. float: right;
  346. background: $btn-confirm;
  347. line-height: 44rpx;
  348. text-align: center;
  349. color: #FFFFFF;
  350. font-size: $font-size-24;
  351. border-radius: 22rpx;
  352. }
  353. }
  354. }
  355. .add-cart-btn {
  356. width: 156rpx;
  357. height: 64rpx;
  358. line-height: 64rpx;
  359. border-radius: 32rpx;
  360. color: #fff;
  361. font-size: 26rpx;
  362. margin-right: 0;
  363. background:linear-gradient(45deg,rgba(255,41,41,1) 0%,rgba(255,109,27,1) 100%);
  364. }
  365. }
  366. .cart-icon {
  367. width: 92rpx;
  368. height: 92rpx;
  369. border-radius: 50%;
  370. background: rgba(255, 147, 0, 0.5);
  371. position: fixed;
  372. right: 24rpx;
  373. bottom: 30%;
  374. display: flex;
  375. align-items: center;
  376. justify-content: center;
  377. cursor: pointer;
  378. image {
  379. width: 58rpx;
  380. height: 58rpx;
  381. }
  382. text {
  383. font-size: 28rpx;
  384. position: absolute;
  385. top: -10rpx;
  386. right: 0;
  387. }
  388. }
  389. </style>