index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <template>
  2. <view>
  3. <!-- 表单区域 -->
  4. <view class="form-container region mar-t-10">
  5. <view class="form-item">
  6. <view class="form-label">评分</view>
  7. <uni-rate size="30" v-model="score.score" />
  8. </view>
  9. <view class="form-item">
  10. <view class="form-label">评价内容</view>
  11. <view class="textarea-container">
  12. <textarea style="width: 100%;" v-model="score.content" placeholder="请详细描述申请说明(选填)"
  13. class="form-textarea" :maxlength="maxLength"></textarea>
  14. <view class="char-count">
  15. 您还可以输入{{ remainingChars }} 字
  16. </view>
  17. </view>
  18. </view>
  19. <!-- 上传凭证 -->
  20. <!-- 媒体上传 -->
  21. <view class="upload-section">
  22. <text class="section-title">图片上传</text>
  23. <media-uploader v-model="mediaList" :maxCount="9" mediaType="image" :media="false"
  24. :uploadUrl="uploadUrl" :token="token" @change="handleMediaChange" />
  25. </view>
  26. </view>
  27. <!-- 提交按钮 -->
  28. <button class="submit-button" @click="submitForm('customForm')">提交评价</button>
  29. </view>
  30. </template>
  31. <script>
  32. import {
  33. UPLOAD_URL
  34. } from '@/common/config.js';
  35. import store from '@/store';
  36. import MediaUploader from '@/components/MediaUploader.vue';
  37. import {
  38. saveScore
  39. } from '@/config/api.js';
  40. export default {
  41. components: {
  42. MediaUploader
  43. },
  44. data() {
  45. return {
  46. mediaList: [], // 媒体文件列表
  47. uploadUrl: UPLOAD_URL, // 上传地址
  48. token: "",
  49. score: {
  50. imgList: [],
  51. score: 5,
  52. content: ""
  53. },
  54. token: '',
  55. imageValue: [],
  56. fileList: [],
  57. images: [],
  58. orderId: "",
  59. maxLength: 200, // 最大字数
  60. };
  61. },
  62. computed: {
  63. // 计算剩余字数
  64. remainingChars() {
  65. return this.maxLength - this.score.content.length;
  66. }
  67. },
  68. onLoad(op) {
  69. this.orderId = op.orderId;
  70. this.token = uni.getStorageSync('access_token');
  71. },
  72. methods: {
  73. // 处理媒体文件变化
  74. handleMediaChange(list) {
  75. console.log('媒体列表变化:', list);
  76. // list 中的每个项目都包含 url 和 type (image/video)
  77. this.mediaList = list;
  78. // 更新 score.imgList,只包含图片类型的URL
  79. this.score.imgList = list
  80. .filter(item => item.type === 'image')
  81. .map(item => item.url);
  82. },
  83. // 提交表单
  84. submitForm() {
  85. this.score.images = this.score.imgList.join(',');
  86. this.score.orderId = this.orderId
  87. saveScore(this.score).then((res) => {
  88. if (res.code == 200) {
  89. uni.showToast({
  90. title: '评价成功',
  91. icon: 'success'
  92. });
  93. setTimeout(() => {
  94. uni.navigateBack({
  95. delta: 1
  96. })
  97. }, 1000)
  98. }
  99. })
  100. }
  101. }
  102. }
  103. </script>
  104. <style scoped>
  105. .page-title {
  106. font-size: 36rpx;
  107. font-weight: bold;
  108. text-align: center;
  109. padding: 20rpx 0;
  110. color: #333;
  111. }
  112. .form-container {
  113. padding: 20rpx;
  114. }
  115. .form-item {
  116. margin-bottom: 20rpx;
  117. }
  118. .form-label {
  119. font-size: 28rpx;
  120. color: #666;
  121. margin-bottom: 10rpx;
  122. }
  123. .textarea-container {
  124. position: relative;
  125. }
  126. .form-textarea {
  127. border: 1px solid #ccc;
  128. border-radius: 5rpx;
  129. padding: 10rpx;
  130. font-size: 28rpx;
  131. height: 150rpx;
  132. resize: none;
  133. }
  134. .char-count {
  135. position: absolute;
  136. bottom: 10rpx;
  137. right: 10rpx;
  138. font-size: 24rpx;
  139. color: #999;
  140. }
  141. .upload-container {
  142. margin-top: 10rpx;
  143. }
  144. .submit-button {
  145. background-color: #F95B5B;
  146. color: #fff;
  147. font-size: 32rpx;
  148. padding: 5rpx;
  149. border-radius: 10rpx;
  150. margin-left: 30rpx;
  151. margin-right: 30rpx;
  152. text-align: center;
  153. margin-top: 30rpx;
  154. }
  155. .videoUpload {
  156. border: 1rpx solid #999;
  157. height: 200rpx;
  158. width: 200rpx;
  159. }
  160. </style>