search.vue 10 KB

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