myFeedback.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. <template>
  2. <view class="feedback">
  3. <!-- 标题栏 -->
  4. <uni-nav-bar status-bar=true fixed=true left-icon="arrowleft" background-color="#3387ff" color="#ffffff"
  5. @clickLeft="navigateBack" :back-text-style="{color:'#fff'}" :back-text="i18n('Back')">
  6. <text slot="default" style="text-align: center; flex: 1; font-size: 18px;">{{i18n('Feedback')}}</text>
  7. <button slot="right" @click="submit" size="mini" class="sunmit-btn" type="submit"
  8. hover-class="button-hover">{{i18n('SubmitAndDownload')}}</button>
  9. </uni-nav-bar>
  10. <!-- <u-navbar back-icon-color="#fff" :back-text="i18n('common.Back')" :is-back="true" :background="{background:'#1777FE'}"
  11. :back-text-style="{color:'#fff'}" :border-bottom="true" title-color="#fff" :title="title">
  12. </u-navbar>
  13. -->
  14. <view class="uni-form">
  15. <u-form :model="form" ref="form" label-position="top">
  16. <!--建议类型-->
  17. <u-form-item required :label="i18n('SuggestedType')" prop="suggestion">
  18. <u-input v-model="form.suggestion" type="select" :border="border" @click="show = true"
  19. :placeholder="i18n('Typeofsuggestion')" />
  20. <u-select v-model="show" :confirm-text="i18n('submit')" :cancel-text="i18n('cancel')"
  21. mode=single-column :list="suggestype" @confirm="confirm"></u-select>
  22. </u-form-item>
  23. <!--内容反馈-->
  24. <u-form-item required :label="i18n('ContentFeedback')" prop="report">
  25. <u-input v-model="form.report" required type="textarea" :border="border" :maxlength="300"
  26. :autoHeight="true" :placeholder="i18n('PleaseInputFeedback')" />
  27. </u-form-item>
  28. <!-- 上传图片-->
  29. <u-form-item label-position="top" :label="i18n('ToUploadPictures')" prop="photo" label-width="150">
  30. <myUpload width="160" :header="myHeaders" :action="uploadUrl" :source-type="sourceType"
  31. upload-text=" " height="160" max-count="5" ref="upImage" :before-upload="beforeUpload">
  32. <!-- <myUpload width="160" :header="myHeaders" :action="'https://m.geidcp.com/api/file/pub/' + '/img?module=feedback'" upload-text=" " height="160" max-count="5" ref="upImage" :before-upload="beforeUpload">-->
  33. </myUpload>
  34. </u-form-item>
  35. <u-form-item>
  36. <view>{{i18n('UploadUupMaxPhotos')}}</view>
  37. </u-form-item>
  38. <!--联系方式-->
  39. <u-form-item required :label="i18n('resourceContact')" prop="phone">
  40. <u-input v-model="form.phone" required type="text" :border="border"
  41. :placeholder="i18n('resourcePleaseEnterYourContactInformation')" />
  42. </u-form-item>
  43. </u-form>
  44. </view>
  45. <!-- <view>
  46. <button class="subBtn" type="submit" plain="true" @click="submit">{{$t('common.submit')}}</button>
  47. </view> -->
  48. </view>
  49. </template>
  50. <script>
  51. import UNavbar from '@/components/uni-nav-bar/uni-nav-bar.vue'
  52. import myUpload from './myUpload.vue'
  53. import {
  54. getToken
  55. } from '@/utils/auth'
  56. import {
  57. saveOrUpdate
  58. } from '@/api/feedback';
  59. import UUpload from "./myUpload";
  60. // import uniIcons from "uni-icons/fensauni-icons.vue";
  61. export default {
  62. name: 'Feedback',
  63. components: {
  64. UNavbar,
  65. myUpload
  66. },
  67. data() {
  68. return {
  69. show: false,
  70. photo: [],
  71. title: '',
  72. // action: 'https://localhost:8081/api/file/upload/img?module=feedback',
  73. // uploadUrl: 'https://m.geidcp.com/api/file/upload/img?module=feedback',
  74. suggestype: [],
  75. suggestionLable: '',
  76. value: '',
  77. type: 'select',
  78. form: {
  79. suggestion: '',
  80. report: '',
  81. picture: [],
  82. phone: '',
  83. },
  84. feedback: {
  85. suggestion: '',
  86. report: '',
  87. picture: [],
  88. phone: '',
  89. account_name: '',
  90. user_id: '',
  91. },
  92. border: true,
  93. filesArr: [],
  94. myHeaders: {
  95. Authorization: ('Bearer ' + getToken())
  96. },
  97. Authtoken: '',
  98. Storage_data: '',
  99. rules: {
  100. suggestion: [{
  101. required: true,
  102. message: this.i18n('Typeofsuggestion'),
  103. trigger: ['change', 'blur'],
  104. }, ],
  105. report: [{
  106. required: true,
  107. message: this.i18n('PleaseInputFeedback'),
  108. },
  109. {
  110. min: 15,
  111. message: this.i18n('PleaseInputFeedback'),
  112. },
  113. ],
  114. phone: [{
  115. required: true,
  116. message: this.i18n('resourcePleaseEnterYourContactInformation')
  117. },
  118. {
  119. pattern: /^[0-9]*$/g,
  120. message: this.i18n('Entercorrectinformation')
  121. },
  122. ]
  123. },
  124. sourceType: ['album'],
  125. }
  126. },
  127. onLoad() {
  128. this.title = this.$i18n.locale == 'zh' ? '用户反馈' : 'User feedback'
  129. this.backtext = this.$i18n.locale == 'zh' ? '返回' : 'Back';
  130. this.getDict()
  131. this.getToken()
  132. },
  133. onReady() {
  134. this.$refs.form.setRules(this.rules);
  135. },
  136. methods: {
  137. async getDict() {
  138. const res = await this.$myRequest({
  139. data: {
  140. type: this.$i18n.locale == "zh" ? 'SUGGESTION_DICT' : 'SUGGESTION_DICT_EN',
  141. },
  142. url: '/sys/sysDicts'
  143. })
  144. this.suggestype = res.data[0]
  145. },
  146. //建议类型选择
  147. confirm(e) {
  148. console.log(e)
  149. this.form.suggestion = e[0].label
  150. this.suggestionLable = e[0].value
  151. },
  152. // 图片上传返回事件
  153. beforeUpload(index, list) {
  154. let one = list[index];
  155. console.log('index, list===============', index, list)
  156. setTimeout(() => {
  157. let tempPhoto = one.response.data
  158. this.form.picture.push(tempPhoto);
  159. }, 1000)
  160. },
  161. async getToken() {
  162. this.Storage_data = JSON.parse(uni.getStorageSync('user'));
  163. const token = await this.$myRequest({
  164. url: '/sys/token',
  165. data: {}
  166. });
  167. this.Authtoken = token;
  168. this.feedback.account_name = this.Storage_data.username;
  169. this.feedback.user_id = this.Storage_data.id;
  170. },
  171. // 表单提交
  172. submit() {
  173. this.$refs.form.validate(valid => {
  174. if (valid) {
  175. this.saveUpdata()
  176. // this.clearForm()
  177. } else {
  178. console.log('验证失败');
  179. }
  180. });
  181. },
  182. //提交方法
  183. async saveUpdata() {
  184. const that = this;
  185. this.feedback.suggestion = this.suggestionLable;
  186. this.feedback.report = this.form.report;
  187. this.feedback.picture = this.form.picture;
  188. this.feedback.phone = this.form.phone;
  189. const res = await this.$myRequest({
  190. url: '/op/feedbacks',
  191. method: 'post',
  192. header: {
  193. token: that.Authtoken.data,
  194. },
  195. data: {
  196. feedback: JSON.stringify(this.feedback),
  197. }
  198. })
  199. if (res.msg == '保存成功') {
  200. if (this.$i18n.locale == 'zh') {
  201. uni.showToast({
  202. title: '保存成功',
  203. icon: 'none'
  204. })
  205. } else {
  206. uni.showToast({
  207. title: 'Feedback success',
  208. icon: 'none'
  209. })
  210. }
  211. this.clearForm()
  212. } else {
  213. if (this.$i18n.locale == 'zh') {
  214. uni.showToast({
  215. title: '保存失败',
  216. icon: 'none'
  217. })
  218. } else {
  219. uni.showToast({
  220. title: 'Feedback faild',
  221. icon: 'none'
  222. })
  223. }
  224. this.clearForm()
  225. }
  226. },
  227. //清空对象集合
  228. clearForm() {
  229. this.form = [];
  230. },
  231. navigateBack() {
  232. uni.navigateBack()
  233. },
  234. i18n(data) {
  235. return this.$t('common.' + data);
  236. },
  237. }
  238. }
  239. </script>
  240. <style scoped>
  241. .subBtn {
  242. width: 60%;
  243. height: 64upx;
  244. border-radius: 40upx;
  245. line-height: 64upx;
  246. /* position: absolute;
  247. right: 15upx;
  248. top: 5px; */
  249. margin-top: 30upx;
  250. color: #ffffff;
  251. background-color: #146AE4;
  252. z-index: 999;
  253. border: none;
  254. }
  255. .uni-form {
  256. padding: 20upx 25upx;
  257. }
  258. /deep/ u-border-bottom {
  259. border: none;
  260. }
  261. .sunmit-btn {
  262. width: 57px;
  263. height: 30px;
  264. color: #FFFFFF;
  265. background-color: #2d79e5;
  266. padding: 0 10px;
  267. border-radius: 18px;
  268. }
  269. .button-hover[type=submit] {
  270. opacity: .75;
  271. transform: scale(0.95, 0.95);
  272. }
  273. </style>