shop.vue 10 KB

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