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
import {
fetchUserBaseInfo,
fetchUserBaseInfoByPhone,
} from '@/api/base/customer';
import { GET_CUSTOMER_BASEINFO } from './mutation-types';
const state = () => ({
areaName: '',
createAt: '',
customerHead: '',
customerName: '',
customerPhone: '',
customerSex: '',
customerType: '',
id: null,
isFirstRecharge: null,
state: '',
});
const getters = {
customerBaseInfo: state => state,
};
const actions = {
fetchUserBaseInfo({ commit }, entity) {
fetchUserBaseInfo(entity)
.then(res => {
const userInfo = res.data;
if (userInfo) {
commit(GET_CUSTOMER_BASEINFO, userInfo);
} else {
commit(GET_CUSTOMER_BASEINFO, state());
}
})
.catch(err => {
console.error(err);
commit(GET_CUSTOMER_BASEINFO, state());
});
},
fetchUserBaseInfoByPhone({ commit }, entity) {
fetchUserBaseInfoByPhone(entity)
.then(res => {
const userInfo = res.data;
if (userInfo) {
commit(GET_CUSTOMER_BASEINFO, userInfo);
} else {
commit(GET_CUSTOMER_BASEINFO, state());
}
})
.catch(err => {
console.error(err);
commit(GET_CUSTOMER_BASEINFO, state());
});
},
};
const mutations = {
[GET_CUSTOMER_BASEINFO](state, userInfo) {
Object.keys(userInfo).map(key => {
state[key] = userInfo[key];
});
},
};
export default {
state,
getters,
actions,
mutations,
};