index.vue 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="roadmap-page">
  3. <view class="section-card">
  4. <text class="section-title">路演材料上传</text>
  5. <text class="card-desc">上传您小组的路演陈述材料</text>
  6. <view class="form-item">
  7. <text class="form-label">路演主题陈述</text>
  8. <textarea class="form-textarea" v-model="proposition" placeholder="请描述您小组的路演主题..." :maxlength="1000" />
  9. </view>
  10. <view class="form-item">
  11. <text class="form-label">附件材料</text>
  12. <button class="upload-btn" @click="chooseFile">选择文件/图片</button>
  13. <image v-if="fileUrl" :src="fileUrl" class="preview-img" mode="aspectFit" />
  14. <text v-if="fileName" class="file-name">{{ fileName }}</text>
  15. </view>
  16. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading || !proposition">提交路演材料</button>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. import { uploadRoadmap, uploadFile } from '@/utils/api.js'
  22. export default {
  23. data() {
  24. return {
  25. proposition: '',
  26. fileUrl: '',
  27. fileName: '',
  28. filePath: '',
  29. loading: false
  30. }
  31. },
  32. methods: {
  33. chooseFile() {
  34. var self = this
  35. uni.chooseImage({
  36. count: 1,
  37. sizeType: ['compressed'],
  38. sourceType: ['album', 'camera'],
  39. success: function(res) {
  40. self.filePath = res.tempFilePaths[0]
  41. self.fileName = res.tempFilePaths[0].split('/').pop()
  42. self.fileUrl = res.tempFilePaths[0]
  43. }
  44. })
  45. },
  46. handleSubmit() {
  47. if (!this.proposition.trim()) {
  48. uni.showToast({ title: '请输入路演主题', icon: 'none' })
  49. return
  50. }
  51. if (this.loading) return
  52. this.loading = true
  53. var self = this
  54. var doSubmit = function(files) {
  55. return uploadRoadmap({ proposition: self.proposition, files: files })
  56. }
  57. var p = this.filePath ? uploadFile(this.filePath).then(function(r) { return r.data.url }) : Promise.resolve(null)
  58. p.then(function(url) {
  59. return doSubmit(url)
  60. }).then(function() {
  61. uni.showToast({ title: '提交成功', icon: 'success' })
  62. setTimeout(function() { uni.navigateBack() }, 800)
  63. }).catch(function(err) {
  64. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  65. }).finally(function() {
  66. self.loading = false
  67. })
  68. }
  69. }
  70. }
  71. </script>
  72. <style scoped>
  73. .roadmap-page { min-height: 100vh; background: #F5F5F5; padding: 32rpx; }
  74. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  75. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E293B; margin-bottom: 12rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  76. .card-desc { display: block; font-size: 26rpx; color: #64748B; margin-bottom: 32rpx; }
  77. .form-item { margin-bottom: 28rpx; }
  78. .form-label { display: block; font-size: 28rpx; color: #1E293B; font-weight: 500; margin-bottom: 12rpx; }
  79. .form-textarea { width: 100%; min-height: 240rpx; border: 2rpx solid #E2E8F0; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx; color: #1E293B; background: #F8FAFC; }
  80. .upload-btn { width: 100%; height: 72rpx; line-height: 72rpx; background: #FFF7ED; color: #F97316; font-size: 28rpx; border: 2rpx dashed #F97316; border-radius: 8rpx; margin-bottom: 16rpx; }
  81. .preview-img { width: 100%; height: 250rpx; border-radius: 8rpx; margin-bottom: 12rpx; }
  82. .file-name { font-size: 24rpx; color: #64748B; }
  83. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #F97316; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 16rpx; }
  84. .submit-btn:active { opacity: 0.85; }
  85. </style>