猫妈狗爸伴宠师小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.3 KiB

  1. import { getConfigList, getPetTypeList, getIncreaseServiceList } from '@/api/config/config.js'
  2. const system = {
  3. state: {
  4. configList: {},
  5. petTypeOptions: [],
  6. increaseServiceOptions: [],
  7. },
  8. mutations: {
  9. setConfigList(state, list) {
  10. const obj = {}
  11. list.forEach(n => {
  12. obj[n.paramCode] = n;
  13. })
  14. state.configList = obj;
  15. },
  16. setPetTypeOptions(state, list) {
  17. state.petTypeOptions = list
  18. },
  19. setIncreaseServiceOptions(state, list) {
  20. state.increaseServiceOptions = list
  21. },
  22. },
  23. actions: {
  24. async fetchConfigList({commit, state}) {
  25. try {
  26. const data = await getConfigList()
  27. commit('setConfigList', data)
  28. } catch (err) {
  29. }
  30. },
  31. async fetchPetTypeOptions({commit, state}) {
  32. if (state.petTypeOptions.length) {
  33. return
  34. }
  35. try {
  36. const data = await getPetTypeList()
  37. commit('setPetTypeOptions', data)
  38. } catch (err) {
  39. }
  40. },
  41. async fetchIncreaseServiceOptions({commit, state}) {
  42. if (state.increaseServiceOptions.length) {
  43. return
  44. }
  45. try {
  46. const data = await getIncreaseServiceList()
  47. commit('setIncreaseServiceOptions', data)
  48. } catch (err) {
  49. }
  50. },
  51. }
  52. }
  53. export default system