problemReporting.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <view class="problem">
  3. <view class="problem-form">
  4. <u--form labelPosition="left" :model="reportForm" :rules="rules" ref="reportForm">
  5. <u-form-item label="问题描述:" prop="content" labelWidth="80">
  6. <u--textarea v-model="reportForm.content" placeholder="请详细描述问题内容" count maxlength="300" height="80">
  7. </u--textarea>
  8. </u-form-item>
  9. <u-form-item label="上传图片:" labelWidth="80">
  10. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  11. :maxCount="10" uploadIcon="plus" uploadIconColor="rgba(0, 0, 0, 0.45)"
  12. uploadText="上传照片" width="104" height="104" bgColor="#fff"></u-upload>
  13. </u-form-item>
  14. <u-form-item label="" labelWidth="20">
  15. <u-button type="primary" text="提交" :loading="loading" @click="submitForm"></u-button>
  16. </u-form-item>
  17. </u--form>
  18. </view>
  19. <u-toast ref="uToast"></u-toast>
  20. </view>
  21. </template>
  22. <script>
  23. export default {
  24. data() {
  25. return {
  26. reportForm: {
  27. content: '',
  28. fileList: []
  29. },
  30. rules: {
  31. content: [
  32. {
  33. type: 'string',
  34. required: true,
  35. message: '请详细描述问题内容',
  36. trigger: ['blur']
  37. }
  38. ]
  39. },
  40. fileList1: [],
  41. loading: false
  42. }
  43. },
  44. methods: {
  45. // 删除图片
  46. deletePic(event) {
  47. this[`fileList${event.name}`].splice(event.index, 1)
  48. },
  49. // 新增图片
  50. async afterRead(event) {
  51. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  52. let lists = [].concat(event.file)
  53. let fileListLen = this[`fileList${event.name}`].length
  54. lists.map((item) => {
  55. this[`fileList${event.name}`].push({
  56. ...item,
  57. status: 'uploading',
  58. message: '上传中'
  59. })
  60. })
  61. for (let i = 0; i < lists.length; i++) {
  62. const result = await this.uploadFilePromise(lists[i].thumb)
  63. let item = this[`fileList${event.name}`][fileListLen]
  64. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  65. status: 'success',
  66. message: '',
  67. url: result
  68. }))
  69. fileListLen++
  70. this.reportForm.fileList = this.fileList1.map(item => {
  71. return item.url.url
  72. })
  73. }
  74. },
  75. uploadFilePromise(url) {
  76. return new Promise((resolve, reject) => {
  77. let a = uni.uploadFile({
  78. url: 'https://wx.hw.hongweisoft.com/veterans/file/upload/single/minio',
  79. filePath: url,
  80. name: 'file',
  81. formData: {
  82. user: 'test'
  83. },
  84. success: (res) => {
  85. setTimeout(() => {
  86. resolve(JSON.parse(res.data)?.data)
  87. }, 1000)
  88. }
  89. });
  90. })
  91. },
  92. submitForm() {
  93. this.$refs.reportForm.validate().then(res => {
  94. console.log(this.reportForm)
  95. this.loading = true
  96. this.$refs.uToast.show({
  97. type: 'success',
  98. title: '提示',
  99. message: "提交成功",
  100. iconUrl: 'https://cdn.uviewui.com/uview/demo/toast/success.png'
  101. })
  102. setTimeout(() => {
  103. uni.$u.route({
  104. url: 'pages/mine/mine',
  105. type: 'switchTab'
  106. })
  107. }, 2000)
  108. }).catch(error => {
  109. })
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss" scoped>
  115. .problem {
  116. padding: 20rpx 40rpx;
  117. }
  118. </style>