index.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <div :style="colorStyle">
  3. <div class="storeBox" ref="container">
  4. <div class="storeBox-box" v-for="(item, index) in storeList" :key="index" @click.stop="checked(item)">
  5. <div class="store-img"><img :src="item.image" lazy-load="true" /></div>
  6. <div class="store-cent-left">
  7. <div class="store-name">{{ item.name }}</div>
  8. <div class="store-address line1">
  9. {{ item.address }}{{ ", " + item.detailed_address }}
  10. </div>
  11. </div>
  12. <div class="row-right">
  13. <div>
  14. <!-- #ifdef H5 -->
  15. <a class="store-phone acea-row row-center-wrapper" :href="'tel:' + item.phone"><span
  16. class="iconfont icon-dadianhua01"></span></a>
  17. <!-- #endif -->
  18. <!-- #ifdef MP || APP-PLUS -->
  19. <view class="store-phone acea-row row-center-wrapper" @click.stop="call(item.phone)"><text
  20. class="iconfont icon-dadianhua01"></text></view>
  21. <!-- #endif -->
  22. </div>
  23. <div class="store-distance" @click.stop="showMaoLocation(item)">
  24. <span class="addressTxt" v-if="item.range">{{ item.range }}{{$t(`千米距离`)}}</span>
  25. <span class="addressTxt" v-else>{{$t(`查看地图`)}}</span>
  26. <span class="iconfont icon-youjian"></span>
  27. </div>
  28. </div>
  29. </div>
  30. <Loading :loaded="loaded" :loading="loading"></Loading>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import Loading from "@/components/Loading";
  36. import {
  37. storeListApi
  38. } from "@/api/store";
  39. import {
  40. isWeixin
  41. } from "@/utils/index";
  42. // #ifdef H5
  43. import {
  44. wechatEvevt,
  45. wxShowLocation
  46. } from "@/libs/wechat";
  47. // #endif
  48. import colors from "@/mixins/color";
  49. import {
  50. mapGetters
  51. } from "vuex";
  52. const LONGITUDE = "user_longitude";
  53. const LATITUDE = "user_latitude";
  54. const MAPKEY = "mapKey";
  55. export default {
  56. name: "storeList",
  57. components: {
  58. Loading
  59. },
  60. mixins: [colors],
  61. data() {
  62. return {
  63. page: 1,
  64. limit: 20,
  65. loaded: false,
  66. loading: false,
  67. storeList: [],
  68. system_store: {},
  69. user_latitude: 0,
  70. user_longitude: 0
  71. };
  72. },
  73. onLoad() {
  74. try {
  75. this.user_latitude = uni.getStorageSync('user_latitude');
  76. this.user_longitude = uni.getStorageSync('user_longitude');
  77. } catch (e) {}
  78. },
  79. mounted() {
  80. if (this.user_latitude && this.user_longitude) {
  81. this.getList();
  82. } else {
  83. this.selfLocation();
  84. }
  85. },
  86. methods: {
  87. call(phone) {
  88. uni.makePhoneCall({
  89. phoneNumber: phone,
  90. });
  91. },
  92. selfLocation() {
  93. let self = this
  94. // #ifdef H5
  95. if (self.$wechat.isWeixin()) {
  96. self.$wechat.location().then(res => {
  97. this.user_latitude = res.latitude;
  98. this.user_longitude = res.longitude;
  99. uni.setStorageSync('user_latitude', res.latitude);
  100. uni.setStorageSync('user_longitude', res.longitude);
  101. self.getList();
  102. })
  103. } else {
  104. // #endif
  105. uni.getLocation({
  106. type: 'wgs84',
  107. success: (res) => {
  108. try {
  109. this.user_latitude = res.latitude;
  110. this.user_longitude = res.longitude;
  111. uni.setStorageSync('user_latitude', res.latitude);
  112. uni.setStorageSync('user_longitude', res.longitude);
  113. } catch {}
  114. self.getList();
  115. },
  116. complete: function() {
  117. self.getList();
  118. }
  119. });
  120. // #ifdef H5
  121. }
  122. // #endif
  123. },
  124. showMaoLocation(e) {
  125. let self = this;
  126. // #ifdef H5
  127. if (self.$wechat.isWeixin()) {
  128. self.$wechat.seeLocation({
  129. latitude: Number(e.latitude),
  130. longitude: Number(e.longitude)
  131. }).then(res => {
  132. })
  133. } else {
  134. // #endif
  135. uni.openLocation({
  136. latitude: Number(e.latitude),
  137. longitude: Number(e.longitude),
  138. name: e.name,
  139. address: `${e.address}-${e.detailed_address}`,
  140. success: function() {
  141. Number
  142. }
  143. });
  144. // #ifdef H5
  145. }
  146. // #endif
  147. },
  148. // 选中门店
  149. checked(e) {
  150. uni.$emit("handClick", {
  151. address: e
  152. });
  153. uni.navigateBack();
  154. },
  155. // 获取门店列表数据
  156. getList: function() {
  157. if (this.loading || this.loaded) return;
  158. this.loading = true;
  159. let data = {
  160. latitude: this.user_latitude || "", //纬度
  161. longitude: this.user_longitude || "", //经度
  162. page: this.page,
  163. limit: this.limit
  164. };
  165. storeListApi(data)
  166. .then(res => {
  167. this.loading = false;
  168. this.loaded = res.data.list.length < this.limit;
  169. this.storeList.push.apply(this.storeList, res.data.list.list);
  170. this.page = this.page + 1;
  171. })
  172. .catch(err => {
  173. this.$util.Tips({
  174. title: err
  175. })
  176. });
  177. }
  178. },
  179. onReachBottom() {
  180. this.getList();
  181. }
  182. };
  183. </script>
  184. <style lang="scss">
  185. .geoPage {
  186. position: fixed;
  187. width: 100%;
  188. height: 100%;
  189. top: 0;
  190. z-index: 10000;
  191. }
  192. .storeBox {
  193. width: 100%;
  194. background-color: #fff;
  195. padding: 0 30rpx;
  196. }
  197. .storeBox-box {
  198. width: 100%;
  199. height: auto;
  200. display: flex;
  201. align-items: center;
  202. padding: 23rpx 0;
  203. justify-content: space-between;
  204. border-bottom: 1px solid #eee;
  205. }
  206. .store-cent {
  207. display: flex;
  208. align-items: center;
  209. width: 80%;
  210. }
  211. .store-cent-left {
  212. width: 45%;
  213. }
  214. .store-img {
  215. width: 120rpx;
  216. height: 120rpx;
  217. border-radius: 6rpx;
  218. margin-right: 22rpx;
  219. }
  220. .store-img img {
  221. width: 100%;
  222. height: 100%;
  223. }
  224. .store-name {
  225. color: #282828;
  226. font-size: 30rpx;
  227. margin-bottom: 22rpx;
  228. font-weight: 800;
  229. }
  230. .store-address {
  231. color: #666666;
  232. font-size: 24rpx;
  233. }
  234. .store-phone {
  235. width: 50rpx;
  236. height: 50rpx;
  237. color: #fff;
  238. border-radius: 50%;
  239. background-color: var(--view-theme);
  240. margin-bottom: 22rpx;
  241. text-decoration: none;
  242. .icon-dadianhua01 {
  243. font-size: 22rpx;
  244. }
  245. }
  246. .store-distance {
  247. font-size: 22rpx;
  248. color: var(--view-theme);
  249. }
  250. .iconfont {
  251. font-size: 20rpx;
  252. }
  253. .row-right {
  254. display: flex;
  255. flex-direction: column;
  256. align-items: flex-end;
  257. width: 33.5%;
  258. }
  259. </style>