store-pick.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <app-layout>
  3. <view class="page">
  4. <template v-if="list !== null">
  5. <view v-if="!list.length" class="no-data">暂无门店</view>
  6. <view v-else class="main-center dir-top-nowrap list">
  7. <view class="manual-location">
  8. <app-button type="general" @click="selectLocation">手动定位</app-button>
  9. <view v-if="locationAddress" class="location-address">
  10. {{locationAddress}}
  11. </view>
  12. </view>
  13. <view v-for="(item,index) in list"
  14. :key="index"
  15. @click="setData(item.id, index)"
  16. class="dir-left-nowrap item">
  17. <view class="box-grow-0">
  18. <image :src="item.cover_url" class="avatar"></image>
  19. </view>
  20. <view class="box-grow-1">
  21. <view class="name mb-8">{{item.name}}</view>
  22. <view class="mobile mb-8">电话: {{item.mobile}}</view>
  23. <view class="distance">距离: {{item.distance}}</view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. </view>
  29. </app-layout>
  30. </template>
  31. <script>
  32. export default {
  33. name: 'store-pick',
  34. data() {
  35. return {
  36. mchIndex: null,
  37. list: null,
  38. firstGoodsId: null,
  39. plugin: null,
  40. manualLocation: false,
  41. longitude: '',
  42. latitude: '',
  43. locationAddress: null,
  44. };
  45. },
  46. onLoad(options) {
  47. this.mchIndex = options.mchIndex;
  48. this.firstGoodsId = options.firstGoodsId || null;
  49. this.plugin = options.plugin || null;
  50. },
  51. onShow() {
  52. if (!this.manualLocation) this.getLocation();
  53. },
  54. methods: {
  55. getLocation() {
  56. uni.showLoading({
  57. mask: true,
  58. title: '正在获取位置信息',
  59. });
  60. uni.getLocation({
  61. success: (e) => {
  62. uni.hideLoading();
  63. this.longitude = e.longitude;
  64. this.latitude = e.latitude;
  65. this.loadData();
  66. },
  67. fail: () => {
  68. uni.hideLoading();
  69. uni.showModal({
  70. title: '提示',
  71. content: '获取位置信息失败,需要授权获取您的位置信息',
  72. showCancel: false,
  73. confirmText: '打开授权',
  74. success(e) {
  75. if (e.confirm) {
  76. uni.openSetting({});
  77. }
  78. }
  79. });
  80. },
  81. });
  82. },
  83. selectLocation() {
  84. this.manualLocation = true;
  85. uni.chooseLocation({
  86. success: e => {
  87. this.longitude = e.longitude;
  88. this.latitude = e.latitude;
  89. this.locationAddress = (e.address || '') + ' ' + e.name || '';
  90. this.locationAddress = this.locationAddress.trim();
  91. this.loadData();
  92. }
  93. });
  94. },
  95. loadData() {
  96. uni.showLoading({
  97. mask: true,
  98. title: '加载中',
  99. });
  100. this.$request({
  101. url: this.plugin === 'booking' ? this.$api.book.store_list : this.$api.order.store_list,
  102. data: {
  103. keyword: '',
  104. longitude: this.longitude,
  105. latitude: this.latitude,
  106. goods_id: this.firstGoodsId,
  107. }
  108. }).then(response => {
  109. uni.hideLoading();
  110. if (response.code === 0) {
  111. this.list = response.data.list;
  112. } else {
  113. }
  114. }).catch(() => {
  115. uni.hideLoading();
  116. });
  117. },
  118. setData(data) {
  119. if (this.plugin === 'gift') {
  120. let store_id = this.$store.state.gift.store_id;
  121. store_id = data;
  122. this.$store.commit('gift/storeId', data);
  123. } else {
  124. const formData = this.$store.state.orderSubmit.formData;
  125. formData.list[this.mchIndex].store_id = data;
  126. this.$store.commit('orderSubmit/mutSetFormData', formData);
  127. }
  128. uni.navigateBack();
  129. },
  130. }
  131. }
  132. </script>
  133. <style lang="scss">
  134. page {
  135. background: $uni-weak-color-two;
  136. }
  137. </style>
  138. <style scoped lang="scss">
  139. .mb-8 {
  140. margin-bottom: #{8rpx};
  141. }
  142. .page {
  143. border-top: #{1rpx} solid $uni-weak-color-one;
  144. }
  145. .manual-location {
  146. padding: #{24rpx};
  147. .location-address {
  148. padding: #{12rpx} 0 0;
  149. font-size: $uni-font-size-general-two;
  150. color: $uni-general-color-two;
  151. }
  152. }
  153. .list {
  154. .item {
  155. padding: #{24rpx};
  156. background: #fff;
  157. border-bottom: #{1rpx} solid $uni-weak-color-one;
  158. .avatar {
  159. width: #{140rpx};
  160. height: #{140rpx};
  161. margin-right: #{24rpx};
  162. border-radius: #{999rpx};
  163. box-shadow: 0 0 #{1rpx} rgba(0, 0, 0, .25);
  164. }
  165. .name {
  166. white-space: nowrap;
  167. overflow: hidden;
  168. text-overflow: ellipsis;
  169. }
  170. .mobile, .distance {
  171. font-size: $uni-font-size-general-one;
  172. color: $uni-general-color-two;
  173. }
  174. }
  175. }
  176. </style>