market.vue 11 KB

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