index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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"><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. <a class="store-phone" :href="'tel:' + item.phone"><span class="iconfont icon-dadianhua01"></span></a>
  15. </div>
  16. <div class="store-distance" @click.stop="showMaoLocation(item)">
  17. <span class="addressTxt" v-if="item.range">距离{{ item.range }}千米</span>
  18. <span class="addressTxt" v-else>查看地图</span>
  19. <span class="iconfont icon-youjian"></span>
  20. </div>
  21. </div>
  22. </div>
  23. <Loading :loaded="loaded" :loading="loading"></Loading>
  24. </div>
  25. <div>
  26. <iframe v-if="locationShow && !isWeixin" ref="geoPage" width="0" height="0" frameborder="0" style="display:none;"
  27. scrolling="no" :src="
  28. 'https://apis.map.qq.com/tools/geolocation?key=' +
  29. mapKey +
  30. '&referer=myapp'
  31. ">
  32. </iframe>
  33. </div>
  34. <div class="geoPage" v-if="mapShow">
  35. <iframe width="100%" height="100%" frameborder="0" scrolling="no" :src="
  36. 'https://apis.map.qq.com/uri/v1/geocoder?coord=' +
  37. system_store.latitude +
  38. ',' +
  39. system_store.longitude +
  40. '&referer=' +
  41. mapKey
  42. ">
  43. </iframe>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import Loading from "@/components/Loading";
  49. import {
  50. storeListApi
  51. } from "@/api/store";
  52. import {
  53. isWeixin
  54. } from "@/utils/index";
  55. // #ifdef H5
  56. import {
  57. wechatEvevt,
  58. wxShowLocation
  59. } from "@/libs/wechat";
  60. // #endif
  61. import {
  62. mapGetters
  63. } from "vuex";
  64. // import cookie from "@/utils/store/cookie";
  65. const LONGITUDE = "user_longitude";
  66. const LATITUDE = "user_latitude";
  67. const MAPKEY = "mapKey";
  68. export default {
  69. name: "storeList",
  70. components: {
  71. Loading
  72. },
  73. // computed: mapGetters(["goName"]),
  74. data() {
  75. return {
  76. page: 1,
  77. limit: 20,
  78. loaded: false,
  79. loading: false,
  80. storeList: [],
  81. mapShow: false,
  82. system_store: {},
  83. // mapKey: cookie.get(MAPKEY),
  84. locationShow: false,
  85. user_latitude: 0,
  86. user_longitude: 0
  87. };
  88. },
  89. onLoad() {
  90. try {
  91. this.user_latitude = uni.getStorageSync('user_latitude');
  92. this.user_longitude = uni.getStorageSync('user_longitude');
  93. } catch (e) {
  94. // error
  95. }
  96. },
  97. mounted() {
  98. if (this.user_latitude && this.user_longitude) {
  99. this.getList();
  100. } else {
  101. this.selfLocation();
  102. }
  103. // this.$scroll(this.$refs.container, () => {
  104. // !this.loading && this.getList();
  105. // });
  106. },
  107. methods: {
  108. selfLocation() {
  109. let self = this
  110. // if (isWeixin()) {
  111. // wxShowLocation()
  112. // .then(res => {
  113. // console.log(res);
  114. // this.getList();
  115. // })
  116. // .catch(err => {
  117. // this.$dialog.error(err.msg);
  118. // this.getList();
  119. // });
  120. // } else {
  121. // if (!cookie.get(MAPKEY))
  122. // return this.$dialog.error(
  123. // "暂无法使用查看地图,请配置您的腾讯地图key"
  124. // );
  125. // let loc;
  126. // let _this = this;
  127. // if (cookie.get(MAPKEY)) _this.locationShow = true;
  128. // //监听定位组件的message事件
  129. // window.addEventListener(
  130. // "message",
  131. // function(event) {
  132. // loc = event.data; // 接收位置信息 LONGITUDE
  133. // console.log("location", loc);
  134. // if (loc && loc.module == "geolocation") {
  135. // cookie.set(LATITUDE, loc.lat);
  136. // cookie.set(LONGITUDE, loc.lng);
  137. // _this.getList();
  138. // } else {
  139. // cookie.remove(LATITUDE);
  140. // cookie.remove(LONGITUDE);
  141. // _this.getList();
  142. // //定位组件在定位失败后,也会触发message, event.data为null
  143. // console.log("定位失败");
  144. // }
  145. // },
  146. // false
  147. // );
  148. // // this.$refs.geoPage.contentWindow.postMessage("getLocation", "*");
  149. // }
  150. uni.getLocation({
  151. type: 'wgs84',
  152. success: function(res) {
  153. try {
  154. uni.setStorageSync('user_latitude', res.latitude);
  155. uni.setStorageSync('user_longitude', res.longitude);
  156. } catch {}
  157. self.getList();
  158. },
  159. complete:function() {
  160. self.getList();
  161. }
  162. });
  163. },
  164. showMaoLocation(e) {
  165. console.log(e)
  166. // this.system_store = e;
  167. // if (isWeixin()) {
  168. // let config = {
  169. // latitude: parseFloat(this.system_store.latitude),
  170. // longitude: parseFloat(this.system_store.longitude),
  171. // name: this.system_store.name,
  172. // address:
  173. // this.system_store.address + this.system_store.detailed_address
  174. // };
  175. // wechatEvevt("openLocation", config)
  176. // .then(res => {
  177. // console.log(res);
  178. // })
  179. // .catch(res => {
  180. // if (res.is_ready) {
  181. // res.wx.openLocation(config);
  182. // }
  183. // });
  184. // } else {
  185. // if (!cookie.get(MAPKEY))
  186. // return this.$dialog.error(
  187. // "暂无法使用查看地图,请配置您的腾讯地图key"
  188. // );
  189. // this.mapShow = true;
  190. // }
  191. uni.openLocation({
  192. latitude: Number(e.latitude),
  193. longitude: Number(e.longitude),
  194. success: function() {
  195. console.log('success');
  196. Number
  197. }
  198. });
  199. },
  200. // 选中门店
  201. checked(e) {
  202. uni.$emit("handClick", {
  203. address: e
  204. });
  205. uni.navigateBack();
  206. // if (this.goName === "orders") {
  207. // this.$store.commit("GET_STORE", e);
  208. // this.$router.go(-1); //返回上一层
  209. // }
  210. },
  211. // 获取门店列表数据
  212. getList: function() {
  213. if (this.loading || this.loaded) return;
  214. this.loading = true;
  215. let data = {
  216. latitude: this.user_latitude || "", //纬度
  217. longitude: this.user_longitude || "", //经度
  218. page: this.page,
  219. limit: this.limit
  220. };
  221. storeListApi(data)
  222. .then(res => {
  223. this.loading = false;
  224. this.loaded = res.data.list.length < this.limit;
  225. this.storeList.push.apply(this.storeList, res.data.list.list);
  226. this.page = this.page + 1;
  227. })
  228. .catch(err => {
  229. this.$dialog.error(err.msg);
  230. });
  231. }
  232. },
  233. onReachBottom() {
  234. this.getList();
  235. }
  236. };
  237. </script>
  238. <style>
  239. .geoPage {
  240. position: fixed;
  241. width: 100%;
  242. height: 100%;
  243. top: 0;
  244. z-index: 10000;
  245. }
  246. .storeBox {
  247. width: 100%;
  248. background-color: #fff;
  249. padding: 0 30rpx;
  250. }
  251. .storeBox-box {
  252. width: 100%;
  253. height: auto;
  254. display: flex;
  255. align-items: center;
  256. padding: 23rpx 0;
  257. justify-content: space-between;
  258. border-bottom: 1px solid #eee;
  259. }
  260. .store-cent {
  261. display: flex;
  262. align-items: center;
  263. width: 80%;
  264. }
  265. .store-cent-left {
  266. width: 45%;
  267. }
  268. .store-img {
  269. width: 120rpx;
  270. height: 120rpx;
  271. border-radius: 6rpx;
  272. margin-right: 22rpx;
  273. }
  274. .store-img img {
  275. width: 100%;
  276. height: 100%;
  277. }
  278. .store-name {
  279. color: #282828;
  280. font-size: 30rpx;
  281. margin-bottom: 22rpx;
  282. font-weight: 800;
  283. }
  284. .store-address {
  285. color: #666666;
  286. font-size: 24rpx;
  287. }
  288. .store-phone {
  289. width: 50rpx;
  290. height: 50rpx;
  291. color: #fff;
  292. border-radius: 50%;
  293. display: block;
  294. text-align: center;
  295. line-height: 50rpx;
  296. background-color: #e83323;
  297. margin-bottom: 22rpx;
  298. }
  299. .store-distance {
  300. font-size: 22rpx;
  301. color: #e83323;
  302. }
  303. .iconfont {
  304. font-size: 20rpx;
  305. }
  306. .row-right {
  307. display: flex;
  308. flex-direction: column;
  309. align-items: flex-end;
  310. width: 33.5%;
  311. }
  312. </style>