index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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. productId: 0
  74. };
  75. },
  76. onLoad(options) {
  77. this.productId = options.productId || 0;
  78. if (options.cartId) {
  79. this.cartId = options.cartId;
  80. this.new = options.new;
  81. this.pinkId = options.pinkId;
  82. this.couponId = options.couponId;
  83. }
  84. this.comeType = options.type
  85. try {
  86. this.user_latitude = uni.getStorageSync('user_latitude');
  87. this.user_longitude = uni.getStorageSync('user_longitude');
  88. this.selfLocation();
  89. if(!this.$util.checkOpenGPSServiceByAndroidIOS()){
  90. this.getList();
  91. }
  92. } catch (e) {
  93. this.getList();
  94. }
  95. },
  96. onShow() {
  97. uni.removeStorageSync('form_type_cart');
  98. },
  99. mounted() {
  100. // if (this.user_latitude && this.user_longitude) {
  101. // this.getList();
  102. // } else {
  103. // this.selfLocation();
  104. // }
  105. },
  106. methods: {
  107. call(phone) {
  108. uni.makePhoneCall({
  109. phoneNumber: phone,
  110. });
  111. },
  112. selfLocation() {
  113. let self = this
  114. // #ifdef H5
  115. if (self.$wechat.isWeixin()) {
  116. self.$wechat.location().then(res => {
  117. this.user_latitude = res.latitude;
  118. this.user_longitude = res.longitude;
  119. uni.setStorageSync('user_latitude', res.latitude);
  120. uni.setStorageSync('user_longitude', res.longitude);
  121. self.getList();
  122. }).catch(err=>{
  123. self.getList();
  124. })
  125. } else {
  126. // #endif
  127. uni.getLocation({
  128. type: 'wgs84',
  129. success: (res) => {
  130. try {
  131. this.user_latitude = res.latitude;
  132. this.user_longitude = res.longitude;
  133. uni.setStorageSync('user_latitude', res.latitude);
  134. uni.setStorageSync('user_longitude', res.longitude);
  135. } catch {}
  136. self.getList();
  137. },
  138. complete: function() {
  139. self.getList();
  140. }
  141. });
  142. // #ifdef H5
  143. }
  144. // #endif
  145. },
  146. showMaoLocation(e) {
  147. let self = this;
  148. // #ifdef H5
  149. if (self.$wechat.isWeixin()) {
  150. self.$wechat.seeLocation({
  151. latitude: Number(e.latitude),
  152. longitude: Number(e.longitude),
  153. name: e.name,
  154. scale: 13,
  155. address: `${e.address}-${e.detailed_address}`,
  156. }).then(res => {})
  157. } else {
  158. // #endif
  159. uni.openLocation({
  160. latitude: Number(e.latitude),
  161. longitude: Number(e.longitude),
  162. name: e.name,
  163. address: `${e.address}-${e.detailed_address}`,
  164. success: function() {
  165. Number
  166. }
  167. });
  168. // #ifdef H5
  169. }
  170. // #endif
  171. },
  172. // 选中门店
  173. checked(e) {
  174. if (this.comeType) {
  175. uni.$emit("handClick", {
  176. address: e,
  177. cartId: this.cartId,
  178. new: this.new,
  179. pinkId: this.pinkId,
  180. couponId: this.couponId
  181. });
  182. uni.navigateBack();
  183. }
  184. },
  185. // 获取门店列表数据
  186. getList: function() {
  187. if (this.loading || this.loaded) return;
  188. this.loading = true;
  189. let data = {
  190. latitude: this.user_latitude || "", //纬度
  191. longitude: this.user_longitude || "", //经度
  192. page: this.page,
  193. limit: this.limit,
  194. product_id: this.productId
  195. };
  196. storeListApi(data)
  197. .then(res => {
  198. this.loading = false;
  199. this.loaded = res.data.list.length < this.limit;
  200. this.storeList.push.apply(this.storeList, res.data.list.list);
  201. this.page = this.page + 1;
  202. })
  203. .catch(err => {
  204. this.$util.Tips({
  205. title: err
  206. })
  207. });
  208. }
  209. },
  210. onReachBottom() {
  211. this.getList();
  212. }
  213. };
  214. </script>
  215. <style lang="scss">
  216. .list{
  217. padding-top: 24rpx;
  218. .item{
  219. width: 690rpx;
  220. background-color: #fff;
  221. border-radius: 12rpx;
  222. margin: 0 auto 24rpx auto;
  223. padding: 28rpx 28rpx 0 28rpx;
  224. box-sizing: border-box;
  225. .name{
  226. font-size: 28rpx;
  227. color: #333;
  228. font-weight: 600;
  229. position: relative;
  230. padding-left: 12rpx;
  231. &::after{
  232. position: absolute;
  233. width: 4rpx;
  234. height: 28rpx;
  235. background-color: #E93323;
  236. content: ' ';
  237. left:0;
  238. top:50%;
  239. margin-top: -14rpx;
  240. }
  241. }
  242. .address{
  243. font-size: 24rpx;
  244. color: #666;
  245. margin-top: 24rpx;
  246. .iconfont{
  247. font-size: 30rpx;
  248. width: 38rpx;
  249. height: 38rpx;
  250. line-height: 38rpx;
  251. }
  252. .right{
  253. width: 594rpx;
  254. .line{
  255. width: 2rpx;
  256. height: 20rpx;
  257. background-color: #ccc;
  258. display: inline-block;
  259. margin: 0 20rpx;
  260. }
  261. }
  262. &.time{
  263. margin-top: 20rpx;
  264. .iconfont{
  265. font-size: 28rpx;
  266. }
  267. }
  268. }
  269. .bottom{
  270. height: 92rpx;
  271. border-top: 1rpx solid #eee;
  272. margin-top: 30rpx;
  273. position: relative;
  274. &::after{
  275. position: absolute;
  276. content: ' ';
  277. width: 1rpx;
  278. height: 60rpx;
  279. background-color: #eee;
  280. }
  281. .bnt{
  282. width: 314rpx;
  283. text-align: center;
  284. font-size: 26rpx;
  285. color: #333;
  286. text-decoration: none;
  287. .iconfont{
  288. font-size: 35rpx;
  289. margin-right: 12rpx;
  290. display: inline-block;
  291. vertical-align: bottom;
  292. }
  293. }
  294. }
  295. }
  296. }
  297. </style>