confirmDrawTypePopup.vue 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <popup v-model:show="showValue" round class="confirm-draw-type-popup" teleport="body">
  3. <div class="popup-title">请确认勾画类型</div>
  4. <div class="type-list">
  5. <div
  6. v-for="item in typeOptions"
  7. :key="item.code"
  8. class="type-item"
  9. :class="{ 'type-item--active': selectedType === item.code }"
  10. @click="handleTypeClick(item)"
  11. >
  12. {{ item.name }}
  13. </div>
  14. </div>
  15. <template v-if="selectedType !== 'DORMANCY'">
  16. <div class="popup-sub-title">请确认 具体勾画类别</div>
  17. <div class="category-list">
  18. <div
  19. v-for="(item, index) in currentCategoryOptions"
  20. :key="`${selectedType}-${index}`"
  21. class="category-item"
  22. :class="{ 'category-item--active': selectedCategory === index }"
  23. @click="selectedCategory = index"
  24. >
  25. {{ item.regionName || item.problemZoneTypeName }}
  26. </div>
  27. </div>
  28. </template>
  29. <textarea v-if="selectedType !== 'ABNORMAL'" v-model="remark" class="remark-input" maxlength="200"
  30. placeholder="添加备注"></textarea>
  31. <div class="confirm-btn" @click="handleConfirm">确认</div>
  32. </popup>
  33. <!-- 异常问题区:点击确认后弹出的照片上传进度弹窗 -->
  34. <popup v-model:show="showUploadProgressPopup" round class="upload-progress-popup" teleport="body">
  35. <div class="upload-progress-title">
  36. <span>{{ uploadPromptText }}</span>
  37. <el-progress class="upload-progress" :percentage="uploadPercentage" :stroke-width="10" :format="format" />
  38. </div>
  39. <div class="upload-box">
  40. <upload
  41. ref="abnormalUploadRef"
  42. :maxCount="10"
  43. :initImgArr="initImgArr"
  44. @handleUpload="handleUploadSuccess"
  45. />
  46. </div>
  47. <textarea v-model="remark" class="remark-input" maxlength="200" placeholder="添加备注"></textarea>
  48. <div class="confirm-btn" :class="{ 'confirm-btn-loading': confirmUploadLoading }" @click="handleConfirmUpload">
  49. {{ confirmUploadLoading ? '上传中...' : '确认上传' }}
  50. </div>
  51. </popup>
  52. </template>
  53. <script setup>
  54. import { Popup } from "vant";
  55. import { computed, ref } from "vue";
  56. import { ElMessage } from "element-plus";
  57. import upload from "@/components/upload.vue";
  58. const emit = defineEmits(["confirm"]);
  59. const showValue = ref(false);
  60. const typeOptions = ref([])
  61. const currentCategoryOptions = ref([]);
  62. const tempCategoryOptions = ref({});
  63. const openPopup = (payload) => {
  64. tempCategoryOptions.value = payload;
  65. remark.value = payload.remark || "";
  66. // remark.value = "";
  67. typeOptions.value = payload.regionInfo.problemZoneList;
  68. if(payload.activeRegionType === 'variety'){
  69. currentCategoryOptions.value = payload.regionInfo.regionList;
  70. }else{
  71. const arr = payload.regionInfo.problemZoneList.filter(item => item.code === payload.activeRegionType);
  72. currentCategoryOptions.value = arr[0].children;
  73. }
  74. selectedType.value = payload.activeRegionType;
  75. selectedCategory.value = payload.activeVarietyIndex;
  76. showValue.value = true;
  77. };
  78. const close = () => {
  79. showValue.value = false;
  80. };
  81. defineExpose({
  82. openPopup,
  83. close,
  84. });
  85. const selectedType = ref("");
  86. const selectedCategory = ref(null);
  87. const remark = ref("");
  88. const handleTypeClick = (item) => {
  89. selectedType.value = item.code;
  90. if(item.code === 'variety'){
  91. currentCategoryOptions.value = tempCategoryOptions.value.regionInfo.regionList;
  92. }else{
  93. currentCategoryOptions.value = item.children;
  94. }
  95. selectedCategory.value = 0;
  96. };
  97. const handleConfirm = () => {
  98. if (!selectedType.value || selectedCategory.value == null) {
  99. ElMessage.warning("请选择勾画类型和类别");
  100. return;
  101. }
  102. const payload = {
  103. type: selectedType.value,
  104. category: currentCategoryOptions.value[selectedCategory.value],
  105. remark: remark.value.trim(),
  106. };
  107. // 异常问题区:先打开上传弹窗,再发出 confirm
  108. if (selectedType.value === "ABNORMAL") {
  109. pendingConfirmPayload.value = payload;
  110. initImgArr.value = [];
  111. uploadData.value = [];
  112. totalUploadCount.value = 0;
  113. uploadedSuccessCount.value = 0;
  114. showUploadProgressPopup.value = true;
  115. close();
  116. return;
  117. }
  118. emit("confirm", payload);
  119. close();
  120. };
  121. // ---------------- 上传进度弹窗逻辑(只用于异常问题区) ----------------
  122. const showUploadProgressPopup = ref(false);
  123. const pendingConfirmPayload = ref(null);
  124. const uploadPromptText = computed(() => {
  125. const c = pendingConfirmPayload.value?.category;
  126. const name = c?.regionName || c?.problemZoneTypeName || c?.name || c?.title || c?.label || "";
  127. return name ? `请上传 ${name} 照片` : "请上传照片";
  128. });
  129. const totalUploadCount = ref(0);
  130. const uploadedSuccessCount = ref(0);
  131. const uploadPercentage = computed(() => {
  132. if (!totalUploadCount.value) return 0;
  133. return Math.round((uploadedSuccessCount.value / totalUploadCount.value) * 100);
  134. });
  135. const format = () => {
  136. if (!totalUploadCount.value) return "0/0";
  137. return `${uploadedSuccessCount.value}/${totalUploadCount.value}`;
  138. };
  139. const initImgArr = ref([]);
  140. const uploadData = ref([]);
  141. const confirmUploadLoading = ref(false);
  142. const abnormalUploadRef = ref(null);
  143. const handleUploadSuccess = (data) => {
  144. uploadData.value = data?.imgArr || [];
  145. const len = (data?.imgArr && data.imgArr.length) || 0;
  146. totalUploadCount.value = len;
  147. uploadedSuccessCount.value = len;
  148. };
  149. const handleConfirmUpload = async () => {
  150. if (confirmUploadLoading.value) return;
  151. if (!uploadData.value || uploadData.value.length === 0) {
  152. ElMessage.warning("请先上传照片");
  153. return;
  154. }
  155. confirmUploadLoading.value = true;
  156. try {
  157. const payload = pendingConfirmPayload.value;
  158. if (pendingConfirmPayload.value) {
  159. pendingConfirmPayload.value.remark = remark.value.trim();
  160. }
  161. const images = [...uploadData.value];
  162. abnormalUploadRef.value?.uploadReset();
  163. initImgArr.value = [];
  164. uploadData.value = [];
  165. totalUploadCount.value = 0;
  166. uploadedSuccessCount.value = 0;
  167. showUploadProgressPopup.value = false;
  168. pendingConfirmPayload.value = null;
  169. emit("confirm", {
  170. ...(payload || {}),
  171. images, // 预留字段,父组件当前逻辑不受影响
  172. });
  173. } finally {
  174. confirmUploadLoading.value = false;
  175. }
  176. };
  177. </script>
  178. <style scoped lang="scss">
  179. .confirm-draw-type-popup {
  180. width: 100%;
  181. padding: 16px 10px;
  182. .popup-title,
  183. .popup-sub-title {
  184. font-size: 16px;
  185. }
  186. .popup-sub-title {
  187. margin-top: 12px;
  188. }
  189. .type-list,
  190. .category-list {
  191. margin-top: 12px;
  192. display: flex;
  193. gap: 6px;
  194. flex-wrap: wrap;
  195. }
  196. .type-item,
  197. .category-item {
  198. padding: 7px 12px;
  199. border-radius: 2px;
  200. font-size: 12px;
  201. color: #575757;
  202. background: #F4F4F4;
  203. border: 1px solid transparent;
  204. box-sizing: border-box;
  205. }
  206. .type-item--active,
  207. .category-item--active {
  208. color: #2199f8;
  209. border-color: #2199f8;
  210. background: rgba(33, 153, 248, 0.1);
  211. }
  212. .remark-input {
  213. margin-top:20px;
  214. width: 100%;
  215. height: 72px;
  216. resize: none;
  217. border: 1px solid #e6e6e6;
  218. border-radius: 8px;
  219. padding: 10px 12px;
  220. box-sizing: border-box;
  221. font-size: 14px;
  222. color: #333;
  223. }
  224. .remark-input::placeholder {
  225. color: #c9c9c9;
  226. }
  227. .confirm-btn {
  228. margin-top: 20px;
  229. padding: 8px;
  230. text-align: center;
  231. color: #fff;
  232. background: #2199f8;
  233. border-radius: 25px;
  234. font-size: 16px;
  235. }
  236. }
  237. .upload-progress-popup {
  238. width: 100%;
  239. padding: 16px 10px;
  240. .upload-progress-title {
  241. display: flex;
  242. align-items: center;
  243. justify-content: space-between;
  244. margin-bottom: 12px;
  245. }
  246. .upload-box {
  247. margin: 10px 0 16px;
  248. }
  249. // 上传弹窗里的备注输入框样式:保持与主弹窗输入框一致
  250. .remark-input {
  251. margin-bottom: 20px;
  252. width: 100%;
  253. height: 72px;
  254. resize: none;
  255. border: 1px solid #e6e6e6;
  256. border-radius: 8px;
  257. padding: 10px 12px;
  258. box-sizing: border-box;
  259. font-size: 14px;
  260. color: #333;
  261. }
  262. .remark-input::placeholder {
  263. color: #c9c9c9;
  264. }
  265. .confirm-btn {
  266. width: 100%;
  267. text-align: center;
  268. color: #fff;
  269. background: #2199f8;
  270. border-radius: 25px;
  271. padding: 10px 0;
  272. font-size: 16px;
  273. }
  274. }
  275. </style>