shop.vue 10 KB

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