storeList.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="store-list">
  3. <scroll-view scroll-y="true" class="list" @scrolltolower="loadData()">
  4. <empty v-if="loaded && list.length == 0"></empty>
  5. <view class="store flex" v-for="item in list" @click="navTo('/pages/store/storeDetail?id=' + item.id)">
  6. <image :src="item.image" mode="" class="store-img"></image>
  7. <view class="store-info">
  8. <view class="store-name clamp">{{item.name}}</view>
  9. <view class="store-detail">{{item.detailed_address}}</view>
  10. <view class="store-tip">门店</view>
  11. <view class="store-des">
  12. <image src="../../static/icon/dingwei.png" mode=""></image>
  13. 距离 {{item.space}}
  14. </view>
  15. </view>
  16. </view>
  17. <uni-load-more :status="loadingType" v-if="list !=0"></uni-load-more>
  18. </scroll-view>
  19. </view>
  20. </template>
  21. <script>
  22. import { getStoreList } from '@/api/index.js';
  23. import { mapState, mapMutations } from 'vuex';
  24. import empty from '@/components/empty';
  25. import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
  26. export default {
  27. components: {
  28. uniLoadMore,
  29. empty
  30. },
  31. data() {
  32. return {
  33. list: [],
  34. storeList: [],
  35. loadingType: 'more',
  36. page: 1,
  37. limit: 10,
  38. height: '',//滚动区域高度
  39. loaded: false,
  40. }
  41. },
  42. onReady(res) {
  43. var _this = this;
  44. uni.getSystemInfo({
  45. success: resu => {
  46. const query = uni.createSelectorQuery();
  47. query.select('.list').boundingClientRect();
  48. query.exec(function(res) {
  49. console.log(res, 'ddddddddddddd');
  50. _this.height = resu.windowHeight - res[0].top + 'px';
  51. console.log('打印页面的剩余高度', _this.height);
  52. });
  53. },
  54. fail: res => {}
  55. });
  56. },
  57. onLoad() {
  58. this.loadData()
  59. },
  60. computed: {
  61. ...mapState('latlon',['lat','lon']),
  62. },
  63. methods: {
  64. //获取门店list
  65. loadData() {
  66. let obj = this
  67. if(obj.loadingType == 'loading') {
  68. return
  69. }
  70. if(obj.loadingType == 'noMore') {
  71. return
  72. }
  73. obj.loadingType = 'loading'
  74. getStoreList({
  75. page: obj.page,
  76. limit: obj.limit,
  77. latitude: obj.lat,
  78. longitude: obj.lon
  79. }).then(({data}) => {
  80. let list = data.list.map(item => {
  81. item.space = obj.space(obj.lat,obj.lon,item.latitude,item.longitude)
  82. console.log(item.space,'item.space++++++++++')
  83. return item
  84. })
  85. obj.list = obj.list.concat(list)
  86. obj.page++;
  87. if (obj.limit == data.list.length) {
  88. //判断是否还有数据, 有改为 more, 没有改为noMore
  89. obj.loadingType = 'more';
  90. return;
  91. } else {
  92. //判断是否还有数据, 有改为 more, 没有改为noMore
  93. obj.loadingType = 'noMore';
  94. }
  95. // uni.hideLoading();
  96. this.$set(obj, 'loaded', true);
  97. })
  98. },
  99. navTo(url) {
  100. uni.navigateTo({
  101. url: url
  102. })
  103. },
  104. getStoreList(latitude,longitude) {
  105. let obj = this
  106. getStoreList({
  107. page: obj.page,
  108. limit: obj.limit,
  109. latitude: latitude,
  110. longitude: longitude
  111. }).then( ({data}) => {
  112. data.list = data.list.map(item => {
  113. item.space = obj.space(obj.lat,obj.lon,item.latitude,item.longitude)
  114. console.log(item.space,'item.space++++++++++')
  115. return item
  116. })
  117. obj.storeList = data.list
  118. })
  119. },
  120. space(lat1, lng1,lat2,lng2) {
  121. console.log(lat1, lng1, lat2, lng2, '位置信息');
  122. var radLat1 = (lat1 * Math.PI) / 180.0;
  123. var radLat2 = (lat2 * Math.PI) / 180.0;
  124. var a = radLat1 - radLat2;
  125. var b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  126. var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
  127. s = s * 6378.137;
  128. s = Math.round(s * 10000) / 10000;
  129. // return s * 1000;
  130. if (s > 1) {
  131. return s.toFixed(2) + 'km';
  132. } else {
  133. return s * 1000 + 'm'; // 单位米
  134. }
  135. },
  136. }
  137. }
  138. </script>
  139. <style lang="scss" scoped>
  140. .store-list {
  141. padding-top: 20rpx;
  142. }
  143. .store {
  144. margin: 0 auto 20rpx;
  145. width: 710rpx;
  146. height: 210rpx;
  147. background: #ffffff;
  148. box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.1);
  149. border-radius: 10rpx;
  150. padding: 19rpx 25rpx 11rpx 20rpx;
  151. justify-content: flex-start;
  152. .store-img {
  153. flex-shrink: 0;
  154. width: 180rpx;
  155. height: 180rpx;
  156. border-radius: 10rpx;
  157. }
  158. .store-info {
  159. width: 100%;
  160. height: 100%;
  161. padding-left: 19rpx;
  162. position: relative;
  163. .store-name {
  164. max-width: 400rpx;
  165. font-size: 30rpx;
  166. font-family: PingFang SC;
  167. font-weight: bold;
  168. color: #333333;
  169. }
  170. .store-detail {
  171. padding-top: 10rpx;
  172. font-size: 22rpx;
  173. font-family: PingFang SC;
  174. font-weight: 500;
  175. color: #666666;
  176. }
  177. .store-tip {
  178. width: 66rpx;
  179. height: 40rpx;
  180. background: linear-gradient(120deg, #ffc063, #ffa163);
  181. border-radius: 8rpx;
  182. position: absolute;
  183. right: 0;
  184. top: 0;
  185. font-size: 24rpx;
  186. font-family: PingFang SC;
  187. font-weight: 500;
  188. color: #ffffff;
  189. line-height: 40rpx;
  190. text-align: center;
  191. }
  192. .store-des {
  193. // width: 400rpx;
  194. position: absolute;
  195. bottom: 0;
  196. font-size: 24rpx;
  197. font-family: PingFang SC;
  198. font-weight: 500;
  199. color: #999999;
  200. height: 35rpx;
  201. image {
  202. margin-right: 8rpx;
  203. width: 17rpx;
  204. height: 24rpx;
  205. }
  206. }
  207. }
  208. }
  209. </style>