adviseForm.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="content">
  3. <u-navbar back-text="返回" title="建议反馈" back-icon-color="#ffffff" :back-text-style="{color: '#ffffff'}" title-color="#ffffff"
  4. :background="{backgroundColor: mainColor}"></u-navbar>
  5. <u-form :model="form" ref="form" label-width="140">
  6. <u-form-item label="建议反馈" prop="content" required>
  7. <u-input v-model="form.content" placeholder="请描述您的建议反馈" type="textarea" auto-height :height="180" />
  8. </u-form-item>
  9. <u-form-item label="上传附件" label-position="top">
  10. <u-upload max-count="1" :multiple="false" :action="uploadUrl" :header="uploadHeader" @on-success="uploadSuccess"
  11. @on-error="uploadError" @on-remove="uploadRemove"></u-upload>
  12. </u-form-item>
  13. </u-form>
  14. <view class="handle-fix-box">
  15. <u-button type="primary" :ripple="true" :custom-style="customStyle" @click="submitForm()">提交</u-button>
  16. </view>
  17. <u-top-tips ref="uTips" :navbar-height="statusBarHeight + navbarHeight"></u-top-tips>
  18. </view>
  19. </template>
  20. <script>
  21. import {
  22. mapGetters
  23. } from 'vuex'
  24. const NET = require('@/utils/request')
  25. const API = require('@/config/api')
  26. export default {
  27. computed: {
  28. ...mapGetters([
  29. 'mainColor',
  30. 'customStyle',
  31. ])
  32. },
  33. data() {
  34. return {
  35. statusBarHeight: uni.getSystemInfoSync().statusBarHeight,
  36. navbarHeight: 44,
  37. form: {
  38. areaId: '',
  39. tenantId: '',
  40. tenantName: '',
  41. assetId: '',
  42. assetName: '',
  43. content: '',
  44. fileList: [],
  45. },
  46. uploadUrl: API.uploadFile,
  47. uploadHeader: {
  48. Authorization: 'Bearer ' + uni.getStorageSync('token')
  49. },
  50. rules: {
  51. content: [{
  52. required: true,
  53. message: '请描述您的建议反馈',
  54. trigger: 'change'
  55. }],
  56. },
  57. }
  58. },
  59. onLoad(options) {
  60. this.form.areaId = options.areaId
  61. this.form.tenantId = options.tenantId
  62. this.form.tenantName = options.tenantName
  63. this.form.assetId = options.assetId
  64. this.form.assetName = options.assetName
  65. },
  66. onReady() {
  67. this.$refs.form.setRules(this.rules);
  68. },
  69. methods: {
  70. // 文件上传成功回调
  71. uploadSuccess(res, index, lists, name) {
  72. this.form.fileList.push(res.data[0])
  73. this.$refs.uTips.show({
  74. title: '文件上传成功',
  75. type: 'success',
  76. })
  77. return true
  78. },
  79. // 文件上传失败回调
  80. uploadError(res, index, lists, name) {
  81. this.$refs.uTips.show({
  82. title: '文件上传失败',
  83. type: 'warning',
  84. })
  85. },
  86. // 移除文件回调
  87. uploadRemove(index, lists, name) {
  88. this.form.fileList.splice(index, 1)
  89. },
  90. // 提交表单
  91. submitForm() {
  92. this.$refs.form.validate(valid => {
  93. if (valid) {
  94. NET.request(API.submitAdviseForm, {
  95. ...this.form
  96. }, 'POST').then(res => {
  97. this.$refs.uTips.show({
  98. title: '提交成功',
  99. type: 'success',
  100. })
  101. setTimeout(() => {
  102. uni.navigateBack()
  103. }, 1000)
  104. }).catch(error => {
  105. this.$refs.uTips.show({
  106. title: error.message,
  107. type: 'warning',
  108. })
  109. })
  110. }
  111. });
  112. },
  113. },
  114. }
  115. </script>
  116. <style>
  117. page {
  118. width: 100%;
  119. height: 100%;
  120. position: relative;
  121. }
  122. </style>
  123. <style lang="scss" scoped>
  124. @import "@/static/css/themes.scss";
  125. .content {
  126. width: 100%;
  127. float: left;
  128. padding: 0 15px 60px 15px;
  129. box-sizing: border-box;
  130. }
  131. </style>