推拿小程序前端代码仓库
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.

261 lines
5.1 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
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. onShow() {
  102. },
  103. onLoad() {
  104. let search = uni.getStorageSync('search')
  105. console.log('onLoad', search)
  106. if (search) {
  107. this.queryParams.title = search
  108. uni.setStorageSync('search', '')
  109. }
  110. this.initList()
  111. },
  112. methods: {
  113. async fetchCategoryList() {
  114. try {
  115. return (await this.$fetch('getCategoryList', { pageSize: 1000 }))?.records?.map(item => ({ id: item.id, name: item.name, childrens: [] }))
  116. } catch(err) {
  117. return []
  118. }
  119. },
  120. async queryProductList(categoryId) {
  121. try {
  122. return (await this.$fetch('queryProductList', { categoryId, pageSize: 1000 }))?.records || []
  123. } catch (err) {
  124. return []
  125. }
  126. },
  127. async initList() {
  128. this.categoryList = await this.fetchCategoryList()
  129. this.categoryList.forEach(async (category) => {
  130. category.childrens = await this.queryProductList(category.id)
  131. })
  132. },
  133. change(e) {
  134. this.current = e
  135. },
  136. search(){
  137. for(let i = 0;i < 10;i++){
  138. delete this.queryParams[i]
  139. }
  140. this.queryParams.pageSize = 10
  141. this.getData()
  142. },
  143. }
  144. }
  145. </script>
  146. <style scoped lang="scss">
  147. .page {
  148. min-height: 100vh;
  149. background-color: #FFFFFF;
  150. /deep/ .nav-bar__view {
  151. background-image: linear-gradient(#84A73F, #D8FF8F);
  152. }
  153. .search {
  154. position: relative;
  155. background: #F5F5F5;
  156. margin: 15rpx 30rpx;
  157. border-radius: 41rpx;
  158. padding: 10rpx 20rpx;
  159. display: flex;
  160. align-items: center;
  161. }
  162. $body-height: calc(100vh - #{$tabbar-height} - env(safe-area-inset-bottom));
  163. $search-height: 108rpx;
  164. $list-height: calc(#{$body-height} - #{$search-height});
  165. /deep/ .uv-vtabs,
  166. /deep/ .uv-vtabs__bar,
  167. /deep/ .uv-vtabs__content {
  168. height: $list-height !important;
  169. }
  170. /deep/ .uv-vtabs {
  171. background-color: #F5F5F5;
  172. overflow: hidden;
  173. }
  174. /deep/ .uv-vtabs__bar {
  175. // box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  176. box-shadow: 0px 3px 6px 0px rgba(0,0,0,0.16);
  177. }
  178. /deep/ .uv-vtabs__content {
  179. margin-left: 6px;
  180. margin-right: 10rpx;
  181. .product-card__view {
  182. width: calc(100vw - 177rpx - 6px - 10rpx);
  183. }
  184. }
  185. /deep/ .uv-vtabs__bar-item {
  186. padding: 25rpx 0 !important;
  187. text-align: center;
  188. }
  189. &::v-deep .uv-vtabs__content {
  190. background: #F5F5F5 !important;
  191. // overflow: hidden;
  192. }
  193. }
  194. .category {
  195. font-size: 30rpx;
  196. color: #333;
  197. .category-title{
  198. position: relative;
  199. display: flex;
  200. justify-content: center;
  201. align-items: center;
  202. height: 120rpx;
  203. &::before,
  204. &::after {
  205. position: absolute;
  206. top: 50%;
  207. content: '';
  208. width: 10%;
  209. border-top: 2rpx solid black;
  210. }
  211. &::before {
  212. left: 25%;
  213. }
  214. &::after {
  215. right: 25%;
  216. }
  217. }
  218. &::v-deep .uv-vtabs {
  219. width: 750rpx;
  220. overflow: hidden;
  221. }
  222. .list {
  223. width: 100%;
  224. padding: 0rpx 20rpx;
  225. box-sizing: border-box;
  226. }
  227. }
  228. </style>