market.vue 12 KB

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