store-choose.vue 6.3 KB

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