search.vue 11 KB

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