message.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <view>
  3. <u-navbar title="意见反馈"></u-navbar>
  4. <view class="message">
  5. <view class="message-form">
  6. <u-form :model="subForm" ref="uForm" label-width ="100">
  7. <u-form-item label-width="0">
  8. <u-input v-model="subForm.content" type="textarea" placeholder="请描述您的意见" height="200"/>
  9. </u-form-item>
  10. <u-form-item label-width="0">
  11. <view class="upload">
  12. <u-upload max-count="3" name="photoFile"
  13. ref="uUpload"
  14. :form-data="formData" :header="header" :action="action"
  15. :file-list="listPic" ></u-upload>
  16. </view>
  17. </u-form-item>
  18. <u-form-item >
  19. <u-input v-model="subForm.telephone" placeholder="请留下联系方式,方便我们与您取得联系(必填)" />
  20. </u-form-item>
  21. </u-form>
  22. </view>
  23. </view>
  24. <u-button class="login-btn" type="success" shape="circle" @click="submit">提交</u-button>
  25. </view>
  26. </template>
  27. <script>
  28. import * as API from '@/apis/user.js'
  29. import * as WxJsApi from '@/utils/wxJsApi'
  30. export default {
  31. data() {
  32. return {
  33. isReady:false,
  34. imgBase64: '',
  35. listPic: [],
  36. action:"",
  37. formData:{},
  38. header:{
  39. },
  40. subForm: {
  41. content: '',
  42. imgUrl: '',
  43. telephone: ''
  44. }
  45. }
  46. },onLoad() {
  47. this.action=process.car.BASE_URL+"uploadPicture"
  48. this.formData.subFolder="/team51/message"
  49. //接口应该免登陆
  50. var token=this.carhelp.getToken()
  51. this.header={
  52. 'Authorization':token
  53. }
  54. //获取微信配置
  55. WxJsApi.getWxConfig(['getLocation','addEventListener']).then((res)=>{
  56. this.isReady=true;
  57. console.log(res)
  58. }).catch(error => {
  59. console.log(res)
  60. })
  61. },
  62. methods: {
  63. //微信选择图片
  64. chooseImage() {
  65. WxJsApi.chooseImage().then(res => {
  66. var localData = res.localData;
  67. if (localData.indexOf('data:image') != 0) {
  68. //判断是否有这样的头部
  69. localData = 'data:image/jpeg;base64,' + localData
  70. }
  71. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  72. this.imgBase64 = localData;
  73. this.uploadpic();
  74. }).catch(error => {
  75. mui.toast(error);
  76. })
  77. },
  78. //上传图片
  79. uploadpic() {
  80. uni.showLoading({
  81. title: "加载中",
  82. mask: true,
  83. })
  84. WxJsApi.uploadPic(this.imgBase64).then(response => {
  85. this.isLoading = false;
  86. this.listPic.push(response);
  87. }).catch(error => {
  88. this.isLoading = false;
  89. mui.toast(error);
  90. })
  91. },
  92. //表单检测
  93. checkFrom() {
  94. if (!this.subForm.content) {
  95. uni.showToast({
  96. title: "请输入内容"
  97. })
  98. return false;
  99. } else {
  100. return true;
  101. }
  102. },
  103. //提交
  104. submit() {
  105. let files = [];
  106. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  107. files = this.$refs.uUpload.lists.filter(val => {
  108. return val.progress == 100;
  109. })
  110. // 如果您不需要进行太多的处理,直接如下即可
  111. // files = this.$refs.uUpload.lists;
  112. console.log(files);
  113. var imgUrl=files.map(item=>{
  114. return item.response.data;
  115. })
  116. console.log(imgUrl);
  117. this.subForm.imgUrl = imgUrl.join(',');
  118. if (this.checkFrom()) {
  119. this.subForm.picUrl = this.listPic.join(',');
  120. uni.showLoading({
  121. title: "加载中",
  122. mask: true,
  123. })
  124. API.feedback(this.subForm).then(response => {
  125. uni.hideLoading()
  126. uni.showModal({
  127. title: '提示',
  128. content: '提交成功',
  129. showCancel:false,
  130. success: res=>{
  131. if (res.confirm) {
  132. uni.navigateBack({
  133. })
  134. } else if (res.cancel) {
  135. console.log('用户点击取消');
  136. }
  137. }
  138. });
  139. }).catch(error => {
  140. uni.showToast({
  141. title: error
  142. })
  143. })
  144. }
  145. },
  146. }
  147. }
  148. </script>
  149. <style lang="scss" scoped>
  150. .upload{
  151. width: 100%;
  152. }
  153. .message-form{
  154. padding:0 10px;
  155. margin-bottom: 10px;
  156. background-color: #fff;
  157. }
  158. .login-btn {
  159. margin: 28px ;
  160. background-color:#00B962!important;
  161. border-color: #00B962!important;
  162. color:#fff!important;
  163. }
  164. </style>