store-choose.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. },3000)
  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. uni.showLoading({
  142. title: '加载中...'
  143. });
  144. let that = this
  145. uni.getLocation({
  146. type: 'gcj02',
  147. success: function (res) {
  148. that.latitude = res.latitude; // 纬度
  149. that.longitude = res.longitude; // 经度
  150. let mapContext = uni.createMapContext("map", this);
  151. mapContext.moveToLocation()
  152. },
  153. fail: function (fail) {
  154. console.log('获取用户地址失败==》', fail)
  155. },
  156. complete: function (complete) {
  157. console.log('获取用户地址失败or成功==》', complete)
  158. // 获取商店数据
  159. if (that.isGetAddress){
  160. console.log("根据位置获取门店执行了 isGetAddress =>",that.isGetAddress)
  161. that.isGetAddress = !that.isGetAddress
  162. that.getStoreListData()
  163. }
  164. }
  165. })
  166. },
  167. // 选择门店
  168. selectStore(item) {
  169. // 更新用户选择的门店信息
  170. uni.setStorageSync('storeInfo', item);
  171. console.log(this.navigateRouter)
  172. if(this.navigateRouter == 1){
  173. uni.reLaunch({
  174. url: '/orderPages/storeService/index'
  175. })
  176. uni.removeStorage({
  177. key: 'router'
  178. });
  179. }else if(this.navigateRouter == 2){
  180. uni.reLaunch({
  181. url: '/orderPages/bookService/index'
  182. })
  183. uni.removeStorage({
  184. key: 'router'
  185. });
  186. }else {
  187. uni.switchTab({
  188. url: '/pages/index/index'
  189. })
  190. }
  191. },
  192. // 获取门店列表数据
  193. getStoreListData() {
  194. let that = this;
  195. this.$api.storeList({
  196. latitude: this.latitude,
  197. longitude: this.longitude,
  198. }).then((res) => {
  199. uni.hideLoading();
  200. console.log(res)
  201. that.storeList = res.data.data
  202. that.latitude = res.data.data[0].latitude
  203. that.longitude = res.data.data[0].longitude
  204. // 添加坐标点
  205. that.addMarkers();
  206. }).catch(() => {
  207. console.log("获取用户门店列表报错")
  208. })
  209. },
  210. addMarkers() {
  211. this.markers = []
  212. // 处理点的数据
  213. this.storeList.forEach((p, i) => {
  214. this.markers.push(
  215. {
  216. id: i,
  217. iconPath: '/static/index/address.png',
  218. width: 28,
  219. height: 35,
  220. latitude: p.latitude,
  221. longitude: p.longitude,
  222. // joinCluster: true, // 指定了该参数才会参与聚合
  223. // label: {
  224. // width: 150,
  225. // height: 30,
  226. // // display:'ALWAYS',
  227. // // borderWidth:200,
  228. // // bgColor:'#ffffff',
  229. // textAlign: 'center',
  230. // content: p.storeName
  231. // },
  232. callout: {
  233. // width: 150,
  234. // height: 30,
  235. display:'ALWAYS',
  236. borderWidth:6,
  237. color:'#ffffff',//文字颜色
  238. borderRadius:5,//边框圆角
  239. fontSize:14,//文本大小
  240. bgColor:'#645d57',//背景颜色
  241. borderColor: '#645d57',
  242. textAlign: 'center',
  243. content: p.storeName
  244. },
  245. // callout:{//自定义标记点上方的气泡窗口 点击有效
  246. // content: p.storeName,//文本
  247. // color:'#000000',//文字颜色
  248. // // fontSize:14,//文本大小
  249. // borderRadius:15,//边框圆角
  250. // borderWidth:'5',
  251. // bgColor:'#ffffff',//背景颜色
  252. // display:'ALWAYS',//常显
  253. // },
  254. }
  255. )
  256. })
  257. },
  258. // 点击地图上的点
  259. handleMarkerTap(marker) {
  260. console.log('Marker tapped:', marker);
  261. console.log(this.storeList[marker.markerId])
  262. },
  263. // 打电话
  264. makePhone(phoneNumber) {
  265. uni.makePhoneCall({
  266. phoneNumber: phoneNumber
  267. });
  268. },
  269. // 去下单页面
  270. gotoOrder(item) {
  271. this.type = '2';
  272. this.selectStore(item);
  273. },
  274. },
  275. };
  276. </script>
  277. <style scoped lang="scss">
  278. .h-store-wrap {
  279. margin-top: 12px;
  280. background: #fff;
  281. padding-top: 4px;
  282. padding-left: 12px;
  283. padding-right: 12px;
  284. border-radius: 12px;
  285. .h-store-content {
  286. margin-top: 12px;
  287. margin-bottom: 12px;
  288. background: #fafafa;
  289. padding: 12px;
  290. border-radius: 6px;
  291. font-family: PingFangSC-Regular, PingFang SC;
  292. .h-row {
  293. display: flex;
  294. justify-content: space-between;
  295. .h-left-value {
  296. .h-name {
  297. font-size: 28rpx;
  298. font-weight: 400;
  299. color: #333333;
  300. line-height: 40rpx;
  301. }
  302. .h-text {
  303. font-size: 24rpx;
  304. font-weight: 400;
  305. color: #999999;
  306. line-height: 40rpx;
  307. display: flex;
  308. align-items: center;
  309. image {
  310. margin-right: 12rpx;
  311. height: 24rpx;
  312. width: 24rpx;
  313. }
  314. }
  315. }
  316. .h-right-value {
  317. width: 100rpx;
  318. .h-text {
  319. font-size: 10px;
  320. font-weight: 400;
  321. color: #999999;
  322. line-height: 18px;
  323. }
  324. image {
  325. height: 40rpx;
  326. width: 40rpx;
  327. }
  328. }
  329. .h-flex {
  330. display: flex;
  331. justify-content: space-between;
  332. }
  333. }
  334. }
  335. }
  336. .h-area-wrap {
  337. margin-right: 12px;
  338. margin-left: 12px;
  339. margin-top: 12px;
  340. }
  341. .h-search {
  342. font-size: 14px;
  343. display: flex;
  344. padding-left: 12px;
  345. padding-top: 8px;
  346. padding-right: 12px;
  347. background: #fff;
  348. padding-bottom: 8px;
  349. border-radius: 6px;
  350. .h-time {
  351. width: 30%;
  352. display: flex;
  353. .time {
  354. padding-right: 2px;
  355. }
  356. }
  357. .h-name {
  358. width: 70%;
  359. text-align: right;
  360. display: flex;
  361. justify-content: flex-end;
  362. .name {
  363. padding-right: 6px;
  364. }
  365. }
  366. }
  367. .juli{
  368. text-align: center;
  369. font-size: 24rpx;
  370. font-weight: 400;
  371. color: #999999;
  372. line-height: 40rpx;
  373. }
  374. /* 隐藏腾讯地图版权标识 */
  375. .tencent-map .qq-map-copyright {
  376. display: none;
  377. }
  378. </style>