message.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. picUrl: '',
  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. mui.toast('请输入内容');
  96. return false;
  97. } else {
  98. return true;
  99. }
  100. },
  101. //提交
  102. submit() {
  103. let files = [];
  104. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  105. files = this.$refs.uUpload.lists.filter(val => {
  106. return val.progress == 100;
  107. })
  108. // 如果您不需要进行太多的处理,直接如下即可
  109. // files = this.$refs.uUpload.lists;
  110. console.log(files);
  111. return
  112. if (this.checkFrom()) {
  113. this.subForm.picUrl = this.listPic.join(',');
  114. uni.showLoading({
  115. title: "加载中",
  116. mask: true,
  117. })
  118. API.problemFeedback(this.subForm).then(response => {
  119. this.isLoading = false;
  120. uni.showToast({
  121. title: '提交成功'
  122. })
  123. uni.navigateBack({
  124. })
  125. }).catch(error => {
  126. this.isLoading = false;
  127. uni.showToast({
  128. title: error
  129. })
  130. })
  131. }
  132. },
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .upload{
  138. width: 100%;
  139. }
  140. .message-form{
  141. padding:0 10px;
  142. margin-bottom: 10px;
  143. background-color: #fff;
  144. }
  145. .login-btn {
  146. margin: 28px ;
  147. background-color:#00B962!important;
  148. border-color: #00B962!important;
  149. color:#fff!important;
  150. }
  151. </style>