index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="teaching-page">
  3. <view class="section-card">
  4. <text class="section-title">教学卡提交</text>
  5. <view class="form-item">
  6. <text class="form-label">账本类型</text>
  7. <picker :range="bookTypes" range-key="label" @change="onBookTypeChange">
  8. <view class="picker-display">{{ selectedBookType.label }} ▼</view>
  9. </picker>
  10. </view>
  11. <view class="form-item">
  12. <text class="form-label">教学步骤</text>
  13. <textarea class="form-textarea" v-model="form.steps" placeholder="请描述您的教学步骤(每行一步)" :maxlength="500" />
  14. </view>
  15. <view class="form-item">
  16. <text class="form-label">附件截图(可选)</text>
  17. <button class="upload-btn" @click="chooseImage">选择图片</button>
  18. <image v-if="image" :src="image" class="preview-img" mode="aspectFit" />
  19. </view>
  20. <view class="form-item">
  21. <text class="form-label">关联成果ID(可选)</text>
  22. <input class="form-input" v-model="form.submissionId" type="number" placeholder="如有对应成果请填写ID" />
  23. </view>
  24. <button class="submit-btn" @click="handleSubmit" :loading="loading" :disabled="loading || !form.steps">提交教学卡</button>
  25. </view>
  26. </view>
  27. </template>
  28. <script>
  29. import { submitTeachingCard, uploadFile } from '@/utils/api.js'
  30. export default {
  31. data() {
  32. return {
  33. bookTypes: [
  34. { value: 'wealth', label: '财富账' },
  35. { value: 'health', label: '健康账' },
  36. { value: 'growth', label: '成长账' }
  37. ],
  38. form: {
  39. bookType: 'wealth',
  40. steps: '',
  41. submissionId: ''
  42. },
  43. image: '',
  44. loading: false
  45. }
  46. },
  47. computed: {
  48. selectedBookType() {
  49. return this.bookTypes.find(b => b.value === this.form.bookType) || this.bookTypes[0]
  50. }
  51. },
  52. methods: {
  53. onBookTypeChange(e) {
  54. this.form.bookType = this.bookTypes[e.detail.value].value
  55. },
  56. chooseImage() {
  57. var self = this
  58. uni.chooseImage({
  59. count: 1,
  60. sizeType: ['compressed'],
  61. sourceType: ['album', 'camera'],
  62. success: function(res) {
  63. self.image = res.tempFilePaths[0]
  64. }
  65. })
  66. },
  67. handleSubmit() {
  68. if (!this.form.steps.trim()) {
  69. uni.showToast({ title: '请填写教学步骤', icon: 'none' })
  70. return
  71. }
  72. if (this.loading) return
  73. this.loading = true
  74. var self = this
  75. var doSubmit = function(imageUrl) {
  76. var data = {
  77. bookType: self.form.bookType,
  78. steps: self.form.steps,
  79. image: imageUrl || null,
  80. submissionId: self.form.submissionId ? parseInt(self.form.submissionId) : null
  81. }
  82. return submitTeachingCard(data)
  83. }
  84. var p = this.image ? uploadFile(this.image).then(function(r) { return r.data.url }) : Promise.resolve(null)
  85. p.then(function(url) {
  86. return doSubmit(url)
  87. }).then(function() {
  88. uni.showToast({ title: '提交成功', icon: 'success' })
  89. setTimeout(function() { uni.navigateBack() }, 800)
  90. }).catch(function(err) {
  91. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  92. }).finally(function() {
  93. self.loading = false
  94. })
  95. }
  96. }
  97. }
  98. </script>
  99. <style scoped>
  100. .teaching-page { min-height: 100vh; background: #F5F5F5; padding: 32rpx; }
  101. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  102. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E293B; margin-bottom: 24rpx; border-left: 8rpx solid #F97316; padding-left: 16rpx; }
  103. .form-item { margin-bottom: 28rpx; }
  104. .form-label { display: block; font-size: 28rpx; color: #1E293B; font-weight: 500; margin-bottom: 12rpx; }
  105. .form-input, .picker-display { width: 100%; height: 80rpx; border: 2rpx solid #E2E8F0; border-radius: 8rpx; padding: 0 20rpx; font-size: 28rpx; color: #1E293B; background: #F8FAFC; line-height: 80rpx; }
  106. .form-textarea { width: 100%; min-height: 200rpx; border: 2rpx solid #E2E8F0; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx; color: #1E293B; background: #F8FAFC; }
  107. .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; }
  108. .preview-img { width: 100%; height: 250rpx; border-radius: 8rpx; margin-bottom: 16rpx; }
  109. .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; }
  110. .submit-btn:active { opacity: 0.85; }
  111. </style>