shopList.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. addressList: [], //显示的地址数据
  52. value: '', //保存查询值
  53. addressListAll: [], //保存地址数据
  54. longitude: '', //经度
  55. latitude: '', //未读
  56. time:'',//保存定时获取对象
  57. type:1//1为创建订单进入2为首页进入
  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. that.type = option.type;
  80. if (!that.longitude) {
  81. uni.showModal({
  82. title: '获取定位',
  83. content: '为了更好的提供最近的门店需要获取您的定位信息',
  84. cancelText: '暂不授权',
  85. confirmText: '立即授权',
  86. success: res => {
  87. if (res.cancel) {
  88. that.getStoreList();
  89. }
  90. if (res.confirm) {
  91. util.$L.getLocation();
  92. that.time = setInterval(()=>{
  93. console.log(uni.getStorageSync('CACHE_LONGITUDE'),'获取到金纬度');
  94. if(uni.getStorageSync('CACHE_LONGITUDE')){
  95. that.longitude = uni.getStorageSync('CACHE_LONGITUDE');
  96. that.latitude = uni.getStorageSync('CACHE_LATITUDE');
  97. that.getStoreList();
  98. clearInterval(that.time)
  99. }
  100. },1000)
  101. }
  102. },
  103. fail: () => {},
  104. complete: () => {}
  105. });
  106. } else {
  107. // 获取当前位置
  108. that.getStoreList();
  109. }
  110. },
  111. methods: {
  112. // 获取列表
  113. getStoreList() {
  114. storeList({
  115. longitude:this.longitude,
  116. latitude:this.latitude,
  117. }).then((res) => {
  118. this.addressListAll = this.addressList = res.data.list;
  119. })
  120. },
  121. // 地址查询功能
  122. searchAddressList() {
  123. let obj = this;
  124. obj.addressList = obj.addressListAll.filter(e => {
  125. // 判断客户是否有输入值并且能查询到
  126. if (e.name.indexOf(obj.value) >= 0 && obj.value) {
  127. return true;
  128. } else if (obj.value.length == 0) {
  129. return true;
  130. }
  131. });
  132. console.log(obj.addressList);
  133. },
  134. //选择地址
  135. checkAddress(item) {
  136. if (this.type==1) {
  137. // 设置商品页面地址
  138. this.$api.prePage().shopAddress = item;
  139. uni.navigateBack();
  140. return
  141. }
  142. if(this.type==2){
  143. uni.openLocation({
  144. longitude:+item.longitude,
  145. latitude:+item.latitude,
  146. fail(res){
  147. console.log(res,'定位获取失败');
  148. }
  149. })
  150. return
  151. }
  152. }
  153. }
  154. };
  155. </script>
  156. <style lang="scss">
  157. .content {
  158. position: relative;
  159. padding-top: 30rpx;
  160. }
  161. .list {
  162. align-items: center;
  163. padding: 20rpx 30rpx;
  164. background: #fff;
  165. margin: 0 $page-row-spacing;
  166. margin-bottom: $page-row-spacing;
  167. border-radius: 20rpx;
  168. .wrapper {
  169. .logo {
  170. width: 180rpx;
  171. height: 180rpx;
  172. border-radius: 10rpx;
  173. }
  174. .list-content {
  175. align-self: stretch;
  176. display: flex;
  177. flex-direction: column;
  178. flex: 1;
  179. .address-box {
  180. .range {
  181. font-size: $font-sm - 2rpx;
  182. color: $font-color-disabled;
  183. flex-shrink: 0;
  184. .address-icon{
  185. width: 28rpx;
  186. height: 28rpx;
  187. }
  188. }
  189. .name {
  190. font-size: $font-lg;
  191. font-weight: bold;
  192. flex-grow: 1;
  193. }
  194. }
  195. .u-box {
  196. font-size: $font-sm;
  197. color: $font-color-light;
  198. margin-top: 16rpx;
  199. .text {
  200. .icon {
  201. width: 28rpx;
  202. margin-right: 10rpx;
  203. }
  204. }
  205. }
  206. .time {
  207. position: absolute;
  208. background: rgba(60, 130, 230, 0.12);
  209. border-radius: 20rpx;
  210. font-size: $font-sm - 4rpx;
  211. color: $base-color;
  212. bottom: 0;
  213. left: 0;
  214. padding: 0 20rpx;
  215. }
  216. }
  217. }
  218. }
  219. </style>