dishFood.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. <template>
  2. <view class="container">
  3. <!-- 空白页 -->
  4. <view style="padding: 150rpx 0rpx;" v-if="loadingType === 'nomore' && tlist.length === 0">
  5. <missing v-if="loadingType === 'nomore' && tlist.length === 0"
  6. :imgUrl="'http://qiniuoss.nauzone.cn/%E7%BB%84%203%20%E6%8B%B7%E8%B4%9D@3x.png'" :desc="'暂时没有菜品哦!'"></missing>
  7. </view>
  8. <view class="favorite-list">
  9. <block v-for="(item, index) in tlist" :key="index">
  10. <navigator class="favorite-item" :class="{'b-b': index!==tlist.length-1}"
  11. :url="`../dishFood/dishDetail?id=${item.id}`">
  12. <view class="image-wrapper">
  13. <image :src="JSON.parse(item.img)[0].url" :class="[item.loaded]" mode="aspectFill" lazy-load
  14. @load="onImageLoad('tlist', index)" @error="onImageError('tlist', index)"></image>
  15. </view>
  16. <view class="item-right">
  17. <text class="clamp title">{{item.title}}</text>
  18. <text class="attr">{{item.detail}}</text>
  19. <view class="pro-box">
  20. <view class="price-box">
  21. <text class="price" style="color: #fa436a; font-size: 36upx;">评分:{{item.score ? item.score : 0.0}}</text>
  22. <text style="color: #6B6B6B; font-size: 28upx; margin-top: 10upx;">{{item.sales}}人做过</text>
  23. </view>
  24. </view>
  25. </view>
  26. </navigator>
  27. </block>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. import missing from '@/components/missing.vue'
  33. export default {
  34. components: {
  35. missing
  36. },
  37. data() {
  38. return {
  39. tlist: [],
  40. pageNum: 1,
  41. loadingType: 'more'
  42. };
  43. },
  44. onLoad() {
  45. this.loadData();
  46. },
  47. //下拉刷新
  48. onPullDownRefresh() {
  49. this.loadData('refresh');
  50. },
  51. //加载更多
  52. onReachBottom() {
  53. this.loadData();
  54. },
  55. methods: {
  56. //获取菜品列表
  57. loadData(type) {
  58. const that = this;
  59. if (type === 'refresh') {
  60. that.pageNum = 1;
  61. that.tlist = [];
  62. that.loadingType = 'more';
  63. }
  64. if (that.loadingType === 'more') {
  65. that.loadingType = 'loading';
  66. that.$api.request('get','dish/composition/app/list', {
  67. storageId: this.$store.state.storageId,
  68. pageNum: that.pageNum,
  69. pageSize: 10
  70. }).then(res => {
  71. that.loadingType = that.pageNum < res.total / 10 + (res.total % 10 === 0 ? 0 : 1) ? 'more' : 'nomore';
  72. that.pageNum++;
  73. res.rows.forEach(item => {
  74. that.tlist.push(item);
  75. });
  76. if (type === 'refresh') {
  77. uni.stopPullDownRefresh();
  78. }
  79. }).catch(err => {
  80. that.$api.msg('请求失败,请稍后再试1');
  81. });
  82. }
  83. },
  84. //监听image加载完成
  85. onImageLoad(key, index) {
  86. this.$set(this[key][index], 'loaded', 'loaded');
  87. },
  88. //监听image加载失败
  89. onImageError(key, index) {
  90. this[key][index].img = '/static/errorImage.jpg';
  91. }
  92. }
  93. };
  94. </script>
  95. <style lang="scss">
  96. .container {
  97. padding-bottom: 134upx;
  98. }
  99. .price-box {
  100. display: flex;
  101. flex-direction: column;
  102. align-items: flex-start;
  103. }
  104. /* 菜品列表项 */
  105. .favorite-item {
  106. display: flex;
  107. position: relative;
  108. padding: 30upx 40upx;
  109. .image-wrapper {
  110. width: 230upx;
  111. height: 230upx;
  112. flex-shrink: 0;
  113. position: relative;
  114. image {
  115. border-radius: 8upx;
  116. }
  117. }
  118. .item-right {
  119. display: flex;
  120. flex-direction: column;
  121. flex: 1;
  122. overflow: hidden;
  123. position: relative;
  124. padding-left: 30upx;
  125. .title {
  126. font-size: $font-base + 2upx;
  127. color: $font-color-dark;
  128. height: 40upx;
  129. line-height: 40upx;
  130. }
  131. .attr {
  132. font-size: $font-sm + 2upx;
  133. color: $font-color-light;
  134. height: 50upx;
  135. line-height: 50upx;
  136. white-space: nowrap; /* 不换行 */
  137. overflow: hidden; /* 超出部分隐藏 */
  138. text-overflow: ellipsis; /* 超出部分显示为... */
  139. max-width: 100%; /* 限制最大宽度 */
  140. }
  141. .pro-box {
  142. display: flex;
  143. align-items: center;
  144. margin-top: 10upx;
  145. font-size: $font-sm;
  146. color: $font-base;
  147. padding-right: 10upx;
  148. .price {
  149. height: 60upx;
  150. line-height: 60upx;
  151. }
  152. }
  153. }
  154. }
  155. </style>