store-choose.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="container">
  3. <!-- 地图容器 -->
  4. <view class="map-wrap">
  5. <map style="width: 100%; height: 300px;"
  6. id="map"
  7. :latitude="latitude"
  8. :longitude="longitude"
  9. :scale="scale"
  10. :show-location="true"
  11. :enable-building="true"
  12. :markers="markers"
  13. @markertap="handleMarkerTap"
  14. >
  15. </map>
  16. </view>
  17. <!-- 地区 -->
  18. <!-- <view class="h-area-wrap">
  19. <view class="h-search">
  20. <view class="h-time">
  21. <view class="time">{{areaName}}</view>
  22. <u-icon name="arrow-down" color="#000" size="18"></u-icon>
  23. </view>
  24. <view class="h-name">
  25. </view>
  26. </view>
  27. </view> -->
  28. <!-- 门店列表 -->
  29. <view class="h-store-wrap">
  30. <view v-for="(item,index) in storeList" class="h-store-content">
  31. <view @click="selectStore(item)" class="h-row">
  32. <view class="h-left-value">
  33. <text class="h-name">{{item.storeName}}</text>
  34. </view>
  35. <view class="h-right-value">
  36. <!-- <text class="h-text">4.2km</text> -->
  37. </view>
  38. </view>
  39. <view class="h-row" @click="selectStore(item)">
  40. <view class="h-left-value">
  41. <view class="h-text">
  42. <image src="../../static/goods/dingwei.png" mode=""></image>
  43. <text>地址:{{item.address}}</text>
  44. </view>
  45. <view class="h-text">
  46. <image src="../../static/goods/time.png" mode=""></image>
  47. 营业时间:
  48. <text>{{item.tradeTime}}~{{item.gooutTime}}</text>
  49. </view>
  50. <view class="h-text">
  51. <image src="../../static/goods/zixun.png" mode=""></image>
  52. 咨询热线:
  53. <text>{{item.phone || ''}}</text>
  54. </view>
  55. </view>
  56. <!-- <view class="h-right-value h-flex">-->
  57. <!-- <view class="phone">-->
  58. <!-- <image src="../../static/goods/u291.png" mode=""></image>-->
  59. <!-- </view>-->
  60. <!-- <view class="sure">-->
  61. <!-- <image src="../../static/goods/u292.png" mode=""></image>-->
  62. <!-- </view>-->
  63. <!-- </view>-->
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. export default {
  71. data() {
  72. return {
  73. markers:[],
  74. areaName: '贵阳市',
  75. latitude: 26.5737,
  76. longitude: 106.7135,
  77. scale: 10,
  78. img: '/static/index/u55.png',
  79. reqParm: {
  80. auth: true,
  81. longitude: 0,
  82. latitude: 0
  83. },
  84. storeList: [],
  85. type: '1'
  86. }
  87. },
  88. onReady() {
  89. // 初始化地图
  90. // this.initMap();
  91. },
  92. onLoad(option) {
  93. // 获取商店数据
  94. this.getStoreListData();
  95. this.getLocation()
  96. // 判断Openid是否为空
  97. if (option.type) {
  98. this.type = option.type;
  99. }
  100. },
  101. methods: {
  102. getLocation() {
  103. let that = this
  104. uni.getLocation({
  105. type: 'gcj02',
  106. success: function (res) {
  107. that.latitude = res.latitude; // 纬度
  108. that.longitude = res.longitude; // 经度
  109. let mapContext = uni.createMapContext("map", this);
  110. mapContext.moveToLocation()
  111. },
  112. fail: function (fail) {
  113. console.log('获取用户地址失败==》', fail)
  114. },
  115. complete: function (complete) {
  116. console.log('获取用户地址失败or成功==》', complete)
  117. }
  118. })
  119. },
  120. // 选择门店
  121. selectStore(item) {
  122. // 更新用户选择的门店信息
  123. uni.setStorageSync('storeInfo', item);
  124. uni.switchTab({
  125. url: '/pages/index/index',
  126. })
  127. },
  128. // 获取门店列表数据
  129. getStoreListData() {
  130. let that = this;
  131. this.$api.storeList({
  132. latitude: this.latitude,
  133. longitude: this.longitude,
  134. }).then((res) => {
  135. console.log(res)
  136. that.storeList = res.data.data
  137. // 添加坐标点
  138. that.addMarkers();
  139. }).catch(() => {
  140. console.log("获取用户门店列表报错")
  141. })
  142. },
  143. addMarkers() {
  144. this.markers = []
  145. // 处理点的数据
  146. this.storeList.forEach((p, i) => {
  147. this.markers.push(
  148. {
  149. id: i,
  150. iconPath: '/static/index/u55.png',
  151. width: 30,
  152. height: 30,
  153. latitude: p.latitude,
  154. longitude: p.longitude,
  155. // joinCluster: true, // 指定了该参数才会参与聚合
  156. label: {
  157. width: 150,
  158. height: 30,
  159. textAlign: 'center',
  160. content: p.storeName
  161. }
  162. }
  163. )
  164. })
  165. },
  166. // 点击地图上的点
  167. handleMarkerTap(marker) {
  168. console.log('Marker tapped:', marker);
  169. console.log(this.storeList[marker.markerId])
  170. },
  171. // 打电话
  172. makePhone(phoneNumber) {
  173. uni.makePhoneCall({
  174. phoneNumber: phoneNumber
  175. });
  176. },
  177. // 去下单页面
  178. gotoOrder(item) {
  179. this.type = '2';
  180. this.selectStore(item);
  181. },
  182. },
  183. };
  184. </script>
  185. <style scoped lang="scss">
  186. .h-store-wrap {
  187. margin-top: 12px;
  188. background: #fff;
  189. padding-top: 4px;
  190. padding-left: 12px;
  191. padding-right: 12px;
  192. border-radius: 12px;
  193. .h-store-content {
  194. margin-top: 12px;
  195. margin-bottom: 12px;
  196. background: #fafafa;
  197. padding: 12px;
  198. border-radius: 6px;
  199. font-family: PingFangSC-Regular, PingFang SC;
  200. .h-row {
  201. display: flex;
  202. justify-content: space-between;
  203. .h-left-value {
  204. .h-name {
  205. font-size: 28rpx;
  206. font-weight: 400;
  207. color: #333333;
  208. line-height: 40rpx;
  209. }
  210. .h-text {
  211. font-size: 24rpx;
  212. font-weight: 400;
  213. color: #999999;
  214. line-height: 40rpx;
  215. display: flex;
  216. align-items: center;
  217. image {
  218. margin-right: 12rpx;
  219. height: 24rpx;
  220. width: 24rpx;
  221. }
  222. }
  223. }
  224. .h-right-value {
  225. .h-text {
  226. font-size: 10px;
  227. font-weight: 400;
  228. color: #999999;
  229. line-height: 18px;
  230. }
  231. }
  232. .h-flex {
  233. display: flex;
  234. justify-content: space-between;
  235. image {
  236. height: 30px;
  237. width: 30px;
  238. }
  239. }
  240. }
  241. }
  242. }
  243. .h-area-wrap {
  244. margin-right: 12px;
  245. margin-left: 12px;
  246. margin-top: 12px;
  247. }
  248. .h-search {
  249. font-size: 14px;
  250. display: flex;
  251. padding-left: 12px;
  252. padding-top: 8px;
  253. padding-right: 12px;
  254. background: #fff;
  255. padding-bottom: 8px;
  256. border-radius: 6px;
  257. .h-time {
  258. width: 30%;
  259. display: flex;
  260. .time {
  261. padding-right: 2px;
  262. }
  263. }
  264. .h-name {
  265. width: 70%;
  266. text-align: right;
  267. display: flex;
  268. justify-content: flex-end;
  269. .name {
  270. padding-right: 6px;
  271. }
  272. }
  273. }
  274. </style>