index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. },
  72. methods: {
  73. call(phone) {
  74. uni.makePhoneCall({
  75. phoneNumber: phone,
  76. });
  77. },
  78. selfLocation() {
  79. let self = this
  80. // #ifdef H5
  81. if (self.$wechat.isWeixin()) {
  82. self.$wechat.location().then(res => {
  83. this.user_latitude = res.latitude;
  84. this.user_longitude = res.longitude;
  85. uni.setStorageSync('user_latitude', res.latitude);
  86. uni.setStorageSync('user_longitude', res.longitude);
  87. self.getList();
  88. })
  89. } else {
  90. // #endif
  91. uni.getLocation({
  92. type: 'wgs84',
  93. success: (res) => {
  94. try {
  95. this.user_latitude = res.latitude;
  96. this.user_longitude = res.longitude;
  97. uni.setStorageSync('user_latitude', res.latitude);
  98. uni.setStorageSync('user_longitude', res.longitude);
  99. } catch {}
  100. self.getList();
  101. },
  102. complete: function() {
  103. self.getList();
  104. }
  105. });
  106. // #ifdef H5
  107. }
  108. // #endif
  109. },
  110. showMaoLocation(e) {
  111. let self = this;
  112. // #ifdef H5
  113. if (self.$wechat.isWeixin()) {
  114. self.$wechat.seeLocation({
  115. latitude: Number(e.latitude),
  116. longitude: Number(e.longitude),
  117. name: e.name,
  118. address: `${e.address}-${e.detailed_address}`,
  119. }).then(res => {
  120. })
  121. } else {
  122. // #endif
  123. uni.openLocation({
  124. latitude: Number(e.latitude),
  125. longitude: Number(e.longitude),
  126. name: e.name,
  127. address: `${e.address}-${e.detailed_address}`,
  128. success: function() {
  129. Number
  130. }
  131. });
  132. // #ifdef H5
  133. }
  134. // #endif
  135. },
  136. // 获取门店列表数据
  137. getList: function() {
  138. if (this.loading || this.loaded) return;
  139. this.loading = true;
  140. let data = {
  141. latitude: this.user_latitude || "", //纬度
  142. longitude: this.user_longitude || "", //经度
  143. page: this.page,
  144. limit: this.limit,
  145. product_id: this.ids
  146. };
  147. storeListApi(data)
  148. .then(res => {
  149. this.loading = false;
  150. this.loaded = res.data.list.length < this.limit;
  151. this.storeList.push.apply(this.storeList, res.data.list.list);
  152. if(this.page == 1){
  153. this.$emit('getStoreList',this.storeList.length)
  154. }
  155. this.page = this.page + 1;
  156. })
  157. .catch(err => {
  158. this.$util.Tips({
  159. title: err
  160. })
  161. });
  162. }
  163. },
  164. onReachBottom() {
  165. this.getList();
  166. }
  167. };
  168. </script>
  169. <style lang="scss">
  170. .list{
  171. width: 508rpx;
  172. margin-left: 28rpx;
  173. .item{
  174. font-size: 26rpx;
  175. color: #333;
  176. .iconfont{
  177. font-size: 30rpx;
  178. margin-right: 10rpx;
  179. color: #333;
  180. }
  181. .address{
  182. font-size: 22rpx;
  183. margin-top: 10rpx;
  184. .spot{
  185. margin: 0 20rpx;
  186. }
  187. }
  188. }
  189. }
  190. </style>