commodityList.vue 11 KB

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