search.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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. bottom_title: this.$config.bottom_title
  119. };
  120. },
  121. onLoad: async function(e) {
  122. const that = this;
  123. that.$set(that, `tags`, e.tags || '');
  124. that.$set(that, `pid`, e.pid || '');
  125. await that.searchOther();
  126. await that.search();
  127. },
  128. onShow: function() {
  129. const that = this;
  130. that.searchConfig();
  131. },
  132. onHide: function() {
  133. const that = this;
  134. // that.clearPage();
  135. },
  136. methods: {
  137. // 查询基本设置
  138. searchConfig() {
  139. const that = this;
  140. uni.getStorage({
  141. key: 'config',
  142. success: function(res) {
  143. if (res.data) that.$set(that, `config`, res.data)
  144. },
  145. fail: function(err) {
  146. console.log(err);
  147. }
  148. })
  149. },
  150. // 选择二级
  151. screenChange(e) {
  152. const that = this;
  153. let data = that.screenList[e.detail.value];
  154. if (data) {
  155. that.$set(that, `tags`, data.code);
  156. that.$set(that, `screen_name`, data.label);
  157. that.clearPage();
  158. that.search();
  159. }
  160. },
  161. async searchOther() {
  162. const that = this;
  163. if (that.pid) {
  164. let info = {};
  165. info.pid = that.pid;
  166. const res = await that.$api(`/goodsTags/tree`, 'GET', {
  167. ...info
  168. })
  169. if (res.errcode == '0' && res.data.length > 0) {
  170. that.$set(that, `screenList`, res.data[0].children)
  171. }
  172. }
  173. },
  174. async search() {
  175. const that = this;
  176. let info = {
  177. skip: that.skip,
  178. limit: that.limit,
  179. tags: that.tags
  180. }
  181. const res = await that.$api(`/viewGoods/indexGoodsList`, `GET`, {
  182. ...info,
  183. ...that.searchInfo
  184. })
  185. if (res.errcode == '0') {
  186. let list = [...that.list, ...res.data]
  187. that.$set(that, `list`, list)
  188. that.$set(that, `total`, res.total)
  189. } else {
  190. uni.showToast({
  191. title: res.errmsg,
  192. });
  193. }
  194. },
  195. // 分页
  196. toPage() {
  197. const that = this;
  198. let list = that.list;
  199. let limit = that.limit;
  200. if (that.total > list.length) {
  201. uni.showLoading({
  202. title: '加载中',
  203. mask: true
  204. })
  205. let page = that.page + 1;
  206. that.$set(that, `page`, page)
  207. let skip = page * limit;
  208. that.$set(that, `skip`, skip)
  209. that.search();
  210. uni.hideLoading();
  211. } else that.$set(that, `is_bottom`, true)
  212. },
  213. toScroll(e) {
  214. const that = this;
  215. let up = that.scrollTop;
  216. that.$set(that, `scrollTop`, e.detail.scrollTop);
  217. let num = Math.sign(up - e.detail.scrollTop);
  218. if (num == 1) that.$set(that, `is_bottom`, false);
  219. },
  220. // 输入框
  221. toInput(e) {
  222. const that = this;
  223. if (e.detail.value) that.$set(that.searchInfo, `name`, e.detail.value);
  224. that.clearPage();
  225. that.search();
  226. },
  227. // 筛选
  228. toCond(index, e) {
  229. const that = this;
  230. let condActive = that.condActive;
  231. that.$set(that, `condActive`, index);
  232. if (condActive != index && that.xia == '') {
  233. that.$set(that, `shang`, '0');
  234. that.$set(that, `xia`, '-1');
  235. } else if (condActive == index && that.xia == '-1') {
  236. that.$set(that, `shang`, '1');
  237. that.$set(that, `xia`, '0');
  238. } else if (condActive == index && that.shang == '1') {
  239. that.$set(that, `shang`, '0');
  240. that.$set(that, `xia`, '-1');
  241. } else if (condActive = index && that.shang == '1') {
  242. that.$set(that, `shang`, '0');
  243. that.$set(that, `xia`, '-1');
  244. }
  245. let value;
  246. if (index != 0) {
  247. value = that.shang == '0' ? that.xia : that.shang;
  248. }
  249. if (index == 1) {
  250. that.$set(that, `searchInfo`, {})
  251. that.$set(that.searchInfo, `sell_num`, value);
  252. } else if (index == 2) {
  253. that.$set(that, `searchInfo`, {})
  254. that.$set(that.searchInfo, `sell_money`, value);
  255. } else if (index == 3) {
  256. that.$set(that, `searchInfo`, {})
  257. that.$set(that.searchInfo, `view_num`, value);
  258. }
  259. that.clearPage();
  260. that.search();
  261. },
  262. toBuy(e) {
  263. uni.navigateTo({
  264. url: `/pagesHome/order/detail?id=${e.id||e._id}`
  265. })
  266. },
  267. // 清空列表
  268. clearPage() {
  269. const that = this;
  270. that.$set(that, `list`, [])
  271. that.$set(that, `skip`, 0)
  272. that.$set(that, `limit`, 6)
  273. that.$set(that, `page`, 0)
  274. }
  275. }
  276. }
  277. </script>
  278. <style lang="scss">
  279. .main {
  280. display: flex;
  281. flex-direction: column;
  282. width: 100vw;
  283. height: 100vh;
  284. .one {
  285. border-bottom: 1px solid var(--f85Color);
  286. padding: 2vw;
  287. input {
  288. padding: 2vw;
  289. background-color: var(--f1Color);
  290. font-size: var(--font14Size);
  291. border-radius: 5px;
  292. }
  293. }
  294. .two {
  295. position: relative;
  296. flex-grow: 1;
  297. .two_1 {
  298. background-color: var(--fffColor);
  299. padding: 2vw;
  300. display: flex;
  301. flex-direction: row;
  302. justify-content: space-around;
  303. .list {
  304. display: flex;
  305. flex-direction: row;
  306. .icon {
  307. position: relative;
  308. top: -5px;
  309. left: 2px;
  310. .icon_1 {
  311. height: 10px;
  312. .iconfont {
  313. font-size: 12px;
  314. }
  315. }
  316. }
  317. }
  318. .activeList {
  319. .name {
  320. color: #ff0000;
  321. }
  322. }
  323. .screenList {
  324. width: 17vw;
  325. display: inline-block;
  326. white-space: nowrap;
  327. overflow: hidden;
  328. text-overflow: ellipsis;
  329. .uni-input {
  330. text-align: center;
  331. }
  332. }
  333. }
  334. .two_2 {
  335. display: flex;
  336. flex-direction: column;
  337. padding: 2vw;
  338. background-color: var(--f1Color);
  339. .pubu {
  340. // column-count: 2;
  341. // column-gap: 2vw;
  342. display: flex;
  343. justify-content: space-between;
  344. flex-wrap: wrap;
  345. .list {
  346. width: 43vw;
  347. // break-inside: avoid;
  348. position: relative;
  349. background-color: var(--fffColor);
  350. padding: 2vw;
  351. margin: 0 0 2vw 0;
  352. border-radius: 9px;
  353. .image {
  354. width: 100%;
  355. height: 40vw;
  356. }
  357. .sale {
  358. position: absolute;
  359. top: 18vw;
  360. text-align: center;
  361. width: 43vw;
  362. text {
  363. background-color: #0000005f;
  364. border-radius: 90px;
  365. display: inline-block;
  366. width: 15vw;
  367. height: 15vw;
  368. color: var(--fffColor);
  369. text-align: center;
  370. line-height: 15vw;
  371. }
  372. }
  373. .name {
  374. font-size: var(--font16Size);
  375. margin: 0 0 1vw 0;
  376. }
  377. .other {
  378. display: flex;
  379. flex-direction: row;
  380. justify-content: space-between;
  381. .money {
  382. font-size: var(--font14Size);
  383. text:nth-child(1) {
  384. font-size: var(--font12Size);
  385. }
  386. }
  387. .other_1 {
  388. font-size: var(--font12Size);
  389. color: var(--f85Color);
  390. text {
  391. font-weight: bold;
  392. padding: 0 2vw;
  393. color: var(--ff0Color);
  394. }
  395. }
  396. .btn {
  397. button {
  398. font-size: var(--font20Size);
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. }
  407. .scroll-view {
  408. position: absolute;
  409. top: 0;
  410. left: 0;
  411. right: 0;
  412. bottom: 0;
  413. .list-scroll-view {
  414. display: flex;
  415. flex-direction: column;
  416. }
  417. }
  418. .is_bottom {
  419. text-align: center;
  420. text {
  421. padding: 2vw 0;
  422. display: inline-block;
  423. color: #858585;
  424. font-size: 14px;
  425. }
  426. }
  427. </style>