search.vue 8.8 KB

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