推拿小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
5.2 KiB

4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
  1. <template>
  2. <view class="page">
  3. <!-- 导航栏 -->
  4. <navbar title="商品" class="nav-bar"
  5. leftClick
  6. @leftClick="$utils.navigateBack"
  7. bgColor="#E3441A"
  8. color="#fff"
  9. />
  10. <!-- 搜索栏 -->
  11. <view class="search">
  12. <uv-search
  13. v-model="queryParams.title"
  14. placeholder="搜索项目名称"
  15. bgColor="#F5F5F5"
  16. :showAction="false"
  17. @search="search"
  18. @change="search"
  19. @custom="search"
  20. ></uv-search>
  21. </view>
  22. <!-- 商品列表 -->
  23. <view v-if="queryParams.title" >
  24. <productCard v-for="item in list" :data="item" :key="item.id"></productCard>
  25. </view>
  26. <!-- 分类商品列表 -->
  27. <!-- todo: check chain? -->
  28. <view v-else class="" >
  29. <uv-vtabs
  30. :list="categoryList"
  31. keyName="name"
  32. :current="current"
  33. :chain="true"
  34. @change="change"
  35. barWidth="177rpx"
  36. barBgColor="#F5F5F5"
  37. :barItemStyle="{
  38. color: '#000000',
  39. fontSize: '28rpx',
  40. fontWeight: 700,
  41. }"
  42. :barItemActiveStyle="{
  43. color: '#84A73F',
  44. backgroundColor: '#FFFFFF',
  45. }"
  46. :barItemActiveLineStyle="{
  47. backgroundImage: 'linear-gradient(#84A73F, #D8FF8F)',
  48. margin: '25rpx 3rpx',
  49. }"
  50. >
  51. <uv-vtabs-item v-for="(item, index) in categoryList" :index="index" :key="item.id">
  52. <template v-if="item.childrens.length">
  53. <productCard
  54. v-for="product in item.childrens"
  55. :key="product.id"
  56. :data="product"
  57. direction="vertical"
  58. ></productCard>
  59. </template>
  60. <template v-else>
  61. <uv-empty text="还没有呢"/>
  62. </template>
  63. </uv-vtabs-item>
  64. </uv-vtabs>
  65. </view>
  66. <!-- tabbar -->
  67. <tabber select="category" />
  68. </view>
  69. </template>
  70. <script>
  71. import productCard from '@/components/product/productCard.vue'
  72. import mixinsList from '@/mixins/list.js'
  73. import {
  74. mapState
  75. } from 'vuex'
  76. import tabber from '@/components/base/tabbar.vue'
  77. import productList from '@/components/user/productList.vue'
  78. export default {
  79. mixins: [mixinsList],
  80. components: {
  81. productCard,
  82. tabber,
  83. productList,
  84. },
  85. data() {
  86. return {
  87. current : 0,
  88. queryParams: {
  89. pageNo: 1,
  90. pageSize: 10,
  91. title: null,
  92. },
  93. categoryList: []
  94. }
  95. },
  96. computed: {
  97. mixinsListApi() {
  98. return this.queryParams.title ? 'queryProductList' : ''
  99. }
  100. },
  101. onLoad() {
  102. let search = uni.getStorageSync('search')
  103. console.log('onLoad', search)
  104. if (search) {
  105. this.queryParams.title = search
  106. uni.setStorageSync('search', '')
  107. this.getData()
  108. }
  109. this.initList()
  110. },
  111. onPullDownRefresh() {
  112. !this.queryParams.title && this.initList()
  113. },
  114. methods: {
  115. async fetchCategoryList() {
  116. try {
  117. return (await this.$fetch('getCategoryList', { pageSize: 1000 }))?.records?.map(item => ({ id: item.id, name: item.name, childrens: [] }))
  118. } catch(err) {
  119. return []
  120. }
  121. },
  122. async queryProductList(categoryId) {
  123. try {
  124. return (await this.$fetch('queryProductList', { categoryId, pageSize: 1000 }))?.records || []
  125. } catch (err) {
  126. return []
  127. }
  128. },
  129. async initList() {
  130. this.categoryList = await this.fetchCategoryList()
  131. this.categoryList.forEach(async (category) => {
  132. category.childrens = await this.queryProductList(category.id)
  133. })
  134. uni.stopPullDownRefresh()
  135. },
  136. change(e) {
  137. this.current = e
  138. },
  139. search(){
  140. for(let i = 0;i < 10;i++){
  141. delete this.queryParams[i]
  142. }
  143. this.queryParams.pageSize = 10
  144. this.getData()
  145. },
  146. }
  147. }
  148. </script>
  149. <style scoped lang="scss">
  150. .page {
  151. min-height: 100vh;
  152. background-color: #FFFFFF;
  153. /deep/ .nav-bar__view {
  154. background-image: linear-gradient(#84A73F, #D8FF8F);
  155. }
  156. .search {
  157. position: relative;
  158. background: #F5F5F5;
  159. margin: 15rpx 30rpx;
  160. border-radius: 41rpx;
  161. padding: 10rpx 20rpx;
  162. display: flex;
  163. align-items: center;
  164. }
  165. $body-height: calc(100vh - #{$tabbar-height} - env(safe-area-inset-bottom));
  166. $search-height: 108rpx;
  167. $list-height: calc(#{$body-height} - #{$search-height});
  168. /deep/ .uv-vtabs,
  169. /deep/ .uv-vtabs__bar,
  170. /deep/ .uv-vtabs__content {
  171. height: $list-height !important;
  172. }
  173. /deep/ .uv-vtabs {
  174. background-color: #F5F5F5;
  175. overflow: hidden;
  176. }
  177. /deep/ .uv-vtabs__bar {
  178. // box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  179. box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  180. }
  181. /deep/ .uv-vtabs__content {
  182. margin-left: 6px;
  183. margin-right: 10rpx;
  184. .product-card__view {
  185. width: calc(100vw - 177rpx - 6px - 10rpx);
  186. }
  187. }
  188. /deep/ .uv-vtabs__bar-item {
  189. padding: 25rpx 0 !important;
  190. text-align: center;
  191. }
  192. &::v-deep .uv-vtabs__content {
  193. background: #F5F5F5 !important;
  194. // overflow: hidden;
  195. }
  196. }
  197. .category {
  198. font-size: 30rpx;
  199. color: #333;
  200. .category-title{
  201. position: relative;
  202. display: flex;
  203. justify-content: center;
  204. align-items: center;
  205. height: 120rpx;
  206. &::before,
  207. &::after {
  208. position: absolute;
  209. top: 50%;
  210. content: '';
  211. width: 10%;
  212. border-top: 2rpx solid black;
  213. }
  214. &::before {
  215. left: 25%;
  216. }
  217. &::after {
  218. right: 25%;
  219. }
  220. }
  221. &::v-deep .uv-vtabs {
  222. width: 750rpx;
  223. overflow: hidden;
  224. }
  225. .list {
  226. width: 100%;
  227. padding: 0rpx 20rpx;
  228. box-sizing: border-box;
  229. }
  230. }
  231. </style>