trainAssess.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="container">
  3. <scroll-view scroll-y class="content">
  4. <!-- 培训信息 -->
  5. <view class="info-card">
  6. <view class="card-title">培训信息</view>
  7. <view class="info-item">
  8. <text class="label">培训主题:</text>
  9. <text class="value">{{ trainName }}</text>
  10. </view>
  11. <view class="info-item">
  12. <text class="label">课程名称:</text>
  13. <text class="value">{{ courseName }}</text>
  14. </view>
  15. </view>
  16. <!-- 评估表单 -->
  17. <view class="form-card">
  18. <view class="card-title">培训评估</view>
  19. <!-- 项目组织评分 -->
  20. <view class="form-item">
  21. <view class="form-label">
  22. <text class="required">*</text>
  23. 项目组织评分:
  24. </view>
  25. <view class="star-rating">
  26. <view
  27. v-for="n in 5"
  28. :key="'project_' + n"
  29. class="star"
  30. :class="{ active: formData.project_org >= n }"
  31. @click="selectRating('project_org', n)"
  32. >
  33. {{ formData.project_org >= n ? '★' : '☆' }}
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 课程评分 -->
  38. <view class="form-item">
  39. <view class="form-label">
  40. <text class="required">*</text>
  41. 课程评分:
  42. </view>
  43. <view class="star-rating">
  44. <view
  45. v-for="n in 5"
  46. :key="'course_' + n"
  47. class="star"
  48. :class="{ active: formData.course_score >= n }"
  49. @click="selectRating('course_score', n)"
  50. >
  51. {{ formData.course_score >= n ? '★' : '☆' }}
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 讲师评分 -->
  56. <view class="form-item">
  57. <view class="form-label">
  58. <text class="required">*</text>
  59. 讲师评分:
  60. </view>
  61. <view class="star-rating">
  62. <view
  63. v-for="n in 5"
  64. :key="'teacher_' + n"
  65. class="star"
  66. :class="{ active: formData.teacher_score >= n }"
  67. @click="selectRating('teacher_score', n)"
  68. >
  69. {{ formData.teacher_score >= n ? '★' : '☆' }}
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 意见建议 -->
  74. <view class="form-item">
  75. <view class="form-label">意见建议:</view>
  76. <textarea
  77. class="textarea"
  78. v-model="formData.advice"
  79. placeholder="请输入您的意见和建议(选填)"
  80. maxlength="500"
  81. ></textarea>
  82. </view>
  83. </view>
  84. </scroll-view>
  85. <!-- 底部按钮 -->
  86. <view class="footer">
  87. <button class="btn btn-cancel" @click="goBack">取消</button>
  88. <button class="btn btn-submit" @click="submitAssess">提交</button>
  89. </view>
  90. </view>
  91. </template>
  92. <script setup>
  93. import { ref, reactive } from 'vue';
  94. import { onLoad } from '@dcloudio/uni-app';
  95. import { getMyTrainDetail, submitTrainAssess } from '@/api/train.js';
  96. import { useUserStore } from '@/store/user.js';
  97. const userStore = useUserStore();
  98. // 页面参数
  99. const universalid = ref('');
  100. const impleId = ref('');
  101. const courseId = ref('');
  102. const traineesId = ref('');
  103. const assessId = ref('');
  104. const trainName = ref('');
  105. const courseName = ref('');
  106. // 表单数据
  107. const formData = reactive({
  108. project_org: 0,
  109. course_score: 0,
  110. teacher_score: 0,
  111. advice: ''
  112. });
  113. onLoad((options) => {
  114. universalid.value = options.universalid || '';
  115. impleId.value = options.imple_id || '';
  116. courseId.value = options.course_id || '';
  117. traineesId.value = options.trainees_id || userStore.user.useId;
  118. assessId.value = options.assess_id || '';
  119. trainName.value = decodeURIComponent(options.train_name || '');
  120. courseName.value = decodeURIComponent(options.course_name || '');
  121. // 如果有 assess_id,加载已有评估数据
  122. if (assessId.value) {
  123. loadTrainDetail();
  124. }
  125. });
  126. // 加载培训详情
  127. async function loadTrainDetail() {
  128. try {
  129. const res = await getMyTrainDetail({
  130. universalid: universalid.value,
  131. imple_id: impleId.value,
  132. course_id: courseId.value,
  133. trainees_id: traineesId.value,
  134. assess_id: assessId.value
  135. });
  136. if (res && res.returnCode === '0' && res.returnParams) {
  137. const data = res.returnParams;
  138. formData.project_org = data.project_org || 0;
  139. formData.course_score = data.course_score || 0;
  140. formData.teacher_score = data.teacher_score || 0;
  141. formData.advice = data.advice || '';
  142. }
  143. } catch (error) {
  144. console.error('加载培训详情失败:', error);
  145. }
  146. }
  147. // 选择评分
  148. function selectRating(field, value) {
  149. formData[field] = value;
  150. }
  151. // 提交评估
  152. async function submitAssess() {
  153. // 验证必填项
  154. if (!formData.project_org) {
  155. uni.showToast({
  156. title: '请选择项目组织评分',
  157. icon: 'none'
  158. });
  159. return;
  160. }
  161. if (!formData.course_score) {
  162. uni.showToast({
  163. title: '请选择课程评分',
  164. icon: 'none'
  165. });
  166. return;
  167. }
  168. if (!formData.teacher_score) {
  169. uni.showToast({
  170. title: '请选择讲师评分',
  171. icon: 'none'
  172. });
  173. return;
  174. }
  175. uni.showLoading({
  176. title: '提交中...'
  177. });
  178. try {
  179. const res = await submitTrainAssess({
  180. universalid: assessId.value, // 使用 assess_id 作为 universalid
  181. imple_id: impleId.value,
  182. course_id: courseId.value,
  183. trainees_id: traineesId.value,
  184. project_org: formData.project_org,
  185. course_score: formData.course_score,
  186. teacher_score: formData.teacher_score,
  187. advice: formData.advice
  188. });
  189. uni.hideLoading();
  190. if (res && res.returnCode === '0') {
  191. uni.showToast({
  192. title: '评估成功',
  193. icon: 'success'
  194. });
  195. setTimeout(() => {
  196. goBack();
  197. }, 1500);
  198. } else {
  199. uni.showToast({
  200. title: '评估失败',
  201. icon: 'none'
  202. });
  203. }
  204. } catch (error) {
  205. uni.hideLoading();
  206. uni.showToast({
  207. title: '提交失败',
  208. icon: 'none'
  209. });
  210. console.error('提交评估失败:', error);
  211. }
  212. }
  213. // 返回
  214. function goBack() {
  215. uni.navigateBack();
  216. }
  217. </script>
  218. <style lang="scss" scoped>
  219. .container {
  220. min-height: 100vh;
  221. background-color: #f5f5f5;
  222. display: flex;
  223. flex-direction: column;
  224. }
  225. .content {
  226. flex: 1;
  227. padding: 20rpx;
  228. }
  229. .info-card, .form-card {
  230. background: #fff;
  231. border-radius: 12rpx;
  232. padding: 30rpx;
  233. margin-bottom: 20rpx;
  234. .card-title {
  235. font-size: 32rpx;
  236. font-weight: 600;
  237. color: #333;
  238. margin-bottom: 24rpx;
  239. padding-bottom: 16rpx;
  240. border-bottom: 1rpx solid #f0f0f0;
  241. }
  242. }
  243. .info-item {
  244. display: flex;
  245. align-items: center;
  246. font-size: 28rpx;
  247. line-height: 1.8;
  248. margin-bottom: 12rpx;
  249. .label {
  250. color: #999;
  251. min-width: 160rpx;
  252. }
  253. .value {
  254. color: #333;
  255. flex: 1;
  256. }
  257. }
  258. .form-item {
  259. margin-bottom: 32rpx;
  260. .form-label {
  261. font-size: 28rpx;
  262. color: #333;
  263. margin-bottom: 16rpx;
  264. .required {
  265. color: #ff4d4f;
  266. margin-right: 4rpx;
  267. }
  268. }
  269. .star-rating {
  270. display: flex;
  271. gap: 16rpx;
  272. .star {
  273. font-size: 48rpx;
  274. color: #d9d9d9;
  275. cursor: pointer;
  276. transition: all 0.3s;
  277. &.active {
  278. color: #FF9912;
  279. }
  280. &:active {
  281. transform: scale(1.2);
  282. }
  283. }
  284. }
  285. .textarea {
  286. width: 100%;
  287. min-height: 200rpx;
  288. padding: 20rpx;
  289. background: #f8f8f8;
  290. border-radius: 8rpx;
  291. font-size: 28rpx;
  292. line-height: 1.6;
  293. box-sizing: border-box;
  294. }
  295. }
  296. .footer {
  297. display: flex;
  298. gap: 20rpx;
  299. padding: 20rpx 30rpx;
  300. background: #fff;
  301. border-top: 1rpx solid #eee;
  302. .btn {
  303. flex: 1;
  304. height: 80rpx;
  305. line-height: 80rpx;
  306. font-size: 30rpx;
  307. border-radius: 8rpx;
  308. padding: 0;
  309. margin: 0;
  310. &::after {
  311. border: none;
  312. }
  313. &.btn-cancel {
  314. background: #f5f5f5;
  315. color: #666;
  316. }
  317. &.btn-submit {
  318. background: #1890ff;
  319. color: #fff;
  320. }
  321. }
  322. }
  323. </style>