feedback.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <view class="feedback-page">
  3. <!-- 顶部banner -->
  4. <view class="banner">
  5. <image src="https://shuhi.oss-cn-qingdao.aliyuncs.com/mini/feedback.png" mode="aspectFill" class="banner-img"></image>
  6. <text class="history-btn" @click="goToHistory">我的历史反馈</text>
  7. </view>
  8. <!-- 反馈类型区域 -->
  9. <view class="form-item type-section flex-a flex-j-b">
  10. <view class="label" style="margin-bottom: 0">
  11. 反馈类型
  12. <text class="required">*</text>
  13. </view>
  14. <view class="picker-box" @click="showTypePicker">
  15. <text :class="['picker-text', !model.type && 'placeholder']">
  16. {{ model.type || "请选择反馈类型" }}
  17. </text>
  18. <u-icon name="arrow-right" color="#999" size="32" top="2rpx"></u-icon>
  19. </view>
  20. </view>
  21. <!-- 反馈描述区域 -->
  22. <view class="form-item content-section">
  23. <view class="label">
  24. 反馈描述
  25. <text class="required">*</text>
  26. </view>
  27. <view class="textarea-box">
  28. <u-input
  29. type="textarea"
  30. v-model="model.content"
  31. placeholder="请输入不少于10个字的描述"
  32. :height="200"
  33. ></u-input>
  34. </view>
  35. </view>
  36. <!-- 图片上传区域 -->
  37. <view class="form-item upload-section">
  38. <view class="label">上传图片(最多五张):</view>
  39. <u-upload
  40. class="upload-image"
  41. :fileList="fileList"
  42. @on-choose-complete="afterRead"
  43. @delete="deletePic"
  44. :maxCount="5"
  45. :auto-upload="false"
  46. :previewFullImage="true"
  47. uploadText="点击上传"
  48. ></u-upload>
  49. </view>
  50. <!-- 提交按钮 -->
  51. <view class="bottom-fixed-con">
  52. <button class="common-btn" @click="submit">提交</button>
  53. </view>
  54. <!-- 反馈类型选择器 -->
  55. <u-picker
  56. v-model="showPicker"
  57. :range="feedbackTypes"
  58. @confirm="onTypeConfirm"
  59. @cancel="showPicker = false"
  60. mode="selector"
  61. ></u-picker>
  62. </view>
  63. </template>
  64. <script>
  65. import ENV_CONFIG from "@/.env.js";
  66. // api前缀
  67. const env = ENV_CONFIG[process.env.ENV_TYPE || "dev"];
  68. export default {
  69. data() {
  70. return {
  71. showPicker: false,
  72. feedbackTypes: [],
  73. model: {
  74. type: "",
  75. content: "",
  76. images: [],
  77. },
  78. fileList: [],
  79. uploadSuccessList: [],
  80. rules: {
  81. type: [
  82. {
  83. required: true,
  84. message: "请选择反馈类型",
  85. },
  86. ],
  87. content: [
  88. {
  89. required: true,
  90. message: "请输入反馈描述",
  91. },
  92. {
  93. min: 10,
  94. message: "描述不能少于10个字",
  95. },
  96. ],
  97. },
  98. };
  99. },
  100. methods: {
  101. // 获取反馈类型选项
  102. getFeedbackTypes() {
  103. uni.$u.http
  104. .get("/token/common/getDictOptions?type=feedback_type")
  105. .then((res) => {
  106. if (res.code === 200) {
  107. this.feedbackTypes = res.data.map((item) => item.dictLabel);
  108. } else {
  109. uni.$u.toast("获取反馈类型失败");
  110. }
  111. })
  112. .catch(() => {
  113. uni.$u.toast("获取反馈类型失败");
  114. });
  115. },
  116. // 显示类型选择器
  117. showTypePicker() {
  118. this.showPicker = true;
  119. },
  120. // 类型选择确认
  121. onTypeConfirm(e) {
  122. let index = e[0];
  123. this.model.type = this.feedbackTypes[index];
  124. this.showPicker = false;
  125. },
  126. // 上传图片
  127. afterRead(lists) {
  128. // 先检查token是否存在
  129. const token = uni.getStorageSync("token");
  130. const uploadTasks = lists.map((item) => {
  131. return new Promise((resolve, reject) => {
  132. uni.uploadFile({
  133. url: env.apiUrl + "/api/token/suggestion/imgUpload",
  134. filePath: item.url,
  135. name: "file",
  136. header: {
  137. Authorization: "Bearer " + token,
  138. },
  139. success: (res) => {
  140. const result = JSON.parse(res.data);
  141. if (result.code === 200 && result.data) {
  142. resolve(result.data);
  143. } else {
  144. uni.$u.toast(result.msg || "上传失败");
  145. reject(new Error(result.msg || "上传失败"));
  146. }
  147. },
  148. fail: (err) => {
  149. uni.$u.toast("上传失败");
  150. reject(err);
  151. },
  152. });
  153. });
  154. });
  155. Promise.all(uploadTasks)
  156. .then((results) => {
  157. this.uploadSuccessList = results.flat();
  158. this.fileList = lists;
  159. this.model.images = this.uploadSuccessList;
  160. })
  161. .catch((err) => {
  162. console.error("Upload failed:", err);
  163. });
  164. },
  165. // 删除图片
  166. deletePic(event) {
  167. this.fileList.splice(event.index, 1);
  168. this.model.images.splice(event.index, 1);
  169. this.uploadSuccessList.splice(event.index, 1);
  170. },
  171. // 去历史记录
  172. goToHistory() {
  173. uni.navigateTo({
  174. url: "/pages/feedback-history/index",
  175. });
  176. },
  177. // 提交表单
  178. submit() {
  179. if (!this.model.type) {
  180. return uni.$u.toast("请选择反馈类型");
  181. }
  182. if (this.model.content.length < 10) {
  183. return uni.$u.toast("反馈描述不能少于10个字");
  184. }
  185. // 提交表单
  186. uni.showLoading({
  187. title: "提交中",
  188. });
  189. // 构建提交参数
  190. const params = {
  191. reason: this.model.type,
  192. description: this.model.content,
  193. images: this.model.images,
  194. };
  195. // 调用提交接口
  196. uni.$u.http
  197. .post("/token/suggestion/submit", params)
  198. .then((res) => {
  199. if (res.code === 200) {
  200. uni.$u.toast("提交成功");
  201. setTimeout(() => {
  202. uni.navigateBack();
  203. }, 1500);
  204. } else {
  205. uni.$u.toast(res.msg || "提交失败");
  206. }
  207. })
  208. .catch(() => {
  209. uni.$u.toast("提交失败");
  210. })
  211. .finally(() => {
  212. uni.hideLoading();
  213. });
  214. },
  215. },
  216. onLoad() {
  217. this.getFeedbackTypes();
  218. },
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. .feedback-page {
  223. min-height: 100vh;
  224. background: #f5f5f5;
  225. // banner样式保持不变
  226. .banner {
  227. position: relative;
  228. height: 230rpx;
  229. overflow: hidden;
  230. .banner-img {
  231. width: 100%;
  232. height: 100%;
  233. }
  234. .history-btn {
  235. position: absolute;
  236. right: 30rpx;
  237. top: 30rpx;
  238. background: rgba(56, 193, 72, 0.9);
  239. color: #ffffff;
  240. padding: 10rpx 20rpx;
  241. border-radius: 10rpx;
  242. font-size: 24rpx;
  243. }
  244. }
  245. // 表单项通用样式
  246. .form-item {
  247. background: #ffffff;
  248. margin: 20rpx;
  249. padding: 30rpx;
  250. border-radius: 12rpx;
  251. .label {
  252. font-size: 28rpx;
  253. color: #333;
  254. margin-bottom: 20rpx;
  255. .required {
  256. color: #ff5b5b;
  257. margin-left: 4rpx;
  258. }
  259. }
  260. }
  261. // 反馈类型区域
  262. .type-section {
  263. position: relative;
  264. z-index: 1;
  265. .picker-box {
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. .picker-text {
  270. font-size: 28rpx;
  271. color: #333;
  272. &.placeholder {
  273. color: #999;
  274. }
  275. }
  276. }
  277. }
  278. // 反馈描述区域
  279. .content-section {
  280. .textarea-box {
  281. background: #f8f8f8;
  282. border-radius: 8rpx;
  283. padding: 20rpx;
  284. }
  285. }
  286. .upload-image {
  287. .u-list-item {
  288. background: #ffffff !important;
  289. }
  290. }
  291. }
  292. </style>