index.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <template>
  2. <view :style="colorStyle">
  3. <view class="list">
  4. <view class="item" v-for="(item, index) in storeList" :key="index" @click.stop="checked(item)">
  5. <view class="name line1">{{ item.name }}</view>
  6. <view class="address acea-row row-top row-between">
  7. <view class="iconfont icon-dingwei1"></view>
  8. <view class="right">
  9. <text v-if="item.range">距离您{{ item.range }}km</text>
  10. <text v-else>查看地图</text>
  11. <text class="line"></text>{{ item.address }}{{ ", " + item.detailed_address }}</view>
  12. </view>
  13. <view class="time address acea-row row-top row-between">
  14. <view class="iconfont icon-yingyeshijian"></view>
  15. <view class="right">营业时间:{{item.day_time}}</view>
  16. </view>
  17. <view class="bottom acea-row row-center-wrapper">
  18. <view class="bnt" @click.stop="showMaoLocation(item)"><text class="iconfont icon-daohangdaodian"></text>导航到店</view>
  19. <!-- #ifdef H5 -->
  20. <a class="bnt" :href="'tel:' + item.phone"><text class="iconfont icon-zhidianzixun"></text>致电咨询</a>
  21. <!-- #endif -->
  22. <!-- #ifdef MP || APP-PLUS -->
  23. <view class="bnt" @click.stop="call(item.phone)"><text class="iconfont icon-zhidianzixun"></text>致电咨询</view>
  24. <!-- #endif -->
  25. </view>
  26. </view>
  27. </view>
  28. <Loading :loaded="loaded" :loading="loading"></Loading>
  29. </view>
  30. </template>
  31. <script>
  32. import Loading from "@/components/Loading";
  33. import {
  34. storeListApi
  35. } from "@/api/store";
  36. import {
  37. isWeixin
  38. } from "@/utils/index";
  39. // #ifdef H5
  40. import {
  41. wechatEvevt,
  42. wxShowLocation
  43. } from "@/libs/wechat";
  44. // #endif
  45. import colors from "@/mixins/color";
  46. import {
  47. mapGetters
  48. } from "vuex";
  49. const LONGITUDE = "user_longitude";
  50. const LATITUDE = "user_latitude";
  51. const MAPKEY = "mapKey";
  52. export default {
  53. name: "storeList",
  54. components: {
  55. Loading
  56. },
  57. mixins: [colors],
  58. data() {
  59. return {
  60. page: 1,
  61. limit: 20,
  62. loaded: false,
  63. loading: false,
  64. storeList: [],
  65. system_store: {},
  66. user_latitude: 0,
  67. user_longitude: 0,
  68. comeType: 0,
  69. cartId: '',
  70. new: '',
  71. pinkId: '',
  72. couponId: ''
  73. };
  74. },
  75. onLoad(options) {
  76. if (options.cartId) {
  77. this.cartId = options.cartId;
  78. this.new = options.new;
  79. this.pinkId = options.pinkId;
  80. this.couponId = options.couponId;
  81. }
  82. this.comeType = options.type
  83. try {
  84. this.user_latitude = uni.getStorageSync('user_latitude');
  85. this.user_longitude = uni.getStorageSync('user_longitude');
  86. } catch (e) {}
  87. },
  88. onShow() {
  89. uni.removeStorageSync('form_type_cart');
  90. },
  91. mounted() {
  92. if (this.user_latitude && this.user_longitude) {
  93. this.getList();
  94. } else {
  95. this.selfLocation();
  96. }
  97. },
  98. methods: {
  99. call(phone) {
  100. uni.makePhoneCall({
  101. phoneNumber: phone,
  102. });
  103. },
  104. selfLocation() {
  105. let self = this
  106. // #ifdef H5
  107. if (self.$wechat.isWeixin()) {
  108. self.$wechat.location().then(res => {
  109. this.user_latitude = res.latitude;
  110. this.user_longitude = res.longitude;
  111. uni.setStorageSync('user_latitude', res.latitude);
  112. uni.setStorageSync('user_longitude', res.longitude);
  113. self.getList();
  114. })
  115. } else {
  116. // #endif
  117. uni.getLocation({
  118. type: 'wgs84',
  119. success: (res) => {
  120. try {
  121. this.user_latitude = res.latitude;
  122. this.user_longitude = res.longitude;
  123. uni.setStorageSync('user_latitude', res.latitude);
  124. uni.setStorageSync('user_longitude', res.longitude);
  125. } catch {}
  126. self.getList();
  127. },
  128. complete: function() {
  129. self.getList();
  130. }
  131. });
  132. // #ifdef H5
  133. }
  134. // #endif
  135. },
  136. showMaoLocation(e) {
  137. let self = this;
  138. // #ifdef H5
  139. if (self.$wechat.isWeixin()) {
  140. self.$wechat.seeLocation({
  141. latitude: Number(e.latitude),
  142. longitude: Number(e.longitude),
  143. name: e.name,
  144. scale: 13,
  145. address: `${e.address}-${e.detailed_address}`,
  146. }).then(res => {})
  147. } else {
  148. // #endif
  149. uni.openLocation({
  150. latitude: Number(e.latitude),
  151. longitude: Number(e.longitude),
  152. name: e.name,
  153. address: `${e.address}-${e.detailed_address}`,
  154. success: function() {
  155. Number
  156. }
  157. });
  158. // #ifdef H5
  159. }
  160. // #endif
  161. },
  162. // 选中门店
  163. checked(e) {
  164. if (this.comeType) {
  165. uni.$emit("handClick", {
  166. address: e,
  167. cartId: this.cartId,
  168. new: this.new,
  169. pinkId: this.pinkId,
  170. couponId: this.couponId
  171. });
  172. uni.navigateBack();
  173. }
  174. },
  175. // 获取门店列表数据
  176. getList: function() {
  177. if (this.loading || this.loaded) return;
  178. this.loading = true;
  179. let data = {
  180. latitude: this.user_latitude || "", //纬度
  181. longitude: this.user_longitude || "", //经度
  182. page: this.page,
  183. limit: this.limit
  184. };
  185. storeListApi(data)
  186. .then(res => {
  187. this.loading = false;
  188. this.loaded = res.data.list.length < this.limit;
  189. this.storeList.push.apply(this.storeList, res.data.list.list);
  190. this.page = this.page + 1;
  191. })
  192. .catch(err => {
  193. this.$util.Tips({
  194. title: err
  195. })
  196. });
  197. }
  198. },
  199. onReachBottom() {
  200. this.getList();
  201. }
  202. };
  203. </script>
  204. <style lang="scss">
  205. .list{
  206. padding-top: 24rpx;
  207. .item{
  208. width: 690rpx;
  209. background-color: #fff;
  210. border-radius: 12rpx;
  211. margin: 0 auto 24rpx auto;
  212. padding: 28rpx 28rpx 0 28rpx;
  213. box-sizing: border-box;
  214. .name{
  215. font-size: 28rpx;
  216. color: #333;
  217. font-weight: 600;
  218. position: relative;
  219. padding-left: 12rpx;
  220. &::after{
  221. position: absolute;
  222. width: 4rpx;
  223. height: 28rpx;
  224. background-color: #E93323;
  225. content: ' ';
  226. left:0;
  227. top:50%;
  228. margin-top: -14rpx;
  229. }
  230. }
  231. .address{
  232. font-size: 24rpx;
  233. color: #666;
  234. margin-top: 24rpx;
  235. .iconfont{
  236. font-size: 30rpx;
  237. width: 38rpx;
  238. height: 38rpx;
  239. line-height: 38rpx;
  240. }
  241. .right{
  242. width: 594rpx;
  243. .line{
  244. width: 2rpx;
  245. height: 20rpx;
  246. background-color: #ccc;
  247. display: inline-block;
  248. margin: 0 20rpx;
  249. }
  250. }
  251. &.time{
  252. margin-top: 20rpx;
  253. .iconfont{
  254. font-size: 28rpx;
  255. }
  256. }
  257. }
  258. .bottom{
  259. height: 92rpx;
  260. border-top: 1rpx solid #eee;
  261. margin-top: 30rpx;
  262. position: relative;
  263. &::after{
  264. position: absolute;
  265. content: ' ';
  266. width: 1rpx;
  267. height: 60rpx;
  268. background-color: #eee;
  269. }
  270. .bnt{
  271. width: 314rpx;
  272. text-align: center;
  273. font-size: 26rpx;
  274. color: #333;
  275. text-decoration: none;
  276. .iconfont{
  277. font-size: 35rpx;
  278. margin-right: 12rpx;
  279. display: inline-block;
  280. vertical-align: bottom;
  281. }
  282. }
  283. }
  284. }
  285. }
  286. </style>