search.vue 9.4 KB

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