store_cate备份.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <!-- 商品分类 -->
  3. <view :style="colorStyle">
  4. <!-- 门店的两种样式布局 -->
  5. <storeCate1 :info="info" :isFooter="isFooter" v-if="storeShow===1" ref="refresh2">
  6. </storeCate1>
  7. <storeCate2 :info="info" :customerType="customerType" v-if="storeShow===2" ref="refresh">
  8. </storeCate2>
  9. <pageFooter @newDataStatus="newDataStatus"></pageFooter>
  10. </view>
  11. </template>
  12. <script>
  13. import colors from "@/mixins/color";
  14. import storeCate1 from './store_cate1.vue'
  15. import storeCate2 from './store_cate2.vue'
  16. import pageFooter from '@/components/pageFooter/index.vue'
  17. import {
  18. getnearbyStore
  19. } from '@/api/new_store.js'
  20. import {
  21. colorChange
  22. } from '@/api/api.js';
  23. export default {
  24. components: {
  25. storeCate1,
  26. storeCate2,
  27. pageFooter
  28. },
  29. mixins: [colors],
  30. data() {
  31. return {
  32. info: {},
  33. id: 0,
  34. isFooter: false,
  35. category: '',
  36. storeShow: 2,
  37. customerType: 1,
  38. where: {
  39. latitude: 0,
  40. longitude: 0,
  41. store_id: 0
  42. },
  43. }
  44. },
  45. onLoad() {
  46. try {
  47. this.where.latitude = uni.getStorageSync('user_latitude');
  48. this.where.longitude = uni.getStorageSync('user_longitude');
  49. } catch (e) {}
  50. },
  51. onShow() {
  52. uni.removeStorageSync('form_type_cart');
  53. let _this = this
  54. uni.$on("handClick", res => {
  55. if (res) {
  56. _this.where.latitude = res.latitude
  57. _this.where.longitude = res.longitude
  58. _this.where.store_id = res.store_id
  59. _this.getStore();
  60. }
  61. // 清除监听
  62. uni.$off('handClick');
  63. })
  64. if (this.where.latitude && this.where.longitude) {
  65. this.getStore();
  66. } else {
  67. this.selfLocation();
  68. }
  69. },
  70. mounted() {},
  71. methods: {
  72. selfLocation() {
  73. let self = this
  74. // #ifdef H5
  75. if (self.$wechat.isWeixin()) {
  76. self.$wechat.location().then(res => {
  77. this.where.latitude = res.latitude;
  78. this.where.longitude = res.longitude;
  79. uni.setStorageSync('user_latitude', res.latitude);
  80. uni.setStorageSync('user_longitude', res.longitude);
  81. self.getStore();
  82. })
  83. } else {
  84. // #endif
  85. uni.getLocation({
  86. type: 'wgs84',
  87. success: (res) => {
  88. try {
  89. this.where.latitude = res.latitude;
  90. this.where.longitude = res.longitude;
  91. uni.setStorageSync('user_latitude', res.latitude);
  92. uni.setStorageSync('user_longitude', res.longitude);
  93. } catch {}
  94. self.getStore();
  95. },
  96. complete: function() {
  97. self.getStore();
  98. }
  99. });
  100. // #ifdef H5
  101. }
  102. // #endif
  103. },
  104. // 获取接口附近门店
  105. getStore() {
  106. this.where.latitude = uni.getStorageSync('user_latitude');
  107. this.where.longitude = uni.getStorageSync('user_longitude');
  108. getnearbyStore(this.where).then(res => {
  109. this.storeShow = res.data.info.home_style
  110. this.info = res.data.info
  111. this.id = this.info.id
  112. this.customerType = parseInt(res.data.info.customer_type)
  113. uni.setStorageSync('user_store_id', this.info.id);
  114. if (this.storeShow === 1) {
  115. setTimeout(() => {
  116. this.$refs.refresh2.getAllCategory();
  117. this.$refs.refresh2.getCartList(1);
  118. this.$refs.refresh2.getMarTop();
  119. }, 10)
  120. } else if (this.storeShow === 2) {
  121. setTimeout(() => {
  122. this.$refs.refresh.where.store_id = this.id
  123. this.$refs.refresh.getProducts(true)
  124. })
  125. }
  126. })
  127. },
  128. newDataStatus(val) {
  129. this.isFooter = val;
  130. },
  131. },
  132. onReachBottom: function() {
  133. if (this.storeShow === 1) {
  134. setTimeout(() => {
  135. this.$refs.refresh2.getProducts()
  136. }, 10)
  137. }
  138. if (this.storeShow === 2) {
  139. this.$refs.refresh.getProducts()
  140. }
  141. }
  142. }
  143. </script>
  144. <style scoped lang="scss">
  145. </style>