search.vue 11 KB

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