shop.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  1. <template>
  2. <mobile-frame>
  3. <view class="main">
  4. <view class="one">
  5. <input type="text" v-model="searchInfo.name" @blur="toInput" placeholder="搜索店铺名称">
  6. </view>
  7. <view class="two">
  8. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  9. <view class="list-scroll-view">
  10. <view class="two_1">
  11. <view :class="['list',condActive==index?'activeList':'']" v-for="(item,index) in condList"
  12. :key="index" @tap="toCond(index,item)">
  13. <view class="name" v-if="index!=2">
  14. {{item.name}}
  15. </view>
  16. <view v-if="index==2" class="icon4">
  17. <view class="icon_1">
  18. <text :class="['iconfont',item.shangActive]"
  19. v-if="condActive==index&&shang=='1'"></text>
  20. <text :class="['iconfont',item.shang]" v-else></text>
  21. </view>
  22. </view>
  23. <view v-else class="icon">
  24. <view class="icon_1">
  25. <text :class="['iconfont',item.shangActive]"
  26. v-if="condActive==index&&shang=='1'"></text>
  27. <text :class="['iconfont',item.shang]" v-else></text>
  28. </view>
  29. <view class="icon_1">
  30. <text :class="['iconfont', item.xiaActive]"
  31. v-if="condActive==index&&xia=='-1'"></text>
  32. <text :class="['iconfont', item.xia]" v-else></text>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="two_2" v-if="type=='list'">
  38. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  39. <image class="image" :src="item.logo&&item.logo.length>0?item.logo[0].url:''" mode="">
  40. </image>
  41. <view class="other">
  42. <view class="name">{{item.name}}</view>
  43. <view class="other_1">
  44. 店铺地址 <text>{{item.address}}</text>
  45. </view>
  46. <view class="other_1">
  47. 关注时间 <text>{{item.time}}</text>
  48. </view>
  49. </view>
  50. <view class="btn">
  51. <text @tap.stop="toDel(item)" class="iconfont icon-del"></text>
  52. </view>
  53. </view>
  54. </view>
  55. <view class="two_3" v-else>
  56. <view class="list" v-for="(item, index) in list" :key="index" @tap="toView(item)">
  57. <image class="image" :src="item.logo&&item.logo.length>0?item.logo[0].url:''" mode="">
  58. </image>
  59. <view class="name">
  60. {{item.name||'暂无'}}
  61. </view>
  62. <view class="address">
  63. <text>{{item.address}}</text>
  64. </view>
  65. <view class="other">
  66. <view class="other_1">
  67. {{item.time}}
  68. </view>
  69. <view class="other_2">
  70. <text @tap.stop="toDel(item)" class="iconfont icon-del"></text>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <view class="is_bottom" v-if="is_bottom">
  76. <text>{{config.bottom_title}}</text>
  77. </view>
  78. </view>
  79. </scroll-view>
  80. </view>
  81. </view>
  82. </mobile-frame>
  83. </template>
  84. <script>
  85. export default {
  86. data() {
  87. return {
  88. // 系统设置
  89. config: {},
  90. searchInfo: {},
  91. user: {},
  92. list: [],
  93. total: 0,
  94. skip: 0,
  95. limit: 5,
  96. page: 0,
  97. condActive: 0,
  98. shang: '',
  99. xia: '',
  100. condList: [ // 筛选
  101. {
  102. name: '默认',
  103. },
  104. {
  105. name: '关注时间',
  106. shang: 'icon-shangjiantou',
  107. shangActive: 'icon-shangjiantou-copy',
  108. xia: 'icon-xiajiantou',
  109. xiaActive: 'icon-xiajiantou-copy'
  110. },
  111. {
  112. shang: 'icon-liebiaoxingshi',
  113. shangActive: 'icon-liebiaoxingshi',
  114. }
  115. ],
  116. type: 'list',
  117. // 数据是否触底
  118. is_bottom: false,
  119. scrollTop: 0
  120. };
  121. },
  122. onShow: function() {
  123. const that = this;
  124. that.searchConfig();
  125. that.watchLogin();
  126. },
  127. methods: {
  128. // 查询基本设置
  129. searchConfig() {
  130. const that = this;
  131. uni.getStorage({
  132. key: 'config',
  133. success: function(res) {
  134. if (res.data) that.$set(that, `config`, res.data)
  135. },
  136. fail: function(err) {
  137. console.log(err);
  138. }
  139. })
  140. },
  141. // 输入框
  142. toInput(e) {
  143. const that = this;
  144. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  145. that.clearPage();
  146. that.search();
  147. },
  148. // 筛选
  149. toCond(index, e) {
  150. const that = this;
  151. let condActive = that.condActive;
  152. that.$set(that, `condActive`, index);
  153. if (condActive != index && that.xia == '') {
  154. that.$set(that, `shang`, '0');
  155. that.$set(that, `xia`, '-1');
  156. } else if (condActive == index && that.xia == '-1') {
  157. that.$set(that, `shang`, '1');
  158. that.$set(that, `xia`, '0');
  159. } else if (condActive == index && that.shang == '1') {
  160. that.$set(that, `shang`, '0');
  161. that.$set(that, `xia`, '-1');
  162. } else if (condActive = index && that.shang == '1') {
  163. that.$set(that, `shang`, '0');
  164. that.$set(that, `xia`, '-1');
  165. }
  166. let value;
  167. if (index != 0) {
  168. value = that.shang == '0' ? that.xia : that.shang;
  169. } else {
  170. that.$set(that, `searchInfo`, {})
  171. }
  172. if (index == 1) {
  173. that.$set(that, `searchInfo`, {})
  174. that.$set(that.searchInfo, `time`, value);
  175. } else if (index == 2) {
  176. if (e.shang == 'icon-shitugonggeListBox') {
  177. that.$set(e, `shang`, 'icon-liebiaoxingshi');
  178. that.$set(that, `type`, 'list');
  179. } else {
  180. that.$set(e, `shang`, 'icon-shitugonggeListBox');
  181. that.$set(that, `type`, 'gongge');
  182. }
  183. }
  184. that.clearPage();
  185. that.search();
  186. },
  187. // 监听用户是否登录
  188. watchLogin() {
  189. const that = this;
  190. uni.getStorage({
  191. key: 'token',
  192. success: function(res) {
  193. let user = that.$jwt(res.data);
  194. that.$set(that, `user`, user);
  195. that.search()
  196. },
  197. fail: function(err) {
  198. uni.reLaunch({
  199. url: `/pages/login/index`
  200. })
  201. }
  202. })
  203. },
  204. // 查询列表
  205. async search() {
  206. const that = this;
  207. let user = that.user;
  208. let info = {
  209. skip: that.skip,
  210. limit: that.limit,
  211. customer: user._id
  212. }
  213. const res = await that.$api(`/storeShop/userView`, 'GET', {
  214. ...info,
  215. ...that.searchInfo
  216. })
  217. if (res.errcode == '0') {
  218. let list = [...that.list, ...res.data];
  219. that.$set(that, `list`, list);
  220. that.$set(that, `total`, res.total)
  221. }
  222. },
  223. // 分页
  224. toPage() {
  225. const that = this;
  226. let list = that.list;
  227. let limit = that.limit;
  228. if (that.total > list.length) {
  229. uni.showLoading({
  230. title: '加载中',
  231. mask: true
  232. })
  233. let page = that.page + 1;
  234. that.$set(that, `page`, page)
  235. let skip = page * limit;
  236. that.$set(that, `skip`, skip)
  237. that.search();
  238. uni.hideLoading();
  239. } else that.$set(that, `is_bottom`, true)
  240. },
  241. toScroll(e) {
  242. const that = this;
  243. let up = that.scrollTop;
  244. that.$set(that, `scrollTop`, e.detail.scrollTop);
  245. let num = Math.sign(up - e.detail.scrollTop);
  246. if (num == 1) that.$set(that, `is_bottom`, false);
  247. },
  248. // 详细信息
  249. toView(e) {
  250. const that = this;
  251. that.clearPage();
  252. uni.navigateTo({
  253. url: `/pagesHome/shop/index?id=${e._id}`
  254. })
  255. },
  256. // 删除
  257. async toDel(e) {
  258. const that = this;
  259. let user = that.user;
  260. if (user && user._id && e && e._id) {
  261. let res = await that.$api(`/storeShop`, `POST`, {
  262. customer: user._id,
  263. shop: e._id
  264. });
  265. if (res.errcode == '0') {
  266. uni.showToast({
  267. title: res.data.msg,
  268. icon: 'none'
  269. })
  270. that.clearPage();
  271. that.search()
  272. }
  273. } else {
  274. uni.showToast({
  275. title: '缺少必要信息,无法收藏',
  276. icon: 'none'
  277. })
  278. }
  279. },
  280. // 清空列表
  281. clearPage() {
  282. const that = this;
  283. that.$set(that, `list`, [])
  284. that.$set(that, `skip`, 0)
  285. that.$set(that, `limit`, 5)
  286. that.$set(that, `page`, 0)
  287. }
  288. },
  289. onPullDownRefresh: async function() {
  290. const that = this;
  291. that.$set(that, `list`, [])
  292. that.$set(that, `skip`, 0)
  293. that.$set(that, `limit`, 6)
  294. that.$set(that, `page`, 0)
  295. await that.search();
  296. uni.stopPullDownRefresh();
  297. }
  298. }
  299. </script>
  300. <style lang="scss">
  301. .main {
  302. display: flex;
  303. flex-direction: column;
  304. width: 100vw;
  305. height: 100vh;
  306. .one {
  307. border-bottom: 1px solid var(--f85Color);
  308. padding: 2vw;
  309. input {
  310. padding: 2vw;
  311. background-color: var(--f1Color);
  312. font-size: var(--font14Size);
  313. border-radius: 5px;
  314. }
  315. }
  316. .two {
  317. position: relative;
  318. flex-grow: 1;
  319. padding: 2vw 0 0 0;
  320. .two_1 {
  321. background-color: var(--fffColor);
  322. padding: 2vw;
  323. display: flex;
  324. width: 100vw;
  325. flex-direction: row;
  326. justify-content: space-around;
  327. .list {
  328. display: flex;
  329. flex-direction: row;
  330. .icon {
  331. position: relative;
  332. top: -5px;
  333. left: 2px;
  334. .icon_1 {
  335. height: 10px;
  336. .iconfont {
  337. font-size: 12px;
  338. }
  339. }
  340. }
  341. .icon4 {
  342. .icon_1 {
  343. .iconfont {
  344. font-size: 17px;
  345. }
  346. }
  347. }
  348. }
  349. .activeList {
  350. .name {
  351. color: #ff0000;
  352. }
  353. }
  354. }
  355. .two_2 {
  356. width: 100vw;
  357. .list {
  358. display: flex;
  359. flex-direction: row;
  360. justify-content: space-between;
  361. width: 91vw;
  362. border: 1px solid var(--f1Color);
  363. margin: 2vw 2vw 0 2vw;
  364. padding: 2vw;
  365. border-radius: 5px;
  366. .image {
  367. width: 25vw;
  368. height: 25vw;
  369. border-radius: 5px;
  370. margin: 0 2vw 0 0;
  371. }
  372. .other {
  373. display: flex;
  374. flex-direction: column;
  375. flex-grow: 1;
  376. .name {
  377. font-size: var(--font16Size);
  378. margin: 0 0 1vw 0;
  379. }
  380. .other_1 {
  381. font-size: var(--font14Size);
  382. color: var(--f85Color);
  383. text {
  384. padding: 0 2vw;
  385. color: var(--ff0Color);
  386. }
  387. }
  388. }
  389. }
  390. }
  391. .two_3 {
  392. width: 100vw;
  393. display: flex;
  394. flex-wrap: wrap;
  395. .list {
  396. width: 42vw;
  397. border: 1px solid var(--f1Color);
  398. margin: 2vw 2vw 0 2vw;
  399. padding: 2vw;
  400. border-radius: 5px;
  401. .image {
  402. width: 100%;
  403. height: 40vw;
  404. border-radius: 5px;
  405. }
  406. .name {
  407. font-size: var(--font16Size);
  408. margin: 0 0 1vw 0;
  409. }
  410. .address {
  411. font-size: var(--font14Size);
  412. color: var(--fFB1Color);
  413. margin: 0 0 1vw 0;
  414. }
  415. .other {
  416. display: flex;
  417. flex-direction: row;
  418. justify-content: space-between;
  419. align-items: center;
  420. .other_1 {
  421. font-size: var(--font14Size);
  422. color: var(--f85Color);
  423. }
  424. }
  425. }
  426. .list:nth-child(2n) {
  427. margin: 2vw 0 0 0;
  428. }
  429. }
  430. }
  431. }
  432. .scroll-view {
  433. position: absolute;
  434. top: 0;
  435. left: 0;
  436. right: 0;
  437. bottom: 0;
  438. .list-scroll-view {
  439. display: flex;
  440. flex-direction: row;
  441. flex-wrap: wrap;
  442. }
  443. }
  444. .is_bottom {
  445. text-align: center;
  446. text {
  447. padding: 2vw 0;
  448. display: inline-block;
  449. color: #858585;
  450. font-size: 14px;
  451. }
  452. }
  453. </style>