index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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.stop="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 state = reactive({
  57. loaded: false,
  58. loading: false,
  59. storeList: [],
  60. system_store: {},
  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. // #ifdef H5
  72. const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
  73. if (jsWxSdk.isWechat()) {
  74. jsWxSdk.getLocation((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 (e) {
  92. console.error(e);
  93. }
  94. getList();
  95. },
  96. complete: () => {
  97. getList();
  98. },
  99. });
  100. // #ifdef H5
  101. }
  102. // #endif
  103. };
  104. const showMaoLocation = (e) => {
  105. // #ifdef H5
  106. const jsWxSdk = sheep.$platform.useProvider('wechat').jsWxSdk;
  107. if (jsWxSdk.isWechat()) {
  108. jsWxSdk.openLocation({
  109. latitude: Number(e.latitude),
  110. longitude: Number(e.longitude),
  111. name: e.name,
  112. address: `${e.areaName}-${e.detailAddress}`
  113. });
  114. } else {
  115. // #endif
  116. uni.openLocation({
  117. latitude: Number(e.latitude),
  118. longitude: Number(e.longitude),
  119. name: e.name,
  120. address: `${e.areaName}-${e.detailAddress}`,
  121. success: function() {
  122. console.log('success');
  123. },
  124. });
  125. // #ifdef H5
  126. }
  127. // #endif
  128. };
  129. /**
  130. * 选中门店
  131. */
  132. const checked = (addressInfo) => {
  133. uni.$emit('SELECT_PICK_UP_INFO', {
  134. addressInfo,
  135. });
  136. sheep.$router.back();
  137. };
  138. /**
  139. * 获取门店列表数据
  140. */
  141. const getList = async () => {
  142. if (state.loading || state.loaded) {
  143. return;
  144. }
  145. state.loading = true;
  146. const { data, code } = await DeliveryApi.getDeliveryPickUpStoreList({
  147. latitude: state.user_latitude,
  148. longitude: state.user_longitude,
  149. });
  150. if (code !== 0) {
  151. return;
  152. }
  153. state.loading = false;
  154. state.storeList = data;
  155. };
  156. onMounted(() => {
  157. if (state.user_latitude && state.user_longitude) {
  158. getList();
  159. } else {
  160. selfLocation();
  161. getList();
  162. }
  163. });
  164. onLoad(() => {
  165. try {
  166. state.user_latitude = uni.getStorageSync(LATITUDE);
  167. state.user_longitude = uni.getStorageSync(LONGITUDE);
  168. } catch (e) {
  169. console.error(e)
  170. }
  171. });
  172. </script>
  173. <style lang="scss" scoped>
  174. .line1 {
  175. overflow: hidden;
  176. text-overflow: ellipsis;
  177. white-space: nowrap
  178. }
  179. .geoPage {
  180. position: fixed;
  181. width: 100%;
  182. height: 100%;
  183. top: 0;
  184. z-index: 10000;
  185. }
  186. .storeBox {
  187. width: 100%;
  188. background-color: #fff;
  189. padding: 0 30rpx;
  190. }
  191. .storeBox-box {
  192. width: 100%;
  193. height: auto;
  194. display: flex;
  195. align-items: center;
  196. padding: 23rpx 0;
  197. justify-content: space-between;
  198. border-bottom: 1px solid #eee;
  199. }
  200. .store-cent {
  201. display: flex;
  202. align-items: center;
  203. width: 80%;
  204. }
  205. .store-cent-left {
  206. //width: 45%;
  207. flex: 2;
  208. }
  209. .store-img {
  210. flex: 1;
  211. width: 120rpx;
  212. height: 120rpx;
  213. border-radius: 6rpx;
  214. margin-right: 22rpx;
  215. }
  216. .store-img .img {
  217. width: 100%;
  218. height: 100%;
  219. }
  220. .store-name {
  221. color: #282828;
  222. font-size: 30rpx;
  223. margin-bottom: 22rpx;
  224. font-weight: 800;
  225. }
  226. .store-address {
  227. color: #666666;
  228. font-size: 24rpx;
  229. }
  230. .store-phone {
  231. width: 50rpx;
  232. height: 50rpx;
  233. color: #fff;
  234. border-radius: 50%;
  235. display: block;
  236. text-align: center;
  237. line-height: 48rpx;
  238. background-color: #e83323;
  239. margin-bottom: 22rpx;
  240. text-decoration: none;
  241. }
  242. .store-distance {
  243. font-size: 22rpx;
  244. color: #e83323;
  245. }
  246. .iconfont {
  247. font-size: 20rpx;
  248. }
  249. .row-right {
  250. flex: 2;
  251. //display: flex;
  252. //flex-direction: column;
  253. //align-items: flex-end;
  254. //width: 33.5%;
  255. }
  256. </style>