shopTab.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <view class="container">
  3. <view class="topNav flex">
  4. <image @click="backIndex" class="back" src="../../static/icon/back.png" mode="widthFix"></image>
  5. <view class="inputbox flex">
  6. <image class="search" src="../../static/icon/search.png" mode="widthFix"></image>
  7. <input class="input" confirm-type='搜索' @confirm='searchData' placeholder="请输入城市或者门店" type="text"
  8. v-model="search" />
  9. </view>
  10. </view>
  11. <!-- <pickerAddress class="" @change="onCityClick">
  12. <view class="address flex">
  13. <view class="flex">
  14. <text class="text">{{province}}</text>
  15. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  16. </view>
  17. <view class="flex">
  18. <text class="text">{{city}}</text>
  19. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  20. </view>
  21. <view class="flex">
  22. <text class="text">{{district}}</text>
  23. <image class="tipButtom" src="../../static/icon/dom.png" mode="widthFix"></image>
  24. </view>
  25. </view>
  26. </pickerAddress> -->
  27. <scroll-view class="list-scroll-content" scroll-y @scrolltolower="storeList">
  28. <!-- 空白页 -->
  29. <!-- <empty v-if="loaded === true && orderList.length === 0"></empty> -->
  30. <!-- 订单列表 -->
  31. <view class="itemList">
  32. <view class="item flex" v-for="(item,index) in orderList" :key='index' @click="onChecked(item)">
  33. <view class="imgBox">
  34. <image class="logo" :src="item.image" mode="aspectFit"></image>
  35. </view>
  36. <view class="padding-l-20 flex-grow-true">
  37. <view class="title clamp flex">
  38. <view class="name">
  39. {{item.name}}
  40. </view>
  41. <view class="km">
  42. {{item.range<1?item.distance+'m':item.range+'km'}}
  43. </view>
  44. </view>
  45. <view class="list margin-t-20">
  46. 营业时间:{{item.day_time}}
  47. </view>
  48. <view class="list">
  49. 联系电话:{{item.phone}}
  50. </view>
  51. <view class="flex addressBox ">
  52. <image class="iconA margin-r-10" src="../../static/icon/shopAddress.png" mode="heightFix">
  53. </image>
  54. <text class="clamp">
  55. {{item.address}}
  56. </text>
  57. </view>
  58. </view>
  59. </view>
  60. </view>
  61. <uni-load-more :status="loadingType"></uni-load-more>
  62. </scroll-view>
  63. </view>
  64. </template>
  65. <script>
  66. import {
  67. storeList,
  68. } from '@/api/shop.js';
  69. import {
  70. mapMutations,
  71. mapState
  72. } from 'vuex';
  73. export default {
  74. computed: {
  75. ...mapState('user', ['address'])
  76. },
  77. data() {
  78. return {
  79. search: '', //查询内容
  80. loadingType: 'more',
  81. orderList: [],
  82. page: 1, //当前页数
  83. limit: 10, //每次信息条数
  84. province: '请选择', //省
  85. city: '请选择', //市
  86. district: '请选择', //区
  87. loaded: false,
  88. type: 0 //默认为切换商店,1为不切换
  89. };
  90. },
  91. onLoad: function(option) {
  92. console.log(option.type);
  93. if (option.type) {
  94. this.type = option.type;
  95. }
  96. this.storeList();
  97. },
  98. methods: {
  99. ...mapMutations('shop', ['setShopInfo']),
  100. toJSON() {
  101. return this;
  102. },
  103. backIndex() {
  104. uni.switchTab({
  105. url: '/pages/index/index'
  106. })
  107. },
  108. // 查询方法
  109. searchData() {
  110. // 初始化数据重新搜索
  111. this.loaded = false;
  112. this.page = 1;
  113. this.orderList = [];
  114. this.loadingType = 'more';
  115. this.storeList()
  116. },
  117. // 存储当前的门店
  118. onChecked(item) {
  119. if (this.type == 0) {
  120. this.setShopInfo(item);
  121. uni.showToast({
  122. title: '切换成功',
  123. mask: true,
  124. duration: 1500
  125. });
  126. setTimeout((e) => {
  127. uni.switchTab({
  128. url: '/pages/index/index'
  129. })
  130. }, 1500)
  131. }
  132. console.log();
  133. if (+this.type == 1) {
  134. this.setShopInfo(item);
  135. uni.navigateTo({
  136. url: '/pages/shop/shopIndex?id=' + item.id
  137. })
  138. }
  139. },
  140. storeList(source) {
  141. //这里是将订单挂载到tab列表下
  142. let navItem = this;
  143. if (source === 'tabChange' && navItem.loaded === true) {
  144. //tab切换只有第一次需要加载数据
  145. return;
  146. }
  147. if (navItem.loadingType === 'loading') {
  148. //防止重复加载
  149. return;
  150. }
  151. if (navItem.loadingType === 'noMore') {
  152. //防止重复加载
  153. return;
  154. }
  155. // 修改当前对象状态为加载中
  156. navItem.loadingType = 'loading';
  157. let city = `${this.province},${this.city},${this.district}`;
  158. if (this.province == '请选择') {
  159. city = '';
  160. }
  161. storeList({
  162. city,
  163. page: navItem.page,
  164. limit: navItem.limit,
  165. key: this.search,
  166. latitude: this.address.latitude,
  167. longitude: this.address.longitude,
  168. })
  169. .then(({
  170. data
  171. }) => {
  172. let arr = data.list.map(e => {
  173. return e;
  174. });
  175. navItem.orderList = navItem.orderList.concat(arr);
  176. // console.log(navItem.orderList);
  177. navItem.page++;
  178. if (navItem.limit == arr.length) {
  179. //判断是否还有数据, 有改为 more, 没有改为noMore
  180. navItem.loadingType = 'more';
  181. return;
  182. } else {
  183. //判断是否还有数据, 有改为 more, 没有改为noMore
  184. navItem.loadingType = 'noMore';
  185. }
  186. uni.hideLoading();
  187. this.$set(navItem, 'loaded', true);
  188. console.log(this, '结果');
  189. })
  190. .catch(e => {
  191. console.log(e);
  192. });
  193. },
  194. // 内容改变事件
  195. onCityClick(item) {
  196. const arr = item.data;
  197. this.province = arr[0];
  198. this.city = arr[1];
  199. this.district = arr[2];
  200. // 开始查询
  201. console.log(this.province, this.city, this.district);
  202. console.log(arr);
  203. this.searchData()
  204. }
  205. },
  206. };
  207. </script>
  208. <style lang="scss">
  209. page,
  210. .container {
  211. height: 100%;
  212. }
  213. /* #ifdef APP */
  214. .container {
  215. padding-top: var(--status-bar-height);
  216. }
  217. /* #endif */
  218. .list-scroll-content {
  219. height: calc(100% - 44px);
  220. position: relative;
  221. overflow: hidden;
  222. z-index: 100;
  223. }
  224. .itemList {
  225. padding: 30rpx $page-row-spacing;
  226. .item {
  227. background-color: #FFFFFF;
  228. margin-bottom: 30rpx;
  229. padding: 30rpx;
  230. border-radius: 20rpx;
  231. .list,.km{
  232. color: $font-color-light;
  233. font-size: $font-sm;
  234. }
  235. .logo {
  236. height: 200rpx;
  237. width: 200rpx;
  238. border-radius: 20rpx;
  239. }
  240. .title {
  241. font-size: 36rpx;
  242. color: $font-color-dark;
  243. }
  244. .iconR {
  245. height: 24rpx;
  246. }
  247. .iconA {
  248. width: 24rpx;
  249. height: 24rpx;
  250. }
  251. .addressBox {
  252. font-size: 24rpx;
  253. color: $font-color-light;
  254. justify-content: flex-start;
  255. }
  256. }
  257. }
  258. .address {
  259. background-color: #FFFFFF;
  260. justify-content: space-around;
  261. height: 40px;
  262. .text {
  263. font-size: 22rpx;
  264. color: $font-color-dark;
  265. margin-right: 5px;
  266. }
  267. .tipButtom {
  268. width: 11px;
  269. }
  270. }
  271. .topNav {
  272. height: 44px;
  273. background-color: #FFFFFF;
  274. padding: 0 15px;
  275. /* #ifdef MP */
  276. height:calc(44px + var(--status-bar-height)) ;
  277. padding-top: calc(var(--status-bar-height) - 15px);
  278. /* #endif */
  279. .back {
  280. width: 13px;
  281. }
  282. .inputbox {
  283. background-color: $page-color-base;
  284. height: 15px;
  285. flex-grow: 1;
  286. margin-left: 15px;
  287. border-radius: 50px;
  288. height: 30px;
  289. padding-left: 20px;
  290. /* #ifdef MP */
  291. margin-right: 200rpx;
  292. /* #endif */
  293. font-size: $font-base;
  294. .search {
  295. width: 18px;
  296. }
  297. .input {
  298. height: 100%;
  299. width: 100%;
  300. text-align: left;
  301. padding-left: 10px;
  302. }
  303. }
  304. }
  305. </style>