index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <s-layout title="选择自提门店" :bgStyle="{ color: '#FFF' }">
  3. <view class="storeBox" ref="container">
  4. <view class="storeBox-box" v-for="(item, index) in state.storeList" :key="index" @tap="checked(item)">
  5. <view class="store-img">
  6. <image :src="item.logo" class="img" />
  7. </view>
  8. <view class="store-cent-left">
  9. <view class="store-name">{{ item.name }}</view>
  10. <view class="store-address line1">
  11. {{ item.areaName }}{{ ', ' + item.detailAddress }}
  12. </view>
  13. </view>
  14. <view class="row-right ss-flex-col ss-col-center">
  15. <view>
  16. <!-- #ifdef H5 -->
  17. <a class="store-phone" :href="'tel:' + item.phone">
  18. <view class="iconfont">
  19. <view class="ss-rest-button">
  20. <text class="_icon-forward" />
  21. </view>
  22. </view>
  23. </a>
  24. <!-- #endif -->
  25. <!-- #ifdef MP -->
  26. <view class="store-phone" @click="call(item.phone)">
  27. <view class="iconfont">
  28. <view class="ss-rest-button">
  29. <text class="_icon-forward" />
  30. </view>
  31. </view>
  32. </view>
  33. <!-- #endif -->
  34. </view>
  35. <view class="store-distance ss-flex ss-row-center" @tap="showMaoLocation(item)">
  36. <text class="addressTxt" v-if="item.distance">距离{{ item.distance.toFixed(2) }}千米</text>
  37. <text class="addressTxt" v-else>查看地图</text>
  38. <view class="iconfont">
  39. <view class="ss-rest-button">
  40. <text class="_icon-forward" />
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. </s-layout>
  48. </template>
  49. <script setup>
  50. import DeliveryApi from '@/sheep/api/trade/delivery';
  51. import { onMounted, reactive } from 'vue';
  52. import { onLoad } from '@dcloudio/uni-app';
  53. import sheep from '@/sheep';
  54. const LONGITUDE = 'user_longitude';
  55. const LATITUDE = 'user_latitude';
  56. const MAPKEY = 'mapKey';
  57. const state = reactive({
  58. loaded: false,
  59. loading: false,
  60. storeList: [],
  61. system_store: {},
  62. // mapKey: cookie.get(MAPKEY),
  63. locationShow: false,
  64. user_latitude: 0,
  65. user_longitude: 0,
  66. });
  67. const call = (phone) => {
  68. uni.makePhoneCall({
  69. phoneNumber: phone,
  70. });
  71. };
  72. const selfLocation = () => {
  73. // TODO h5 地图
  74. // #ifdef H5
  75. // if (state.$wechat.isWeixin()) {
  76. // state.$wechat.location().then(res => {
  77. // state.user_latitude = res.latitude;
  78. // state.user_longitude = res.longitude;
  79. // uni.setStorageSync(LATITUDE, res.latitude);
  80. // uni.setStorageSync(LONGITUDE, res.longitude);
  81. // getList();
  82. // });
  83. // } else {
  84. // #endif
  85. uni.getLocation({
  86. type: 'gcj02',
  87. success: (res) => {
  88. try {
  89. state.user_latitude = res.latitude;
  90. state.user_longitude = res.longitude;
  91. uni.setStorageSync(LATITUDE, res.latitude);
  92. uni.setStorageSync(LONGITUDE, res.longitude);
  93. } catch {
  94. }
  95. getList();
  96. },
  97. complete: () => {
  98. getList();
  99. },
  100. });
  101. // #ifdef H5
  102. // }
  103. // #endif
  104. };
  105. const showMaoLocation = (e) => {
  106. // TODO h5 地图
  107. // #ifdef H5
  108. // if (state.$wechat.isWeixin()) {
  109. // state.$wechat.seeLocation({
  110. // latitude: Number(e.latitude),
  111. // longitude: Number(e.longitude),
  112. // }).then(res => {
  113. // console.log('success');
  114. // });
  115. // } else {
  116. // #endif
  117. uni.openLocation({
  118. latitude: Number(e.latitude),
  119. longitude: Number(e.longitude),
  120. name: e.name,
  121. address: `${e.areaName}-${e.detailAddress}`,
  122. success: function() {
  123. console.log('success');
  124. },
  125. });
  126. // #ifdef H5
  127. // }
  128. // #endif
  129. };
  130. /**
  131. * 选中门店
  132. */
  133. const checked = (addressInfo) => {
  134. uni.$emit('SELECT_PICK_UP_INFO', {
  135. addressInfo,
  136. });
  137. sheep.$router.back();
  138. };
  139. /**
  140. * 获取门店列表数据
  141. */
  142. const getList = async () => {
  143. if (state.loading || state.loaded) {
  144. return;
  145. }
  146. state.loading = true;
  147. const { data, code } = await DeliveryApi.getDeliveryPickUpStoreList({
  148. latitude: state.user_latitude,
  149. longitude: state.user_longitude,
  150. });
  151. if (code !== 0) {
  152. return;
  153. }
  154. state.loading = false;
  155. state.storeList = data;
  156. };
  157. onMounted(() => {
  158. if (state.user_latitude && state.user_longitude) {
  159. getList();
  160. } else {
  161. selfLocation();
  162. getList();
  163. }
  164. });
  165. onLoad(() => {
  166. try {
  167. state.user_latitude = uni.getStorageSync(LATITUDE);
  168. state.user_longitude = uni.getStorageSync(LONGITUDE);
  169. } catch (e) {
  170. // error
  171. }
  172. });
  173. </script>
  174. <style lang="scss" scoped>
  175. .line1 {
  176. overflow: hidden;
  177. text-overflow: ellipsis;
  178. white-space: nowrap
  179. }
  180. .geoPage {
  181. position: fixed;
  182. width: 100%;
  183. height: 100%;
  184. top: 0;
  185. z-index: 10000;
  186. }
  187. .storeBox {
  188. width: 100%;
  189. background-color: #fff;
  190. padding: 0 30rpx;
  191. }
  192. .storeBox-box {
  193. width: 100%;
  194. height: auto;
  195. display: flex;
  196. align-items: center;
  197. padding: 23rpx 0;
  198. justify-content: space-between;
  199. border-bottom: 1px solid #eee;
  200. }
  201. .store-cent {
  202. display: flex;
  203. align-items: center;
  204. width: 80%;
  205. }
  206. .store-cent-left {
  207. //width: 45%;
  208. flex: 2;
  209. }
  210. .store-img {
  211. flex: 1;
  212. width: 120rpx;
  213. height: 120rpx;
  214. border-radius: 6rpx;
  215. margin-right: 22rpx;
  216. }
  217. .store-img .img {
  218. width: 100%;
  219. height: 100%;
  220. }
  221. .store-name {
  222. color: #282828;
  223. font-size: 30rpx;
  224. margin-bottom: 22rpx;
  225. font-weight: 800;
  226. }
  227. .store-address {
  228. color: #666666;
  229. font-size: 24rpx;
  230. }
  231. .store-phone {
  232. width: 50rpx;
  233. height: 50rpx;
  234. color: #fff;
  235. border-radius: 50%;
  236. display: block;
  237. text-align: center;
  238. line-height: 48rpx;
  239. background-color: #e83323;
  240. margin-bottom: 22rpx;
  241. text-decoration: none;
  242. }
  243. .store-distance {
  244. font-size: 22rpx;
  245. color: #e83323;
  246. }
  247. .iconfont {
  248. font-size: 20rpx;
  249. }
  250. .row-right {
  251. flex: 2;
  252. //display: flex;
  253. //flex-direction: column;
  254. //align-items: flex-end;
  255. //width: 33.5%;
  256. }
  257. </style>