medicationSurvey.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <template>
  2. <view class="container">
  3. <!-- 标签栏 -->
  4. <view class="tabs-bar">
  5. <view class="tab-item"
  6. :class="{ active: currentTab === item.value }"
  7. v-for="(item, index) in tabs"
  8. :key="index"
  9. @click="switchTab(item.value)">
  10. {{ item.label }}
  11. </view>
  12. </view>
  13. <!-- 问卷列表 -->
  14. <scroll-view class="content" scroll-y>
  15. <view class="questionnaire-card" v-for="(item, index) in questionnaireList" :key="index">
  16. <!-- 左侧缩略图 -->
  17. <view class="card-thumbnail">
  18. <image class="thumbnail-img" :src="item.coverImage" mode="aspectFill"></image>
  19. </view>
  20. <!-- 右侧内容 -->
  21. <view class="card-content">
  22. <view class="card-title">{{ item.title }}</view>
  23. <view class="card-date">{{ item.startTime+'-'+ item.endTime}}</view>
  24. <view class="card-status-section">
  25. <view class="status-badge" :class="item.timeStatus">{{ item.timeStatus=='before'?'未完成':item.timeStatus=='during'?'进行中':'已结束'}}</view>
  26. <view class="action-btn" v-if="currentTab == 'before'" @click="goToForm(item)">
  27. 填写问卷
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="no-more" v-if="!hasMore && questionnaireList.length > 0">没有更多了~</view>
  33. <view class="empty-state y-bc" v-if="questionnaireList.length === 0">
  34. <image class="w300 h300" src="@/static/image/img_blank_nodata.png" mode=""></image>
  35. <text>暂无数据</text>
  36. </view>
  37. </scroll-view>
  38. </view>
  39. </template>
  40. <script>
  41. import { getMedicationSurveyList } from '@/api/medicationSurvey'
  42. export default {
  43. data() {
  44. return {
  45. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  46. currentTab: 'before',
  47. tabs: [
  48. { label: '未完成', value: 'before' },
  49. { label: '进行中', value: 'during' },
  50. { label: '已结束', value: 'after' }
  51. ],
  52. questionnaireList: [],
  53. pageNum: 1,
  54. pageSize: 10,
  55. hasMore: true,
  56. loading: false
  57. }
  58. },
  59. onLoad() {
  60. },
  61. onShow() {
  62. this.loadData()
  63. },
  64. onReachBottom() {
  65. this.loadMore()
  66. },
  67. methods: {
  68. goBack() {
  69. uni.navigateBack()
  70. },
  71. switchTab(tab) {
  72. this.currentTab = tab
  73. this.pageNum = 1
  74. this.hasMore = true
  75. this.loadData()
  76. },
  77. goToForm(item) {
  78. uni.navigateTo({
  79. url: `/pages_task/caseCollection?id=${item.id}&title=${encodeURIComponent(item.title)}`
  80. })
  81. },
  82. async loadData() {
  83. try {
  84. this.pageNum = 1
  85. this.hasMore = true
  86. uni.showLoading({ title: '加载中...' })
  87. const res = await getMedicationSurveyList({
  88. timeStatus: this.currentTab,
  89. pageNum: 1,
  90. pageSize: this.pageSize
  91. })
  92. uni.hideLoading()
  93. if (res.code === 200) {
  94. this.questionnaireList = res.data.rows || []
  95. // 判断是否还有更多数据
  96. if (!res.data.rows || res.data.rows.length < this.pageSize) {
  97. this.hasMore = false
  98. }
  99. } else {
  100. uni.showToast({
  101. icon: 'none',
  102. title: res.msg
  103. })
  104. this.hasMore = false
  105. }
  106. } catch (e) {
  107. uni.hideLoading()
  108. console.error('加载数据失败', e)
  109. this.hasMore = false
  110. }
  111. },
  112. async loadMore() {
  113. if (!this.hasMore || this.loading) return
  114. try {
  115. this.loading = true
  116. const nextPage = this.pageNum + 1
  117. const res = await getMedicationSurveyList({
  118. timeStatus: this.currentTab,
  119. pageNum: nextPage,
  120. pageSize: this.pageSize
  121. })
  122. if (res.code === 200) {
  123. const newData = res.data.rows || []
  124. if (newData.length > 0) {
  125. // 追加新数据到列表
  126. this.questionnaireList = [...this.questionnaireList, ...newData]
  127. this.pageNum = nextPage
  128. // 如果返回的数据量小于 pageSize,说明没有更多数据了
  129. if (newData.length < this.pageSize) {
  130. this.hasMore = false
  131. }
  132. } else {
  133. // 没有新数据,说明已经加载完所有数据
  134. this.hasMore = false
  135. }
  136. } else {
  137. this.hasMore = false
  138. }
  139. } catch (e) {
  140. console.error('加载更多数据失败', e)
  141. this.hasMore = false
  142. } finally {
  143. this.loading = false
  144. }
  145. }
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .container {
  151. min-height: 100vh;
  152. display: flex;
  153. flex-direction: column;
  154. }
  155. .navbar {
  156. display: flex;
  157. align-items: center;
  158. justify-content: space-between;
  159. padding: 20rpx 24rpx;
  160. background: #fff;
  161. border-bottom: 1rpx solid #f0f0f0;
  162. .nav-left {
  163. width: 60rpx;
  164. .back-icon {
  165. font-size: 36rpx;
  166. color: #333;
  167. font-weight: bold;
  168. }
  169. }
  170. .nav-title {
  171. flex: 1;
  172. text-align: center;
  173. font-size: 36rpx;
  174. font-weight: bold;
  175. color: #333;
  176. }
  177. .nav-right {
  178. display: flex;
  179. align-items: center;
  180. gap: 24rpx;
  181. width: 120rpx;
  182. justify-content: flex-end;
  183. .more-icon {
  184. font-size: 32rpx;
  185. color: #333;
  186. }
  187. .target-icon {
  188. font-size: 32rpx;
  189. color: #333;
  190. }
  191. }
  192. }
  193. .tabs-bar {
  194. display: flex;
  195. background: #fff;
  196. border-bottom: 1rpx solid #f0f0f0;
  197. .tab-item {
  198. flex: 1;
  199. height: 88rpx;
  200. line-height: 88rpx;
  201. text-align: center;
  202. font-family: PingFang SC, PingFang SC;
  203. font-weight: 400;
  204. font-size: 28rpx;
  205. color: #969799;
  206. position: relative;
  207. &.active {
  208. font-family: PingFang SC, PingFang SC;
  209. font-weight: 500;
  210. font-size: 32rpx;
  211. color: #333333;
  212. &::after {
  213. content: '';
  214. position: absolute;
  215. bottom: 0;
  216. left: 50%;
  217. transform: translateX(-50%);
  218. width: 80rpx;
  219. height: 6rpx;
  220. border-radius: 3rpx;
  221. background: #388BFF;
  222. }
  223. }
  224. }
  225. }
  226. .content {
  227. flex: 1;
  228. padding: 24rpx;
  229. box-sizing: border-box;
  230. }
  231. .questionnaire-card {
  232. display: flex;
  233. background: #fff;
  234. border-radius: 16rpx;
  235. margin-bottom: 24rpx;
  236. padding: 24rpx;
  237. .card-thumbnail {
  238. width: 320rpx;
  239. height: 180rpx;
  240. border-radius: 16rpx 16rpx 16rpx 16rpx;
  241. overflow: hidden;
  242. margin-right: 24rpx;
  243. flex-shrink: 0;
  244. .thumbnail-img {
  245. width: 100%;
  246. height: 100%;
  247. }
  248. }
  249. .card-content {
  250. flex: 1;
  251. display: flex;
  252. flex-direction: column;
  253. justify-content: space-between;
  254. .card-title {
  255. font-family: PingFang SC, PingFang SC;
  256. font-weight: 500;
  257. font-size: 28rpx;
  258. color: #333333;
  259. margin-bottom: 16rpx;
  260. }
  261. .card-date {
  262. font-family: PingFang SC, PingFang SC;
  263. font-weight: 400;
  264. font-size: 24rpx;
  265. color: #999999;
  266. margin-bottom: 16rpx;
  267. }
  268. .card-status-section {
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. .status-badge {
  273. padding: 8rpx 16rpx;
  274. border-radius: 8rpx;
  275. font-family: PingFang SC, PingFang SC;
  276. font-weight: 400;
  277. font-size: 24rpx;
  278. &.before {
  279. background: #FFF7E6;
  280. color: #FF9500;
  281. }
  282. &.during {
  283. background: #E6F4FF;
  284. color: #388BFF;
  285. }
  286. &.after {
  287. background: #F6F6F6;
  288. color: #999999;
  289. }
  290. }
  291. .action-btn {
  292. padding: 12rpx 32rpx;
  293. background: #388BFF;
  294. border-radius: 34rpx;
  295. font-family: PingFang SC, PingFang SC;
  296. font-weight: 500;
  297. font-size: 24rpx;
  298. color: #FFFFFF;
  299. }
  300. }
  301. }
  302. }
  303. .no-more {
  304. text-align: center;
  305. padding: 48rpx 0;
  306. font-size: 24rpx;
  307. color: #999;
  308. }
  309. .empty-state {
  310. padding: 120rpx 24rpx;
  311. text-align: center;
  312. font-size: 28rpx;
  313. color: #999;
  314. }
  315. </style>