search.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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">
  13. {{item.name}}
  14. </view>
  15. <view class="icon">
  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 class="icon_1">
  21. <text :class="['iconfont', item.xiaActive]" v-if="condActive==index&&xia=='-1'"></text>
  22. <text :class="['iconfont', item.xia]" v-else></text>
  23. </view>
  24. </view>
  25. </view>
  26. <view class="screenList" v-if="pid">
  27. <picker @change="screenChange" name="screen" :value="screen" :range="screenList" range-key="label">
  28. <view class="uni-input">{{screen_name||'筛选'}}</view>
  29. </picker>
  30. </view>
  31. </view>
  32. <view class="two_2">
  33. <view class="pubu">
  34. <view class="list" v-for="(item,index) in list" :key="index" @tap="toBuy(item)">
  35. <image class="image" :src="item.file&&item.file.length>0?item.file[0].url:''" mode="">
  36. </image>
  37. <view class="sale" v-if="item.is_sale==true">
  38. <text>已售尽</text>
  39. </view>
  40. <view class="name textOver">
  41. {{item.name}}
  42. </view>
  43. <view class="other">
  44. <view class="money">
  45. <text>¥</text>
  46. <text>{{item.sell_money}}</text>
  47. </view>
  48. <view class="other_1">
  49. {{item.view_num||0}}人浏览
  50. </view>
  51. <view class="btn" v-if="item.is_sale==false">
  52. <text class="iconfont icon-gouwuche"></text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </scroll-view>
  60. </view>
  61. <view class="is_bottom" v-if="is_bottom">
  62. <text>{{config.bottom_title}}</text>
  63. </view>
  64. </view>
  65. </mobile-frame>
  66. </template>
  67. <script>
  68. export default {
  69. data() {
  70. return {
  71. // 系统设置
  72. config: {},
  73. tags: '',
  74. // 一级id
  75. pid: '',
  76. searchInfo: {},
  77. list: [],
  78. total: 0,
  79. page: 0,
  80. skip: 0,
  81. limit: 6,
  82. condActive: 0,
  83. shang: '',
  84. xia: '',
  85. condList: [ // 筛选
  86. {
  87. name: '默认',
  88. },
  89. {
  90. name: '销量',
  91. shang: 'icon-shangjiantou',
  92. shangActive: 'icon-shangjiantou-copy',
  93. xia: 'icon-xiajiantou',
  94. xiaActive: 'icon-xiajiantou-copy'
  95. },
  96. {
  97. name: '价格',
  98. shang: 'icon-shangjiantou',
  99. shangActive: 'icon-shangjiantou-copy',
  100. xia: 'icon-xiajiantou',
  101. xiaActive: 'icon-xiajiantou-copy'
  102. },
  103. {
  104. name: '浏览量',
  105. shang: 'icon-shangjiantou',
  106. shangActive: 'icon-shangjiantou-copy',
  107. xia: 'icon-xiajiantou',
  108. xiaActive: 'icon-xiajiantou-copy'
  109. }
  110. ],
  111. // 筛选
  112. screenList: [],
  113. screen: '',
  114. screen_name: '',
  115. // 数据是否触底
  116. is_bottom: false,
  117. scrollTop: 0
  118. };
  119. },
  120. onLoad: async function(e) {
  121. const that = this;
  122. that.$set(that, `tags`, e.tags || '');
  123. that.$set(that, `pid`, e.pid || '');
  124. that.searchConfig();
  125. await that.searchOther();
  126. await that.search();
  127. uni.startPullDownRefresh();
  128. },
  129. methods: {
  130. // 查询基本设置
  131. searchConfig() {
  132. const that = this;
  133. uni.getStorage({
  134. key: 'config',
  135. success: function(res) {
  136. if (res.data) that.$set(that, `config`, res.data)
  137. },
  138. fail: function(err) {
  139. console.log(err);
  140. }
  141. })
  142. },
  143. // 选择二级
  144. screenChange(e) {
  145. const that = this;
  146. let data = that.screenList[e.detail.value];
  147. if (data) {
  148. that.$set(that, `tags`, data.code);
  149. that.$set(that, `screen_name`, data.label);
  150. that.clearPage();
  151. that.search();
  152. }
  153. },
  154. async searchOther() {
  155. const that = this;
  156. if (that.pid) {
  157. let info = {};
  158. info.pid = that.pid;
  159. const res = await that.$api(`/goodsTags/tree`, 'GET', {
  160. ...info
  161. })
  162. if (res.errcode == '0' && res.data.length > 0) {
  163. that.$set(that, `screenList`, res.data[0].children)
  164. }
  165. }
  166. },
  167. async search() {
  168. const that = this;
  169. let info = {
  170. skip: that.skip,
  171. limit: that.limit,
  172. tags: that.tags
  173. }
  174. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  175. ...info,
  176. ...that.searchInfo
  177. })
  178. if (res.errcode == '0') {
  179. let list = [...that.list, ...res.data]
  180. that.$set(that, `list`, list)
  181. that.$set(that, `total`, res.total)
  182. } else {
  183. uni.showToast({
  184. title: res.errmsg,
  185. });
  186. }
  187. },
  188. // 分页
  189. toPage() {
  190. const that = this;
  191. let list = that.list;
  192. let limit = that.limit;
  193. if (that.total > list.length) {
  194. uni.showLoading({
  195. title: '加载中',
  196. mask: true
  197. })
  198. let page = that.page + 1;
  199. that.$set(that, `page`, page)
  200. let skip = page * limit;
  201. that.$set(that, `skip`, skip)
  202. that.search();
  203. uni.hideLoading();
  204. } else that.$set(that, `is_bottom`, true)
  205. },
  206. toScroll(e) {
  207. const that = this;
  208. let up = that.scrollTop;
  209. that.$set(that, `scrollTop`, e.detail.scrollTop);
  210. let num = Math.sign(up - e.detail.scrollTop);
  211. if (num == 1) that.$set(that, `is_bottom`, false);
  212. },
  213. // 输入框
  214. toInput(e) {
  215. const that = this;
  216. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  217. that.clearPage();
  218. that.search();
  219. },
  220. // 筛选
  221. toCond(index, e) {
  222. const that = this;
  223. let condActive = that.condActive;
  224. that.$set(that, `condActive`, index);
  225. if (condActive != index && that.xia == '') {
  226. that.$set(that, `shang`, '0');
  227. that.$set(that, `xia`, '-1');
  228. } else if (condActive == index && that.xia == '-1') {
  229. that.$set(that, `shang`, '1');
  230. that.$set(that, `xia`, '0');
  231. } else if (condActive == index && that.shang == '1') {
  232. that.$set(that, `shang`, '0');
  233. that.$set(that, `xia`, '-1');
  234. } else if (condActive = index && that.shang == '1') {
  235. that.$set(that, `shang`, '0');
  236. that.$set(that, `xia`, '-1');
  237. }
  238. let value;
  239. if (index != 0) {
  240. value = that.shang == '0' ? that.xia : that.shang;
  241. }
  242. if (index == 1) {
  243. that.$set(that, `searchInfo`, {})
  244. that.$set(that.searchInfo, `sell_num`, value);
  245. } else if (index == 2) {
  246. that.$set(that, `searchInfo`, {})
  247. that.$set(that.searchInfo, `sell_money`, value);
  248. } else if (index == 3) {
  249. that.$set(that, `searchInfo`, {})
  250. that.$set(that.searchInfo, `view_num`, value);
  251. }
  252. that.clearPage();
  253. that.search();
  254. },
  255. toBuy(e) {
  256. uni.navigateTo({
  257. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  258. })
  259. },
  260. // 清空列表
  261. clearPage() {
  262. const that = this;
  263. that.$set(that, `list`, [])
  264. that.$set(that, `skip`, 0)
  265. that.$set(that, `limit`, 6)
  266. that.$set(that, `page`, 0)
  267. }
  268. },
  269. onPullDownRefresh: async function() {
  270. const that = this;
  271. that.$set(that, `list`, [])
  272. that.$set(that, `skip`, 0)
  273. that.$set(that, `limit`, 6)
  274. that.$set(that, `page`, 0)
  275. await that.search();
  276. uni.stopPullDownRefresh();
  277. }
  278. }
  279. </script>
  280. <style lang="scss">
  281. .main {
  282. display: flex;
  283. flex-direction: column;
  284. width: 100vw;
  285. height: 100vh;
  286. .one {
  287. border-bottom: 1px solid var(--f85Color);
  288. padding: 2vw;
  289. input {
  290. padding: 2vw;
  291. background-color: var(--f1Color);
  292. font-size: var(--font14Size);
  293. border-radius: 5px;
  294. }
  295. }
  296. .two {
  297. position: relative;
  298. flex-grow: 1;
  299. .two_1 {
  300. background-color: var(--fffColor);
  301. padding: 2vw;
  302. display: flex;
  303. flex-direction: row;
  304. justify-content: space-around;
  305. .list {
  306. display: flex;
  307. flex-direction: row;
  308. .icon {
  309. position: relative;
  310. top: -5px;
  311. left: 2px;
  312. .icon_1 {
  313. height: 10px;
  314. .iconfont {
  315. font-size: 12px;
  316. }
  317. }
  318. }
  319. }
  320. .activeList {
  321. .name {
  322. color: #ff0000;
  323. }
  324. }
  325. .screenList {
  326. width: 17vw;
  327. display: inline-block;
  328. white-space: nowrap;
  329. overflow: hidden;
  330. text-overflow: ellipsis;
  331. .uni-input {
  332. text-align: center;
  333. }
  334. }
  335. }
  336. .two_2 {
  337. display: flex;
  338. flex-direction: column;
  339. padding: 2vw;
  340. background-color: var(--f1Color);
  341. .pubu {
  342. // column-count: 2;
  343. // column-gap: 2vw;
  344. display: flex;
  345. justify-content: space-between;
  346. flex-wrap: wrap;
  347. .list {
  348. width: 43vw;
  349. // break-inside: avoid;
  350. position: relative;
  351. background-color: var(--fffColor);
  352. padding: 2vw;
  353. margin: 0 0 2vw 0;
  354. border-radius: 9px;
  355. .image {
  356. width: 100%;
  357. height: 40vw;
  358. }
  359. .sale {
  360. position: absolute;
  361. top: 18vw;
  362. text-align: center;
  363. width: 43vw;
  364. text {
  365. background-color: #0000005f;
  366. border-radius: 90px;
  367. display: inline-block;
  368. width: 15vw;
  369. height: 15vw;
  370. color: var(--fffColor);
  371. text-align: center;
  372. line-height: 15vw;
  373. }
  374. }
  375. .name {
  376. font-size: var(--font16Size);
  377. margin: 0 0 1vw 0;
  378. }
  379. .other {
  380. display: flex;
  381. flex-direction: row;
  382. justify-content: space-between;
  383. .money {
  384. font-size: var(--font14Size);
  385. text:nth-child(1) {
  386. font-size: var(--font12Size);
  387. }
  388. }
  389. .other_1 {
  390. font-size: var(--font12Size);
  391. color: var(--f85Color);
  392. text {
  393. font-weight: bold;
  394. padding: 0 2vw;
  395. color: var(--ff0Color);
  396. }
  397. }
  398. .btn {
  399. button {
  400. font-size: var(--font20Size);
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }
  409. .scroll-view {
  410. position: absolute;
  411. top: 0;
  412. left: 0;
  413. right: 0;
  414. bottom: 0;
  415. .list-scroll-view {
  416. display: flex;
  417. flex-direction: column;
  418. }
  419. }
  420. .is_bottom {
  421. text-align: center;
  422. text {
  423. padding: 2vw 0;
  424. display: inline-block;
  425. color: #858585;
  426. font-size: 14px;
  427. }
  428. }
  429. </style>