index.vue 6.4 KB

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