problem-feedback.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="page-container ">
  3. <u-nav-bar title="问题反馈" color="#333" bg="white" ref="uNavBar"></u-nav-bar>
  4. <view class="main-content">
  5. <u-des-row label="问题描述" />
  6. <uni-easyinput type="textarea" :maxlength="300" autoHeight v-model="form.content" placeholder="请输入问题描述(最多300字)">
  7. </uni-easyinput>
  8. <!-- <u-des-row label="附件" :value="form.attachmentList.length + '/9'" /> -->
  9. <uni-file-picker v-model="form.attachmentList" @select="imgSelect" fileMediatype="image" style="margin-top: 24rpx;"
  10. file-extname="png,jpg" :auto-upload="false" mode="grid" :limit="9" title="附件">
  11. <view class="choose-image u-flex-center">
  12. <image src="/static/upload_icon.png" style="width: 70rpx;height: 60rpx;" mode=""></image>
  13. <view class="choose-image-tip">上传图片</view>
  14. </view>
  15. </uni-file-picker>
  16. <view class="u-flex" style="margin-top: 56rpx;">
  17. <button class="u-button sumbit-button" @click="onSumbit">
  18. 提交
  19. </button>
  20. </view>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. import formChecker from '@/common/formChecker.js'
  26. export default {
  27. data() {
  28. return {
  29. form: {
  30. content: '',
  31. attachmentList: [],
  32. },
  33. }
  34. },
  35. mounted() {},
  36. methods: {
  37. imgSelect(res) {
  38. let error2M = 0
  39. const newImgs = res.tempFiles.filter(file => {
  40. const isLt2M = file.size / 1024 / 1024 < 2
  41. if (!isLt2M) {
  42. error2M++
  43. }
  44. return isLt2M
  45. })
  46. if (error2M) {
  47. uni.showToast({
  48. title: `当前选择了${res.tempFiles.length}个文件,${error2M}个文件大于2M`,
  49. icon: "none"
  50. });
  51. }
  52. console.log(111, newImgs)
  53. this.form.attachmentList = this.form.attachmentList.concat(newImgs)
  54. },
  55. // api
  56. async onSumbit(type) { // 1:暂存 2:提交
  57. //定义表单规则
  58. var rule = [{
  59. name: "content",
  60. checkType: "notnull",
  61. errorMsg: "请输入问题描述"
  62. }, {
  63. name: "attachmentList",
  64. // checkType: "notnull",
  65. errorMsg: "请添加附件"
  66. }];
  67. //进行表单检查
  68. var checkRes = formChecker.check(this.form, rule);
  69. if (!checkRes) {
  70. uni.showToast({
  71. title: formChecker.error,
  72. icon: "none"
  73. });
  74. return
  75. }
  76. await this.uploadFiles()
  77. const that = this
  78. uni.showLoading()
  79. const params = {
  80. ...that.form
  81. }
  82. params.attachmentList = params.attachmentList.map(item => item.path)
  83. uni.showLoading()
  84. that.$ajax.post('/shunt/proposal-apply', params).then(res => {
  85. uni.hideLoading()
  86. uni.showToast({
  87. title: '提交成功',
  88. duration: 2000
  89. });
  90. setTimeout(function() {
  91. that.$refs.uNavBar.toBack()
  92. }, 2000);
  93. }).catch(error => {
  94. uni.hideLoading()
  95. uni.showModal({
  96. title: '错误',
  97. content: error.msg || error,
  98. showCancel: false
  99. })
  100. })
  101. },
  102. async uploadFiles(success) {
  103. uni.showLoading({
  104. title: '上传文件中...'
  105. });
  106. const promiseList = []
  107. const indexList = []
  108. const that = this
  109. that.form.attachmentList.forEach((element, index) => {
  110. if (element.status) {
  111. indexList.push(index)
  112. promiseList.push(uni.uploadFile({
  113. url: `/shunt/upload`,
  114. filePath: element.url,
  115. // fileType: 'image',
  116. name: 'file',
  117. header: {
  118. token: uni.getStorageSync('TOKEN')
  119. },
  120. formData: {
  121. // file: res.tempFiles[0],
  122. fileType: 'APPLY',
  123. },
  124. // success(uploadFileRes) {
  125. // const data = JSON.parse(uploadFileRes.data)
  126. // const filePath = data.data.filePath
  127. // console.log(1111, filePath)
  128. // that.form.attachmentList[index] = filePath
  129. // }
  130. }))
  131. }
  132. })
  133. await Promise.all(promiseList).then(resList => {
  134. resList.forEach((element, index) => {
  135. let uploadFileRes = element[1]
  136. const data = JSON.parse(uploadFileRes.data)
  137. const filePath = data.data.filePath
  138. const formIndex = indexList[index]
  139. that.form.attachmentList[formIndex].path = filePath
  140. })
  141. })
  142. uni.hideLoading()
  143. }
  144. }
  145. }
  146. </script>
  147. <style lang="scss" scoped>
  148. .page-container {
  149. // background-color: #F5f5f5;
  150. // min-height: 100vh;
  151. .main-content {
  152. background-color: white;
  153. padding: 32rpx;
  154. }
  155. .save-button,
  156. .sumbit-button {
  157. flex: 1;
  158. height: 88rpx;
  159. background: linear-gradient(90deg, #FFCF18 0%, #FFB300 100%);
  160. border-radius: 8rpx;
  161. &.disabled {
  162. cursor: not-allowed;
  163. opacity: 0.3;
  164. }
  165. }
  166. .sumbit-button {
  167. background: linear-gradient(90deg, #36ACFC 0%, #078EF7 100%);
  168. }
  169. .choose-image {
  170. width: 100%;
  171. height: 100%;
  172. background: #FFFFFF;
  173. cursor: pointer;
  174. text-align: center;
  175. border: 1rpx dashed #A3ABBF;
  176. flex-direction: column;
  177. .choose-image-tip {
  178. font-size: 24rpx;
  179. font-weight: 400;
  180. color: #078EF7;
  181. margin-top: 24rpx;
  182. }
  183. }
  184. }
  185. </style>