store-choose.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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">
  38. <view @click="selectStore(item)" class="h-left-value">
  39. <view class="h-text">
  40. <image src="../../static/index/u55.png" mode=""></image>
  41. <text>地址:{{item.address}}</text>
  42. </view>
  43. <view class="h-text">
  44. <image src="../../static/me/u1796.png" mode=""></image>
  45. 营业时间:<text>{{item.tradeTime}}~{{item.gooutTime}}</text>
  46. </view>
  47. </view>
  48. <view class="h-right-value h-flex">
  49. <view class="phone">
  50. <image src="../../static/goods/u291.png" mode=""></image>
  51. </view>
  52. <view class="sure">
  53. <image src="../../static/goods/u292.png" mode=""></image>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. </template>
  61. <script>
  62. export default {
  63. data() {
  64. return {
  65. areaName: '贵阳市',
  66. latitude: 26.5737,
  67. longitude: 106.7135,
  68. scale: 12,
  69. img: '/static/index/u55.png',
  70. reqParm: {
  71. auth: true,
  72. longitude: 0,
  73. latitude: 0
  74. },
  75. storeList: [
  76. {
  77. latitude: 26.5737,
  78. longitude: 106.7135,
  79. abcname: '123',
  80. idx: 0
  81. }, {
  82. latitude: 23.099994,
  83. longitude: 113.322520,
  84. abcname: '123',
  85. idx: 1
  86. }, {
  87. latitude: 23.099994,
  88. longitude: 113.326520,
  89. abcname: '123',
  90. idx: 2
  91. }, {
  92. latitude: 23.096994,
  93. longitude: 113.329520,
  94. abcname: '123',
  95. idx: 3
  96. }
  97. ],
  98. type: '1'
  99. }
  100. },
  101. onReady() {
  102. // 初始化地图
  103. this.initMap();
  104. },
  105. onLoad(option) {
  106. // 获取商店数据
  107. this.getStoreListData();
  108. // 判断Openid是否为空
  109. if(option.type){
  110. this.type = option.type;
  111. }
  112. },
  113. methods: {
  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({data:this.reqParm}).then((res)=>{
  126. console.log(res)
  127. that.storeList = res.data.data
  128. // 添加坐标点
  129. // that.addMarkers();
  130. }).catch(() =>{
  131. console.log("获取用户门店列表报错")
  132. // uni.showToast({
  133. // title: "操作失败"
  134. // })
  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.on("markerClusterCreate", (e) => {
  149. console.log("markerClusterCreate", e);
  150. });
  151. },
  152. addMarkers() {
  153. const markers = []
  154. // 处理点的数据
  155. this.storeList.forEach((p, i) => {
  156. console.log(i)
  157. markers.push(
  158. Object.assign({},{
  159. id: i,
  160. iconPath: this.img,
  161. width: 50,
  162. height: 50,
  163. // joinCluster: true, // 指定了该参数才会参与聚合
  164. label: {
  165. width: 150,
  166. height: 30,
  167. // borderWidth: 1,
  168. // borderRadius: 10,
  169. // bgColor: 'red',
  170. textAlign: 'center',
  171. // anchorX: -40,
  172. // anchorY: -70,
  173. content: p.storeName
  174. }
  175. },p)
  176. )
  177. })
  178. // 添加点
  179. this._mapContext.addMarkers({
  180. markers,
  181. clear: false,
  182. complete(res) {
  183. console.log('addMarkers', res)
  184. }
  185. })
  186. },
  187. // 点击地图上的点
  188. handleMarkerTap(marker){
  189. console.log('Marker tapped:', marker);
  190. console.log(this.storeList[marker.markerId])
  191. },
  192. // 打电话
  193. makePhone(phoneNumber){
  194. uni.makePhoneCall({
  195. phoneNumber: phoneNumber
  196. });
  197. },
  198. // 去下单页面
  199. gotoOrder(item){
  200. this.type = '2';
  201. this.selectStore(item);
  202. },
  203. },
  204. };
  205. </script>
  206. <style scoped lang="scss">
  207. .h-store-wrap{
  208. margin-top: 12px;
  209. background: #fff;
  210. padding-top:4px;
  211. padding-left: 12px;
  212. padding-right: 12px;
  213. border-radius: 12px;
  214. .h-store-content{
  215. margin-top: 12px;
  216. margin-bottom: 12px;
  217. background: #fafafa;
  218. padding: 12px;
  219. border-radius: 6px;
  220. font-family: PingFangSC-Regular, PingFang SC;
  221. .h-row{
  222. display: flex;
  223. justify-content: space-between;
  224. .h-left-value{
  225. .h-name{
  226. height: 22px;
  227. font-size: 14px;
  228. font-weight: 400;
  229. color: #333333;
  230. line-height: 22px;
  231. }
  232. .h-text{
  233. font-size: 10px;
  234. font-weight: 400;
  235. color: #999999;
  236. line-height: 18px;
  237. display: flex;
  238. align-items: center;
  239. image{
  240. margin-right: 6px;
  241. height: 12px;
  242. width: 12px;
  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>