market.vue 11 KB

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