score.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. <view class="form-item">
  21. <view class="form-label">上传图片/视频(可选)</view>
  22. <view class=" flex-items">
  23. <view>
  24. <uni-file-picker @delete="delFile" v-model="imageValue" fileMediatype="image" mode="grid"
  25. @select="select">
  26. <view class="videoUpload flex-items-plus">
  27. <view class="text-align">
  28. <uni-icons type="image" size="30"></uni-icons>
  29. <view>
  30. 添加图片
  31. </view>
  32. </view>
  33. </view>
  34. </uni-file-picker>
  35. </view>
  36. <view>
  37. <uni-file-picker @delete="delFile" v-model="imageValue" fileMediatype="video" mode="grid"
  38. @select="select">
  39. <view class="videoUpload flex-items-plus">
  40. <view class="text-align">
  41. <uni-icons type="videocam" size="30"></uni-icons>
  42. <view>
  43. 添加短视频
  44. </view>
  45. </view>
  46. </view>
  47. </uni-file-picker>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <!-- 提交按钮 -->
  53. <button class="submit-button" @click="submitForm('customForm')">提交评价</button>
  54. </view>
  55. </template>
  56. <script>
  57. import {
  58. UPLOAD_URL
  59. } from '../../common/config.js';
  60. import {
  61. saveScore
  62. } from '../../config/api.js';
  63. export default {
  64. data() {
  65. return {
  66. score: {
  67. imgList: [],
  68. score: 5,
  69. content: ""
  70. },
  71. token: '',
  72. imageValue: [],
  73. fileList: [],
  74. images: [],
  75. orderId: "",
  76. maxLength: 200, // 最大字数
  77. };
  78. },
  79. computed: {
  80. // 计算剩余字数
  81. remainingChars() {
  82. return this.maxLength - this.score.content.length;
  83. }
  84. },
  85. onLoad(op) {
  86. this.orderId = op.orderId;
  87. this.token = uni.getStorageSync('access_token');
  88. },
  89. methods: {
  90. delFile(e) {
  91. this.score.imgList.splice(e.index, 1); // 删除对应 index 的附件
  92. },
  93. // 获取选择的文件
  94. async select(e) {
  95. console.log(e)
  96. let list = [].concat(e.tempFiles);
  97. // for (let i = 0; i < list.length; i++) {
  98. // const result = await this.uploadFilePromise(list[i].url);
  99. // this.score.imgList.push(result.data.link);
  100. // }
  101. },
  102. uploadFilePromise(url) {
  103. return new Promise((resolve, reject) => {
  104. uni.uploadFile({
  105. url: UPLOAD_URL,
  106. filePath: url,
  107. header: {
  108. "Blade-Auth": this.token
  109. },
  110. name: 'file',
  111. formData: {
  112. user: 'test'
  113. },
  114. success: (res) => {
  115. resolve(JSON.parse(res.data));
  116. }
  117. });
  118. });
  119. },
  120. // 提交表单
  121. submitForm() {
  122. this.score.images = this.score.imgList.join(',');
  123. this.score.orderId = this.orderId
  124. saveScore(this.score).then((res) => {
  125. if (res.code == 200) {
  126. uni.showToast({
  127. title: '评价成功',
  128. icon: 'success'
  129. });
  130. setTimeout(() => {
  131. uni.navigateBack({
  132. delta: 1
  133. })
  134. }, 1000)
  135. }
  136. })
  137. }
  138. }
  139. }
  140. </script>
  141. <style scoped>
  142. .page-title {
  143. font-size: 36rpx;
  144. font-weight: bold;
  145. text-align: center;
  146. padding: 20rpx 0;
  147. color: #333;
  148. }
  149. .form-container {
  150. padding: 20rpx;
  151. }
  152. .form-item {
  153. margin-bottom: 20rpx;
  154. }
  155. .form-label {
  156. font-size: 28rpx;
  157. color: #666;
  158. margin-bottom: 10rpx;
  159. }
  160. .textarea-container {
  161. position: relative;
  162. }
  163. .form-textarea {
  164. border: 1px solid #ccc;
  165. border-radius: 5rpx;
  166. padding: 10rpx;
  167. font-size: 28rpx;
  168. height: 150rpx;
  169. resize: none;
  170. }
  171. .char-count {
  172. position: absolute;
  173. bottom: 10rpx;
  174. right: 10rpx;
  175. font-size: 24rpx;
  176. color: #999;
  177. }
  178. .upload-container {
  179. margin-top: 10rpx;
  180. }
  181. .submit-button {
  182. background-color: #F95B5B;
  183. color: #fff;
  184. font-size: 32rpx;
  185. padding: 5rpx;
  186. border-radius: 10rpx;
  187. margin-left: 30rpx;
  188. margin-right: 30rpx;
  189. text-align: center;
  190. margin-top: 30rpx;
  191. }
  192. .videoUpload {
  193. border: 1rpx solid #999;
  194. height: 200rpx;
  195. width: 200rpx;
  196. }
  197. </style>