market.vue 12 KB

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