search.vue 9.6 KB

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