index.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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="goToGoodDetails(item)">
  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. } else{
  67. uni.showToast({
  68. title: "获取商品分类失败",
  69. icon: "none"
  70. })
  71. }
  72. }
  73. }).catch(res => {})
  74. },
  75. methods: {
  76. // 切换一级分类
  77. checkFirstSort(item) {
  78. this.sortFirstCode = item.cateCode
  79. this.sortSecondList = []
  80. if (item.oneCategory.length) {
  81. this.sortSecondList = item.oneCategory
  82. this.checkSecondSort(item.oneCategory[0])
  83. }
  84. },
  85. // 切换二级分类
  86. checkSecondSort(item) {
  87. this.sortSecondCode = item.cateCode
  88. this.goodsList = []
  89. if (this.triggered = 'restore') {
  90. this.pageIndex = 1
  91. this.getGoodsList()
  92. }
  93. },
  94. // 搜索商品
  95. search(data) {
  96. this.goodName = data.value
  97. this.goodsList = []
  98. this.pageIndex = 1
  99. this.getGoodsList()
  100. },
  101. // 下拉刷新
  102. handlePullDown(stopLoad) {
  103. this.pageIndex = 1
  104. this.goodsList = []
  105. this.getGoodsList(stopLoad)
  106. stopLoad ? stopLoad() : '';
  107. },
  108. // 懒加载
  109. handleLoadMore(stopLoad) {
  110. if (!this.isOver) {
  111. this.pageIndex++
  112. this.getGoodsList()
  113. } else{
  114. stopLoad ? stopLoad({ isEnd: true }) : '';
  115. }
  116. },
  117. // 获取商品
  118. getGoodsList(stopLoad) {
  119. NET.request(API.getGoodsBySort, {
  120. name: this.goodName,
  121. oneId: this.sortFirstCode,
  122. twoId: this.sortSecondCode,
  123. pageIndex: this.pageIndex,
  124. pageSize: 10,
  125. }, 'POST').then(res => {
  126. if (res.code == 0) {
  127. this.isOver = res.data.list.length != 10
  128. this.goodsList = this.goodsList.concat(res.data.list)
  129. } else{
  130. uni.showToast({
  131. title: "获取商品列表失败",
  132. icon: "none"
  133. })
  134. }
  135. }).catch(res => {})
  136. },
  137. // 跳转商品详情
  138. goToGoodDetails(item) {
  139. uni.navigateTo({
  140. url: '/pagesGood/goodDetails?goodId=' + item.productId
  141. });
  142. }
  143. }
  144. }
  145. </script>
  146. <style lang="less" scoped>
  147. page {
  148. width: 100%;
  149. height: 100%;
  150. }
  151. .container {
  152. width: 100%;
  153. height: 100%;
  154. .search-box {
  155. width: 100%;
  156. height: 58px;
  157. box-sizing: border-box;
  158. padding: 2px 12px 1px 12px;
  159. border-bottom: 1px solid #DDDDDD;
  160. /deep/.search-bar {
  161. .uni-searchbar__box {
  162. border-color: #F8F8F8;
  163. }
  164. }
  165. }
  166. .sort-left-box {
  167. width: 80px;
  168. height: calc(100% - 58px);
  169. border-right: 1px solid #DDDDDD;
  170. float: left;
  171. .sort-left-row {
  172. width: 100%;
  173. height: 45px;
  174. box-sizing: border-box;
  175. padding-left: 9px;
  176. border-left: 3px solid #FFFFFF;
  177. font-size: 15px;
  178. font-family: PingFang SC;
  179. color: #333333;
  180. line-height: 16px;
  181. align-items: center;
  182. display: flex;
  183. }
  184. .sort-left-row-active {
  185. color: #51A539;
  186. border-left: 3px solid #51A539;
  187. }
  188. }
  189. .sort-right-box {
  190. width: calc(100% - 81px);
  191. height: calc(100% - 58px);
  192. float: left;
  193. .sort-right-row {
  194. width: 100%;
  195. height: 44px;
  196. padding: 9px 2px 0px 7px;
  197. box-sizing: border-box;
  198. white-space: nowrap;
  199. .sort-right-col {
  200. height: 26px;
  201. margin-right: 10px;
  202. display: inline-block;
  203. border: 1px solid #DCDCDC;
  204. border-radius: 13px;
  205. padding: 0 25px;
  206. box-sizing: border-box;
  207. font-size: 12px;
  208. font-family: PingFang SC;
  209. color: #666666;
  210. line-height: 24px;
  211. }
  212. .sort-right-col-active {
  213. color: #FFFFFF;
  214. background: #52A63A;
  215. border: 1px solid #51A539;
  216. }
  217. }
  218. .goods-box {
  219. width: 100%;
  220. height: calc(100% - 44px)!important;
  221. padding: 6px 0 0px 0;
  222. box-sizing: border-box;
  223. overflow-y: auto;
  224. .goods-row {
  225. width: calc(100% - 24px);
  226. height: 104px;
  227. padding: 11px 11px 11px 7px;
  228. box-sizing: border-box;
  229. margin: 4px 0 12px 12px;
  230. background: #FFFFFF;
  231. box-shadow: 0px 1px 5px 0px rgba(102, 102, 102, 0.43);
  232. border-radius: 15px;
  233. .goods-img {
  234. width: 84px;
  235. height: 84px;
  236. float: left;
  237. }
  238. .goods-info {
  239. width: calc(100% - 108px);
  240. height: 84px;
  241. float: left;
  242. .goods-name {
  243. height: 18px;
  244. font-size: 15px;
  245. font-family: PingFang SC;
  246. color: #333333;
  247. line-height: 18px;
  248. white-space: nowrap;
  249. text-overflow: ellipsis;
  250. overflow: hidden;
  251. }
  252. .goods-details {
  253. height: 28px;
  254. font-size: 12px;
  255. font-family: PingFang SC;
  256. color: #999999;
  257. line-height: 14px;
  258. overflow: hidden;
  259. text-overflow: ellipsis;
  260. display: -webkit-box;
  261. -webkit-line-clamp: 2;
  262. -webkit-box-orient: vertical;
  263. word-wrap: break-word;
  264. margin: 4px 0 12px 0;
  265. }
  266. .goods-number {
  267. height: 16px;
  268. font-family: PingFang SC;
  269. line-height: 16px;
  270. .goods-icon {
  271. font-size: 12px;
  272. color: #52A63A;
  273. }
  274. .goods-spec {
  275. font-size: 15px;
  276. color: #52A63A;
  277. margin-right: 15px;
  278. }
  279. .goods-sales {
  280. font-size: 12px;
  281. color: #999999;
  282. }
  283. }
  284. }
  285. .goods-cart {
  286. width: 24px;
  287. height: 84px;
  288. float: left;
  289. .cart-button{
  290. width: 24px;
  291. height: 24px;
  292. margin-top: 30px;
  293. background-color: #52A63A;
  294. border-radius: 50%;
  295. text-align: center;
  296. .iconfont{
  297. color: #FFFFFF;
  298. font-size: 18px;
  299. line-height: 24px;
  300. }
  301. }
  302. }
  303. }
  304. }
  305. }
  306. }
  307. </style>