messageForm.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <view class="container">
  3. <view class="message-form">
  4. <u-cell-group :border="false">
  5. <u-field type="textarea" placeholder="请输入留言" v-model="formData.leaMsgContent" label-width="0"></u-field>
  6. </u-cell-group>
  7. <u-upload :action="uploadUrl" :form-data="uploadData" @on-success="uploadSuccess" @on-error="uploadError" @on-remove="uploadRemove"></u-upload>
  8. </view>
  9. <view class="form-handle">
  10. <u-button type="success" shape="circle" :ripple="true" @click="submitData" class="handle-custom">发布</u-button>
  11. </view>
  12. <u-top-tips ref="uTips"></u-top-tips>
  13. </view>
  14. </template>
  15. <script>
  16. const NET = require('@/utils/request')
  17. const API = require('@/config/api')
  18. export default {
  19. data() {
  20. return {
  21. formData: {
  22. orderId: '',
  23. tenantCode: '',
  24. leaMsgContent: '',
  25. },
  26. uploadData: {
  27. folderId: 0,
  28. },
  29. uploadUrl: '',
  30. fileList: []
  31. }
  32. },
  33. onLoad(options) {
  34. this.uploadUrl = API.uploadFile
  35. this.formData.orderId = options.orderId
  36. this.formData.tenantCode = options.tenantCode
  37. },
  38. methods: {
  39. // 文件上传成功回调
  40. uploadSuccess(res, index, lists, name) {
  41. this.fileList.push(res.data.url)
  42. this.$refs.uTips.show({
  43. title: '文件上传成功',
  44. type: 'success',
  45. })
  46. return true
  47. },
  48. // 文件上传失败回调
  49. uploadError(res, index, lists, name) {
  50. this.$refs.uTips.show({
  51. title: '文件上传失败',
  52. type: 'warning',
  53. })
  54. },
  55. // 移除文件回调
  56. uploadRemove(index, lists, name) {
  57. this.fileList.splice(index, 1)
  58. },
  59. // 提交数据
  60. submitData() {
  61. NET.request(API.addMessage, {
  62. ...this.formData,
  63. leaMsgType: 1,
  64. mid: uni.getStorageSync("userData").userId,
  65. orderLeaImgResVOs: this.fileList.map((site, index) => {
  66. return {
  67. fileType: 1,
  68. imgUrl: site,
  69. sortOrder: index + 1,
  70. }
  71. })
  72. },
  73. 'POST').then(res => {
  74. this.$refs.uTips.show({
  75. title: '留言成功',
  76. type: 'success',
  77. })
  78. setTimeout(() => {
  79. uni.navigateBack()
  80. }, 1000)
  81. }).catch(error => {
  82. this.modalShow = false
  83. this.$refs.uTips.show({
  84. title: error.data.msg,
  85. type: 'warning',
  86. })
  87. })
  88. },
  89. },
  90. }
  91. </script>
  92. <style lang="less" scoped>
  93. page {
  94. width: 100%;
  95. height: 100%;
  96. }
  97. .container {
  98. width: 100%;
  99. height: 100%;
  100. float: left;
  101. box-sizing: border-box;
  102. background-color: #FFFFFF;
  103. padding-bottom: 70px;
  104. overflow-y: auto;
  105. .message-form {
  106. width: 100%;
  107. float: left;
  108. box-sizing: border-box;
  109. padding: 0 15px;
  110. background-color: #ffffff;
  111. /deep/.u-field {
  112. padding-left: 0px;
  113. padding-right: 0px;
  114. }
  115. /deep/.u-cell {
  116. padding-left: 0px;
  117. padding-right: 0px;
  118. }
  119. }
  120. .form-handle {
  121. width: calc(100% - 30px);
  122. height: 40px;
  123. position: fixed;
  124. bottom: 20px;
  125. left: 15px;
  126. .handle-custom {
  127. background-color: #51A539;
  128. }
  129. }
  130. }
  131. </style>