store-choose.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  1. <template>
  2. <view class="container">
  3. <!-- 地图容器 -->
  4. <view class="map-wrap">
  5. <map class="tencent-map" style="width: 100%; height: 300px;"
  6. id="map"
  7. :latitude="latitude"
  8. :longitude="longitude"
  9. :scale="scale"
  10. :enable-building="true"
  11. :markers="markers"
  12. :show-location="false"
  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">{{item.distanceDesc}}</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>
  57. <view class="h-right-value flex-row justify-between">
  58. <view class="phone" @click.stop="makePhoneCall(item.phone)">
  59. <image src="../../static/goods/phone.png" mode=""></image>
  60. </view>
  61. <view class="sure" @click.stop="openmap(item)">
  62. <image src="../../static/goods/daohang.png" mode=""></image>
  63. </view>
  64. </view>
  65. <view class="juli">
  66. {{item.distanceDesc}}
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. export default {
  76. data() {
  77. return {
  78. isGetAddress:true, //是否获取到了经纬度
  79. markers:[],
  80. areaName: '贵阳市',
  81. latitude: 26.5737,
  82. longitude: 106.7135,
  83. scale: 12,
  84. img: '/static/index/u55.png',
  85. reqParm: {
  86. auth: true,
  87. longitude: 0,
  88. latitude: 0
  89. },
  90. storeList: [],
  91. type: '1',
  92. navigateRouter:null
  93. }
  94. },
  95. onReady() {
  96. // 初始化地图
  97. // this.initMap();
  98. },
  99. onLoad(option) {
  100. this.getLocation()
  101. setTimeout(e=>{
  102. console.log('定时器要执行了 isGetAddress =>',this.isGetAddress)
  103. if (this.isGetAddress){
  104. console.log('定时器执行了isGetAddress =>',this.isGetAddress)
  105. this.isGetAddress = !this.isGetAddress
  106. this.getStoreListData()
  107. }
  108. },5000)
  109. // 判断Openid是否为空
  110. if (option.type) {
  111. this.type = option.type;
  112. }
  113. },
  114. onShow(){
  115. this.navigateRouter = uni.getStorageSync('router');
  116. },
  117. methods: {
  118. openmap(selfTake) {
  119. uni.openLocation({
  120. latitude: selfTake.latitude * 1,
  121. longitude: selfTake.longitude * 1,
  122. address: selfTake.address,
  123. success: function () {
  124. console.log('success');
  125. },
  126. fail(err){
  127. console.log(err,"++++++++++++++++++++++++++++++")
  128. },
  129. });
  130. },
  131. makePhoneCall(phone){
  132. if (!phone){
  133. uni.$u.toast('该门店没有设置电话')
  134. return
  135. }
  136. uni.makePhoneCall({
  137. phoneNumber:phone
  138. })
  139. },
  140. getLocation() {
  141. let that = this
  142. uni.getLocation({
  143. type: 'gcj02',
  144. success: function (res) {
  145. that.latitude = res.latitude; // 纬度
  146. that.longitude = res.longitude; // 经度
  147. let mapContext = uni.createMapContext("map", this);
  148. mapContext.moveToLocation()
  149. },
  150. fail: function (fail) {
  151. console.log('获取用户地址失败==》', fail)
  152. },
  153. complete: function (complete) {
  154. console.log('获取用户地址失败or成功==》', complete)
  155. // 获取商店数据
  156. if (that.isGetAddress){
  157. console.log("根据位置获取门店执行了 isGetAddress =>",that.isGetAddress)
  158. that.isGetAddress = !that.isGetAddress
  159. that.getStoreListData()
  160. }
  161. }
  162. })
  163. },
  164. // 选择门店
  165. selectStore(item) {
  166. // 更新用户选择的门店信息
  167. uni.setStorageSync('storeInfo', item);
  168. console.log(this.navigateRouter)
  169. if(this.navigateRouter == 1){
  170. uni.reLaunch({
  171. url: '/orderPages/storeService/index'
  172. })
  173. uni.removeStorage({
  174. key: 'router'
  175. });
  176. }else if(this.navigateRouter == 2){
  177. uni.reLaunch({
  178. url: '/orderPages/bookService/index'
  179. })
  180. uni.removeStorage({
  181. key: 'router'
  182. });
  183. }else {
  184. uni.switchTab({
  185. url: '/pages/index/index'
  186. })
  187. }
  188. },
  189. // 获取门店列表数据
  190. getStoreListData() {
  191. let that = this;
  192. this.$api.storeList({
  193. latitude: this.latitude,
  194. longitude: this.longitude,
  195. }).then((res) => {
  196. console.log(res)
  197. that.storeList = res.data.data
  198. that.latitude = res.data.data[0].latitude
  199. that.longitude = res.data.data[0].longitude
  200. // 添加坐标点
  201. that.addMarkers();
  202. }).catch(() => {
  203. console.log("获取用户门店列表报错")
  204. })
  205. },
  206. addMarkers() {
  207. this.markers = []
  208. // 处理点的数据
  209. this.storeList.forEach((p, i) => {
  210. this.markers.push(
  211. {
  212. id: i,
  213. iconPath: '/static/index/address.png',
  214. width: 28,
  215. height: 35,
  216. latitude: p.latitude,
  217. longitude: p.longitude,
  218. // joinCluster: true, // 指定了该参数才会参与聚合
  219. // label: {
  220. // width: 150,
  221. // height: 30,
  222. // // display:'ALWAYS',
  223. // // borderWidth:200,
  224. // // bgColor:'#ffffff',
  225. // textAlign: 'center',
  226. // content: p.storeName
  227. // },
  228. callout: {
  229. // width: 150,
  230. // height: 30,
  231. display:'ALWAYS',
  232. borderWidth:6,
  233. color:'#ffffff',//文字颜色
  234. borderRadius:5,//边框圆角
  235. fontSize:14,//文本大小
  236. bgColor:'#645d57',//背景颜色
  237. borderColor: '#645d57',
  238. textAlign: 'center',
  239. content: p.storeName
  240. },
  241. // callout:{//自定义标记点上方的气泡窗口 点击有效
  242. // content: p.storeName,//文本
  243. // color:'#000000',//文字颜色
  244. // // fontSize:14,//文本大小
  245. // borderRadius:15,//边框圆角
  246. // borderWidth:'5',
  247. // bgColor:'#ffffff',//背景颜色
  248. // display:'ALWAYS',//常显
  249. // },
  250. }
  251. )
  252. })
  253. },
  254. // 点击地图上的点
  255. handleMarkerTap(marker) {
  256. console.log('Marker tapped:', marker);
  257. console.log(this.storeList[marker.markerId])
  258. },
  259. // 打电话
  260. makePhone(phoneNumber) {
  261. uni.makePhoneCall({
  262. phoneNumber: phoneNumber
  263. });
  264. },
  265. // 去下单页面
  266. gotoOrder(item) {
  267. this.type = '2';
  268. this.selectStore(item);
  269. },
  270. },
  271. };
  272. </script>
  273. <style scoped lang="scss">
  274. .h-store-wrap {
  275. margin-top: 12px;
  276. background: #fff;
  277. padding-top: 4px;
  278. padding-left: 12px;
  279. padding-right: 12px;
  280. border-radius: 12px;
  281. .h-store-content {
  282. margin-top: 12px;
  283. margin-bottom: 12px;
  284. background: #fafafa;
  285. padding: 12px;
  286. border-radius: 6px;
  287. font-family: PingFangSC-Regular, PingFang SC;
  288. .h-row {
  289. display: flex;
  290. justify-content: space-between;
  291. .h-left-value {
  292. .h-name {
  293. font-size: 28rpx;
  294. font-weight: 400;
  295. color: #333333;
  296. line-height: 40rpx;
  297. }
  298. .h-text {
  299. font-size: 24rpx;
  300. font-weight: 400;
  301. color: #999999;
  302. line-height: 40rpx;
  303. display: flex;
  304. align-items: center;
  305. image {
  306. margin-right: 12rpx;
  307. height: 24rpx;
  308. width: 24rpx;
  309. }
  310. }
  311. }
  312. .h-right-value {
  313. width: 100rpx;
  314. .h-text {
  315. font-size: 10px;
  316. font-weight: 400;
  317. color: #999999;
  318. line-height: 18px;
  319. }
  320. image {
  321. height: 40rpx;
  322. width: 40rpx;
  323. }
  324. }
  325. .h-flex {
  326. display: flex;
  327. justify-content: space-between;
  328. }
  329. }
  330. }
  331. }
  332. .h-area-wrap {
  333. margin-right: 12px;
  334. margin-left: 12px;
  335. margin-top: 12px;
  336. }
  337. .h-search {
  338. font-size: 14px;
  339. display: flex;
  340. padding-left: 12px;
  341. padding-top: 8px;
  342. padding-right: 12px;
  343. background: #fff;
  344. padding-bottom: 8px;
  345. border-radius: 6px;
  346. .h-time {
  347. width: 30%;
  348. display: flex;
  349. .time {
  350. padding-right: 2px;
  351. }
  352. }
  353. .h-name {
  354. width: 70%;
  355. text-align: right;
  356. display: flex;
  357. justify-content: flex-end;
  358. .name {
  359. padding-right: 6px;
  360. }
  361. }
  362. }
  363. .juli{
  364. text-align: center;
  365. font-size: 24rpx;
  366. font-weight: 400;
  367. color: #999999;
  368. line-height: 40rpx;
  369. }
  370. /* 隐藏腾讯地图版权标识 */
  371. .tencent-map .qq-map-copyright {
  372. display: none;
  373. }
  374. </style>