shopTab.vue 7.4 KB

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