shopTab.vue 9.4 KB

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