shoplist.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <template>
  2. <view class="center">
  3. <view class="djq-wrap flex f-ai-s" v-for="storeitem in storeList">
  4. <image :src="storeitem.image" mode="" class="djq-img"></image>
  5. <view class="djq-right pl20">
  6. <view class="djq-tit flex f-j-sb f-ai-s">
  7. <view class="djq-name clamp">{{ storeitem.name }}</view>
  8. <!-- <view class="djq-dis">
  9. <image src="../../static/icon/index10.png" mode=""></image>
  10. 距离{{ storeitem.range * 1 }}KM
  11. </view> -->
  12. </view>
  13. <view class="flex f-d-c f-j-sb f-ai-s fg1" style="height: 110rpx;">
  14. <view class="djq-dz clamp">{{ storeitem.detailed_address }}</view>
  15. <view class="djq-hd flex f-j-sb">
  16. <view class="buy-info"><!-- {{storeitem.count}}人已购买 --></view>
  17. <view class="hd-btn">
  18. <image src="../../static/icon/call.png" mode="" style="margin-right: 15rpx;" @click.stop="makeCall(storeitem.phone)"></image>
  19. <!-- #ifdef H5 -->
  20. <image src="../../static/icon/dh.png" mode="" @click.stop="toGaodeMap(storeitem.latitude, storeitem.longitude, storeitem.name)"></image>
  21. <!-- #endif -->
  22. <!-- #ifdef MP -->
  23. <image src="../../static/icon/dh.png" mode="" @click.stop="dh(storeitem)"></image>
  24. <!-- #endif -->
  25. </view>
  26. </view>
  27. </view>
  28. </view>
  29. </view>
  30. <uni-load-more :status="loadingType"></uni-load-more>
  31. </view>
  32. </template>
  33. <script>
  34. import { store_list } from '@/api/coupon.js';
  35. export default {
  36. data() {
  37. return {
  38. page: 1,
  39. limitt: 20,
  40. loadingType: 'more',
  41. district: '定位中',
  42. storeList: [],
  43. latitude: '',
  44. longitude: ''
  45. };
  46. },
  47. onReachBottom() {
  48. this.getStoreList();
  49. },
  50. onLoad: function(option) {
  51. this.getaddress();
  52. },
  53. onShow: function() {
  54. this.getStoreList();
  55. },
  56. methods: {
  57. getaddress() {
  58. console.log('dizhi+++++++++++');
  59. let obj = this;
  60. uni.getLocation({
  61. type: 'gcj02',
  62. success: res => {
  63. obj.latitude = res.latitude;
  64. obj.longitude = res.longitude;
  65. },
  66. fail: err => {
  67. console.log(err, 'shi+++++++++++++++');
  68. openMap().then(e => {
  69. this.getaddress();
  70. });
  71. }
  72. });
  73. },
  74. getStoreList() {
  75. let obj = this;
  76. if (obj.loadingType == 'loading' || obj.loadingType == 'noMore') {
  77. return;
  78. }
  79. obj.loadingType = 'loading';
  80. store_list({
  81. page: obj.page,
  82. latitude: obj.latitude,
  83. longitude: obj.longitude,
  84. limit: obj.limitt
  85. }).then(res => {
  86. if (res.data.list.length > 0) {
  87. res.data.list.forEach(e => {
  88. e.range = this.getFlatternDistance(this.latitude, this.longitude, e.latitude, e.longitude);
  89. });
  90. obj.storeList = obj.storeList.concat(res.data.list);
  91. obj.page++;
  92. console.log('数据加载完毕');
  93. }
  94. if (obj.limitt == res.data.list.length) {
  95. //说明数据已经加载完毕了
  96. obj.loadingType = 'more';
  97. console.log('加载完毕1111111');
  98. } else {
  99. console.log('加载完毕1222222222211');
  100. obj.loadingType = 'noMore';
  101. }
  102. //说明还有数据
  103. this.$set(obj.storeList, 'loaded', true);
  104. });
  105. },
  106. // 导航
  107. dh(item) {
  108. wx.openLocation({
  109. latitude: item.latitude * 1,
  110. longitude: item.longitude * 1,
  111. name: item.name,
  112. address: item.detailed_address
  113. });
  114. },
  115. //根据经纬度计算距离
  116. getFlatternDistance(lat1, lng1, lat2, lng2) {
  117. let radLat1 = (lat1 * Math.PI) / 180.0;
  118. let radLat2 = (lat2 * Math.PI) / 180.0;
  119. let a = radLat1 - radLat2;
  120. let b = (lng1 * Math.PI) / 180.0 - (lng2 * Math.PI) / 180.0;
  121. let 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)));
  122. s = s * 6378.137;
  123. s = Math.round(s * 10000) / 10000;
  124. return s;
  125. },
  126. // 拨打电话
  127. makeCall(phone) {
  128. uni.makePhoneCall({
  129. phoneNumber: phone //仅为示例
  130. });
  131. }
  132. }
  133. };
  134. </script>
  135. <style lang="scss">
  136. .djq-wrap {
  137. width: 701rpx;
  138. // height: 255rpx;
  139. background: #ffffff;
  140. box-shadow: 0px 0px 27rpx 0px rgba(50, 50, 52, 0.06);
  141. border-radius: 20rpx;
  142. margin: 0 auto 20rpx;
  143. padding: 23rpx 22rpx;
  144. &:last-of-type {
  145. margin-bottom: 0;
  146. }
  147. .djq-img {
  148. flex-shrink: 0;
  149. width: 150rpx;
  150. height: 150rpx;
  151. border-radius: 10rpx;
  152. }
  153. .djq-right {
  154. flex-grow: 1;
  155. .djq-tit {
  156. font-size: 34rpx;
  157. font-weight: bold;
  158. color: #333333;
  159. line-height: 52rpx;
  160. .djq-name {
  161. max-width: 300rpx;
  162. }
  163. .djq-dis {
  164. flex-shrink: 0;
  165. image {
  166. width: 20rpx;
  167. height: 28rpx;
  168. margin-right: 10rpx;
  169. }
  170. font-size: 22rpx;
  171. font-weight: 500;
  172. color: #666666;
  173. }
  174. }
  175. .djq-dz {
  176. width: 100%;
  177. font-size: 24rpx;
  178. font-weight: 500;
  179. color: #666666;
  180. }
  181. .djq-hd {
  182. width: 100%;
  183. // border-bottom: 1rpx solid #EAECED;
  184. .buy-info {
  185. display: inline-block;
  186. height: 32rpx;
  187. border-radius: 16rpx 16rpx 16rpx 0px;
  188. line-height: 32rpx;
  189. font-size: 20rpx;
  190. font-weight: 500;
  191. color: #ff440d;
  192. padding: 0 15rpx;
  193. background-color: #fff;
  194. }
  195. .hd-btn {
  196. image {
  197. width: 46rpx;
  198. height: 46rpx;
  199. }
  200. }
  201. }
  202. }
  203. }
  204. </style>