store-pick.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. console.log('onLoad->', options);
  48. this.mchIndex = options.mchIndex;
  49. this.firstGoodsId = options.firstGoodsId || null;
  50. this.plugin = options.plugin || null;
  51. },
  52. onShow() {
  53. if (!this.manualLocation) this.getLocation();
  54. },
  55. methods: {
  56. getLocation() {
  57. console.log('getLocation-->');
  58. uni.showLoading({
  59. mask: true,
  60. title: '正在获取位置信息',
  61. });
  62. uni.getLocation({
  63. success: (e) => {
  64. console.log('getLocation success->', e);
  65. uni.hideLoading();
  66. this.longitude = e.longitude;
  67. this.latitude = e.latitude;
  68. this.loadData();
  69. },
  70. fail: () => {
  71. uni.hideLoading();
  72. uni.showModal({
  73. title: '提示',
  74. content: '获取位置信息失败,需要授权获取您的位置信息',
  75. showCancel: false,
  76. confirmText: '打开授权',
  77. success(e) {
  78. if (e.confirm) {
  79. uni.openSetting({});
  80. }
  81. }
  82. });
  83. },
  84. });
  85. },
  86. selectLocation() {
  87. console.log('selectLocation-->');
  88. this.manualLocation = true;
  89. uni.chooseLocation({
  90. success: e => {
  91. console.log('chooseLocation success->', e);
  92. this.longitude = e.longitude;
  93. this.latitude = e.latitude;
  94. this.locationAddress = (e.address || '') + ' ' + e.name || '';
  95. this.locationAddress = this.locationAddress.trim();
  96. this.loadData();
  97. },
  98. fail: e => {
  99. console.log('chooseLocation fail->', e);
  100. },
  101. });
  102. },
  103. loadData() {
  104. uni.showLoading({
  105. mask: true,
  106. title: '加载中',
  107. });
  108. this.$request({
  109. url: this.plugin === 'booking' ? this.$api.book.store_list : this.$api.order.store_list,
  110. data: {
  111. keyword: '',
  112. longitude: this.longitude,
  113. latitude: this.latitude,
  114. goods_id: this.firstGoodsId,
  115. }
  116. }).then(response => {
  117. uni.hideLoading();
  118. if (response.code === 0) {
  119. this.list = response.data.list;
  120. } else {
  121. }
  122. }).catch(() => {
  123. uni.hideLoading();
  124. });
  125. },
  126. setData(data) {
  127. if (this.plugin === 'gift') {
  128. let store_id = this.$store.state.gift.store_id;
  129. store_id = data;
  130. this.$store.commit('gift/storeId', data);
  131. } else {
  132. const formData = this.$store.state.orderSubmit.formData;
  133. formData.list[this.mchIndex].store_id = data;
  134. this.$store.commit('orderSubmit/mutSetFormData', formData);
  135. }
  136. uni.navigateBack();
  137. },
  138. }
  139. }
  140. </script>
  141. <style lang="scss">
  142. page {
  143. background: $uni-weak-color-two;
  144. }
  145. </style>
  146. <style scoped lang="scss">
  147. .mb-8 {
  148. margin-bottom: #{8rpx};
  149. }
  150. .page {
  151. border-top: #{1rpx} solid $uni-weak-color-one;
  152. }
  153. .manual-location {
  154. padding: #{24rpx};
  155. .location-address {
  156. padding: #{12rpx} 0 0;
  157. font-size: $uni-font-size-general-two;
  158. color: $uni-general-color-two;
  159. }
  160. }
  161. .list {
  162. .item {
  163. padding: #{24rpx};
  164. background: #fff;
  165. border-bottom: #{1rpx} solid $uni-weak-color-one;
  166. .avatar {
  167. width: #{140rpx};
  168. height: #{140rpx};
  169. margin-right: #{24rpx};
  170. border-radius: #{999rpx};
  171. box-shadow: 0 0 #{1rpx} rgba(0, 0, 0, .25);
  172. }
  173. .name {
  174. white-space: nowrap;
  175. overflow: hidden;
  176. text-overflow: ellipsis;
  177. }
  178. .mobile, .distance {
  179. font-size: $uni-font-size-general-one;
  180. color: $uni-general-color-two;
  181. }
  182. }
  183. }
  184. </style>