猫妈狗爸伴宠师小程序前端代码
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.

75 lines
1.2 KiB

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