index.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <div class="p-fill-order">
  3. <h3 class="ptc-title">Fill Order</h3>
  4. <component :is="Component" @go="go" />
  5. </div>
  6. </template>
  7. <script lang="ts">
  8. import { defineComponent, onUnmounted } from 'vue'
  9. import { initProducts } from './store'
  10. export default defineComponent({
  11. name: 'FillOrder',
  12. beforeRouteEnter(to, from, next) {
  13. initProducts().then(next)
  14. },
  15. })
  16. </script>
  17. <script setup lang="ts">
  18. import { ref, computed, watch } from 'vue'
  19. import { useRoute } from 'vue-router'
  20. import StepOne from './StepOne.vue'
  21. import StepTwo from './StepTwo.vue'
  22. import StepThree from './StepThree.vue'
  23. import { state, resetState, getModelList } from './store'
  24. import { state as rootState, getCurrentOrder } from '@/store'
  25. const step = ref(0)
  26. const Component = computed(() => [StepOne, StepTwo, StepThree][step.value])
  27. const { from, invitee, renewal } = useRoute().query as any
  28. state.form.from = from || ''
  29. state.form.invitor = invitee || ''
  30. if (renewal) {
  31. state.form.renewal = +renewal
  32. getCurrentOrder(renewal).then(() => {
  33. const order = rootState.currentOrder
  34. if (state.productList.some(item => item.id === +order.product_id)) {
  35. state.form.product_id = +order.product_id
  36. }
  37. state.form.subscribe_type = +order.subscribe_type === 1 ? 'month' : 'year'
  38. state.form.brand_id = +order.brand_id
  39. state.form.phone_id = +order.phone_id
  40. getModelList()
  41. })
  42. }
  43. // 此处不直接传入resetState是有必要的,否则resetState在整个应用生命周期只会执行一次
  44. onUnmounted(() => resetState())
  45. watch(step, () => window.scrollTo(0, 0))
  46. function go(delta = 1) {
  47. step.value += delta
  48. }
  49. </script>
  50. <style lang="scss">
  51. .p-fill-order {
  52. background: #f7f7f7;
  53. .detail {
  54. display: flex;
  55. align-items: flex-end;
  56. .s1,
  57. .s2 {
  58. font-size: 40px;
  59. font-weight: bold;
  60. color: #1a1a1a;
  61. }
  62. .s2 {
  63. margin: 0 20px 0 48px;
  64. }
  65. .s3 {
  66. font-size: 28px;
  67. color: #1a1a1a;
  68. }
  69. .s4 {
  70. margin-left: auto;
  71. font-size: 32px;
  72. font-weight: bold;
  73. color: $primary-color;
  74. cursor: pointer;
  75. }
  76. }
  77. }
  78. </style>