shopTab.vue 7.4 KB

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