|
1 |
| -(function(vc) { |
| 1 | +(function (vc) { |
2 | 2 | vc.extends({
|
3 | 3 | data: {
|
4 |
| - initDataInfo: {} |
| 4 | + initDataInfo: { |
| 5 | + loginUsers: [], |
| 6 | + pageUrl: '' |
| 7 | + } |
5 | 8 | },
|
6 |
| - _initMethod: function() { |
| 9 | + _initMethod: function () { |
7 | 10 |
|
8 | 11 | },
|
9 |
| - _initEvent: function() { |
10 |
| - vc.on('initData', 'loadCommunityInfo', function(_param) { |
11 |
| - |
12 |
| - vc.component._validateHasStore(_param); |
| 12 | + _initEvent: function () { |
| 13 | + vc.on('initData', 'loadCommunityInfo', function (_param) { |
| 14 | + $that.loginInfo.loginUsers = _param.loginUsers; |
| 15 | + $that.loginInfo.pageUrl = _param.url; |
| 16 | + if ($that.loginInfo.loginUsers.length > 1) { |
| 17 | + $that._initOpenModal(); |
| 18 | + return; |
| 19 | + } |
| 20 | + $that._initLoginUserInfo($that.loginInfo.loginUsers[0]); |
13 | 21 | })
|
14 | 22 | },
|
15 | 23 | methods: {
|
16 |
| - _loadCommunityInfo: function(_param) { |
17 |
| - var param = { |
| 24 | + _initOpenModal: function () { |
| 25 | + var content = '<div style="padding: 20px;">'; |
| 26 | + content += '<table class="layui-table">'; |
| 27 | + content += '<thead><tr><th>选择</th><th>账号</th><th>隶属</th><th>角色</th></tr></thead>'; |
| 28 | + content += '<tbody>'; |
| 29 | + $that.loginInfo.loginUsers.forEach(function (item) { |
| 30 | + content += `<tr> |
| 31 | + <td><input type="radio" name="selectedItem" value='${JSON.stringify(item)}'></td> |
| 32 | + <td>${item.userName}(${item.userId})</td> |
| 33 | + <td>${item.storeName}</td> |
| 34 | + <td>${item.relCdName}</td> |
| 35 | + </tr>`; |
| 36 | + }); |
| 37 | + content += '</tbody></table>'; |
| 38 | + content += '</div>'; |
| 39 | + |
| 40 | + // 打开弹框 |
| 41 | + layer.open({ |
| 42 | + type: 1, |
| 43 | + title: '请选择账号', |
| 44 | + content: content, |
| 45 | + area: ['600px', '400px'], |
| 46 | + btn: ['确定', '取消'], |
| 47 | + yes: function (index, layero) { |
| 48 | + // 获取用户选择的数据 |
| 49 | + let selected = document.querySelector('input[name="selectedItem"]:checked'); |
| 50 | + if (selected) { |
| 51 | + let selectedData = JSON.parse(selected.value); |
| 52 | + $that._initLoginUserInfo(selectedData); |
| 53 | + |
| 54 | + } else { |
| 55 | + vc.toast('请选择'); |
| 56 | + } |
| 57 | + layer.close(index); // 关闭弹框 |
| 58 | + }, |
| 59 | + btn2: function (index, layero) { |
| 60 | + layer.close(index); // 关闭弹框 |
| 61 | + } |
| 62 | + }); |
| 63 | + }, |
| 64 | + _initLoginUserInfo: function (_user) { |
| 65 | + vc.saveData('hc_accessToken', { |
| 66 | + token: _user.token |
| 67 | + }); |
| 68 | + $that._validateHasStore(); |
| 69 | + }, |
| 70 | + _loadCommunityInfo: function () { |
| 71 | + let param = { |
18 | 72 | params: {
|
19 | 73 | _uId: 'ccdd00opikookjuhyyttvhnnjuuu',
|
20 | 74 | page: 1,
|
|
23 | 77 | };
|
24 | 78 | vc.http.apiGet('/community.listMyEnteredCommunitys',
|
25 | 79 | param,
|
26 |
| - function(json, res) { |
27 |
| - if (res.status == 200) { |
28 |
| - var _communityInfos = JSON.parse(json).communitys; |
29 |
| - if (_communityInfos != null && _communityInfos.length > 0) { |
| 80 | + function (json, res) { |
| 81 | + let _json = JSON.parse(json); |
| 82 | + if (_json.code == 0) { |
| 83 | + let _communityInfos = _json.communitys; |
| 84 | + if (_communityInfos && _communityInfos.length > 0) { |
30 | 85 | vc.setCurrentCommunity(_communityInfos[0]);
|
31 | 86 | vc.setCommunitys(_communityInfos);
|
32 | 87 | } else {
|
33 | 88 | vc.toast('运营团队未分配小区,请联系运营团队');
|
34 | 89 | return;
|
35 | 90 | }
|
36 |
| - vc.jumpToPage(_param.url); |
| 91 | + vc.jumpToPage($that.loginInfo.pageUrl); |
37 | 92 | }
|
38 | 93 | },
|
39 |
| - function() { |
40 |
| - console.log('请求失败处理'); |
41 |
| - vc.jumpToPage(_param.url); |
| 94 | + function () { |
| 95 | + vc.jumpToPage($that.loginInfo.pageUrl); |
42 | 96 | }
|
43 | 97 | );
|
44 | 98 | },
|
45 |
| - _validateHasStore: function(_param) { |
46 |
| - var param = { |
| 99 | + _validateHasStore: function () { |
| 100 | + let param = { |
47 | 101 | params: {
|
48 | 102 | _uId: 'ccdd00opikookjuhyyttvhnnjuuu'
|
49 | 103 | }
|
50 | 104 | };
|
51 | 105 | vc.http.apiGet('/query.store.byuser',
|
52 | 106 | param,
|
53 |
| - function(json, res) { |
| 107 | + function (json, res) { |
54 | 108 | if (res.status == 200) {
|
55 |
| - $that._loadStaffPrivileges(_param); |
56 |
| - //vc.component._loadCommunityInfo(_param); |
| 109 | + $that._loadStaffPrivileges(); |
57 | 110 | } else {
|
58 | 111 | vc.toast(json);
|
59 | 112 | }
|
60 | 113 | },
|
61 |
| - function(e, res) { |
| 114 | + function (e, res) { |
62 | 115 | console.log('请求失败处理', e);
|
63 | 116 | //vc.jumpToPage(_param.url);
|
64 | 117 | vc.toast(e);
|
65 | 118 | }
|
66 | 119 | );
|
67 | 120 | },
|
68 |
| - _loadStaffPrivileges: function(_param) { |
| 121 | + _loadStaffPrivileges: function (_param) { |
69 | 122 |
|
70 | 123 | let param = {
|
71 | 124 | params: {
|
|
75 | 128 | //发送get请求
|
76 | 129 | vc.http.apiGet('/query.user.privilege',
|
77 | 130 | param,
|
78 |
| - function(json) { |
79 |
| - let _staffPrivilegeInfo = JSON.parse(json); |
| 131 | + function (json) { |
| 132 | + let _json = JSON.parse(json); |
80 | 133 |
|
81 | 134 | let _privilege = [];
|
82 |
| - _staffPrivilegeInfo.datas.forEach(item => { |
| 135 | + _json.datas.forEach(item => { |
83 | 136 | _privilege.push(item.pId);
|
84 | 137 | });
|
85 | 138 |
|
86 | 139 | vc.saveData('hc_staff_privilege', _privilege);
|
87 |
| - vc.component._loadCommunityInfo(_param); |
| 140 | + $that._loadCommunityInfo(); |
88 | 141 | },
|
89 |
| - function() { |
| 142 | + function () { |
90 | 143 | console.log('请求失败处理');
|
91 | 144 | });
|
92 | 145 | },
|
|
0 commit comments