store-choose.vue 6.2 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. latitude: 26.5737,
  82. longitude: 106.7135,
  83. abcname: '123',
  84. idx: 0
  85. }, {
  86. latitude: 23.099994,
  87. longitude: 113.322520,
  88. abcname: '123',
  89. idx: 1
  90. }, {
  91. latitude: 23.099994,
  92. longitude: 113.326520,
  93. abcname: '123',
  94. idx: 2
  95. }, {
  96. latitude: 23.096994,
  97. longitude: 113.329520,
  98. abcname: '123',
  99. idx: 3
  100. }
  101. ],
  102. type: '1'
  103. }
  104. },
  105. onReady() {
  106. // 初始化地图
  107. this.initMap();
  108. },
  109. onLoad(option) {
  110. // 获取商店数据
  111. this.getStoreListData();
  112. // 判断Openid是否为空
  113. if(option.type){
  114. this.type = option.type;
  115. }
  116. },
  117. methods: {
  118. // 选择门店
  119. selectStore(item){
  120. // 更新用户选择的门店信息
  121. uni.setStorageSync('storeInfo', item);
  122. uni.switchTab({
  123. url: '/pages/index/index',
  124. })
  125. },
  126. // 获取门店列表数据
  127. getStoreListData(){
  128. let that = this;
  129. this.$api.storeList({data:this.reqParm}).then((res)=>{
  130. console.log(res)
  131. that.storeList = res.data.data
  132. // 添加坐标点
  133. // that.addMarkers();
  134. }).catch(() =>{
  135. console.log("获取用户门店列表报错")
  136. // uni.showToast({
  137. // title: "操作失败"
  138. // })
  139. })
  140. },
  141. initMap(){
  142. this._mapContext = uni.createMapContext("map", this);
  143. // 仅调用初始化,才会触发 on.("markerClusterCreate", (e) => {})
  144. this._mapContext.initMarkerCluster({
  145. enableDefaultStyle: false,
  146. zoomOnClick: true,
  147. gridSize: 60,
  148. complete(res) {
  149. console.log('initMarkerCluster', res)
  150. }
  151. });
  152. this._mapContext.on("markerClusterCreate", (e) => {
  153. console.log("markerClusterCreate", e);
  154. });
  155. },
  156. addMarkers() {
  157. const markers = []
  158. // 处理点的数据
  159. this.storeList.forEach((p, i) => {
  160. console.log(i)
  161. markers.push(
  162. Object.assign({},{
  163. id: i,
  164. iconPath: this.img,
  165. width: 50,
  166. height: 50,
  167. // joinCluster: true, // 指定了该参数才会参与聚合
  168. label: {
  169. width: 150,
  170. height: 30,
  171. // borderWidth: 1,
  172. // borderRadius: 10,
  173. // bgColor: 'red',
  174. textAlign: 'center',
  175. // anchorX: -40,
  176. // anchorY: -70,
  177. content: p.storeName
  178. }
  179. },p)
  180. )
  181. })
  182. // 添加点
  183. this._mapContext.addMarkers({
  184. markers,
  185. clear: false,
  186. complete(res) {
  187. console.log('addMarkers', res)
  188. }
  189. })
  190. },
  191. // 点击地图上的点
  192. handleMarkerTap(marker){
  193. console.log('Marker tapped:', marker);
  194. console.log(this.storeList[marker.markerId])
  195. },
  196. // 打电话
  197. makePhone(phoneNumber){
  198. uni.makePhoneCall({
  199. phoneNumber: phoneNumber
  200. });
  201. },
  202. // 去下单页面
  203. gotoOrder(item){
  204. this.type = '2';
  205. this.selectStore(item);
  206. },
  207. },
  208. };
  209. </script>
  210. <style scoped lang="scss">
  211. .h-store-wrap{
  212. margin-top: 12px;
  213. background: #fff;
  214. padding-top:4px;
  215. padding-left: 12px;
  216. padding-right: 12px;
  217. border-radius: 12px;
  218. .h-store-content{
  219. margin-top: 12px;
  220. margin-bottom: 12px;
  221. background: #fafafa;
  222. padding: 12px;
  223. border-radius: 6px;
  224. font-family: PingFangSC-Regular, PingFang SC;
  225. .h-row{
  226. display: flex;
  227. justify-content: space-between;
  228. .h-left-value{
  229. .h-name{
  230. font-size: 28rpx;
  231. font-weight: 400;
  232. color: #333333;
  233. line-height: 40rpx;
  234. }
  235. .h-text{
  236. font-size: 24rpx;
  237. font-weight: 400;
  238. color: #999999;
  239. line-height: 40rpx;
  240. display: flex;
  241. align-items: center;
  242. image{
  243. margin-right: 12rpx;
  244. height: 24rpx;
  245. width: 24rpx;
  246. }
  247. }
  248. }
  249. .h-right-value{
  250. .h-text{
  251. font-size: 10px;
  252. font-weight: 400;
  253. color: #999999;
  254. line-height: 18px;
  255. }
  256. }
  257. .h-flex{
  258. display: flex;
  259. justify-content: space-between;
  260. image{
  261. height: 30px;
  262. width: 30px;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. .h-area-wrap{
  269. margin-right: 12px;
  270. margin-left: 12px;
  271. margin-top: 12px;
  272. }
  273. .h-search{
  274. font-size: 14px;
  275. display: flex;
  276. padding-left: 12px;
  277. padding-top: 8px;
  278. padding-right: 12px;
  279. background: #fff;
  280. padding-bottom: 8px;
  281. border-radius: 6px;
  282. .h-time{
  283. width: 30%;
  284. display: flex;
  285. .time{
  286. padding-right: 2px;
  287. }
  288. }
  289. .h-name{
  290. width: 70%;
  291. text-align: right;
  292. display: flex;
  293. justify-content: flex-end;
  294. .name{
  295. padding-right: 6px;
  296. }
  297. }
  298. }
  299. </style>