store-pick.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <app-layout>
  3. <view class="page">
  4. <view class="top">
  5. <view class="dir-left-nowrap box">
  6. <input type="text" class="box-grow-1 input" confirm-type="搜索" @confirm="search"
  7. v-model="keyword">
  8. <view class="close-tip" @click="clear">
  9. <image class="search-close" v-if="keyword"
  10. src="/static/image/icon/delete-yuan.png"></image>
  11. </view>
  12. <view class="box-grow-0 cross-center" @click="search">搜索</view>
  13. </view>
  14. </view>
  15. <template v-if="list !== null">
  16. <template v-if="!list.length">
  17. <view class="main-center no-result" style="margin-top: 100rpx">
  18. <view class="dir-left-nowrap cross-center">
  19. <image class="box-grow-0 empty" src="../../static/image/icon/empty.png"></image>
  20. <view class="box-grow-1">
  21. <view>抱歉,没有相关门店</view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <view v-else class="main-center dir-top-nowrap list" style="margin-top: 100rpx">
  27. <view class="manual-location" v-if="!keyword">
  28. <app-button type="general" @click="selectLocation">手动定位</app-button>
  29. <view v-if="locationAddress" class="location-address">
  30. {{locationAddress}}
  31. </view>
  32. </view>
  33. <view v-for="(item,index) in list"
  34. :key="index"
  35. @click="setData(item.id, index)"
  36. class="dir-left-nowrap item">
  37. <view class="box-grow-0">
  38. <image :src="item.cover_url" class="avatar"></image>
  39. </view>
  40. <view class="box-grow-1">
  41. <view class="name mb-8">{{item.name}}</view>
  42. <view class="mobile mb-8">电话: {{item.mobile}}</view>
  43. <view class="distance">距离: {{item.distance}}</view>
  44. </view>
  45. </view>
  46. </view>
  47. </template>
  48. </view>
  49. </app-layout>
  50. </template>
  51. <script>
  52. export default {
  53. name: 'store-pick',
  54. data() {
  55. return {
  56. mchIndex: null,
  57. list: null,
  58. firstGoodsId: null,
  59. plugin: null,
  60. manualLocation: false,
  61. longitude: '',
  62. latitude: '',
  63. locationAddress: null,
  64. keyword: '',
  65. };
  66. },
  67. onLoad(options) { this.$commonLoad.onload(options);
  68. this.mchIndex = options.mchIndex;
  69. this.firstGoodsId = options.firstGoodsId || null;
  70. this.plugin = options.plugin || null;
  71. },
  72. onShow() {
  73. if (!this.manualLocation) this.getLocation();
  74. },
  75. methods: {
  76. //搜索
  77. clear() {
  78. uni.hideKeyboard()
  79. this.keyword = '';
  80. this.loadData();
  81. },
  82. search() {
  83. this.loadData();
  84. },
  85. getLocation() {
  86. uni.showLoading({
  87. mask: true,
  88. title: '正在获取位置信息',
  89. });
  90. // #ifdef MP
  91. uni.getLocation({
  92. success: (e) => {
  93. uni.hideLoading();
  94. this.longitude = e.longitude;
  95. this.latitude = e.latitude;
  96. this.loadData();
  97. },
  98. fail: () => {
  99. uni.hideLoading();
  100. uni.showModal({
  101. title: '提示',
  102. content: '获取位置信息失败,需要授权获取您的位置信息',
  103. showCancel: false,
  104. confirmText: '打开授权',
  105. success(e) {
  106. if (e.confirm) {
  107. uni.openSetting({});
  108. }
  109. }
  110. });
  111. },
  112. });
  113. // #endif
  114. // #ifdef H5
  115. let _this = this;
  116. this.$jwx.getLocation({
  117. success(e) {
  118. uni.hideLoading();
  119. _this.longitude = e.longitude;
  120. _this.latitude = e.latitude;
  121. _this.loadData();
  122. },
  123. fail() {
  124. uni.hideLoading();
  125. uni.showToast({
  126. title: '需要授权获取您的位置信息',
  127. icon: 'none'
  128. });
  129. }
  130. });
  131. // #endif
  132. },
  133. selectLocation() {
  134. this.manualLocation = true;
  135. uni.chooseLocation({
  136. success: e => {
  137. this.longitude = e.longitude;
  138. this.latitude = e.latitude;
  139. this.locationAddress = (e.address || '') + ' ' + e.name || '';
  140. this.locationAddress = this.locationAddress.trim();
  141. this.loadData();
  142. }
  143. });
  144. },
  145. loadData() {
  146. uni.showLoading({
  147. mask: true,
  148. title: '加载中',
  149. });
  150. this.$request({
  151. url: this.plugin === 'booking' ? this.$api.book.store_list : this.$api.order.store_list,
  152. data: {
  153. keyword: this.keyword,
  154. longitude: this.longitude,
  155. latitude: this.latitude,
  156. goods_id: this.firstGoodsId,
  157. }
  158. }).then(response => {
  159. uni.hideLoading();
  160. if (response.code === 0) {
  161. this.list = response.data.list;
  162. } else {
  163. }
  164. }).catch(() => {
  165. uni.hideLoading();
  166. });
  167. },
  168. setData(data) {
  169. if (this.plugin === 'gift') {
  170. let store_id = this.$store.state.gift.store_id;
  171. store_id = data;
  172. this.$store.commit('gift/storeId', data);
  173. } else {
  174. const formData = this.$store.state.orderSubmit.formData;
  175. formData.list[this.mchIndex].store_id = data;
  176. this.$store.commit('orderSubmit/mutSetFormData', formData);
  177. }
  178. uni.navigateBack();
  179. },
  180. }
  181. }
  182. </script>
  183. <style lang="scss">
  184. page {
  185. background: $uni-weak-color-two;
  186. }
  187. </style>
  188. <style scoped lang="scss">
  189. .no-result {
  190. height: #{156rpx};
  191. padding: #{28rpx} 0;
  192. font-size: $uni-font-size-general-one;
  193. background-color: #ffffff;
  194. .text {
  195. color: $uni-general-color-two;
  196. }
  197. .empty {
  198. width: #{100rpx};
  199. height: #{100rpx};
  200. display: block;
  201. margin-right: #{40rpx};
  202. }
  203. }
  204. .top {
  205. position: fixed;
  206. width: 100%;
  207. top: 0;
  208. z-index: 15;
  209. padding: #{20rpx} #{24rpx};
  210. background-color: #efeff4;
  211. font-size: $uni-font-size-import-two;
  212. color: $uni-general-color-one;
  213. .input {
  214. background-color: #ffffff;
  215. border-radius: #{50rpx 0 0 50rpx};
  216. padding: 0 #{32rpx};
  217. font-size: $uni-font-size-general-one;
  218. height: #{64rpx};
  219. }
  220. .box {
  221. position: relative;
  222. .close-tip {
  223. width: #{64rpx};
  224. height: #{64rpx};
  225. background-color: #ffffff;
  226. border-radius: #{0 50rpx 50rpx 0};
  227. margin-right: #{20rpx};
  228. }
  229. .search-close {
  230. width: #{32rpx};
  231. height: #{32rpx};
  232. border-radius: 50%;
  233. margin: #{16rpx};
  234. }
  235. }
  236. .radio {
  237. margin-top: #{32rpx};
  238. .radio-item {
  239. padding-bottom: #{12rpx};
  240. }
  241. .active {
  242. border-bottom: #{4rpx} solid;
  243. }
  244. }
  245. }
  246. .mb-8 {
  247. margin-bottom: #{8rpx};
  248. }
  249. .page {
  250. border-top: #{1rpx} solid $uni-weak-color-one;
  251. }
  252. .manual-location {
  253. padding: #{24rpx};
  254. .location-address {
  255. padding: #{12rpx} 0 0;
  256. font-size: $uni-font-size-general-two;
  257. color: $uni-general-color-two;
  258. }
  259. }
  260. .list {
  261. .item {
  262. padding: #{24rpx};
  263. background: #fff;
  264. border-bottom: #{1rpx} solid $uni-weak-color-one;
  265. .avatar {
  266. width: #{140rpx};
  267. height: #{140rpx};
  268. margin-right: #{24rpx};
  269. border-radius: #{999rpx};
  270. box-shadow: 0 0 #{1rpx} rgba(0, 0, 0, .25);
  271. }
  272. .name {
  273. white-space: nowrap;
  274. overflow: hidden;
  275. text-overflow: ellipsis;
  276. }
  277. .mobile, .distance {
  278. font-size: $uni-font-size-general-one;
  279. color: $uni-general-color-two;
  280. }
  281. }
  282. }
  283. </style>