当前位置:   article > 正文

uniapp h5项目切换导航栏及动态渲染按钮颜色

uniapp h5项目切换导航栏及动态渲染按钮颜色

1.效果图

2.html,动态渲染按钮样式---三元判断

  1. <!-- 切换栏 -->
  2. <view class="statusList">
  3. <block v-for="(item,index) in list" :key="index">
  4. <view class="swiper-tab-list" :class="current == item.id?'active':''" @tap="getSize(item.id)">
  5. {{item.name}}
  6. <view :class="current == item.id?'bottomLine':''"></view>
  7. </view>
  8. </block>
  9. </view>
  10. <view class="main" v-for="(item,index) in orderList1" :key="index">
  11. <view class="part1">
  12. <!-- 动态样式 -->
  13. <view
  14. :class="item.state == 0 ? 'status' : item.state == 1 ? 'status1' : item.state == 2 ? 'status2' : item.state == 3 ? 'status3' : ''">
  15. {{item.state == 0 ? '已取消' : item.state == 1 ? '待接单' :item.state == 2 ? '待回收' : item.state == 3 ? '已回收' : ''}}
  16. </view>
  17. </view>
  18. <view class="part2">
  19. <text class="type">
  20. {{item.type}}
  21. </text>
  22. <view class="">
  23. <!-- <view class="pad"> -->
  24. <!-- </view> -->
  25. <text class="weight">
  26. {{item.weight}}
  27. </text>
  28. <!-- <view class="unit"> -->
  29. kg
  30. <!-- </view> -->
  31. </view>
  32. </view>
  33. <view class="line">
  34. </view>
  35. <view class="part3">
  36. <view class="">
  37. <view class="appointment">
  38. 预约时间:
  39. <text class="time">2024-02-20 11:00</text>
  40. </view>
  41. <view class="">
  42. 回收人员:
  43. </view>
  44. </view>
  45. <view :class="item.evaluate == 0 ? 'evaluate' : item.evaluate == 1 ? 'evaluate1' : ''">
  46. {{item.evaluate == 0 ? '未评价' : item.evaluate == 1 ? '已评价' : ''}}
  47. </view>
  48. </view>
  49. </view>

3.javaScript

  1. data() {
  2. return {
  3. // 切换栏
  4. list: [{
  5. id: 1,
  6. name: '待接单'
  7. },
  8. {
  9. id: 2,
  10. name: '待回收'
  11. },
  12. {
  13. id: 3,
  14. name: '已回收'
  15. },
  16. {
  17. id: 0,
  18. name: '已取消'
  19. },
  20. ],
  21. current: 1,
  22. orderList1: [{
  23. state: 1,
  24. type: '纸类',
  25. weight: '5.5',
  26. evaluate: 0
  27. },
  28. {
  29. state: 1,
  30. type: '塑料瓶',
  31. weight: '6.5',
  32. evaluate: 1
  33. }
  34. ],
  35. orderList2: [{
  36. state: 2,
  37. type: '纸类',
  38. weight: '7.5',
  39. evaluate: 0
  40. },
  41. {
  42. state: 2,
  43. type: '塑料瓶',
  44. weight: '8.5',
  45. evaluate: 1
  46. }
  47. ],
  48. orderList3: [{
  49. state: 3,
  50. type: '纸类',
  51. weight: '9.5',
  52. evaluate: 0
  53. },
  54. {
  55. state: 3,
  56. type: '塑料瓶',
  57. weight: '10.5',
  58. evaluate: 1
  59. }
  60. ],
  61. orderList4: [{
  62. state: 0,
  63. type: '纸类',
  64. weight: '11.5',
  65. evaluate: 0
  66. },
  67. {
  68. state: 0,
  69. type: '塑料瓶',
  70. weight: '12.5',
  71. evaluate: 0
  72. }
  73. ]
  74. }
  75. },
  76. getSize(id) {
  77. if (this.current != id) {
  78. this.current = id
  79. if (this.current == 0) {
  80. this.page = 1
  81. this.state = 0
  82. this.orderList1 = this.orderList4
  83. } else if (this.current == 1) {
  84. console.log(this.current, '11111')
  85. uni.pageScrollTo({
  86. scrollTop: this.scrollTop1,
  87. duration: 100
  88. });
  89. this.orderList1 = [{
  90. state: 1,
  91. type: '纸类',
  92. weight: '5.5',
  93. evaluate: 0
  94. },
  95. {
  96. state: 1,
  97. type: '塑料瓶',
  98. weight: '6.5',
  99. evaluate: 1
  100. }
  101. ]
  102. } else if (this.current == 2) {
  103. console.log(this.current, '222222')
  104. uni.pageScrollTo({
  105. scrollTop: this.scrollTop2,
  106. duration: 100
  107. });
  108. this.orderList1 = this.orderList2
  109. } else {
  110. uni.pageScrollTo({
  111. scrollTop: this.scrollTop3,
  112. duration: 100
  113. });
  114. this.orderList1 = this.orderList3
  115. }
  116. }
  117. },

4.css

  1. page {
  2. background: #F1F4F9;
  3. }
  4. .statusList {
  5. width: 100%;
  6. background: #fff;
  7. z-index: 999;
  8. height: 120rpx;
  9. display: flex;
  10. justify-content: space-around;
  11. align-items: center;
  12. .swiper-tab-list {
  13. position: relative;
  14. font-size: 36rpx;
  15. font-weight: 500;
  16. color: #999;
  17. .bottomLine {
  18. position: absolute;
  19. left: 50%;
  20. bottom: -10rpx;
  21. transform: translateX(-50%);
  22. width: 48rpx;
  23. height: 6rpx;
  24. background: orange;
  25. border-radius: 5rpx;
  26. text-align: center;
  27. }
  28. }
  29. .active {
  30. font-weight: bold;
  31. color: #333;
  32. }
  33. }
  34. .main {
  35. margin: 28rpx 24rpx;
  36. background: #fff;
  37. .part1 {
  38. padding: 28rpx 36rpx 15rpx 36rpx;
  39. .status,
  40. .status1,
  41. .status2,
  42. .status3,
  43. {
  44. width: 120rpx;
  45. height: 50rpx;
  46. background-color: red;
  47. border-radius: 15rpx;
  48. color: white;
  49. text-align: center;
  50. line-height: 50rpx;
  51. // margin: 28rpx 0 24rpx 36rpx;
  52. }
  53. .status1 {
  54. background-color: rgb(214, 170, 75);
  55. }
  56. .status2 {
  57. background-color: orange;
  58. }
  59. .status3 {
  60. background-color: orange;
  61. }
  62. }
  63. .part2 {
  64. display: flex;
  65. justify-content: center;
  66. // align-items: center;
  67. height: 57rpx;
  68. line-height: 57rpx;
  69. margin-bottom: 34rpx;
  70. .type {
  71. font-family: Source Han Sans SC;
  72. font-weight: 500;
  73. font-size: 36rpx;
  74. color: #000000;
  75. opacity: 0.85;
  76. margin-right: 35rpx;
  77. line-height: 70rpx;
  78. }
  79. .pad {
  80. margin-right: 15rpx;
  81. font-family: Source Han Sans SC;
  82. font-size: 24rpx;
  83. color: #000000;
  84. opacity: 0.85;
  85. line-height: 76rpx;
  86. }
  87. .weight {
  88. font-family: Source Han Sans SC;
  89. font-weight: 500;
  90. font-size: 60rpx;
  91. color: #3EAAFB;
  92. margin-right: 16rpx;
  93. // line-height: 11rpx;
  94. }
  95. .unit {
  96. font-size: 24rpx;
  97. color: #000000;
  98. opacity: 0.85;
  99. line-height: 76rpx;
  100. }
  101. }
  102. .part3 {
  103. padding: 0 36rpx 15rpx 36rpx;
  104. display: flex;
  105. justify-content: space-between;
  106. align-items: flex-end;
  107. .appointment {
  108. display: flex;
  109. align-items: flex-end;
  110. .time {
  111. font-family: Source Han Sans SC;
  112. font-weight: 400;
  113. font-size: 24rpx;
  114. color: #000000;
  115. opacity: 0.45;
  116. }
  117. }
  118. .evaluate,
  119. .evaluate1 {
  120. width: 120rpx;
  121. height: 50rpx;
  122. background-color: red;
  123. text-align: center;
  124. color: white;
  125. border-radius: 15rpx;
  126. }
  127. .evaluate {
  128. background: red;
  129. }
  130. .evaluate1 {
  131. font-family: Source Han Sans SC;
  132. font-weight: 400;
  133. color: #000000;
  134. opacity: 0.45;
  135. background: #EBEBEB;
  136. }
  137. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/626597
推荐阅读
相关标签
  

闽ICP备14008679号