store_cate.vue 4.5 KB

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