123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <template>
- <!-- 商品分类 -->
- <view :style="colorStyle">
- <!-- 门店的两种样式布局 -->
- <storeCate1 :info="info" :isFooter="isFooter" v-if="storeShow===1" ref="refresh2">
- </storeCate1>
- <storeCate2 :info="info" :customerType="customerType" v-if="storeShow===2" ref="refresh">
- </storeCate2>
- <pageFooter @newDataStatus="newDataStatus"></pageFooter>
- </view>
- </template>
- <script>
- import colors from "@/mixins/color";
- import storeCate1 from './store_cate1.vue'
- import storeCate2 from './store_cate2.vue'
- import pageFooter from '@/components/pageFooter/index.vue'
- import {
- getnearbyStore
- } from '@/api/new_store.js'
- import {
- colorChange
- } from '@/api/api.js';
- export default {
- components: {
- storeCate1,
- storeCate2,
- pageFooter
- },
- mixins: [colors],
- data() {
- return {
- info: {},
- id: 0,
- isFooter: false,
- category: '',
- storeShow: 2,
- customerType: 1,
- where: {
- latitude: 0,
- longitude: 0,
- store_id: 0
- },
- }
- },
- onLoad() {
- try {
- this.where.latitude = uni.getStorageSync('user_latitude');
- this.where.longitude = uni.getStorageSync('user_longitude');
- } catch (e) {}
- },
- onShow() {
- uni.removeStorageSync('form_type_cart');
- let _this = this
- uni.$on("handClick", res => {
- if (res) {
- _this.where.latitude = res.latitude
- _this.where.longitude = res.longitude
- _this.where.store_id = res.store_id
- _this.getStore();
- }
- // 清除监听
- uni.$off('handClick');
- })
- if (this.where.latitude && this.where.longitude) {
- this.getStore();
- } else {
- this.selfLocation();
- }
- },
- mounted() {},
- methods: {
- selfLocation() {
- let self = this
- // #ifdef H5
- if (self.$wechat.isWeixin()) {
- self.$wechat.location().then(res => {
- this.where.latitude = res.latitude;
- this.where.longitude = res.longitude;
- uni.setStorageSync('user_latitude', res.latitude);
- uni.setStorageSync('user_longitude', res.longitude);
- self.getStore();
- })
- } else {
- // #endif
- uni.getLocation({
- type: 'wgs84',
- success: (res) => {
- try {
- this.where.latitude = res.latitude;
- this.where.longitude = res.longitude;
- uni.setStorageSync('user_latitude', res.latitude);
- uni.setStorageSync('user_longitude', res.longitude);
- } catch {}
- self.getStore();
- },
- complete: function() {
- self.getStore();
- }
- });
- // #ifdef H5
- }
- // #endif
- },
- // 获取接口附近门店
- getStore() {
- this.where.latitude = uni.getStorageSync('user_latitude');
- this.where.longitude = uni.getStorageSync('user_longitude');
- getnearbyStore(this.where).then(res => {
- this.storeShow = res.data.info.home_style
- this.info = res.data.info
- this.id = this.info.id
- this.customerType = parseInt(res.data.info.customer_type)
- uni.setStorageSync('user_store_id', this.info.id);
- if (this.storeShow === 1) {
- setTimeout(() => {
- this.$refs.refresh2.getAllCategory();
- this.$refs.refresh2.getCartList(1);
- this.$refs.refresh2.getMarTop();
- }, 10)
- } else if (this.storeShow === 2) {
- setTimeout(() => {
- this.$refs.refresh.where.store_id = this.id
- this.$refs.refresh.getProducts(true)
- })
- }
- })
- },
- newDataStatus(val) {
- this.isFooter = val;
- },
- },
- onReachBottom: function() {
- if (this.storeShow === 1) {
- setTimeout(() => {
- this.$refs.refresh2.getProducts()
- }, 10)
- }
- if (this.storeShow === 2) {
- this.$refs.refresh.getProducts()
- }
- }
- }
- </script>
- <style scoped lang="scss">
- </style>
|