store_cate.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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-else-if="storeShow==2" :cart_num="cart_num" :info="info" :customerType="customerType" :isFooter="isFooter" ref="refresh">
  8. </storeCate2>
  9. <pageFooter @newDataStatus="newDataStatus"></pageFooter>
  10. </view>
  11. </template>
  12. <script>
  13. import {
  14. mapState,
  15. mapGetters
  16. } from 'vuex';
  17. import colors from "@/mixins/color";
  18. import storeCate1 from './store_cate1.vue'
  19. import storeCate2 from './store_cate2.vue'
  20. import pageFooter from '@/components/pageFooter/index.vue'
  21. import {
  22. getnearbyStore
  23. } from '@/api/new_store.js'
  24. import {
  25. colorChange
  26. } from '@/api/api.js';
  27. import {
  28. getCartCounts
  29. } from '@/api/order.js';
  30. // #ifdef MP
  31. import util from '@/utils/util.js';
  32. // #endif
  33. export default {
  34. computed: {
  35. ...mapState({
  36. nearbyStore: state => state.app.nearbyStore
  37. }),
  38. ...mapGetters(['isLogin', 'uid'])
  39. },
  40. components: {
  41. storeCate1,
  42. storeCate2,
  43. pageFooter
  44. },
  45. mixins: [colors],
  46. data() {
  47. return {
  48. info: {},
  49. id:0,
  50. isFooter: false,
  51. category: '',
  52. storeShow: 0,
  53. customerType:1,
  54. where: {
  55. latitude: 0,
  56. longitude: 0,
  57. store_id: 0
  58. },
  59. cart_num:0,
  60. mapFrom:0,
  61. }
  62. },
  63. watch: {
  64. nearbyStore(value) {
  65. this.where.store_id = value;
  66. this.getStore();
  67. }
  68. },
  69. onLoad(options){
  70. // #ifdef MP
  71. if (options.scene) {
  72. options = util.getUrlParams(decodeURIComponent(options.scene));
  73. }
  74. // #endif
  75. this.where.store_id = this.nearbyStore;
  76. if (options.mapFrom) {
  77. this.mapFrom = options.mapFrom;
  78. }
  79. if (options.id) {
  80. this.where.store_id = options.id;
  81. uni.setStorageSync('user_store_id', options.id);
  82. }
  83. // this.mapFrom = options.mapFrom || 0;
  84. // this.where.store_id = options.id;
  85. // uni.setStorageSync('user_store_id', options.id);
  86. try {
  87. this.where.latitude = uni.getStorageSync('user_latitude');
  88. this.where.longitude = uni.getStorageSync('user_longitude');
  89. if(options.mapFrom==1){
  90. this.getStore();
  91. //this.getCartNum(options.id);
  92. }else{
  93. this.selfLocation();
  94. if(!this.$util.checkOpenGPSServiceByAndroidIOS()){
  95. this.getStore();
  96. }
  97. }
  98. } catch (e) {
  99. this.getStore();
  100. }
  101. },
  102. onUnload(){
  103. this.mapFrom = 0;
  104. uni.$off('newAttrNum')
  105. },
  106. onHide() {
  107. this.mapFrom = 0;
  108. },
  109. onShow(){
  110. // if(uni.getStorageSync('form_type_cart')){
  111. // this.getStore();
  112. // }
  113. if(this.mapFrom==0){
  114. if(this.storeShow==1){
  115. setTimeout(()=>{
  116. this.$refs.refresh2.getNoCart();
  117. },10)
  118. }
  119. }
  120. },
  121. mounted() {},
  122. methods: {
  123. otherFun(object){
  124. if(!!object){
  125. if(this.storeShow==1){
  126. this.$refs.refresh2.updateFun(object);
  127. }
  128. }
  129. },
  130. selfLocation() {
  131. let self = this
  132. // #ifdef H5
  133. if (self.$wechat.isWeixin()) {
  134. self.$wechat.location().then(res => {
  135. // this.where.latitude = res.latitude;
  136. // this.where.longitude = res.longitude;
  137. uni.setStorageSync('user_latitude', res.latitude);
  138. uni.setStorageSync('user_longitude', res.longitude);
  139. self.getStore();
  140. }).catch(err=>{
  141. self.getStore();
  142. })
  143. } else {
  144. // #endif
  145. uni.getLocation({
  146. type: 'gcj02',
  147. success: (res) => {
  148. try {
  149. // this.where.latitude = res.latitude;
  150. // this.where.longitude = res.longitude;
  151. uni.setStorageSync('user_latitude', res.latitude);
  152. uni.setStorageSync('user_longitude', res.longitude);
  153. } catch {}
  154. // self.getStore();
  155. },
  156. fail:(err)=>{
  157. // return self.$util.Tips({
  158. // title: err.errMsg
  159. // });
  160. },
  161. complete: function() {
  162. self.getStore();
  163. }
  164. });
  165. // #ifdef H5
  166. }
  167. // #endif
  168. },
  169. // 获取接口附近门店
  170. getStore() {
  171. this.where.latitude = uni.getStorageSync('user_latitude');
  172. this.where.longitude = uni.getStorageSync('user_longitude');
  173. getnearbyStore(this.where).then(res => {
  174. let info = res.data.info;
  175. this.cart_num = res.data.cart_num;
  176. if(Object.prototype.toString.call(info) === "[object Array]"){
  177. this.info = {}
  178. this.storeShow = 2;
  179. }else{
  180. this.info = res.data.info
  181. this.storeShow = res.data.info.home_style;
  182. }
  183. this.id = this.info.id
  184. this.customerType = parseInt(res.data.info.customer_type)
  185. uni.setStorageSync('user_store_id', this.info.id);
  186. // #ifdef H5 || MP
  187. this.info = { ...this.info, store_splicing_switch: res.data.store_splicing_switch };
  188. // #endif
  189. if (this.storeShow === 1) {
  190. setTimeout(()=>{
  191. this.$refs.refresh2.getAllCategory();
  192. if(this.isLogin){
  193. this.$refs.refresh2.getCartList(1);
  194. }
  195. this.$refs.refresh2.getMarTop();
  196. },10)
  197. } else if (this.storeShow === 2) {
  198. setTimeout(()=>{
  199. this.$refs.refresh.where.store_id = this.id
  200. this.$refs.refresh.loadend = false
  201. this.$refs.refresh.getProducts(true)
  202. })
  203. }
  204. })
  205. },
  206. newDataStatus(val) {
  207. this.isFooter = val;
  208. },
  209. },
  210. onReachBottom: function() {
  211. if (this.storeShow === 1) {
  212. setTimeout(()=>{
  213. this.$refs.refresh2.getProducts()
  214. },10)
  215. }
  216. if(this.storeShow === 2){
  217. this.$refs.refresh.getProducts()
  218. }
  219. }
  220. }
  221. </script>
  222. <style scoped lang="scss">
  223. /deep/.goodCate .uni-badge-left-margin .uni-badge--error{
  224. background-color: #fff !important;
  225. color: var(--view-theme);
  226. border-color: var(--view-theme);
  227. z-index: 8;
  228. }
  229. /deep/.goodCate .footer .cartIcon .uni-badge-left-margin .uni-badge--error{
  230. right: 0 !important;
  231. top: 10px !important;
  232. }
  233. /deep/.one .uni-badge-left-margin .uni-badge--error{
  234. background-color: var(--view-theme) !important;
  235. color: #fff;
  236. border-color: #fff;
  237. z-index: 8;
  238. }
  239. /deep/.mask{
  240. z-index: 99;
  241. }
  242. /deep/.good-cate {
  243. padding: 80rpx;
  244. }
  245. /deep/.address-window {
  246. /* #ifdef H5 */
  247. bottom: 94rpx !important;
  248. bottom: calc(94rpx+ constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  249. bottom: calc(94rpx + env(safe-area-inset-bottom)) !important; ///兼容 IOS>11.2/
  250. /* #endif */
  251. /* #ifndef H5 */
  252. bottom: 98rpx;
  253. bottom: calc(98rpx + constant(safe-area-inset-bottom)) !important; ///兼容 IOS<11.2/
  254. bottom: calc(98rpx + env(safe-area-inset-bottom)) !important; ///兼容 IOS>11.2/
  255. /* #endif */
  256. &.ons {
  257. bottom: 0 !important;
  258. bottom: constant(safe-area-inset-bottom) !important; ///兼容 IOS<11.2/
  259. bottom: env(safe-area-inset-bottom) !important; ///兼容 IOS>11.2/
  260. }
  261. }
  262. </style>