shop.vue 9.6 KB

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