favourite - 副本.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="collect">
  3. <view class="collect_list">
  4. <u-tabs
  5. :list="listCollect"
  6. @click="clickCollect"
  7. lineWidth="30"
  8. lineColor="#5992bb"
  9. :activeStyle="{
  10. color: '#303133',
  11. fontWeight: 'bold',
  12. transform: 'scale(1.05)',
  13. }"
  14. :inactiveStyle="{
  15. color: '#606266',
  16. transform: 'scale(1)',
  17. }"
  18. itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"
  19. />
  20. </view>
  21. <view>
  22. <view v-if="init_list.length > 0">
  23. <view class="text">以下是您收藏的商品服务</view>
  24. <!-- 收藏的服务 -->
  25. <serviceItem
  26. v-if="indexs == 0"
  27. :item="init_list"
  28. @uploadIniList="uploadIniList"
  29. ></serviceItem>
  30. <goodsItem v-else :item="init_list" @uploadIniList="uploadIniList" />
  31. </view>
  32. <u-empty v-else mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" />
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import serviceItem from '@/components/service/serviceItem.vue';
  38. import goodsItem from './components/goodsItem';
  39. import { maintainFavoritePaging, getFavouriteGoods } from '@/api/client/mine.js';
  40. import { getCurrentLocation } from '@/api/client/home';
  41. import { mapGetters } from 'vuex';
  42. export default {
  43. components: {
  44. serviceItem,
  45. goodsItem,
  46. },
  47. data() {
  48. return {
  49. queryParams: {
  50. size: 10,
  51. type: 'MERCHANT',
  52. region: null, //地区编码
  53. longitude: null, //经度
  54. latitude: null, //纬度
  55. },
  56. init_list: [],
  57. listCollect: [
  58. {
  59. id: 1,
  60. name: '商家',
  61. },
  62. {
  63. id: 1,
  64. name: '服务',
  65. },
  66. ],
  67. indexs: 0,
  68. };
  69. },
  70. mounted() {
  71. let { latitude, longitude, region } = this.location;
  72. this.queryParams.latitude = latitude;
  73. this.queryParams.longitude = longitude;
  74. this.queryParams.region = region;
  75. this.handlerInitList();
  76. },
  77. computed: {
  78. ...mapGetters(['location']),
  79. },
  80. methods: {
  81. // 初始化商家列表信息
  82. handlerInitList() {
  83. maintainFavoritePaging(this.queryParams).then(res => {
  84. if (res.code === 'OK' && res.data) {
  85. res.data.map(rs => {
  86. this.init_list.push(rs.simpleMerchantVO);
  87. });
  88. } else {
  89. uni.showToast({
  90. title: '数据请求失败',
  91. icon: 'none',
  92. });
  93. }
  94. });
  95. },
  96. // 初始化服务列表
  97. handlerInitGoodsList() {
  98. getFavouriteGoods().then(res => {
  99. if (res.code === 'OK' && res.data) {
  100. res.data.map(rs => {
  101. this.init_list.push(rs.goods);
  102. });
  103. } else {
  104. uni.showToast({
  105. title: '数据请求失败',
  106. icon: 'none',
  107. });
  108. }
  109. });
  110. },
  111. clickCollect(e) {
  112. this.init_list = [];
  113. this.indexs = e.index;
  114. switch (e.index) {
  115. case 0:
  116. this.handlerInitList();
  117. break;
  118. case 1:
  119. this.handlerInitGoodsList();
  120. break;
  121. }
  122. },
  123. uploadIniList(e) {
  124. this.init_list = [];
  125. if (e == 1) {
  126. this.handlerInitGoodsList();
  127. this.indexs = 1;
  128. } else {
  129. this.handlerInitList();
  130. this.indexs = 0;
  131. }
  132. },
  133. },
  134. };
  135. </script>
  136. <style lang="scss" scoped>
  137. .collect {
  138. min-height: 100vh;
  139. background-color: #f9f9f9;
  140. &_list {
  141. display: flex;
  142. height: 70rpx;
  143. justify-content: center;
  144. align-items: center;
  145. background-color: #fff;
  146. margin-bottom: 40rpx;
  147. }
  148. .text {
  149. text-align: center;
  150. padding: 40rpx;
  151. color: #999;
  152. }
  153. }
  154. </style>