shop.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  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: 10,
  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. onPullDownRefresh: async function() {
  128. const that = this;
  129. that.clearPage();
  130. await that.search();
  131. uni.stopPullDownRefresh();
  132. },
  133. methods: {
  134. // 查询基本设置
  135. searchConfig() {
  136. const that = this;
  137. uni.getStorage({
  138. key: 'config',
  139. success: function(res) {
  140. if (res.data) that.$set(that, `config`, res.data)
  141. },
  142. fail: function(err) {
  143. console.log(err);
  144. }
  145. })
  146. },
  147. // 监听用户是否登录
  148. watchLogin() {
  149. const that = this;
  150. uni.getStorage({
  151. key: 'token',
  152. success: function(res) {
  153. let user = that.$jwt(res.data);
  154. that.$set(that, `user`, user);
  155. that.search()
  156. },
  157. fail: function(err) {
  158. uni.navigateTo({
  159. url: `/pages/login/index`
  160. })
  161. }
  162. })
  163. },
  164. // 查询列表
  165. async search() {
  166. const that = this;
  167. let user = that.user;
  168. let info = {
  169. skip: that.skip,
  170. limit: that.limit,
  171. customer: user._id
  172. }
  173. const res = await that.$api(`/storeShop/userView`, 'GET', {
  174. ...info,
  175. ...that.searchInfo
  176. })
  177. if (res.errcode == '0') {
  178. let list = [...that.list, ...res.data];
  179. that.$set(that, `list`, list);
  180. that.$set(that, `total`, res.total)
  181. }
  182. },
  183. // 分页
  184. toPage() {
  185. const that = this;
  186. let list = that.list;
  187. let limit = that.limit;
  188. if (that.total > list.length) {
  189. uni.showLoading({
  190. title: '加载中',
  191. mask: true
  192. })
  193. let page = that.page + 1;
  194. that.$set(that, `page`, page)
  195. let skip = page * limit;
  196. that.$set(that, `skip`, skip)
  197. that.search();
  198. uni.hideLoading();
  199. } else that.$set(that, `is_bottom`, true)
  200. },
  201. toScroll(e) {
  202. const that = this;
  203. let up = that.scrollTop;
  204. that.$set(that, `scrollTop`, e.detail.scrollTop);
  205. let num = Math.sign(up - e.detail.scrollTop);
  206. if (num == 1) that.$set(that, `is_bottom`, false);
  207. },
  208. // 输入框
  209. toInput(e) {
  210. const that = this;
  211. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  212. that.clearPage();
  213. that.search();
  214. },
  215. // 筛选
  216. toCond(index, e) {
  217. const that = this;
  218. let condActive = that.condActive;
  219. that.$set(that, `condActive`, index);
  220. if (condActive != index && that.xia == '') {
  221. that.$set(that, `shang`, '0');
  222. that.$set(that, `xia`, '-1');
  223. } else if (condActive == index && that.xia == '-1') {
  224. that.$set(that, `shang`, '1');
  225. that.$set(that, `xia`, '0');
  226. } else if (condActive == index && that.shang == '1') {
  227. that.$set(that, `shang`, '0');
  228. that.$set(that, `xia`, '-1');
  229. } else if (condActive = index && that.shang == '1') {
  230. that.$set(that, `shang`, '0');
  231. that.$set(that, `xia`, '-1');
  232. }
  233. let value;
  234. if (index != 0) {
  235. value = that.shang == '0' ? that.xia : that.shang;
  236. } else {
  237. that.$set(that, `searchInfo`, {})
  238. }
  239. if (index == 1) {
  240. that.$set(that, `searchInfo`, {})
  241. that.$set(that.searchInfo, `time`, value);
  242. } else if (index == 2) {
  243. if (e.shang == 'icon-shitugonggeListBox') {
  244. that.$set(e, `shang`, 'icon-liebiaoxingshi');
  245. that.$set(that, `type`, 'list');
  246. } else {
  247. that.$set(e, `shang`, 'icon-shitugonggeListBox');
  248. that.$set(that, `type`, 'gongge');
  249. }
  250. }
  251. that.clearPage();
  252. that.search();
  253. },
  254. // 详细信息
  255. toView(e) {
  256. const that = this;
  257. that.clearPage();
  258. uni.navigateTo({
  259. url: `/pagesHome/shop/index?id=${e._id}`
  260. })
  261. },
  262. // 删除
  263. async toDel(e) {
  264. const that = this;
  265. let user = that.user;
  266. uni.showModal({
  267. title: '提示',
  268. content: '确定取消收藏吗?',
  269. success: async function(res) {
  270. if (res.confirm) {
  271. const arr = await that.$api(`/storeShop`, 'POST', {
  272. customer: user._id,
  273. shop: e._id
  274. });
  275. if (arr.errcode == '0') {
  276. uni.showToast({
  277. title: '取消收藏成功',
  278. icon: 'none'
  279. })
  280. that.clearPage();
  281. that.search();
  282. } else {
  283. uni.showToast({
  284. title: arr.errmsg,
  285. icon: 'none'
  286. })
  287. }
  288. }
  289. }
  290. });
  291. },
  292. // 清空列表
  293. clearPage() {
  294. const that = this;
  295. that.$set(that, `list`, [])
  296. that.$set(that, `skip`, 0)
  297. that.$set(that, `limit`, 6)
  298. that.$set(that, `page`, 0)
  299. }
  300. }
  301. }
  302. </script>
  303. <style lang="scss">
  304. .main {
  305. display: flex;
  306. flex-direction: column;
  307. width: 100vw;
  308. height: 100vh;
  309. .one {
  310. border-bottom: 1px solid var(--f85Color);
  311. padding: 2vw;
  312. input {
  313. padding: 2vw;
  314. background-color: var(--f1Color);
  315. font-size: var(--font14Size);
  316. border-radius: 5px;
  317. }
  318. }
  319. .two {
  320. position: relative;
  321. flex-grow: 1;
  322. padding: 2vw 0 0 0;
  323. .two_1 {
  324. background-color: var(--fffColor);
  325. padding: 2vw;
  326. display: flex;
  327. width: 100vw;
  328. flex-direction: row;
  329. justify-content: space-around;
  330. .list {
  331. display: flex;
  332. flex-direction: row;
  333. .icon {
  334. position: relative;
  335. top: -5px;
  336. left: 2px;
  337. .icon_1 {
  338. height: 10px;
  339. .iconfont {
  340. font-size: 12px;
  341. }
  342. }
  343. }
  344. .icon4 {
  345. .icon_1 {
  346. .iconfont {
  347. font-size: 17px;
  348. }
  349. }
  350. }
  351. }
  352. .activeList {
  353. .name {
  354. color: var(--fFB1Color);
  355. }
  356. }
  357. }
  358. .two_2 {
  359. width: 100vw;
  360. .list {
  361. display: flex;
  362. flex-direction: row;
  363. justify-content: space-between;
  364. width: 91vw;
  365. border: 1px solid var(--f1Color);
  366. margin: 2vw 2vw 0 2vw;
  367. padding: 2vw;
  368. border-radius: 5px;
  369. .image {
  370. width: 25vw;
  371. height: 25vw;
  372. border-radius: 5px;
  373. margin: 0 2vw 0 0;
  374. }
  375. .other {
  376. display: flex;
  377. flex-direction: column;
  378. flex-grow: 1;
  379. .name {
  380. font-size: var(--font16Size);
  381. margin: 0 0 1vw 0;
  382. }
  383. .other_1 {
  384. font-size: var(--font14Size);
  385. color: var(--f85Color);
  386. text {
  387. padding: 0 2vw;
  388. color: var(--fFB1Color);
  389. }
  390. }
  391. }
  392. }
  393. }
  394. .two_3 {
  395. width: 100vw;
  396. display: flex;
  397. flex-wrap: wrap;
  398. .list {
  399. width: 42vw;
  400. border: 1px solid var(--f1Color);
  401. margin: 2vw 2vw 0 2vw;
  402. padding: 2vw;
  403. border-radius: 5px;
  404. .image {
  405. width: 100%;
  406. height: 40vw;
  407. border-radius: 5px;
  408. }
  409. .name {
  410. font-size: var(--font16Size);
  411. margin: 0 0 1vw 0;
  412. }
  413. .address {
  414. font-size: var(--font14Size);
  415. color: var(--fFB1Color);
  416. margin: 0 0 1vw 0;
  417. }
  418. .other {
  419. display: flex;
  420. flex-direction: row;
  421. justify-content: space-between;
  422. align-items: center;
  423. .other_1 {
  424. font-size: var(--font14Size);
  425. color: var(--f85Color);
  426. }
  427. }
  428. }
  429. .list:nth-child(2n) {
  430. margin: 2vw 0 0 0;
  431. }
  432. }
  433. }
  434. }
  435. .scroll-view {
  436. position: absolute;
  437. top: 0;
  438. left: 0;
  439. right: 0;
  440. bottom: 0;
  441. .list-scroll-view {
  442. display: flex;
  443. flex-direction: row;
  444. flex-wrap: wrap;
  445. }
  446. }
  447. .is_bottom {
  448. text-align: center;
  449. text {
  450. padding: 2vw 0;
  451. display: inline-block;
  452. color: #858585;
  453. font-size: 14px;
  454. }
  455. }
  456. </style>