selectProject.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="hui-flex hui-dialog select-project-index">
  3. <div class="hui-flex-box hui-dialog-content">
  4. <el-table :data="tableData" row-key="id" border height="100%">
  5. <el-table-column label="序号" width="50">
  6. <template slot-scope="scope">
  7. <div style="text-align: center;">{{scope.$index + 1}}</div>
  8. </template>
  9. </el-table-column>
  10. <el-table-column label="项目名称" prop="projectName"></el-table-column>
  11. <el-table-column label="所属企业" prop="organizationName"></el-table-column>
  12. <el-table-column label="项目身份">
  13. <template slot-scope="scope">
  14. <div class="hui-table-tag" style="display: flex;align-items: center;">
  15. <div class="hui-tag hui-tag-success" v-if="scope.row.identityId === 1">客户</div>
  16. <div class="hui-tag hui-tag-success" v-else-if="scope.row.identityId === 2">中介</div>
  17. <div class="hui-tag hui-tag-success" v-else-if="scope.row.identityId === 3">
  18. 公司成员
  19. </div>
  20. <div class="hui-tag hui-tag-success" v-else-if="scope.row.identityId === 4">
  21. 关联公司
  22. </div>
  23. <div class="hui-tag hui-tag-success" v-else-if="scope.row.identityId === 5">
  24. 经纪公司
  25. </div>
  26. <div class="hui-tag hui-tag-success" v-else-if="scope.row.identityId === 6">
  27. 所有者
  28. </div>
  29. </div>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="操作" width="100">
  33. <template slot-scope="scope">
  34. <div class="hui-table-operation">
  35. <span class="table-operation"
  36. v-if="$store.getters.project.id != scope.row.projectId || $store.getters.identityId != scope.row.identityId"
  37. @click="changeProject(scope.row)">
  38. 切换项目
  39. </span>
  40. </div>
  41. </template>
  42. </el-table-column>
  43. <template slot="empty">
  44. <empty description="暂无数据"></empty>
  45. </template>
  46. </el-table>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import {
  52. selectProject,
  53. getOrganizedProjectList,
  54. selectOrangaized
  55. } from '@/httpApi/loginRegister'
  56. import {
  57. bindProjectDetail,
  58. getOrganizationDetailById
  59. } from '@/httpApi/organization'
  60. import {
  61. getProjectDetailById,
  62. getProjectListByPage
  63. } from '@/httpApi/space'
  64. import {
  65. getIdentityResource
  66. } from '@/httpApi/system'
  67. import {
  68. setComment
  69. } from '@/uitls/auth';
  70. export default {
  71. data() {
  72. return {
  73. tableData: []
  74. }
  75. },
  76. created() {
  77. let user = this.$store.getters.user;
  78. if (user.userId === 1) {
  79. getProjectListByPage({
  80. currPage: 1,
  81. pageSize: 100
  82. }).then(res => {
  83. if (res.state) {
  84. this.tableData = res.data.dataList.map(node => {
  85. let organization = user.organizationList.find(item => item.id === node
  86. .organizationId);
  87. return {
  88. projectId: node.id,
  89. projectName: node.name,
  90. organizationId: node.organizationId,
  91. organizationName: !organization ? '' : organization.name,
  92. identityId: 6
  93. }
  94. })
  95. }
  96. })
  97. } else {
  98. this.init();
  99. }
  100. },
  101. methods: {
  102. init() {
  103. bindProjectDetail({
  104. userId: this.$store.getters.user.userId
  105. }).then(res => {
  106. if (res.state) {
  107. let clientData = res.data;
  108. bindProjectDetail({
  109. bindOrganizationId: this.$store.getters.organization.id
  110. }).then(res => {
  111. if (res.state) {
  112. let organizationData = res.data;
  113. if (this.$store.getters.user.phone == this.$store.getters.organization
  114. .contactTel) {
  115. getOrganizedProjectList(this.$store.getters.organization.id).then(
  116. res => {
  117. if (res.state) {
  118. let data = res.data || [];
  119. let obj = data.map(node => {
  120. return {
  121. projectId: node.id,
  122. projectName: node.name,
  123. organizationId: node.organizationId,
  124. organizationName: node
  125. .organizationName,
  126. identityId: 6
  127. }
  128. })
  129. let list = clientData.concat(organizationData,
  130. obj).sort((a, b) => a.projectId - b.projectId);
  131. this.tableData = list.filter((item, index) => {
  132. return list.findIndex(t => t.projectId ===
  133. item.projectId && t.identityId ===
  134. item.identityId) === index;
  135. })
  136. }
  137. });
  138. } else {
  139. this.tableData = clientData.concat(organizationData).sort((a, b) => a
  140. .projectId - b.projectId);
  141. }
  142. }
  143. })
  144. }
  145. })
  146. },
  147. changeProject(item) {
  148. if (item.identityId == 6 || item.identityId == 3) {
  149. getOrganizationDetailById(item.organizationId).then(res => {
  150. if (res.state) {
  151. this.$store.dispatch('app/changeOrganization', res.data);
  152. selectOrangaized(res.data)
  153. }
  154. })
  155. }
  156. getProjectDetailById(item.projectId).then(res => {
  157. if (res.state) {
  158. let data = res.data;
  159. selectProject(data.id).then(res => {
  160. if (res.state) {
  161. let user = res.data;
  162. this.$store.dispatch('app/changeiIdentityId', item.identityId);
  163. this.$store.dispatch('projectBase/changeProject', data);
  164. localStorage.setItem('projectId', data.id);
  165. this.$store.dispatch('app/changeUser', user);
  166. if (item.identityId === 3 || user.userId === 1) {
  167. this.$store.dispatch('app/changeMenuData', user.resource ? JSON.parse(
  168. user.resource) : []);
  169. setComment(user.menu ? user.menu : JSON.stringify([]));
  170. this.$emit('callback');
  171. this.$router.push({
  172. path: '/',
  173. replace: true
  174. })
  175. this.$message.success('切换成功');
  176. } else {
  177. getIdentityResource({
  178. identityId: item.identityId,
  179. type: data.type
  180. }).then(node => {
  181. if (node.state) {
  182. let role = node.data[0] || {};
  183. this.$store.dispatch('app/changeMenuData', role
  184. .resource ? JSON.parse(role.resource) : []);
  185. setComment(role.menus ? role.menus : JSON.stringify(
  186. []));
  187. this.$emit('callback');
  188. this.$router.push({
  189. path: '/',
  190. replace: true
  191. })
  192. this.$message.success('切换成功');
  193. } else {
  194. this.loginLoading = false;
  195. }
  196. })
  197. }
  198. } else {
  199. this.$message.error('切换失败');
  200. }
  201. });
  202. }
  203. })
  204. },
  205. submit() {
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss">
  211. .select-project-index {
  212. .select-project-item {
  213. flex: 1;
  214. height: 0;
  215. display: flex;
  216. flex-direction: column;
  217. .select-project-title {
  218. padding: 10px 15px;
  219. position: relative;
  220. &::before {
  221. content: '';
  222. width: 4px;
  223. height: 18px;
  224. left: 4px;
  225. top: 11px;
  226. background: $--color-primary;
  227. position: absolute;
  228. }
  229. }
  230. }
  231. }
  232. </style>