Blame view

src/store/modules/generator.js 2.02 KB
c21fb5b0   monkeyhouyi   巡查上报页面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  import { getOrganizeTree } from '@/api/permission/organize'
  import { getDepartmentSelector } from '@/api/permission/department'
  import { getDictionaryType } from '@/api/systemData/dictionary'
  
  const state = {
    companyTree: [],
    depTree: [],
    dicTree: [],
    formItemList: [],
    subTable: [],
    hasTable: false,
    relationData: {}
  }
  
  const mutations = {
    SET_COMPANY_TREE: (state, companyTree) => {
      state.companyTree = companyTree
    },
    SET_DEP_TREE: (state, depTree) => {
      state.depTree = depTree
    },
    SET_DIC_TREE: (state, dicTree) => {
      state.dicTree = dicTree
    },
    UPDATE_FORMITEM_LIST(state, list) {
      state.formItemList = list
    },
    UPDATE_SUB_TABLE(state, subTable) {
      state.subTable = subTable
    },
    SET_TABLE(state, val) {
      state.hasTable = val
    },
    UPDATE_RELATION_DATA(state, val) {
      state.relationData = val
    }
  }
  
  const actions = {
    getCompanyTree({ state, commit }) {
      return new Promise((resolve, reject) => {
        if (!state.companyTree.length) {
          getOrganizeTree().then(res => {
            commit('SET_COMPANY_TREE', res.data.list)
            resolve(res.data.list)
          }).catch(error => {
            reject(error)
          })
        } else {
          resolve(state.companyTree)
        }
      })
    },
    getDepTree({ state, commit }) {
      return new Promise((resolve, reject) => {
        if (!state.depTree.length) {
          getDepartmentSelector().then(res => {
            commit('SET_DEP_TREE', res.data.list)
            resolve(res.data.list)
          }).catch(error => {
            reject(error)
          })
        } else {
          resolve(state.depTree)
        }
      })
    },
    getDicTree({ state, commit }) {
      return new Promise((resolve, reject) => {
        if (!state.dicTree.length) {
          getDictionaryType().then(res => {
            commit('SET_DIC_TREE', res.data.list)
            resolve(res.data.list)
          }).catch(error => {
            reject(error)
          })
        } else {
          resolve(state.dicTree)
        }
      })
    },
  }
  
  export default {
    namespaced: true,
    state,
    mutations,
    actions
  }