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

271 lines
5.2 KiB

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