index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <uni-search-bar radius="5" placeholder="搜索" clearButton="auto" cancelButton="none" bgColor="#F8F8F8" @confirm="search"
  5. class="search-bar" />
  6. </view>
  7. <scroll-view show-scrollbar="true" scroll-y="true" class="sort-left-box">
  8. <view class="sort-left-row" :class="sortFirstCode == item.cateCode ? 'sort-left-row-active' : ''" v-for="(item,index) in sortFirstList"
  9. @click="checkFirstSort(item)" :key="index">
  10. <text>{{item.cateValue}}</text>
  11. </view>
  12. </scroll-view>
  13. <view class="sort-right-box">
  14. <scroll-view show-scrollbar="true" scroll-x="true" class="sort-right-row">
  15. <view class="sort-right-col" :class="sortSecondCode == item.cateCode ? 'sort-right-col-active' : ''" v-for="(item,index) in sortSecondList"
  16. :key="index" @click="checkSecondSort(item)">{{item.cateValue}}</view>
  17. </scroll-view>
  18. <k-scroll-view @onPullDown="handlePullDown" @onPullUp="handleLoadMore" class="goods-box">
  19. <view class="goods-row" v-for="item in goodsList" @click="">
  20. <cover-image class="goods-img" :src="item.imgPath"></cover-image>
  21. <view class="goods-info">
  22. <view class="goods-name">{{item.productName}}</view>
  23. <view class="goods-details">{{item.details}}</view>
  24. <view class="goods-number">
  25. <text class="goods-icon">¥</text>
  26. <text class="goods-spec">{{item.bizPrice}}/{{item.spec}}</text>
  27. <text class="goods-sales">{{item.sellCount}}人付款</text>
  28. </view>
  29. </view>
  30. <view class="goods-cart">
  31. <view class="cart-button">
  32. <view class="iconfont icongouwuche"></view>
  33. </view>
  34. </view>
  35. </view>
  36. </k-scroll-view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. const NET = require('../../utils/request')
  42. const API = require('../../config/api')
  43. import kScrollView from '@/components/k-scroll-view/k-scroll-view.vue'
  44. export default {
  45. components: {
  46. kScrollView
  47. },
  48. data() {
  49. return {
  50. pageIndex: 1,
  51. isOver: false,
  52. goodName: '',
  53. sortFirstCode: '',
  54. sortFirstList: [],
  55. sortSecondCode: '',
  56. sortSecondList: [],
  57. goodsList: [],
  58. }
  59. },
  60. onLoad() {
  61. NET.request(API.getSortList, {}, 'POST').then(res => {
  62. if (res.code == 0) {
  63. this.sortFirstList = res.data
  64. if (res.data.length) {
  65. this.checkFirstSort(res.data[0])
  66. }
  67. }
  68. }).catch(res => {})
  69. },
  70. methods: {
  71. // 切换一级分类
  72. checkFirstSort(item) {
  73. this.sortFirstCode = item.cateCode
  74. this.sortSecondList = []
  75. if (item.oneCategory.length) {
  76. this.sortSecondList = item.oneCategory
  77. this.checkSecondSort(item.oneCategory[0])
  78. }
  79. },
  80. // 切换二级分类
  81. checkSecondSort(item) {
  82. this.sortSecondCode = item.cateCode
  83. this.goodsList = []
  84. if (this.triggered = 'restore') {
  85. this.getGoodsList()
  86. }
  87. },
  88. // 搜索商品
  89. search(data) {
  90. this.goodName = data.value
  91. this.goodsList = []
  92. this.getGoodsList()
  93. },
  94. // 下拉刷新
  95. handlePullDown(stopLoad) {
  96. this.goodsList = []
  97. this.getGoodsList(stopLoad)
  98. stopLoad ? stopLoad() : '';
  99. },
  100. // 懒加载
  101. handleLoadMore(stopLoad) {
  102. if (!this.isOver) {
  103. this.getGoodsList()
  104. } else{
  105. stopLoad ? stopLoad({ isEnd: true }) : '';
  106. }
  107. },
  108. // 获取商品
  109. getGoodsList(stopLoad) {
  110. NET.request(API.getGoodsBySort, {
  111. name: this.goodName,
  112. oneId: this.sortFirstCode,
  113. twoId: this.sortSecondCode,
  114. pageIndex: this.pageIndex,
  115. pageSize: 10,
  116. }, 'POST').then(res => {
  117. if (res.code == 0) {
  118. for (let i = 0; i < 8; i++) {
  119. res.data.list.push({
  120. ...res.data.list[0],
  121. productName: res.data.list[i].productName + 1
  122. })
  123. }
  124. this.isOver = res.data.list.length != 10
  125. this.goodsList = this.goodsList.concat(res.data.list)
  126. }
  127. }).catch(res => {})
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="less" scoped>
  133. page {
  134. width: 100%;
  135. height: 100%;
  136. }
  137. .container {
  138. width: 100%;
  139. height: 100%;
  140. .search-box {
  141. width: 100%;
  142. height: 58px;
  143. box-sizing: border-box;
  144. padding: 2px 12px 1px 12px;
  145. border-bottom: 1px solid #DDDDDD;
  146. /deep/.search-bar {
  147. .uni-searchbar__box {
  148. border-color: #F8F8F8;
  149. }
  150. }
  151. }
  152. .sort-left-box {
  153. width: 80px;
  154. height: calc(100% - 58px);
  155. border-right: 1px solid #DDDDDD;
  156. float: left;
  157. .sort-left-row {
  158. width: 100%;
  159. height: 45px;
  160. box-sizing: border-box;
  161. padding-left: 9px;
  162. border-left: 3px solid #FFFFFF;
  163. font-size: 15px;
  164. font-family: PingFang SC;
  165. color: #333333;
  166. line-height: 16px;
  167. align-items: center;
  168. display: flex;
  169. }
  170. .sort-left-row-active {
  171. color: #51A539;
  172. border-left: 3px solid #51A539;
  173. }
  174. }
  175. .sort-right-box {
  176. width: calc(100% - 81px);
  177. height: calc(100% - 58px);
  178. float: left;
  179. .sort-right-row {
  180. width: 100%;
  181. height: 44px;
  182. padding: 9px 2px 0px 7px;
  183. box-sizing: border-box;
  184. white-space: nowrap;
  185. .sort-right-col {
  186. height: 26px;
  187. margin-right: 10px;
  188. display: inline-block;
  189. border: 1px solid #DCDCDC;
  190. border-radius: 13px;
  191. padding: 0 25px;
  192. box-sizing: border-box;
  193. font-size: 12px;
  194. font-family: PingFang SC;
  195. color: #666666;
  196. line-height: 24px;
  197. }
  198. .sort-right-col-active {
  199. color: #FFFFFF;
  200. background: #52A63A;
  201. border: 1px solid #51A539;
  202. }
  203. }
  204. .goods-box {
  205. width: 100%;
  206. height: calc(100% - 44px)!important;
  207. padding: 6px 0 0px 0;
  208. box-sizing: border-box;
  209. overflow-y: auto;
  210. .goods-row {
  211. width: calc(100% - 24px);
  212. height: 104px;
  213. padding: 11px 11px 11px 7px;
  214. box-sizing: border-box;
  215. margin: 4px 0 12px 12px;
  216. background: #FFFFFF;
  217. box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
  218. border-radius: 15px;
  219. .goods-img {
  220. width: 84px;
  221. height: 84px;
  222. float: left;
  223. }
  224. .goods-info {
  225. width: calc(100% - 108px);
  226. height: 84px;
  227. float: left;
  228. .goods-name {
  229. height: 18px;
  230. font-size: 15px;
  231. font-family: PingFang SC;
  232. color: #333333;
  233. line-height: 18px;
  234. white-space: nowrap;
  235. text-overflow: ellipsis;
  236. overflow: hidden;
  237. }
  238. .goods-details {
  239. height: 28px;
  240. font-size: 12px;
  241. font-family: PingFang SC;
  242. color: #999999;
  243. line-height: 14px;
  244. overflow: hidden;
  245. text-overflow: ellipsis;
  246. display: -webkit-box;
  247. -webkit-line-clamp: 2;
  248. -webkit-box-orient: vertical;
  249. word-wrap: break-word;
  250. margin: 4px 0 12px 0;
  251. }
  252. .goods-number {
  253. height: 16px;
  254. font-family: PingFang SC;
  255. line-height: 16px;
  256. .goods-icon {
  257. font-size: 12px;
  258. color: #52A63A;
  259. }
  260. .goods-spec {
  261. font-size: 15px;
  262. color: #52A63A;
  263. margin-right: 15px;
  264. }
  265. .goods-sales {
  266. font-size: 12px;
  267. color: #999999;
  268. }
  269. }
  270. }
  271. .goods-cart {
  272. width: 24px;
  273. height: 84px;
  274. float: left;
  275. .cart-button{
  276. width: 24px;
  277. height: 24px;
  278. margin-top: 30px;
  279. background-color: #52A63A;
  280. border-radius: 50%;
  281. text-align: center;
  282. .iconfont{
  283. color: #FFFFFF;
  284. font-size: 18px;
  285. line-height: 24px;
  286. }
  287. }
  288. }
  289. }
  290. }
  291. }
  292. }
  293. </style>