index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. import { guardPage } from '@/utils/guard.js'
  31. export default {
  32. data() {
  33. return {
  34. bookTypes: [
  35. { value: 'wealth', label: '财富账' },
  36. { value: 'health', label: '健康账' },
  37. { value: 'growth', label: '成长账' }
  38. ],
  39. form: {
  40. bookType: 'wealth',
  41. steps: '',
  42. submissionId: ''
  43. },
  44. image: '',
  45. loading: false
  46. }
  47. },
  48. computed: {
  49. selectedBookType() {
  50. return this.bookTypes.find(b => b.value === this.form.bookType) || this.bookTypes[0]
  51. }
  52. },
  53. onLoad() {
  54. if (!guardPage()) return
  55. },
  56. methods: {
  57. onBookTypeChange(e) {
  58. this.form.bookType = this.bookTypes[e.detail.value].value
  59. },
  60. chooseImage() {
  61. var self = this
  62. uni.chooseImage({
  63. count: 1,
  64. sizeType: ['compressed'],
  65. sourceType: ['album', 'camera'],
  66. success: function(res) {
  67. self.image = res.tempFilePaths[0]
  68. }
  69. })
  70. },
  71. handleSubmit() {
  72. if (!guardPage()) return
  73. if (!this.form.steps.trim()) {
  74. uni.showToast({ title: '请填写教学步骤', icon: 'none' })
  75. return
  76. }
  77. if (this.loading) return
  78. this.loading = true
  79. var self = this
  80. var doSubmit = function(imageUrl) {
  81. var data = {
  82. bookType: self.form.bookType,
  83. steps: self.form.steps,
  84. image: imageUrl || null,
  85. submissionId: self.form.submissionId ? parseInt(self.form.submissionId) : null
  86. }
  87. return submitTeachingCard(data)
  88. }
  89. var p = this.image ? uploadFile(this.image).then(function(r) { return r.data.url }) : Promise.resolve(null)
  90. p.then(function(url) {
  91. return doSubmit(url)
  92. }).then(function() {
  93. uni.showToast({ title: '提交成功', icon: 'success' })
  94. setTimeout(function() { uni.navigateBack() }, 800)
  95. }).catch(function(err) {
  96. uni.showToast({ title: (err && err.message) || '提交失败', icon: 'none' })
  97. }).finally(function() {
  98. self.loading = false
  99. })
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped>
  105. .teaching-page { min-height: 100vh; background: #F5FAFE; padding: 32rpx; }
  106. .section-card { background: #FFF; border-radius: 16rpx; padding: 32rpx; }
  107. .section-title { display: block; font-size: 32rpx; font-weight: 700; color: #1E3A5F; margin-bottom: 24rpx; border-left: 8rpx solid #2E6FA8; padding-left: 16rpx; }
  108. .form-item { margin-bottom: 28rpx; }
  109. .form-label { display: block; font-size: 28rpx; color: #1E3A5F; font-weight: 500; margin-bottom: 12rpx; }
  110. .form-input, .picker-display { width: 100%; height: 80rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 0 20rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; line-height: 80rpx; }
  111. .form-textarea { width: 100%; min-height: 200rpx; border: 2rpx solid #E3ECF4; border-radius: 8rpx; padding: 20rpx; font-size: 28rpx; color: #1E3A5F; background: #F5FAFE; }
  112. .upload-btn { width: 100%; height: 72rpx; line-height: 72rpx; background: #E8F3FC; color: #2E6FA8; font-size: 28rpx; border: 2rpx dashed #2E6FA8; border-radius: 8rpx; margin-bottom: 16rpx; }
  113. .preview-img { width: 100%; height: 250rpx; border-radius: 8rpx; margin-bottom: 16rpx; }
  114. .submit-btn { width: 100%; height: 88rpx; line-height: 88rpx; background: #2E6FA8; color: #FFF; font-size: 30rpx; font-weight: 600; border-radius: 44rpx; border: none; margin-top: 16rpx; }
  115. .submit-btn:active { opacity: 0.85; }
  116. </style>