shopTab.vue 7.6 KB

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