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