search.vue 7.6 KB

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