敢为人鲜小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
4.8 KiB

  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="取餐点" leftClick @leftClick="$utils.navigateBack" color="#fff" />
  5. <view class="container">
  6. <view class="header">
  7. <view class="title">附近取餐点</view>
  8. </view>
  9. <!-- 取餐点列表 -->
  10. <view class="pickup-list">
  11. <view class="pickup-item" v-for="(item, index) in pickupPoints" :key="index">
  12. <view class="left">
  13. <image :src="item.spotImage" class="shop-image" mode="aspectFill"></image>
  14. </view>
  15. <view class="center">
  16. <view class="shop-name">{{item.spotName}}</view>
  17. <view class="shop-address">
  18. <uv-icon name="map-fill" color="#019245" size="34rpx"></uv-icon>
  19. <text class="address-text"> {{ item.area }} {{ item.address }}{{item.area }}</text>
  20. </view>
  21. <view class="shop-phone">
  22. <uv-icon name="phone-fill" color="#019245" size="34rpx"></uv-icon>
  23. <text class="phone-text">{{item.phone}}</text>
  24. </view>
  25. </view>
  26. <view class="right">
  27. <button class="select-btn" hover-class="select-btn-active" @tap="selectPoint(item)">选择</button>
  28. </view>
  29. </view>
  30. </view>
  31. <!-- 无数据提示 -->
  32. <uv-empty v-if="pickupPoints.length === 0" text="暂无取餐点" mode="list" />
  33. </view>
  34. </view>
  35. </template>
  36. <script>
  37. import navbar from '@/components/base/navbar.vue'
  38. import position from '@/utils/position.js'
  39. export default {
  40. components: {
  41. navbar
  42. },
  43. data() {
  44. return {
  45. pickupPoints: [],
  46. location: {
  47. latitude: 0,
  48. longitude: 0
  49. }
  50. }
  51. },
  52. methods: {
  53. // 选择取餐点
  54. selectPoint(point) {
  55. // 将选择的取餐点信息存储到 store 或 storage 中
  56. uni.setStorageSync('selectedPickupPoint', JSON.stringify(point));
  57. // 通知上一页面已选择取餐点,并返回
  58. // const pages = getCurrentPages();
  59. // const prevPage = pages[pages.length - 2];
  60. // if (prevPage) {
  61. // // 如果需要可以设置上一页的数据
  62. // prevPage.$vm.pickupPoint = point;
  63. // }
  64. uni.$emit('updatePickupPoint', point);
  65. uni.showToast({
  66. title: '已选择取餐点',
  67. icon: 'success',
  68. duration: 400
  69. });
  70. setTimeout(() => {
  71. // uni.navigateBack();
  72. this.$utils.navigateBack()
  73. }, 800);
  74. }
  75. },
  76. finalPickupPoints() {
  77. // 算出一定范围内的取餐点
  78. const arr = this.pickupPoints.filter(item => position.calculateDistance(this.location.latitude, this.location.longitude, item.latitude, item.longitude) < 1000)
  79. console.log('算出一定范围内的取餐点', arr);
  80. // 根据近距离取餐点 进行排序
  81. this.pickupPoints = arr.sort((a, b) => position.calculateDistance(this.location.latitude, this.location.longitude, a.latitude, a.longitude) - position.calculateDistance(this.location.latitude, this.location.longitude, b.latitude, b.longitude))
  82. console.log('根据近距离取餐点 进行排序', this.pickupPoints);
  83. },
  84. onLoad() {
  85. this.$api('queryLeaderList', {}, res => {
  86. if (res.code == 200) {
  87. this.pickupPoints = res.result.records
  88. }
  89. })
  90. position.getLocation( res => {
  91. if (res.latitude && res.longitude) {
  92. this.location.latitude = res.latitude
  93. this.location.longitude = res.longitude
  94. this.finalPickupPoints()
  95. }
  96. })
  97. }
  98. }
  99. </script>
  100. <style lang="scss" scoped>
  101. .page {
  102. background-color: #f5f5f5;
  103. min-height: 100vh;
  104. }
  105. .container {
  106. padding: 0 20rpx;
  107. }
  108. .header {
  109. margin-top: 20rpx;
  110. background-color: #f2f2f2;
  111. border-radius: 8rpx;
  112. .title {
  113. font-size: 32rpx;
  114. // font-weight: bold;
  115. padding: 20rpx;
  116. }
  117. }
  118. .pickup-list {
  119. margin-top: 20rpx;
  120. .pickup-item {
  121. display: flex;
  122. background-color: #fff;
  123. padding: 20rpx;
  124. margin-bottom: 20rpx;
  125. border-radius: 8rpx;
  126. .left {
  127. width: 160rpx;
  128. height: 160rpx;
  129. margin-right: 20rpx;
  130. .shop-image {
  131. width: 100%;
  132. height: 100%;
  133. border-radius: 8rpx;
  134. }
  135. }
  136. .center {
  137. flex: 1;
  138. display: flex;
  139. flex-direction: column;
  140. justify-content: space-between;
  141. // gap: 8rpx;
  142. .shop-name {
  143. font-size: 32rpx;
  144. // font-weight: bold;
  145. margin-bottom: 10rpx;
  146. }
  147. .shop-address, .shop-phone {
  148. font-size: 24rpx;
  149. color: #999;
  150. display: flex;
  151. align-items: start;
  152. margin-bottom: 6rpx;
  153. gap: 8rpx;
  154. width: 90%;
  155. }
  156. }
  157. .right {
  158. width: 100rpx;
  159. display: flex;
  160. align-items: center;
  161. justify-content: center;
  162. .select-btn {
  163. width: 90rpx;
  164. height: 60rpx;
  165. line-height: 60rpx;
  166. text-align: center;
  167. background-color: $uni-color;
  168. color: #fff;
  169. font-size: 24rpx;
  170. border-radius: 12rpx;
  171. padding: 0;
  172. }
  173. .select-btn-active {
  174. background-color: #106035;
  175. }
  176. }
  177. }
  178. }
  179. </style>