questionnaire.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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.thumbnail" 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.dateRange }}</view>
  24. <view class="card-status-section">
  25. <view class="status-badge" :class="item.statusClass">{{ item.statusText }}</view>
  26. <view class="action-btn" v-if="currentTab === 'incomplete'" @click.stop="goToForm(item)">
  27. 填写问卷
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="no-more">没有更多了~</view>
  33. </scroll-view>
  34. </view>
  35. </template>
  36. <script>
  37. import { getQuestionnaireList } from '@/api-js/questionnaire'
  38. export default {
  39. data() {
  40. return {
  41. statusBarHeight: uni.getSystemInfoSync().statusBarHeight + 'px',
  42. currentTab: 'incomplete',
  43. tabs: [
  44. { label: '未完成', value: 'incomplete' },
  45. { label: '未开始', value: 'notStarted' },
  46. { label: '已结束', value: 'ended' }
  47. ],
  48. questionnaireList: []
  49. }
  50. },
  51. onLoad() {
  52. this.loadData()
  53. },
  54. methods: {
  55. goBack() {
  56. uni.navigateBack()
  57. },
  58. switchTab(tab) {
  59. this.currentTab = tab
  60. this.loadData()
  61. },
  62. goToForm(item) {
  63. uni.navigateTo({
  64. url: `/pages_task/questionnaireForm?id=${item.id}&title=${encodeURIComponent(item.title)}`
  65. })
  66. },
  67. async loadData() {
  68. try {
  69. uni.showLoading({ title: '加载中...' })
  70. const res = await getQuestionnaireList({
  71. status: this.currentTab,
  72. page: 1,
  73. pageSize: 20
  74. })
  75. uni.hideLoading()
  76. if (res.code === 200 && res.data) {
  77. this.questionnaireList = res.data.list || this.getDefaultData()
  78. } else {
  79. this.questionnaireList = this.getDefaultData()
  80. }
  81. } catch (e) {
  82. uni.hideLoading()
  83. console.error('加载数据失败', e)
  84. this.questionnaireList = this.getDefaultData()
  85. }
  86. },
  87. getDefaultData() {
  88. const defaultThumbnail = 'https://hos-1309931967.cos.ap-chongqing.myqcloud.com/fs/20240516/b091048293f142608f99eaf1b0b1510a.png'
  89. if (this.currentTab === 'notStarted') {
  90. return [
  91. {
  92. id: 1,
  93. thumbnail: defaultThumbnail,
  94. title: '康复医学调研',
  95. dateRange: '2024-09-15~2025-09-30',
  96. status: 'notStarted',
  97. statusText: '待开始',
  98. statusClass: 'status-pending'
  99. },
  100. {
  101. id: 2,
  102. thumbnail: defaultThumbnail,
  103. title: '康复医学调研',
  104. dateRange: '2024-09-15~2025-09-30',
  105. status: 'notStarted',
  106. statusText: '待开始',
  107. statusClass: 'status-pending'
  108. },
  109. {
  110. id: 3,
  111. thumbnail: defaultThumbnail,
  112. title: '糖尿病并发症调研',
  113. dateRange: '2024-09-15~2025-09-30',
  114. status: 'notStarted',
  115. statusText: '待开始',
  116. statusClass: 'status-pending'
  117. }
  118. ]
  119. } else if (this.currentTab === 'incomplete') {
  120. return [
  121. {
  122. id: 4,
  123. thumbnail: defaultThumbnail,
  124. title: '康复医学调研',
  125. dateRange: '2024-09-15~2025-09-30',
  126. status: 'incomplete',
  127. statusText: '待完成',
  128. statusClass: 'status-incomplete'
  129. },
  130. {
  131. id: 5,
  132. thumbnail: defaultThumbnail,
  133. title: '康复医学调研',
  134. dateRange: '2024-09-15~2025-09-30',
  135. status: 'incomplete',
  136. statusText: '待完成',
  137. statusClass: 'status-incomplete'
  138. },
  139. {
  140. id: 6,
  141. thumbnail: defaultThumbnail,
  142. title: '糖尿病并发症调研',
  143. dateRange: '2024-09-15~2025-09-30',
  144. status: 'incomplete',
  145. statusText: '待完成',
  146. statusClass: 'status-incomplete'
  147. }
  148. ]
  149. } else {
  150. return [
  151. {
  152. id: 7,
  153. thumbnail: defaultThumbnail,
  154. title: '康复医学调研',
  155. dateRange: '2024-09-15~2025-09-30',
  156. status: 'ended',
  157. statusText: '已结束',
  158. statusClass: 'status-ended'
  159. },
  160. {
  161. id: 8,
  162. thumbnail: defaultThumbnail,
  163. title: '康复医学调研',
  164. dateRange: '2024-09-15~2025-09-30',
  165. status: 'ended',
  166. statusText: '已结束',
  167. statusClass: 'status-ended'
  168. },
  169. {
  170. id: 9,
  171. thumbnail: defaultThumbnail,
  172. title: '糖尿病并发症调研',
  173. dateRange: '2024-09-15~2025-09-30',
  174. status: 'ended',
  175. statusText: '已结束',
  176. statusClass: 'status-ended'
  177. }
  178. ]
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss" scoped>
  185. .container {
  186. min-height: 100vh;
  187. background: #f5f5f5;
  188. display: flex;
  189. flex-direction: column;
  190. }
  191. .navbar {
  192. display: flex;
  193. align-items: center;
  194. justify-content: space-between;
  195. padding: 20rpx 24rpx;
  196. background: #fff;
  197. border-bottom: 1rpx solid #f0f0f0;
  198. .nav-left {
  199. width: 60rpx;
  200. .back-icon {
  201. font-size: 36rpx;
  202. color: #333;
  203. font-weight: bold;
  204. }
  205. }
  206. .nav-title {
  207. flex: 1;
  208. text-align: center;
  209. font-size: 36rpx;
  210. font-weight: bold;
  211. color: #333;
  212. }
  213. .nav-right {
  214. display: flex;
  215. align-items: center;
  216. gap: 24rpx;
  217. width: 120rpx;
  218. justify-content: flex-end;
  219. .more-icon {
  220. font-size: 32rpx;
  221. color: #333;
  222. }
  223. .target-icon {
  224. font-size: 32rpx;
  225. color: #333;
  226. }
  227. }
  228. }
  229. .tabs-bar {
  230. display: flex;
  231. background: #fff;
  232. border-bottom: 1rpx solid #f0f0f0;
  233. .tab-item {
  234. flex: 1;
  235. height: 88rpx;
  236. line-height: 88rpx;
  237. text-align: center;
  238. font-family: PingFang SC, PingFang SC;
  239. font-weight: 400;
  240. font-size: 28rpx;
  241. color: #969799;
  242. position: relative;
  243. &.active {
  244. font-family: PingFang SC, PingFang SC;
  245. font-weight: 500;
  246. font-size: 32rpx;
  247. color: #333333;
  248. &::after {
  249. content: '';
  250. position: absolute;
  251. bottom: 0;
  252. left: 50%;
  253. transform: translateX(-50%);
  254. width: 80rpx;
  255. height: 6rpx;
  256. border-radius: 3rpx;
  257. background: #388BFF;
  258. }
  259. }
  260. }
  261. }
  262. .content {
  263. flex: 1;
  264. padding: 24rpx;
  265. box-sizing: border-box;
  266. }
  267. .questionnaire-card {
  268. display: flex;
  269. background: #fff;
  270. border-radius: 16rpx;
  271. margin-bottom: 24rpx;
  272. padding: 24rpx;
  273. .card-thumbnail {
  274. width: 320rpx;
  275. height: 180rpx;
  276. border-radius: 16rpx 16rpx 16rpx 16rpx;
  277. overflow: hidden;
  278. margin-right: 24rpx;
  279. flex-shrink: 0;
  280. .thumbnail-img {
  281. width: 100%;
  282. height: 100%;
  283. }
  284. }
  285. .card-content {
  286. flex: 1;
  287. display: flex;
  288. flex-direction: column;
  289. justify-content: space-between;
  290. .card-title {
  291. font-family: PingFang SC, PingFang SC;
  292. font-weight: 500;
  293. font-size: 28rpx;
  294. color: #333333;
  295. margin-bottom: 16rpx;
  296. }
  297. .card-date {
  298. font-family: PingFang SC, PingFang SC;
  299. font-weight: 400;
  300. font-size: 24rpx;
  301. color: #999999;
  302. margin-bottom: 16rpx;
  303. }
  304. .card-status-section {
  305. display: flex;
  306. align-items: center;
  307. justify-content: space-between;
  308. .status-badge {
  309. padding: 8rpx 16rpx;
  310. border-radius: 8rpx;
  311. font-family: PingFang SC, PingFang SC;
  312. font-weight: 400;
  313. font-size: 24rpx;
  314. &.status-pending {
  315. background: #FFF7E6;
  316. color: #FF9500;
  317. }
  318. &.status-incomplete {
  319. background: #E6F4FF;
  320. color: #388BFF;
  321. }
  322. &.status-ended {
  323. background: #F5F5F5;
  324. color: #999999;
  325. }
  326. }
  327. .action-btn {
  328. padding: 12rpx 32rpx;
  329. background: #388BFF;
  330. border-radius: 34rpx;
  331. font-family: PingFang SC, PingFang SC;
  332. font-weight: 500;
  333. font-size: 24rpx;
  334. color: #FFFFFF;
  335. }
  336. }
  337. }
  338. }
  339. .no-more {
  340. text-align: center;
  341. padding: 48rpx 0;
  342. font-size: 24rpx;
  343. color: #999;
  344. }
  345. </style>