shopTab.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef MP -->
  4. <view class="" style="height: 44rpx;">
  5. </view>
  6. <!-- #endif -->
  7. <view class="topNav flex">
  8. <image @click="backIndex" class="back" src="../../static/icon/back.png" mode="widthFix"></image>
  9. <view class="inputbox flex">
  10. <image class="search" src="../../static/icon/search.png" mode="widthFix"></image>
  11. <input class="input" confirm-type='搜索' @confirm='searchData' placeholder="请输入城市或者门店" type="text"
  12. v-model="search" />
  13. </view>
  14. </view>
  15. <!-- <pickerAddress class="" @change="onCityClick">
  16. <view class="address flex">
  17. <view class="flex">
  18. <text class="text">{{province}}</text>
  19. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  20. </view>
  21. <view class="flex">
  22. <text class="text">{{city}}</text>
  23. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  24. </view>
  25. <view class="flex">
  26. <text class="text">{{district}}</text>
  27. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  28. </view>
  29. </view>
  30. </pickerAddress> -->
  31. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="storeList">
  32. <!-- 空白页 -->
  33. <!-- <empty v-if="loaded === true && orderList.length === 0"></empty> -->
  34. <!-- 订单列表 -->
  35. <view class="itemList">
  36. <view class="item flex" v-for="(item,index) in orderList" :key='index' @click="onChecked(item)">
  37. <view class="imgBox">
  38. <image class="logo" :src="item.image" mode="aspectFit"></image>
  39. </view>
  40. <view class="padding-l-20 flex-grow-true">
  41. <view class="title clamp flex">
  42. <view class="name">
  43. {{item.name}}
  44. </view>
  45. <view class="km" v-if="item.range">
  46. {{(item.range<1?item.distance+'m':item.range+'km') || index + 1 + 'km'}}
  47. </view>
  48. </view>
  49. <view class="flex addressBox margin-t-20">
  50. <image class="iconA margin-r-10" src="../../static/icon/shop.png" mode="">
  51. </image>
  52. <text class="clamp">
  53. {{item.detailed_address}}
  54. </text>
  55. </view>
  56. <view class="addressBox flex">
  57. <image class="iconA margin-r-10" src="../../static/icon/shopPhone.png" mode="">
  58. <text class="clamp">
  59. {{item.phone}}
  60. </text>
  61. </view>
  62. <view class="yysj">
  63. 营业时间:{{item.day_time}}
  64. </view>
  65. </view>
  66. <view class="dh-wrap" @click.stop="todh(item)">
  67. <image src="../../static/icon/dh.png" mode=""></image>
  68. </view>
  69. </view>
  70. </view>
  71. <uni-load-more :status="loadingType"></uni-load-more>
  72. </scroll-view>
  73. </view>
  74. </template>
  75. <script>
  76. // #ifdef MP-WEIXIN
  77. import {
  78. openMap
  79. } from '@/utils/rocessor.js';
  80. // #endif
  81. import {
  82. storeList,
  83. } from '@/api/product.js';
  84. import {
  85. mapMutations,
  86. mapState
  87. } from 'vuex';
  88. export default {
  89. computed: {
  90. ...mapState('user', ['address'])
  91. },
  92. data() {
  93. return {
  94. search: '', //查询内容
  95. loadingType: 'more',
  96. orderList: [],
  97. page: 1, //当前页数
  98. limit: 10, //每次信息条数
  99. province: '请选择', //省
  100. city: '请选择', //市
  101. district: '请选择', //区
  102. loaded: false,
  103. type: 0 ,//默认为切换商店,1为不切换
  104. select: 0,//0为不选择商店,1为选择商店
  105. };
  106. },
  107. onLoad: function(option) {
  108. console.log(option.type);
  109. if (option.type) {
  110. this.type = option.type;
  111. }
  112. if(option.select) {
  113. this.select = option.select;
  114. }
  115. this.getlocation()
  116. },
  117. methods: {
  118. ...mapMutations('shop', ['setShopInfo']),
  119. ...mapMutations('user',['setAddress']),
  120. // 获取经纬度
  121. getlocation() {
  122. let obj = this;
  123. // #ifdef H5
  124. this.storeList();
  125. // #endif
  126. // #ifdef APP
  127. uni.getLocation({
  128. type: 'gcj02',
  129. success(e) {
  130. console.log(e,'获取地址');
  131. obj.getlocationSetInit(e)
  132. },
  133. fail(e) {
  134. console.log(e,'获取地址失败');
  135. if(e.errCode==22){
  136. uni.showModal({
  137. title: '定位开启错误',
  138. content: '请查看是否已经开启定位服务',
  139. showCancel: false,
  140. });
  141. }
  142. console.log(e, 'cw');
  143. }
  144. })
  145. // #endif
  146. // #ifdef MP-WEIXIN
  147. openMap().then((e) => {
  148. console.log("授权");
  149. wx.getLocation({
  150. type: 'gcj02',
  151. success: (e) => {
  152. console.log(e);
  153. // 调用鉴定位置变化事件
  154. this.getlocationSetInit(e)
  155. },
  156. fail() {
  157. }
  158. })
  159. })
  160. // #endif
  161. },
  162. // 获取经纬度完毕后回调处理
  163. getlocationSetInit(data) {
  164. const obj = this;
  165. try {
  166. console.log(data, '位置数据');
  167. // 保存当前经纬度
  168. obj.setAddress({
  169. latitude: data.latitude,
  170. longitude: data.longitude
  171. })
  172. this.storeList();
  173. } catch (e) {
  174. console.log(e, 'cww');
  175. this.storeList();
  176. }
  177. },
  178. toJSON() {
  179. return this;
  180. },
  181. backIndex() {
  182. uni.switchTab({
  183. url: '/pages/index/index'
  184. })
  185. },
  186. // 查询方法
  187. searchData() {
  188. // 初始化数据重新搜索
  189. this.loaded = false;
  190. this.page = 1;
  191. this.orderList = [];
  192. this.loadingType = 'more';
  193. this.storeList()
  194. },
  195. // 存储当前的门店
  196. onChecked(item) {
  197. // if (this.type == 0) {
  198. // this.setShopInfo(item);
  199. // uni.showToast({
  200. // title: '切换成功',
  201. // mask: true,
  202. // duration: 1500
  203. // });
  204. // setTimeout((e) => {
  205. // uni.switchTab({
  206. // url: '/pages/index/index'
  207. // })
  208. // }, 1500)
  209. // }
  210. // console.log();
  211. // if (+this.type == 1) {
  212. // this.setShopInfo(item);
  213. // uni.navigateTo({
  214. // url: '/pages/shop/shopIndex?id=' + item.id
  215. // })
  216. // }
  217. let that = this
  218. if(that.select == 1) {
  219. let prepage = that.$api.prePage();
  220. prepage.selctStore = item
  221. uni.navigateBack()
  222. }
  223. },
  224. storeList(source) {
  225. //这里是将订单挂载到tab列表下
  226. let navItem = this;
  227. if (source === 'tabChange' && navItem.loaded === true) {
  228. //tab切换只有第一次需要加载数据
  229. return;
  230. }
  231. if (navItem.loadingType === 'loading') {
  232. //防止重复加载
  233. return;
  234. }
  235. if (navItem.loadingType === 'noMore') {
  236. //防止重复加载
  237. return;
  238. }
  239. // 修改当前对象状态为加载中
  240. navItem.loadingType = 'loading';
  241. let city = `${this.province},${this.city},${this.district}`;
  242. if (this.province == '请选择') {
  243. city = '';
  244. }
  245. storeList({
  246. city,
  247. page: navItem.page,
  248. limit: navItem.limit,
  249. key: this.search,
  250. latitude: this.address.latitude,
  251. longitude: this.address.longitude,
  252. })
  253. .then(({
  254. data
  255. }) => {
  256. let arr = data.list.map(e => {
  257. return e;
  258. });
  259. navItem.orderList = navItem.orderList.concat(arr);
  260. // console.log(navItem.orderList);
  261. navItem.page++;
  262. if (navItem.limit == arr.length) {
  263. //判断是否还有数据, 有改为 more, 没有改为noMore
  264. navItem.loadingType = 'more';
  265. return;
  266. } else {
  267. //判断是否还有数据, 有改为 more, 没有改为noMore
  268. navItem.loadingType = 'noMore';
  269. }
  270. uni.hideLoading();
  271. this.$set(navItem, 'loaded', true);
  272. console.log(this, '结果');
  273. })
  274. .catch(e => {
  275. console.log(e);
  276. });
  277. },
  278. // 内容改变事件
  279. onCityClick(item) {
  280. const arr = item.data;
  281. this.province = arr[0];
  282. this.city = arr[1];
  283. this.district = arr[2];
  284. // 开始查询
  285. console.log(this.province, this.city, this.district);
  286. console.log(arr);
  287. this.searchData()
  288. },
  289. todh(item) {
  290. wx.openLocation({
  291. latitude: item.latitude * 1,
  292. longitude: item.longitude * 1,
  293. name: item.name,
  294. address: item.detailed_address
  295. })
  296. }
  297. },
  298. };
  299. </script>
  300. <style lang="scss">
  301. page,
  302. .container {
  303. height: 100%;
  304. }
  305. /* #ifdef APP */
  306. .container {
  307. padding-top: var(--status-bar-height);
  308. }
  309. /* #endif */
  310. .list-scroll-content {
  311. height: calc(100% - 44px);
  312. position: relative;
  313. overflow: hidden;
  314. z-index: 100;
  315. }
  316. .itemList {
  317. padding: 30rpx $page-row-spacing;
  318. .item {
  319. background-color: #FFFFFF;
  320. margin-bottom: 30rpx;
  321. padding: 30rpx;
  322. border-radius: 20rpx;
  323. position: relative;
  324. .list,.km{
  325. color: $font-color-light;
  326. font-size: $font-sm;
  327. }
  328. .logo {
  329. height: 200rpx;
  330. width: 200rpx;
  331. border-radius: 20rpx;
  332. }
  333. .title {
  334. font-size: 36rpx;
  335. color: $font-color-dark;
  336. }
  337. .iconR {
  338. height: 24rpx;
  339. }
  340. .iconA {
  341. width: 24rpx;
  342. height: 24rpx;
  343. }
  344. .addressBox {
  345. font-size: 24rpx;
  346. color: $font-color-light;
  347. justify-content: flex-start;
  348. padding: 10rpx 0;
  349. }
  350. .yysj {
  351. display: inline-block;
  352. // width: 239rpx;
  353. padding: 0 10rpx;
  354. height: 32rpx;
  355. background: #ddf8f1;
  356. border-radius: 16rpx 16rpx 16rpx 0rpx;
  357. font-size: 20rpx;
  358. font-weight: bold;
  359. color: #5FCCA7;
  360. text-align: center;
  361. line-height: 32rpx;
  362. margin-top: 10rpx;
  363. }
  364. }
  365. }
  366. .address {
  367. background-color: #FFFFFF;
  368. justify-content: space-around;
  369. height: 40px;
  370. .text {
  371. font-size: 22rpx;
  372. color: $font-color-dark;
  373. margin-right: 5px;
  374. }
  375. .tipButtom {
  376. width: 11px;
  377. }
  378. }
  379. .topNav {
  380. height: 44px;
  381. background-color: #FFFFFF;
  382. padding: 0 15px;
  383. /* #ifdef MP */
  384. height:calc(44px + var(--status-bar-height)) ;
  385. padding-top: calc(var(--status-bar-height) - 15px);
  386. /* #endif */
  387. .back {
  388. width: 13px;
  389. }
  390. .inputbox {
  391. background-color: $page-color-base;
  392. height: 15px;
  393. flex-grow: 1;
  394. margin-left: 15px;
  395. border-radius: 50px;
  396. height: 30px;
  397. padding-left: 20px;
  398. /* #ifdef MP */
  399. margin-right: 200rpx;
  400. /* #endif */
  401. font-size: $font-base;
  402. .search {
  403. width: 18px;
  404. }
  405. .input {
  406. height: 100%;
  407. width: 100%;
  408. text-align: left;
  409. padding-left: 10px;
  410. }
  411. }
  412. }
  413. .dh-wrap {
  414. width: 40rpx;
  415. height: 40rpx;
  416. position: absolute;
  417. bottom:50rpx;
  418. right: 50rpx;
  419. image {
  420. width: 100%;
  421. height: 100%;
  422. }
  423. }
  424. </style>