index.vue 5.7 KB

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