index.vue 4.0 KB

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