index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!-- 商品分类 -->
  3. <view :style="colorStyle">
  4. <!-- 门店的两种样式布局 -->
  5. <storeCate1 :info="info" ref="refresh2"></storeCate1>
  6. </view>
  7. </template>
  8. <script>
  9. import {
  10. mapGetters
  11. } from 'vuex';
  12. import colors from "@/mixins/color";
  13. import storeCate1 from './cart.vue'
  14. import {
  15. getnearbyStore
  16. } from '@/api/new_store.js'
  17. import {
  18. colorChange
  19. } from '@/api/api.js';
  20. import {
  21. getCartCounts
  22. } from '@/api/order.js';
  23. export default {
  24. computed: mapGetters(['isLogin']),
  25. components: {
  26. storeCate1,
  27. },
  28. mixins: [colors],
  29. data() {
  30. return {
  31. info: {},
  32. id: 0,
  33. category: '',
  34. storeShow: 1,
  35. customerType: 1,
  36. where: {
  37. latitude: 0,
  38. longitude: 0,
  39. store_id: 0
  40. },
  41. cart_num: 0,
  42. delivery_type: 3,
  43. }
  44. },
  45. onLoad(options) {
  46. this.collage_id = options.collage_id;
  47. this.delivery_type = options.delivery_type;
  48. this.where.store_id = options.id;
  49. // uni.setStorageSync('user_store_id', options.id);
  50. try {
  51. this.where.latitude = uni.getStorageSync('user_latitude');
  52. this.where.longitude = uni.getStorageSync('user_longitude');
  53. this.selfLocation();
  54. if (!this.$util.checkOpenGPSServiceByAndroidIOS()) {
  55. this.getStore();
  56. }
  57. } catch (e) {}
  58. },
  59. onPageScroll(e) {
  60. uni.$emit('onPageScroll', e.scrollTop);
  61. },
  62. onReachBottom() {
  63. uni.$emit('onReachBottom');
  64. },
  65. methods: {
  66. otherFun(object) {
  67. if (!!object) {
  68. if (this.storeShow == 1) {
  69. this.$refs.refresh2.updateFun(object);
  70. }
  71. }
  72. },
  73. selfLocation() {
  74. let self = this
  75. // #ifdef H5
  76. if (self.$wechat.isWeixin()) {
  77. self.$wechat.location().then(res => {
  78. // this.where.latitude = res.latitude;
  79. // this.where.longitude = res.longitude;
  80. uni.setStorageSync('user_latitude', res.latitude);
  81. uni.setStorageSync('user_longitude', res.longitude);
  82. self.getStore();
  83. }).catch(err => {
  84. self.getStore();
  85. })
  86. } else {
  87. // #endif
  88. uni.getLocation({
  89. type: 'gcj02',
  90. success: (res) => {
  91. try {
  92. // this.where.latitude = res.latitude;
  93. // this.where.longitude = res.longitude;
  94. uni.setStorageSync('user_latitude', res.latitude);
  95. uni.setStorageSync('user_longitude', res.longitude);
  96. } catch {}
  97. // self.getStore();
  98. },
  99. fail: (err) => {
  100. self.$util.Tips({
  101. title: err
  102. });
  103. },
  104. complete: function() {
  105. self.getStore();
  106. }
  107. });
  108. // #ifdef H5
  109. }
  110. // #endif
  111. },
  112. // 获取接口附近门店
  113. getStore() {
  114. this.where.latitude = uni.getStorageSync('user_latitude');
  115. this.where.longitude = uni.getStorageSync('user_longitude');
  116. getnearbyStore(this.where).then(res => {
  117. let info = res.data.info;
  118. this.cart_num = res.data.cart_num;
  119. if (Object.prototype.toString.call(info) === "[object Array]") {
  120. this.info = {}
  121. } else {
  122. this.info = res.data.info
  123. }
  124. this.info = {
  125. ...this.info,
  126. collage_id: this.collage_id,
  127. delivery_type: this.delivery_type
  128. };
  129. this.id = this.info.id
  130. this.customerType = parseInt(res.data.info.customer_type)
  131. setTimeout(() => {
  132. this.$refs.refresh2.getAllCategory();
  133. this.$refs.refresh2.getCartNum();
  134. if (this.isLogin) {
  135. this.$refs.refresh2.getCartList(1);
  136. }
  137. }, 10)
  138. })
  139. },
  140. },
  141. }
  142. </script>
  143. <style scoped lang="scss">
  144. /deep/.goodCate .uni-badge-left-margin .uni-badge--error {
  145. background-color: #fff !important;
  146. color: var(--view-theme);
  147. border-color: var(--view-theme);
  148. z-index: 8;
  149. }
  150. /deep/.goodCate .footer .cartIcon .uni-badge-left-margin .uni-badge--error {
  151. right: 0 !important;
  152. top: 10px !important;
  153. }
  154. /deep/.mask {
  155. z-index: 99;
  156. }
  157. /deep/.good-cate {
  158. padding: 80rpx;
  159. }
  160. </style>