You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
6.4 KiB

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