store-choose.vue 6.3 KB

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