feedbackPopup.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <u-popup mode="center" :show="show" @close="handleCancel" :closeOnClickOverlay="false">
  3. <view class="popup-container">
  4. <u-form
  5. ref="formRef"
  6. :model="formData"
  7. :rules="rules"
  8. labelPosition="top"
  9. labelWidth="100%"
  10. error-type="toast"
  11. >
  12. <!-- 反馈信息 -->
  13. <u-form-item label="反馈图书信息" prop="feedbackContent" :borderBottom="true">
  14. <u-input
  15. v-model="formData.feedbackContent"
  16. type="textarea"
  17. placeholder="请输入反馈信息"
  18. height="100"
  19. ></u-input>
  20. </u-form-item>
  21. <!-- 图片上传 -->
  22. <u-form-item label="上传照片" prop="imgUrl" :borderBottom="false">
  23. <cy-upload v-model:filename="formData.imgUrl" multiple :maxCount="4" :loading="loading">
  24. <view class="upload-slot">
  25. <u-icon name="plus" size="30"></u-icon>
  26. <text class="upload-text">上传照片</text>
  27. </view>
  28. </cy-upload>
  29. </u-form-item>
  30. </u-form>
  31. <!-- 按钮组 -->
  32. <view class="button-group">
  33. <u-button type="info" text="取消" :plain="true" @click="handleCancel" :disabled="submitting"></u-button>
  34. <u-button type="primary" text="确认" @click="handleConfirm" :loading="submitting" :disabled="loading"></u-button>
  35. </view>
  36. </view>
  37. </u-popup>
  38. </template>
  39. <script setup>
  40. import cyUpload from "@/components/cy-upload/index.vue";
  41. import { ref, reactive } from "vue";
  42. const show = ref(false);
  43. const emit = defineEmits(["submit"]);
  44. // 表单引用
  45. const formRef = ref(null);
  46. // 提交状态
  47. const submitting = ref(false);
  48. // 上传状态
  49. const loading = ref(false);
  50. // 表单数据
  51. const formData = reactive({
  52. feedbackContent: "",
  53. imgUrl: [],
  54. isbn: "",
  55. });
  56. // 表单验证规则
  57. const rules = {
  58. feedbackContent: [
  59. {
  60. required: true,
  61. message: "请输入反馈信息",
  62. trigger: ["blur", "change"],
  63. },
  64. ],
  65. };
  66. //打开
  67. function open(data) {
  68. show.value = true;
  69. formData.isbn = data.isbn;
  70. }
  71. // 取消操作
  72. function handleCancel() {
  73. resetForm();
  74. show.value = false;
  75. }
  76. // 确认操作
  77. async function handleConfirm() {
  78. // 表单验证
  79. formRef.value?.validate().then((res) => {
  80. submitting.value = true;
  81. let data = JSON.parse(JSON.stringify(formData));
  82. data.imgUrl = data.imgUrl.join(",");
  83. uni.$u.http
  84. .post("/app/feedback/add", data)
  85. .then((res) => {
  86. if (res.code == 200) {
  87. // 提交成功
  88. uni.showToast({
  89. title: "反馈已提交",
  90. icon: "success",
  91. });
  92. // 触发提交事件
  93. emit("submit", formData);
  94. show.value = false;
  95. } else {
  96. uni.$u.toast(res.msg);
  97. }
  98. })
  99. .finally(() => {
  100. submitting.value = false;
  101. });
  102. });
  103. }
  104. // 重置表单
  105. function resetForm() {
  106. formData.feedbackContent = "";
  107. formData.imgUrl = "";
  108. formRef.value?.resetFields();
  109. }
  110. defineExpose({
  111. open,
  112. });
  113. </script>
  114. <style lang="scss" scoped>
  115. :deep(.u-popup__content) {
  116. border-radius: 12px;
  117. }
  118. .popup-container {
  119. width: 640rpx;
  120. background-color: #ffffff;
  121. border-radius: 12rpx;
  122. padding: 30rpx;
  123. :deep(.u-form) {
  124. .u-form-item {
  125. &__body {
  126. padding: 20rpx 0;
  127. }
  128. &__body__left__content {
  129. padding-bottom: 8rpx;
  130. }
  131. }
  132. }
  133. .upload-slot {
  134. width: 160rpx;
  135. height: 160rpx;
  136. border: 2rpx dashed #dcdfe6;
  137. border-radius: 8rpx;
  138. display: flex;
  139. flex-direction: column;
  140. align-items: center;
  141. justify-content: center;
  142. .upload-text {
  143. font-size: 24rpx;
  144. color: #909399;
  145. margin-top: 10rpx;
  146. }
  147. }
  148. .button-group {
  149. display: flex;
  150. justify-content: space-between;
  151. margin-top: 40rpx;
  152. padding: 0 20rpx;
  153. :deep(.u-button) {
  154. width: 45%;
  155. border-radius: 8rpx;
  156. }
  157. }
  158. }
  159. </style>