search.vue 11 KB

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