chooseService.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <template>
  2. <view class="container">
  3. <view class="service-list">
  4. <view class="service-item" v-for="item,index in serviceList" :key="index" @click="chooseItem(item)">
  5. <view class="title-box">
  6. <span class="title">{{item.name}}</span>
  7. <span class="price-box">
  8. <span class="tip">¥</span>
  9. <span class="price">{{item.sellingPrice}}</span>
  10. <span class="unit">/{{ getUnitTxt(item.serviceUnit) || ''}}</span>
  11. </span>
  12. </view>
  13. <view class="service-content">
  14. <!-- 内容限制为两行省略,超过的部分能展开 content-text根据expand 切换active样式-->
  15. <span class="content-text" :class="item.expand?'active':''">{{item.serviceDescription}}</span>
  16. <!-- content-text超过两行时显示展开 -->
  17. <span class="expand" v-if="item.serviceDescription.length>40"
  18. @click="expand(index)">{{item.expand?'收起':'展开'}}</span>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="empty-box" v-if="serviceList.length == 0">
  23. <u-empty marginTop="100" style="width: 100%;"></u-empty>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. import {
  29. getServiceList
  30. } from '@/api/home.js'
  31. import {
  32. getServiceUnit,
  33. } from '@/api/order.js'
  34. export default {
  35. data() {
  36. return {
  37. serviceList: [],
  38. unitList: [],
  39. }
  40. },
  41. onLoad() {
  42. this.getServiceList()
  43. this.getServiceUnit();
  44. },
  45. methods: {
  46. getServiceList() {
  47. getServiceList().then(res => {
  48. if(res.code == 200){
  49. let data = res.data;
  50. data.forEach(item => {
  51. item.expand = false
  52. })
  53. this.serviceList = data
  54. }
  55. })
  56. },
  57. getUnitTxt(value) {
  58. let obj = this.unitList.find(item => item.code == value);;
  59. return obj ? obj.value : ''
  60. },
  61. //查询订单状态
  62. getServiceUnit() {
  63. let that = this;
  64. getServiceUnit().then(res => {
  65. if (res.code == 200) {
  66. this.unitList = res.data.serviceUnit;
  67. }
  68. })
  69. .catch((err) => {
  70. console.log(err);
  71. })
  72. },
  73. expand(index) {
  74. this.serviceList[index].expand = !this.serviceList[index].expand
  75. },
  76. chooseItem(item) {
  77. uni.$emit('returnService', item);
  78. uni.navigateBack({
  79. delta: 1,
  80. });
  81. }
  82. },
  83. }
  84. </script>
  85. <style scoped lang="scss">
  86. ::v-deep body,
  87. html {
  88. height: 100% !important;
  89. }
  90. // .service-content中的 content-text限制为两行,超过的部分能展开
  91. .container {
  92. width: 100%;
  93. height: 100%;
  94. padding: 20rpx;
  95. box-sizing: border-box;
  96. overflow: hidden;
  97. background-color: #f6f6f6;
  98. .service-list {
  99. width: 100%;
  100. max-height: 100%;
  101. overflow-y: scroll;
  102. .service-item {
  103. width: 100%;
  104. padding: 20rpx;
  105. box-sizing: border-box;
  106. margin-bottom: 20rpx;
  107. background-color: #fff;
  108. border-radius: 10rpx;
  109. .title-box {
  110. width: 100%;
  111. display: flex;
  112. justify-content: space-between;
  113. align-items: center;
  114. .title {
  115. width: 490rpx;
  116. font-size: 32rpx;
  117. font-weight: bold;
  118. color: #1A1A1A;
  119. }
  120. .price-box{
  121. display: flex;
  122. align-items: flex-end;
  123. color: #FF0000;
  124. .price {
  125. font-size: 40rpx;
  126. line-height: 36rpx;
  127. }
  128. .unit,.tip{
  129. font-size: 24rpx;
  130. }
  131. }
  132. }
  133. .service-content {
  134. width: 100%;
  135. display: flex;
  136. justify-content: space-between;
  137. align-items: flex-start;
  138. margin-top: 20rpx;
  139. .content-text {
  140. width: 600rpx;
  141. font-size: 28rpx;
  142. color: #666666;
  143. overflow: hidden;
  144. text-overflow: ellipsis;
  145. display: -webkit-box;
  146. -webkit-line-clamp: 2;
  147. -webkit-box-orient: vertical;
  148. }
  149. .active {
  150. display: inline-flex;
  151. // height: auto;
  152. -webkit-line-clamp: 0;
  153. //动画效果,缓慢展开
  154. transition: all 0.3s ease-in-out;
  155. }
  156. .expand {
  157. flex: 1;
  158. text-align: right;
  159. font-size: 28rpx;
  160. color: #007AFF;
  161. }
  162. }
  163. }
  164. }
  165. }
  166. </style>