index.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <template>
  2. <!-- 门店列表 -->
  3. <view class="list">
  4. <view class="item" v-for="(item, index) in storeList" :key="index" v-if="index<num">
  5. <view class="name line1"><text class="iconfont icon-shangjiadingdan"></text>{{item.name}}</view>
  6. <view class="address line1"><text class="font-num" v-if="item.range">距您{{ item.range }}km</text><text class="spot" v-if="item.range">·</text>{{ item.address }}{{ ", " + item.detailed_address }}</view>
  7. <!-- #ifdef H5 || APP-PLUS -->
  8. <slot name="bottom" :item="item"></slot>
  9. <!-- #endif -->
  10. <!-- #ifdef MP -->
  11. <slot name="bottom{{index}}"></slot>
  12. <!-- #endif -->
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. import {
  18. storeListApi
  19. } from "@/api/store";
  20. import {
  21. isWeixin
  22. } from "@/utils/index";
  23. // #ifdef H5
  24. import {
  25. wechatEvevt,
  26. wxShowLocation
  27. } from "@/libs/wechat";
  28. // #endif
  29. import {
  30. mapGetters
  31. } from "vuex";
  32. const LONGITUDE = "user_longitude";
  33. const LATITUDE = "user_latitude";
  34. const MAPKEY = "mapKey";
  35. export default {
  36. name: "storeList",
  37. props: {
  38. num : {
  39. type: Number,
  40. default: 1,
  41. },
  42. ids: {
  43. type: Number,
  44. default: 0,
  45. }
  46. },
  47. data() {
  48. return {
  49. page: 1,
  50. limit: 20,
  51. loaded: false,
  52. loading: false,
  53. storeList: [],
  54. system_store: {},
  55. user_latitude: 0,
  56. user_longitude: 0
  57. };
  58. },
  59. created() {
  60. try {
  61. this.user_latitude = uni.getStorageSync('user_latitude');
  62. this.user_longitude = uni.getStorageSync('user_longitude');
  63. } catch (e) {}
  64. },
  65. mounted() {
  66. // if (this.user_latitude && this.user_longitude) {
  67. // this.getList();
  68. // } else {
  69. // this.selfLocation();
  70. // }
  71. this.selfLocation();
  72. if(!this.$util.checkOpenGPSServiceByAndroidIOS()){
  73. this.getList();
  74. }
  75. },
  76. methods: {
  77. call(phone) {
  78. uni.makePhoneCall({
  79. phoneNumber: phone,
  80. });
  81. },
  82. selfLocation() {
  83. let self = this
  84. // #ifdef H5
  85. if (self.$wechat.isWeixin()) {
  86. self.$wechat.location().then(res => {
  87. this.user_latitude = res.latitude;
  88. this.user_longitude = res.longitude;
  89. uni.setStorageSync('user_latitude', res.latitude);
  90. uni.setStorageSync('user_longitude', res.longitude);
  91. self.getList();
  92. }).catch(err=>{
  93. self.getList();
  94. })
  95. } else {
  96. // #endif
  97. uni.getLocation({
  98. type: 'wgs84',
  99. success: (res) => {
  100. try {
  101. this.user_latitude = res.latitude;
  102. this.user_longitude = res.longitude;
  103. uni.setStorageSync('user_latitude', res.latitude);
  104. uni.setStorageSync('user_longitude', res.longitude);
  105. } catch {}
  106. self.getList();
  107. },
  108. complete: function() {
  109. self.getList();
  110. }
  111. });
  112. // #ifdef H5
  113. }
  114. // #endif
  115. },
  116. showMaoLocation(e) {
  117. let self = this;
  118. // #ifdef H5
  119. if (self.$wechat.isWeixin()) {
  120. self.$wechat.seeLocation({
  121. latitude: Number(e.latitude),
  122. longitude: Number(e.longitude),
  123. name: e.name,
  124. address: `${e.address}-${e.detailed_address}`,
  125. }).then(res => {
  126. })
  127. } else {
  128. // #endif
  129. uni.openLocation({
  130. latitude: Number(e.latitude),
  131. longitude: Number(e.longitude),
  132. name: e.name,
  133. address: `${e.address}-${e.detailed_address}`,
  134. success: function() {
  135. Number
  136. }
  137. });
  138. // #ifdef H5
  139. }
  140. // #endif
  141. },
  142. // 获取门店列表数据
  143. getList: function() {
  144. if (this.loading || this.loaded) return;
  145. this.loading = true;
  146. let data = {
  147. latitude: this.user_latitude || "", //纬度
  148. longitude: this.user_longitude || "", //经度
  149. page: this.page,
  150. limit: this.limit,
  151. product_id: this.ids
  152. };
  153. storeListApi(data)
  154. .then(res => {
  155. this.loading = false;
  156. this.loaded = res.data.list.length < this.limit;
  157. this.storeList.push.apply(this.storeList, res.data.list.list);
  158. if(this.page == 1){
  159. this.$emit('getStoreList',this.storeList.length)
  160. }
  161. this.page = this.page + 1;
  162. })
  163. .catch(err => {
  164. this.$util.Tips({
  165. title: err
  166. })
  167. });
  168. }
  169. },
  170. onReachBottom() {
  171. this.getList();
  172. }
  173. };
  174. </script>
  175. <style lang="scss">
  176. .list{
  177. width: 508rpx;
  178. margin-left: 28rpx;
  179. .item{
  180. font-size: 26rpx;
  181. color: #333;
  182. .iconfont{
  183. font-size: 30rpx;
  184. margin-right: 10rpx;
  185. color: #333;
  186. }
  187. .address{
  188. font-size: 22rpx;
  189. margin-top: 10rpx;
  190. .spot{
  191. margin: 0 20rpx;
  192. }
  193. }
  194. }
  195. }
  196. </style>