shopTab.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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 || APP
  124. uni.getLocation({
  125. type: 'gcj02',
  126. success(e) {
  127. obj.getlocationSetInit(e)
  128. },
  129. fail(e) {
  130. if(e.errCode==22){
  131. uni.showModal({
  132. title: '定位开启错误',
  133. content: '请查看是否已经开启定位服务',
  134. showCancel: false,
  135. });
  136. }
  137. console.log(e, 'cw');
  138. }
  139. })
  140. // #endif
  141. // #ifdef MP-WEIXIN
  142. openMap().then((e) => {
  143. console.log("授权");
  144. wx.getLocation({
  145. type: 'gcj02',
  146. success: (e) => {
  147. console.log(e);
  148. // 调用鉴定位置变化事件
  149. this.getlocationSetInit(e)
  150. },
  151. fail() {
  152. }
  153. })
  154. })
  155. // #endif
  156. },
  157. // 获取经纬度完毕后回调处理
  158. getlocationSetInit(data) {
  159. const obj = this;
  160. try {
  161. console.log(data, '位置数据');
  162. // 保存当前经纬度
  163. obj.setAddress({
  164. latitude: data.latitude,
  165. longitude: data.longitude
  166. })
  167. this.storeList();
  168. } catch (e) {
  169. console.log(e, 'cww');
  170. this.storeList();
  171. }
  172. },
  173. toJSON() {
  174. return this;
  175. },
  176. backIndex() {
  177. uni.switchTab({
  178. url: '/pages/index/index'
  179. })
  180. },
  181. // 查询方法
  182. searchData() {
  183. // 初始化数据重新搜索
  184. this.loaded = false;
  185. this.page = 1;
  186. this.orderList = [];
  187. this.loadingType = 'more';
  188. this.storeList()
  189. },
  190. // 存储当前的门店
  191. onChecked(item) {
  192. // if (this.type == 0) {
  193. // this.setShopInfo(item);
  194. // uni.showToast({
  195. // title: '切换成功',
  196. // mask: true,
  197. // duration: 1500
  198. // });
  199. // setTimeout((e) => {
  200. // uni.switchTab({
  201. // url: '/pages/index/index'
  202. // })
  203. // }, 1500)
  204. // }
  205. // console.log();
  206. // if (+this.type == 1) {
  207. // this.setShopInfo(item);
  208. // uni.navigateTo({
  209. // url: '/pages/shop/shopIndex?id=' + item.id
  210. // })
  211. // }
  212. let that = this
  213. if(that.select == 1) {
  214. let prepage = that.$api.prePage();
  215. prepage.selctStore = item
  216. uni.navigateBack()
  217. }
  218. },
  219. storeList(source) {
  220. //这里是将订单挂载到tab列表下
  221. let navItem = this;
  222. if (source === 'tabChange' && navItem.loaded === true) {
  223. //tab切换只有第一次需要加载数据
  224. return;
  225. }
  226. if (navItem.loadingType === 'loading') {
  227. //防止重复加载
  228. return;
  229. }
  230. if (navItem.loadingType === 'noMore') {
  231. //防止重复加载
  232. return;
  233. }
  234. // 修改当前对象状态为加载中
  235. navItem.loadingType = 'loading';
  236. let city = `${this.province},${this.city},${this.district}`;
  237. if (this.province == '请选择') {
  238. city = '';
  239. }
  240. storeList({
  241. city,
  242. page: navItem.page,
  243. limit: navItem.limit,
  244. key: this.search,
  245. latitude: this.address.latitude,
  246. longitude: this.address.longitude,
  247. })
  248. .then(({
  249. data
  250. }) => {
  251. let arr = data.list.map(e => {
  252. return e;
  253. });
  254. navItem.orderList = navItem.orderList.concat(arr);
  255. // console.log(navItem.orderList);
  256. navItem.page++;
  257. if (navItem.limit == arr.length) {
  258. //判断是否还有数据, 有改为 more, 没有改为noMore
  259. navItem.loadingType = 'more';
  260. return;
  261. } else {
  262. //判断是否还有数据, 有改为 more, 没有改为noMore
  263. navItem.loadingType = 'noMore';
  264. }
  265. uni.hideLoading();
  266. this.$set(navItem, 'loaded', true);
  267. console.log(this, '结果');
  268. })
  269. .catch(e => {
  270. console.log(e);
  271. });
  272. },
  273. // 内容改变事件
  274. onCityClick(item) {
  275. const arr = item.data;
  276. this.province = arr[0];
  277. this.city = arr[1];
  278. this.district = arr[2];
  279. // 开始查询
  280. console.log(this.province, this.city, this.district);
  281. console.log(arr);
  282. this.searchData()
  283. },
  284. todh(item) {
  285. wx.openLocation({
  286. latitude: item.latitude * 1,
  287. longitude: item.longitude * 1,
  288. name: item.name,
  289. address: item.detailed_address
  290. })
  291. }
  292. },
  293. };
  294. </script>
  295. <style lang="scss">
  296. page,
  297. .container {
  298. height: 100%;
  299. }
  300. /* #ifdef APP */
  301. .container {
  302. padding-top: var(--status-bar-height);
  303. }
  304. /* #endif */
  305. .list-scroll-content {
  306. height: calc(100% - 44px);
  307. position: relative;
  308. overflow: hidden;
  309. z-index: 100;
  310. }
  311. .itemList {
  312. padding: 30rpx $page-row-spacing;
  313. .item {
  314. background-color: #FFFFFF;
  315. margin-bottom: 30rpx;
  316. padding: 30rpx;
  317. border-radius: 20rpx;
  318. position: relative;
  319. .list,.km{
  320. color: $font-color-light;
  321. font-size: $font-sm;
  322. }
  323. .logo {
  324. height: 200rpx;
  325. width: 200rpx;
  326. border-radius: 20rpx;
  327. }
  328. .title {
  329. font-size: 36rpx;
  330. color: $font-color-dark;
  331. }
  332. .iconR {
  333. height: 24rpx;
  334. }
  335. .iconA {
  336. width: 24rpx;
  337. height: 24rpx;
  338. }
  339. .addressBox {
  340. font-size: 24rpx;
  341. color: $font-color-light;
  342. justify-content: flex-start;
  343. padding: 10rpx 0;
  344. }
  345. .yysj {
  346. display: inline-block;
  347. // width: 239rpx;
  348. padding: 0 10rpx;
  349. height: 32rpx;
  350. background: #ddf8f1;
  351. border-radius: 16rpx 16rpx 16rpx 0rpx;
  352. font-size: 20rpx;
  353. font-weight: bold;
  354. color: #5FCCA7;
  355. text-align: center;
  356. line-height: 32rpx;
  357. margin-top: 10rpx;
  358. }
  359. }
  360. }
  361. .address {
  362. background-color: #FFFFFF;
  363. justify-content: space-around;
  364. height: 40px;
  365. .text {
  366. font-size: 22rpx;
  367. color: $font-color-dark;
  368. margin-right: 5px;
  369. }
  370. .tipButtom {
  371. width: 11px;
  372. }
  373. }
  374. .topNav {
  375. height: 44px;
  376. background-color: #FFFFFF;
  377. padding: 0 15px;
  378. /* #ifdef MP */
  379. height:calc(44px + var(--status-bar-height)) ;
  380. padding-top: calc(var(--status-bar-height) - 15px);
  381. /* #endif */
  382. .back {
  383. width: 13px;
  384. }
  385. .inputbox {
  386. background-color: $page-color-base;
  387. height: 15px;
  388. flex-grow: 1;
  389. margin-left: 15px;
  390. border-radius: 50px;
  391. height: 30px;
  392. padding-left: 20px;
  393. /* #ifdef MP */
  394. margin-right: 200rpx;
  395. /* #endif */
  396. font-size: $font-base;
  397. .search {
  398. width: 18px;
  399. }
  400. .input {
  401. height: 100%;
  402. width: 100%;
  403. text-align: left;
  404. padding-left: 10px;
  405. }
  406. }
  407. }
  408. .dh-wrap {
  409. width: 40rpx;
  410. height: 40rpx;
  411. position: absolute;
  412. bottom:50rpx;
  413. right: 50rpx;
  414. image {
  415. width: 100%;
  416. height: 100%;
  417. }
  418. }
  419. </style>