search.vue 7.2 KB

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