index.vue 6.5 KB

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