questionnaire.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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="survey-card" v-for="(item, index) in surveyList" :key="index" @click="handleAction(item)">
  16. <!-- 卡片头部背景 -->
  17. <view class="card-header-bg" :style="{ backgroundImage: `url(${item.coverImage})` }">
  18. <view class="banner-content">
  19. <!-- <view class="banner-title">{{ item.bannerTitle }}</view> -->
  20. <view class="collection-time">
  21. 征集时间: {{ formatTime(item.periodStartTime) }} 至 {{ formatTime(item.periodEndTime) }}
  22. </view>
  23. <!-- <view class="banner-info" v-if="item.title">{{ item.title }}</view> -->
  24. </view>
  25. </view>
  26. <!-- 卡片内容 -->
  27. <view class="card-body">
  28. <view class="description">{{ item.title }}</view>
  29. <view class="x-bc">
  30. <view class="progress-section" v-if="item.periodDataDto && shouldShowProgress(item)">
  31. <view class="progress-bar">
  32. <view class="progress-fill" :style="{ width: getProgressWidth(item) }"></view>
  33. </view>
  34. <view class="progress-text">{{ getProgressText(item) }}</view>
  35. </view>
  36. <view class="card-action">
  37. <view class="action-btn" v-if="currentTab == 'before'" :class="item.timeStatus" @click.stop="handleAction(item)">
  38. 填写问卷
  39. </view>
  40. <view class="action-btn" v-else :class="currentTab">
  41. {{currentTab == 'during'?'进行中':'已结束'}}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <view class="no-more" v-if="!hasMore && surveyList.length > 0">没有更多了~</view>
  48. <view class="empty-state y-bc" v-if="surveyList.length === 0">
  49. <image class="w300 h300" src="@/static/image/img_blank_nodata.png" mode=""></image>
  50. <text>暂无数据</text>
  51. </view>
  52. </scroll-view>
  53. </view>
  54. </template>
  55. <script>
  56. import {
  57. getQuestionnaireList
  58. } from '@/api/questionnaire'
  59. export default {
  60. data() {
  61. return {
  62. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  63. currentTab: 'before',
  64. tabs: [
  65. { label: '未完成', value: 'before' },
  66. { label: '进行中', value: 'during' },
  67. { label: '已结束', value: 'after' }
  68. ],
  69. surveyList: [],
  70. pageNum: 1,
  71. pageSize: 10,
  72. hasMore: true,
  73. loading: false
  74. }
  75. },
  76. onLoad() {
  77. },
  78. onShow() {
  79. // 从表单页返回时刷新列表
  80. this.loadData()
  81. },
  82. onReachBottom() {
  83. this.loadMore()
  84. },
  85. methods: {
  86. goBack() {
  87. uni.navigateBack()
  88. },
  89. switchTab(tab) {
  90. this.currentTab = tab
  91. this.pageNum = 1
  92. this.hasMore = true
  93. this.loadData()
  94. },
  95. goToDetail(item) {
  96. uni.navigateTo({
  97. url: `/pages_task/activityDetail?id=${item.id}`
  98. })
  99. },
  100. handleAction(item) {
  101. if (this.currentTab == 'after') {
  102. uni.showToast({
  103. icon: 'none',
  104. title: '活动已结束'
  105. })
  106. } else {
  107. // 跳转到填写问卷或上传病例页面
  108. uni.navigateTo({
  109. url: `/pages_task/questionnaireForm?id=${item.id}`
  110. })
  111. }
  112. },
  113. // 判断是否显示进度条
  114. shouldShowProgress(item) {
  115. if (!item.periodDataDto) return false
  116. const { alreadyPeriodNum, totalPeriodNum } = item.periodDataDto
  117. return totalPeriodNum != null && totalPeriodNum > 0
  118. },
  119. // 计算进度条宽度百分比
  120. getProgressWidth(item) {
  121. if (!item.periodDataDto) return '0%'
  122. const { alreadyPeriodNum, totalPeriodNum } = item.periodDataDto
  123. if (!totalPeriodNum || totalPeriodNum === 0) return '0%'
  124. const percentage = Math.min(100, Math.max(0, (alreadyPeriodNum / totalPeriodNum) * 100))
  125. return percentage.toFixed(2) + '%'
  126. },
  127. // 获取进度文本
  128. getProgressText(item) {
  129. if (!item.periodDataDto) return '0/0'
  130. const { alreadyPeriodNum, totalPeriodNum } = item.periodDataDto
  131. const already = alreadyPeriodNum != null ? alreadyPeriodNum : 0
  132. const total = totalPeriodNum != null ? totalPeriodNum : 0
  133. return `${already}/${total}`
  134. },
  135. // 格式化时间,去掉秒数
  136. formatTime(timeStr) {
  137. if (!timeStr) return '-'
  138. // 如果时间格式包含秒数(如 "YYYY-MM-DD HH:mm:ss"),则去掉秒数部分
  139. if (timeStr.length >= 19 && timeStr.indexOf(':') !== -1) {
  140. // 匹配 "YYYY-MM-DD HH:mm:ss" 格式,去掉最后的 ":ss"
  141. return timeStr.substring(0, 16)
  142. }
  143. return timeStr
  144. },
  145. async loadData() {
  146. try {
  147. this.pageNum = 1
  148. this.hasMore = true
  149. uni.showLoading({ title: '加载中...' })
  150. const res = await getQuestionnaireList({
  151. timeStatus: this.currentTab,
  152. pageNum: 1,
  153. pageSize: this.pageSize
  154. })
  155. uni.hideLoading()
  156. if (res.code === 200) {
  157. this.surveyList = res.data.rows || []
  158. // 判断是否还有更多数据
  159. if (!res.data.rows || res.data.rows.length < this.pageSize) {
  160. this.hasMore = false
  161. }
  162. } else {
  163. uni.showToast({
  164. icon: 'none',
  165. title: res.msg
  166. })
  167. }
  168. } catch (e) {
  169. uni.hideLoading()
  170. console.error('加载数据失败', e)
  171. }
  172. },
  173. async loadMore() {
  174. // 如果没有更多数据或正在加载,则不执行
  175. if (!this.hasMore || this.loading) {
  176. return
  177. }
  178. try {
  179. this.loading = true
  180. const nextPage = this.pageNum + 1
  181. const res = await getQuestionnaireList({
  182. timeStatus: this.currentTab,
  183. pageNum: nextPage,
  184. pageSize: this.pageSize
  185. })
  186. if (res.code === 200) {
  187. const newData = res.data.rows || []
  188. if (newData.length > 0) {
  189. // 追加新数据到列表
  190. this.surveyList = [...this.surveyList, ...newData]
  191. this.pageNum = nextPage
  192. // 如果返回的数据量小于 pageSize,说明没有更多数据了
  193. if (newData.length < this.pageSize) {
  194. this.hasMore = false
  195. }
  196. } else {
  197. // 没有新数据,说明已经加载完所有数据
  198. this.hasMore = false
  199. }
  200. } else {
  201. uni.showToast({
  202. icon: 'none',
  203. title: res.msg || '加载失败'
  204. })
  205. }
  206. } catch (e) {
  207. console.error('加载更多数据失败', e)
  208. uni.showToast({
  209. icon: 'none',
  210. title: '加载失败'
  211. })
  212. } finally {
  213. this.loading = false
  214. }
  215. }
  216. }
  217. }
  218. </script>
  219. <style lang="scss" scoped>
  220. .container {
  221. min-height: 100vh;
  222. display: flex;
  223. flex-direction: column;
  224. }
  225. .status-bar {
  226. width: 100%;
  227. background: #fff;
  228. }
  229. .header {
  230. position: relative;
  231. height: 88rpx;
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. background: #fff;
  236. border-bottom: 1rpx solid #f0f0f0;
  237. .back-btn {
  238. position: absolute;
  239. left: 24rpx;
  240. width: 40rpx;
  241. height: 40rpx;
  242. image {
  243. width: 100%;
  244. height: 100%;
  245. }
  246. }
  247. .title {
  248. font-size: 36rpx;
  249. font-weight: bold;
  250. color: #333;
  251. }
  252. .header-right {
  253. position: absolute;
  254. right: 24rpx;
  255. display: flex;
  256. align-items: center;
  257. gap: 16rpx;
  258. .more-icon {
  259. font-size: 32rpx;
  260. color: #333;
  261. }
  262. }
  263. }
  264. .tabs-bar {
  265. display: flex;
  266. background: #fff;
  267. border-bottom: 1rpx solid #f0f0f0;
  268. .tab-item {
  269. flex: 1;
  270. height: 88rpx;
  271. line-height: 88rpx;
  272. text-align: center;
  273. font-family: PingFang SC, PingFang SC;
  274. font-weight: 400;
  275. font-size: 28rpx;
  276. color: #969799;
  277. position: relative;
  278. &.active {
  279. font-family: PingFang SC, PingFang SC;
  280. font-weight: 500;
  281. font-size: 28rpx;
  282. color: #333333;
  283. font-weight: bold;
  284. &::after {
  285. content: '';
  286. position: absolute;
  287. bottom: 0;
  288. left: 50%;
  289. transform: translateX(-50%);
  290. right: 0;
  291. width: 80rpx;
  292. height: 6rpx;
  293. border-radius: 3rpx 3rpx 3rpx 3rpx;
  294. background: #388BFF;
  295. }
  296. }
  297. }
  298. }
  299. .content {
  300. flex: 1;
  301. padding: 24rpx;
  302. box-sizing: border-box;
  303. }
  304. .survey-card {
  305. background: #fff;
  306. border-radius: 16rpx;
  307. margin-bottom: 24rpx;
  308. overflow: hidden;
  309. .card-header-bg {
  310. position: relative;
  311. height: 240rpx;
  312. background: linear-gradient(135deg, #87CEEB 0%, #98D8C8 100%);
  313. display: flex;
  314. align-items: flex-start;
  315. justify-content: flex-end;
  316. flex-direction: column;
  317. padding: 24rpx;
  318. .banner-content {
  319. width: 100%;
  320. text-align:left;
  321. .collection-time {
  322. font-family: PingFang SC, PingFang SC;
  323. font-weight: 600;
  324. font-size: 26rpx;
  325. color: #FFFFFF;
  326. }
  327. .banner-info {
  328. font-size: 24rpx;
  329. color: #fff;
  330. margin-bottom: 8rpx;
  331. }
  332. }
  333. }
  334. .card-body {
  335. padding: 24rpx;
  336. .description {
  337. font-family: PingFang SC, PingFang SC;
  338. font-weight: 500;
  339. font-size: 28rpx;
  340. color: #333333;
  341. margin-bottom: 30rpx;
  342. }
  343. .progress-section {
  344. width: 60%;
  345. display: flex;
  346. align-items: center;
  347. justify-content: space-between;
  348. gap: 16rpx;
  349. .progress-bar {
  350. flex: 1;
  351. height: 12rpx;
  352. background: #f0f0f0;
  353. border-radius: 4rpx;
  354. overflow: hidden;
  355. .progress-fill {
  356. height: 100%;
  357. background: #388BFF;
  358. border-radius: 4rpx;
  359. transition: width 0.3s;
  360. }
  361. }
  362. .progress-text {
  363. font-size: 24rpx;
  364. color: #388BFF;
  365. min-width: 60rpx;
  366. }
  367. }
  368. .card-action {
  369. display: flex;
  370. justify-content: flex-end;
  371. .action-btn {
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. padding: 12rpx 24rpx;
  376. background: #388BFF;
  377. border-radius: 34rpx 34rpx 34rpx 34rpx;
  378. font-family: PingFang SC, PingFang SC;
  379. font-weight: 500;
  380. font-size: 24rpx;
  381. color: #FFFFFF;
  382. &.before {
  383. background: #388BFF;
  384. }
  385. &.during {
  386. background: #EFEFEF;
  387. color: #999999;
  388. }
  389. &.after {
  390. background: #EFEFEF;
  391. color: #999999;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. .no-more {
  398. text-align: center;
  399. padding: 48rpx 0;
  400. font-size: 24rpx;
  401. color: #999;
  402. }
  403. .empty-state {
  404. padding: 120rpx 24rpx;
  405. text-align: center;
  406. font-size: 28rpx;
  407. color: #999;
  408. }
  409. </style>