message.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="all">
  3. <ujp-navbar title="意见反馈"></ujp-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 :customStyle="customStyle" :placeholderStyle="placeholderStyle" 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 :customStyle="customStyle" :placeholderStyle="placeholderStyle" 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. elderMode:false,
  34. customStyle:{
  35. 'font-size':'28rpx'
  36. },
  37. placeholderStyle:"font-size:28rpx",
  38. isReady:false,
  39. imgBase64: '',
  40. listPic: [],
  41. action:"",
  42. formData:{},
  43. header:{
  44. },
  45. subForm: {
  46. content: '',
  47. imgUrl: '',
  48. telephone: ''
  49. }
  50. }
  51. },onLoad() {
  52. this.action=process.car.BASE_URL+"uploadPicture"
  53. this.formData.subFolder="/team51/message"
  54. //接口应该免登陆
  55. var token=this.carhelp.getToken()
  56. this.header={
  57. 'Authorization':token
  58. }
  59. //获取微信配置
  60. WxJsApi.getWxConfig(['getLocation','addEventListener']).then((res)=>{
  61. this.isReady=true;
  62. //(res)
  63. }).catch(error => {
  64. //(res)
  65. })
  66. },
  67. onReady(){
  68. this.elderMode = this.carhelp.get('getElderModeClass') == '长辈模式';
  69. if(this.elderMode)
  70. this.theme('elder')
  71. else
  72. this.theme('standard')
  73. },
  74. methods: {
  75. theme(type) {
  76. if(type == 'elder')
  77. {
  78. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  79. let data = {
  80. "font-size":'32rpx',
  81. };
  82. this.customStyle = data;
  83. this.placeholderStyle = "font-size:32rpx";//data;
  84. }
  85. else
  86. {
  87. document.getElementsByTagName('body')[0].setAttribute('data-theme',type);
  88. let data = {
  89. "font-size":'28rpx'
  90. };
  91. this.customStyle = data;
  92. this.placeholderStyle = "font-size:28rpx";//data;
  93. }
  94. },
  95. //微信选择图片
  96. chooseImage() {
  97. WxJsApi.chooseImage().then(res => {
  98. var localData = res.localData;
  99. if (localData.indexOf('data:image') != 0) {
  100. //判断是否有这样的头部
  101. localData = 'data:image/jpeg;base64,' + localData
  102. }
  103. localData = localData.replace(/\r|\n/g, '').replace('data:image/jgp', 'data:image/jpeg')
  104. this.imgBase64 = localData;
  105. this.uploadpic();
  106. }).catch(error => {
  107. mui.toast(error);
  108. })
  109. },
  110. //上传图片
  111. uploadpic() {
  112. uni.showLoading({
  113. title: "加载中",
  114. mask: true,
  115. })
  116. WxJsApi.uploadPic(this.imgBase64).then(response => {
  117. this.isLoading = false;
  118. this.listPic.push(response);
  119. }).catch(error => {
  120. this.isLoading = false;
  121. mui.toast(error);
  122. })
  123. },
  124. //表单检测
  125. checkFrom() {
  126. if (!this.subForm.content) {
  127. uni.showToast({
  128. title: "请输入内容"
  129. })
  130. return false;
  131. } else {
  132. return true;
  133. }
  134. },
  135. //提交
  136. submit() {
  137. let files = [];
  138. // 通过filter,筛选出上传进度为100的文件(因为某些上传失败的文件,进度值不为100,这个是可选的操作)
  139. files = this.$refs.uUpload.lists.filter(val => {
  140. return val.progress == 100;
  141. })
  142. // 如果您不需要进行太多的处理,直接如下即可
  143. // files = this.$refs.uUpload.lists;
  144. //(files);
  145. var imgUrl=files.map(item=>{
  146. return item.response.data;
  147. })
  148. //(imgUrl);
  149. this.subForm.imgUrl = imgUrl.join(',');
  150. if (this.checkFrom()) {
  151. this.subForm.picUrl = this.listPic.join(',');
  152. uni.showLoading({
  153. title: "加载中",
  154. mask: true,
  155. })
  156. API.feedback(this.subForm).then(response => {
  157. uni.hideLoading()
  158. uni.showModal({
  159. title: '提示',
  160. content: '提交成功',
  161. showCancel:false,
  162. success: res=>{
  163. if (res.confirm) {
  164. uni.navigateBack({
  165. })
  166. } else if (res.cancel) {
  167. //('用户点击取消');
  168. }
  169. }
  170. });
  171. }).catch(error => {
  172. uni.showToast({
  173. title: error
  174. })
  175. })
  176. }
  177. },
  178. }
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. @import "@/_theme.scss";
  183. .all{
  184. @include themeify{
  185. font-size: themed('font-size2');
  186. }
  187. }
  188. .upload{
  189. width: 100%;
  190. }
  191. .message-form{
  192. padding:0 10px;
  193. margin-bottom: 10px;
  194. background-color: #fff;
  195. }
  196. .login-btn {
  197. margin: 28px ;
  198. background-color:#00B962!important;
  199. border-color: #00B962!important;
  200. color:#fff!important;
  201. @include themeify{
  202. font-size: themed('font-size3');
  203. }
  204. }
  205. </style>