Feedback.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <div class="autoBox box">
  3. <div class="crumbs">
  4. <el-breadcrumb separator="/">
  5. <el-breadcrumb-item :to="{ path: 'home' }">{{
  6. $t("common.Home")
  7. }}</el-breadcrumb-item>
  8. <el-breadcrumb-item>{{ $t("common.Feedback") }}</el-breadcrumb-item>
  9. </el-breadcrumb>
  10. </div>
  11. <div class="suggess">
  12. <el-form ref="form" :model="form" :rules="formrules">
  13. <!-- 建议类型-->
  14. <el-form-item
  15. :label="$t('common.SuggestedType') + ':'"
  16. prop="suggestion"
  17. >
  18. <el-radio-group v-model="form.suggestion" style="width: 100%">
  19. <el-radio-button
  20. v-for="(item, index) in suggestype"
  21. :key="index"
  22. :label="item.value"
  23. border
  24. >{{ item.label }}</el-radio-button
  25. >
  26. </el-radio-group>
  27. </el-form-item>
  28. <!-- 反馈内容-->
  29. <el-form-item
  30. :label="$t('common.ContentFeedback') + ':'"
  31. prop="report"
  32. style="margin-top: 45px"
  33. >
  34. <el-input
  35. type="textarea"
  36. v-model="form.report"
  37. :autosize="{ minRows: 5, maxRows: 10 }"
  38. :placeholder="$t('common.PleaseInputFeedback')"
  39. maxlength="300"
  40. minlength="15"
  41. show-word-limit
  42. class="feedtext"
  43. ></el-input>
  44. </el-form-item>
  45. <!-- 上传图片-->
  46. <el-form-item style="margin-top: 50px">
  47. <div class="uploadText">{{ $t("common.ToUploadPictures") }}:</div>
  48. <div style="display: inline-block">
  49. <el-upload
  50. action="/api/file/upload/img?module=feedback"
  51. :headers="myHeaders"
  52. list-type="picture-card"
  53. :on-success="handleAvatarSuccess"
  54. :before-upload="beforeAvatarUpload"
  55. :limit="5"
  56. ref="upImage"
  57. >
  58. <i class="el-icon-plus"></i>
  59. </el-upload>
  60. </div>
  61. <span class="maxupload">{{ $t("common.UploadUupMaxPhotos") }}</span>
  62. </el-form-item>
  63. <!-- 联系方式-->
  64. <el-form-item
  65. :label="$t('common.ContactWay') + ':'"
  66. prop="phone"
  67. style="margin-top: 50px"
  68. >
  69. <el-input
  70. type="text"
  71. v-model="form.phone"
  72. style="width: 240px"
  73. ></el-input>
  74. </el-form-item>
  75. <!-- 提交反馈-->
  76. <el-form-item>
  77. <el-button
  78. type="primary"
  79. @click="onSubmit"
  80. style="margin-left: 155px"
  81. >{{ $t("common.SubmitFeedback") }}</el-button
  82. >
  83. </el-form-item>
  84. </el-form>
  85. </div>
  86. </div>
  87. </template>
  88. <script>
  89. import Base from "@/views/base/Base";
  90. import { getToken, resetToken } from "@/utils/auth";
  91. import { saveOrUpdate } from "@/api/feedback";
  92. import { getDicts } from "@/api/dict";
  93. import { addGrowth } from "@/utils/toCompleteTask";
  94. import { getUserPointPage } from "@/api/user";
  95. export default {
  96. name: "Feedback",
  97. extends: Base,
  98. data() {
  99. return {
  100. suggestype: [],
  101. dialogImageUrl: "",
  102. dialogVisible: false,
  103. form: {
  104. suggestion: "",
  105. report: "",
  106. picture: [],
  107. phone: "",
  108. },
  109. feedback: {
  110. suggestion: "",
  111. report: "",
  112. picture: [],
  113. phone: "",
  114. account_name: "",
  115. user_id: "",
  116. },
  117. myHeaders: { Authorization: "Bearer " + getToken() },
  118. user: {
  119. umsUser: {},
  120. },
  121. pointStatus: null,
  122. };
  123. },
  124. mounted() {
  125. this.getType();
  126. this.getUser();
  127. this.clearForm();
  128. this.initData();
  129. },
  130. computed: {
  131. formrules() {
  132. return {
  133. suggestion: [
  134. {
  135. required: true,
  136. message:
  137. this.$i18n.locale == "zh"
  138. ? "请选择建议类型"
  139. : "Please select the type of suggestion",
  140. trigger: "change",
  141. },
  142. ],
  143. report: [
  144. {
  145. required: true,
  146. message:
  147. this.$i18n.locale == "zh"
  148. ? "请输入反馈内容"
  149. : "Please enter feedback",
  150. trigger: "change",
  151. },
  152. {
  153. min: 15,
  154. message:
  155. this.$i18n.locale == "zh"
  156. ? "不得少于15字"
  157. : "No less than 15 words",
  158. trigger: "change",
  159. },
  160. ],
  161. phone: [
  162. {
  163. required: true,
  164. message:
  165. this.$i18n.locale == "zh"
  166. ? "请输入联系方式"
  167. : "Please enter your mobile phone number",
  168. trigger: "change",
  169. },
  170. {
  171. pattern: /^([0-9]*)$/,
  172. message:
  173. this.$i18n.locale == "zh"
  174. ? "请输入合法的手机号"
  175. : "Please enter a valid mobile phone number",
  176. },
  177. ],
  178. };
  179. },
  180. },
  181. watch: {
  182. "$i18n.locale"() {
  183. this.getType();
  184. this.getUser();
  185. },
  186. },
  187. methods: {
  188. initData() {
  189. getUserPointPage().then((res) => {
  190. this.pointStatus = res.data.umsUserPoints[0].pointStatus;
  191. });
  192. },
  193. //图片上传成功
  194. handleAvatarSuccess(res, file) {
  195. // console.log(this.form.picture)
  196. this.form.picture.push(res.data);
  197. // this.photoLength = this.form.picture.length;
  198. },
  199. //图片格式验证
  200. beforeAvatarUpload(file) {
  201. let photoStr = [];
  202. let photorules = ["jpg", "jpeg", "png", "webp"];
  203. let isJPG = false;
  204. photoStr = file.name.split(".")[1];
  205. if (photorules.indexOf(photoStr) == -1) {
  206. this.$message.error(this.$t("common.CorrectPictureFormat"));
  207. } else {
  208. isJPG = true;
  209. }
  210. return isJPG;
  211. },
  212. //清空对象集合
  213. clearForm() {
  214. this.$refs["form"].resetFields();
  215. this.$refs["upImage"].clearFiles();
  216. this.form = {
  217. suggestion: "",
  218. report: "",
  219. picture: [],
  220. phone: "",
  221. };
  222. },
  223. //获取建议类型
  224. getType() {
  225. if (this.$i18n.locale == "zh") {
  226. getDicts("SUGGESTION_DICT").then((res) => {
  227. this.suggestype = res.data[0];
  228. });
  229. } else if (this.$i18n.locale == "en") {
  230. getDicts("SUGGESTION_DICT_EN").then((res) => {
  231. this.suggestype = res.data[0];
  232. });
  233. }
  234. },
  235. //表单提交
  236. onSubmit(form) {
  237. this.$refs["form"].validate((valid) => {
  238. if (valid) {
  239. this.feedback.suggestion = this.form.suggestion;
  240. this.feedback.report = this.form.report;
  241. this.feedback.picture = this.form.picture;
  242. this.feedback.phone = this.form.phone;
  243. this.submitHandler((token) => {
  244. saveOrUpdate(JSON.stringify(this.feedback), token)
  245. .then((res) => {
  246. if (
  247. this.user.umsUser.userUsertypeDict !== "2" &&
  248. this.pointStatus == "y"
  249. ) {
  250. addGrowth("platform_problem_feedback");
  251. }
  252. this.$message({
  253. message:
  254. this.$i18n.locale.toUpperCase() == "ZH"
  255. ? "提交成功"
  256. : "Submitted successfully",
  257. type: "success",
  258. });
  259. this.resetToken();
  260. this.clearForm();
  261. })
  262. .catch((error) => {
  263. this.$notify.error({
  264. title: "common.Error",
  265. message: error.msg,
  266. });
  267. this.resetToken();
  268. this.clearForm();
  269. });
  270. });
  271. } else {
  272. console.log("error submit!!");
  273. return false;
  274. }
  275. });
  276. },
  277. //获取用户信息
  278. getUser() {
  279. let user = JSON.parse(window.localStorage.getItem("user"));
  280. this.feedback.account_name = user.username;
  281. this.feedback.user_id = user.userId;
  282. },
  283. //跳转链接
  284. toView(router, json) {
  285. this.$router.push({
  286. name: router,
  287. query: { key: json },
  288. });
  289. },
  290. },
  291. };
  292. </script>
  293. <style scoped>
  294. body {
  295. margin: 0;
  296. }
  297. .box {
  298. margin-top: 10px;
  299. background: #fff;
  300. /* height: 500px; */
  301. padding: 20px 0;
  302. }
  303. .crumbs {
  304. margin-left: 20px;
  305. }
  306. .suggess {
  307. padding: 10px 30px;
  308. margin-top: 20px;
  309. }
  310. .feedtext {
  311. width: 555px;
  312. display: block;
  313. }
  314. .el-form-item .el-form-item__label {
  315. font-size: 18px;
  316. color: black;
  317. font-weight: 600;
  318. }
  319. .el-radio-button {
  320. margin: 20px 40px 0 0;
  321. border: 1px solid rgba(204, 204, 204, 0.36);
  322. }
  323. .el-textarea__inner {
  324. height: 250px;
  325. }
  326. >>> .el-upload-list__item-actions {
  327. display: none;
  328. }
  329. .avatar-uploader .el-upload {
  330. border: 1px solid #d9d9d9;
  331. border-radius: 6px;
  332. cursor: pointer;
  333. position: relative;
  334. overflow: hidden;
  335. }
  336. .avatar-uploader .el-upload:hover {
  337. border-color: #409eff;
  338. }
  339. .uploadText {
  340. display: inline-block;
  341. }
  342. .maxupload {
  343. position: absolute;
  344. bottom: 0;
  345. margin-left: 10px;
  346. }
  347. .avatar-uploader-icon {
  348. font-size: 28px;
  349. color: #8c939d;
  350. width: 178px;
  351. height: 178px;
  352. line-height: 178px;
  353. text-align: center;
  354. }
  355. .avatar {
  356. width: 178px;
  357. height: 178px;
  358. display: inline-block;
  359. }
  360. </style>