search.vue 7.4 KB

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