policy_rich_card.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <template>
  2. <div class="card-situation">
  3. <div class="card-title">{{ model.title }}</div>
  4. <div
  5. v-html="model.text"
  6. class="card-text"
  7. :class="{ isfold: isfold }"
  8. ></div>
  9. <div class="fold" v-if="isFold && localIsFold" @click="changeFoldState">
  10. 点击{{ foldText }}
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. export default {
  16. props: ["model", "isFold"],
  17. data() {
  18. return {
  19. isfold: false,
  20. height: 0,
  21. foldText: "展开",
  22. scrollTop: 0,
  23. localIsFold: true,
  24. };
  25. },
  26. mounted() {
  27. let query = uni.createSelectorQuery().in(this);
  28. let cardText = query.select(".card-text");
  29. cardText
  30. .boundingClientRect((res) => {
  31. this.height = res.height;
  32. })
  33. .exec(() => {
  34. if (this.height < 500) {
  35. this.localIsFold = false;
  36. } else {
  37. this.isfold = true;
  38. }
  39. });
  40. },
  41. watch: {
  42. isfold(newValue, oldValue) {
  43. if (newValue) {
  44. this.foldText = "展开";
  45. } else {
  46. this.foldText = "收起";
  47. }
  48. },
  49. },
  50. methods: {
  51. changeFoldState() {
  52. let poor = 0,
  53. Bheight = 0,
  54. Eheight = 0;
  55. let query = uni.createSelectorQuery().in(this);
  56. let con = query.select(".card-situation");
  57. con
  58. .fields({ size: true }, (e) => {
  59. Bheight = e.height;
  60. })
  61. .exec(() => {
  62. console.log("开始高度", Bheight);
  63. });
  64. this.isfold = !this.isfold;
  65. con
  66. .fields({ size: true }, (e) => {
  67. Eheight = e.height;
  68. })
  69. .exec(() => {
  70. // this.$emit("changeScroll", Bheight - Eheight);
  71. console.log("结束高度", Eheight);
  72. });
  73. this.$emit("changeScroll");
  74. },
  75. },
  76. };
  77. </script>
  78. <style lang="scss" scoped>
  79. .card-situation {
  80. // margin-top: 20rpx;
  81. padding: 20rpx;
  82. border-top: 8rpx solid #f2f2f2;
  83. box-shadow: 0px 4rpx 32rpx rgba(0, 0, 0, 0.1);
  84. border-radius: 32rpx;
  85. .card-title {
  86. font-weight: 600;
  87. padding: 20rpx 20rpx 0rpx 20rpx;
  88. }
  89. .card-text {
  90. padding: 20rpx;
  91. margin-top: 20rpx;
  92. font-size: 27rpx;
  93. letter-spacing: 1rpx;
  94. line-height: 50rpx;
  95. overflow: hidden;
  96. }
  97. .fold {
  98. display: flex;
  99. justify-content: center;
  100. align-items: center;
  101. color: $uni-color-primary;
  102. }
  103. }
  104. .isfold {
  105. max-height: 340rpx;
  106. }
  107. </style>