shopList.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <view class="content b-t">
  3. <view class="list" v-for="(item, index) in addressList" :key="index" @click="checkAddress(item)">
  4. <view class="wrapper flex ">
  5. <image class="logo margin-r-20" :src="item.image" mode="scaleToFill"></image>
  6. <view class="list-content position-relative">
  7. <view class="address-box flex">
  8. <view class="name clamp">{{ item.name }}</view>
  9. <view class="range flex" v-if="item.distance<1000">
  10. <text>
  11. 距离{{ item.distance }}M
  12. </text>
  13. </view>
  14. <view class="range flex" v-else>
  15. <image class="address-icon" src="../../static/icon/shopAddress.png" mode="scaleToFill"></image>
  16. <text>
  17. 距离{{ item.range }}KM
  18. </text>
  19. </view>
  20. </view>
  21. <view class="u-box">
  22. <view class="text flex-start">
  23. <image class="icon" src="../../static/icon/shopIcon2.png" mode="widthFix"></image>
  24. <text>
  25. {{ item.phone }}
  26. </text>
  27. </view>
  28. <view class="text flex-start">
  29. <image class="icon" src="../../static/icon/shopIcon1.png" mode="widthFix"></image>
  30. <text>
  31. {{ item.address + item.detailed_address }}
  32. </text>
  33. </view>
  34. </view>
  35. <view class="time">
  36. 营业时间:{{item.day_time}}
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. import {
  45. storeList
  46. } from '@/api/order.js';
  47. import util from '@/utils/util.js';
  48. export default {
  49. data() {
  50. return {
  51. source: 0,
  52. addressList: [], //显示的地址数据
  53. value: '', //保存查询值
  54. addressListAll: [], //保存地址数据
  55. longitude: '', //经度
  56. latitude: '', //未读
  57. time:''//保存定时获取对象
  58. };
  59. },
  60. // #ifdef APP-PLUS || H5
  61. onNavigationBarButtonTap(e) {
  62. if (e.text === '搜索') {
  63. this.searchAddressList();
  64. }
  65. },
  66. // 监听原生标题栏搜索输入框输入内容变化事件
  67. onNavigationBarSearchInputChanged(e) {
  68. this.value = e.text;
  69. },
  70. // 监听原生标题栏搜索输入框搜索事件,用户点击软键盘上的“搜索”按钮时触发
  71. onNavigationBarSearchInputConfirmed() {
  72. this.searchAddressList();
  73. },
  74. // #endif
  75. onLoad(option) {
  76. const that = this;
  77. that.longitude = uni.getStorageSync('CACHE_LONGITUDE');
  78. that.latitude = uni.getStorageSync('CACHE_LATITUDE');
  79. if (!that.longitude) {
  80. uni.showModal({
  81. title: '获取定位',
  82. content: '为了更好的提供最近的门店需要获取您的定位信息',
  83. cancelText: '暂不授权',
  84. confirmText: '立即授权',
  85. success: res => {
  86. if (res.cancel) {
  87. that.getStoreList();
  88. }
  89. if (res.confirm) {
  90. util.$L.getLocation();
  91. that.time = setInterval(()=>{
  92. console.log(uni.getStorageSync('CACHE_LONGITUDE'),'获取到金纬度');
  93. if(uni.getStorageSync('CACHE_LONGITUDE')){
  94. that.longitude = uni.getStorageSync('CACHE_LONGITUDE');
  95. that.latitude = uni.getStorageSync('CACHE_LATITUDE');
  96. that.getStoreList();
  97. clearInterval(that.time)
  98. }
  99. },1000)
  100. }
  101. },
  102. fail: () => {},
  103. complete: () => {}
  104. });
  105. } else {
  106. // 获取当前位置
  107. that.getStoreList();
  108. }
  109. },
  110. methods: {
  111. // 获取列表
  112. getStoreList() {
  113. storeList({
  114. longitude:this.longitude,
  115. latitude:this.latitude,
  116. }).then((res) => {
  117. this.addressListAll = this.addressList = res.data.list;
  118. })
  119. },
  120. // 地址查询功能
  121. searchAddressList() {
  122. let obj = this;
  123. obj.addressList = obj.addressListAll.filter(e => {
  124. // 判断客户是否有输入值并且能查询到
  125. if (e.name.indexOf(obj.value) >= 0 && obj.value) {
  126. return true;
  127. } else if (obj.value.length == 0) {
  128. return true;
  129. }
  130. });
  131. console.log(obj.addressList);
  132. },
  133. //选择地址
  134. checkAddress(item) {
  135. // 设置商品页面地址
  136. this.$api.prePage().shopAddress = item;
  137. uni.navigateBack();
  138. }
  139. }
  140. };
  141. </script>
  142. <style lang="scss">
  143. .content {
  144. position: relative;
  145. padding-top: 30rpx;
  146. }
  147. .list {
  148. align-items: center;
  149. padding: 20rpx 30rpx;
  150. background: #fff;
  151. margin: 0 $page-row-spacing;
  152. margin-bottom: $page-row-spacing;
  153. border-radius: 20rpx;
  154. .wrapper {
  155. .logo {
  156. width: 180rpx;
  157. height: 180rpx;
  158. border-radius: 10rpx;
  159. }
  160. .list-content {
  161. align-self: stretch;
  162. display: flex;
  163. flex-direction: column;
  164. flex: 1;
  165. .address-box {
  166. .range {
  167. font-size: $font-sm - 2rpx;
  168. color: $font-color-disabled;
  169. flex-shrink: 0;
  170. .address-icon{
  171. width: 28rpx;
  172. height: 28rpx;
  173. }
  174. }
  175. .name {
  176. font-size: $font-lg;
  177. font-weight: bold;
  178. flex-grow: 1;
  179. }
  180. }
  181. .u-box {
  182. font-size: $font-sm;
  183. color: $font-color-light;
  184. margin-top: 16rpx;
  185. .text {
  186. .icon {
  187. width: 28rpx;
  188. margin-right: 10rpx;
  189. }
  190. }
  191. }
  192. .time {
  193. position: absolute;
  194. background: rgba(60, 130, 230, 0.12);
  195. border-radius: 20rpx;
  196. font-size: $font-sm - 4rpx;
  197. color: $base-color;
  198. bottom: 0;
  199. left: 0;
  200. padding: 0 20rpx;
  201. }
  202. }
  203. }
  204. }
  205. </style>