index.vue 6.1 KB

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