shop.vue 9.6 KB

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