index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <div class="entry-information-page">
  3. <custom-header name="录入信息" bgColor="#fff"></custom-header>
  4. <div class="entry-information-body">
  5. <service-information v-if="currentStep === 1 && isServiceEntry" @next="handleNext" />
  6. <ba-information v-else-if="currentStep === 1" @next="handleNext" />
  7. <select-category v-else-if="currentStep === 2" :multiple="isServiceEntry" @prev="handlePrev" @next="handleNext" />
  8. <select-equipment
  9. v-else-if="showEquipmentStep"
  10. :key="equipmentScope || 'farmer'"
  11. :is-service="isServiceEntry"
  12. :is-last-step="equipmentIsLastStep"
  13. :equipment-scope="equipmentScope"
  14. :total-steps="totalSteps"
  15. @prev="handlePrev"
  16. @next="handleNext"
  17. @confirm="handleConfirm"
  18. />
  19. <select-variety
  20. v-else-if="showVarietyStep"
  21. :multiple="isServiceEntry"
  22. @prev="handlePrev"
  23. @next="handleNext"
  24. />
  25. <manual-farming-service
  26. v-else-if="showManualStep"
  27. :has-field="hasFieldSelected"
  28. :has-fruit="hasFruitSelected"
  29. @prev="handlePrev"
  30. @next="handleNext"
  31. @confirm="handleConfirm"
  32. />
  33. </div>
  34. </div>
  35. </template>
  36. <script setup>
  37. import { computed, onActivated, onMounted, ref, watch } from "vue";
  38. import { useRoute, useRouter } from "vue-router";
  39. import customHeader from "@/components/customHeader.vue";
  40. import baInformation from "./components/baInformation.vue";
  41. import serviceInformation from "./components/serviceInformation.vue";
  42. import selectCategory from "./components/selectCategory.vue";
  43. import selectVariety from "./components/selectVariety.vue";
  44. import selectEquipment from "./components/selectEquipment.vue";
  45. import manualFarmingService from "./components/manualFarmingService.vue";
  46. const STEP_KEY = "ENTRY_INFORMATION_STEP";
  47. const INVITE_TYPE_KEY = "ENTRY_INVITE_TYPE";
  48. const CATEGORY_SESSION_KEY = "ENTRY_SELECTED_CATEGORY";
  49. const router = useRouter();
  50. const route = useRoute();
  51. function readStep() {
  52. const step = Number(sessionStorage.getItem(STEP_KEY));
  53. return step >= 1 && step <= 5 ? step : 1;
  54. }
  55. function readInviteType() {
  56. const fromQuery = route.query.inviteType;
  57. if (fromQuery === "service" || fromQuery === "farmer") {
  58. sessionStorage.setItem(INVITE_TYPE_KEY, fromQuery);
  59. return fromQuery;
  60. }
  61. return sessionStorage.getItem(INVITE_TYPE_KEY) || "farmer";
  62. }
  63. const currentStep = ref(readStep());
  64. const inviteType = ref(readInviteType());
  65. const isServiceEntry = computed(() => inviteType.value === "service");
  66. const hasFieldSelected = ref(false);
  67. const hasFruitSelected = ref(false);
  68. const isBothCrops = computed(() => hasFieldSelected.value && hasFruitSelected.value);
  69. const totalSteps = computed(() => {
  70. if (!isServiceEntry.value) return 4;
  71. return isBothCrops.value ? 6 : 4;
  72. });
  73. const maxStep = computed(() => {
  74. if (!isServiceEntry.value) return 4;
  75. return isBothCrops.value ? 5 : 4;
  76. });
  77. const showEquipmentStep = computed(() => {
  78. if (!isServiceEntry.value) return currentStep.value === 4;
  79. if (hasFieldSelected.value && currentStep.value === 3) return true;
  80. if (isBothCrops.value && currentStep.value === 5) return true;
  81. if (hasFruitSelected.value && !hasFieldSelected.value && currentStep.value === 4) return true;
  82. return false;
  83. });
  84. const equipmentScope = computed(() => {
  85. if (!isServiceEntry.value) return "";
  86. if (!hasFieldSelected.value) return "fruit";
  87. return currentStep.value === 5 ? "fruit" : "field";
  88. });
  89. const equipmentIsLastStep = computed(() => {
  90. if (!isServiceEntry.value) return true;
  91. return equipmentScope.value === "fruit";
  92. });
  93. const showVarietyStep = computed(() => !isServiceEntry.value && currentStep.value === 3);
  94. const showManualStep = computed(() => {
  95. if (!isServiceEntry.value) return false;
  96. if (hasFieldSelected.value) return currentStep.value === 4;
  97. return hasFruitSelected.value && currentStep.value === 3;
  98. });
  99. function refreshHasField() {
  100. try {
  101. const list = JSON.parse(sessionStorage.getItem(CATEGORY_SESSION_KEY) || "[]");
  102. const items = Array.isArray(list) ? list : [];
  103. hasFieldSelected.value = items.some(
  104. (item) => item?.firstCrop === "大田" || item?.majorKey === "field"
  105. );
  106. hasFruitSelected.value = items.some(
  107. (item) => item?.firstCrop === "果树" || item?.majorKey === "fruit"
  108. );
  109. } catch {
  110. hasFieldSelected.value = false;
  111. hasFruitSelected.value = false;
  112. }
  113. }
  114. function clampStep() {
  115. if (currentStep.value > maxStep.value) {
  116. currentStep.value = maxStep.value;
  117. }
  118. }
  119. function syncEntryState() {
  120. inviteType.value = readInviteType();
  121. currentStep.value = readStep();
  122. refreshHasField();
  123. clampStep();
  124. }
  125. onMounted(syncEntryState);
  126. onActivated(syncEntryState);
  127. watch(
  128. currentStep,
  129. (step) => {
  130. sessionStorage.setItem(STEP_KEY, String(step));
  131. },
  132. { immediate: true }
  133. );
  134. const handleNext = () => {
  135. refreshHasField();
  136. if (hasFieldSelected.value && currentStep.value === 3) {
  137. sessionStorage.removeItem("ENTRY_MANUAL_VIEW");
  138. }
  139. if (currentStep.value < maxStep.value) {
  140. currentStep.value += 1;
  141. }
  142. };
  143. const handlePrev = () => {
  144. if (currentStep.value > 1) {
  145. currentStep.value -= 1;
  146. }
  147. };
  148. const handleConfirm = () => {
  149. router.replace("/growth_report");
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. .entry-information-page {
  154. height: 100vh;
  155. background: linear-gradient(270deg, rgba(218, 195, 255, 0.59) 0%, #E6F2FF 0.01%, #8FC5FE 100%);
  156. display: flex;
  157. flex-direction: column;
  158. }
  159. .entry-information-body {
  160. height: 100%;
  161. display: flex;
  162. flex-direction: column;
  163. overflow: hidden;
  164. }
  165. </style>