store.ts 769 B

123456789101112131415161718192021222324252627282930313233
  1. import { reactive } from 'vue'
  2. import * as api from '@/service/order'
  3. export const state = reactive({
  4. productList: [] as any[],
  5. brandList: [] as any[],
  6. modelList: [] as any[],
  7. form: {
  8. product_id: '',
  9. subscribe_type: '' as 'year' | 'month',
  10. discount_code: '',
  11. brand_id: '',
  12. phone_id: '',
  13. email: '',
  14. from: '',
  15. invitor: '',
  16. },
  17. })
  18. export async function initProducts() {
  19. if (!state.productList.length) {
  20. state.productList = (await api.getProductList()).results
  21. }
  22. state.form.product_id = state.productList[0].id
  23. }
  24. export async function getBrandList() {
  25. state.brandList = (await api.getBrands()).results
  26. }
  27. export async function getModelList() {
  28. state.brandList = (await api.getModels(state.form.brand_id)).results
  29. }