user.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true" :model="filters">
  6. <el-col :span="3">
  7. <el-form-item>
  8. <el-select v-model="filters.companyId" clearable filterable placeholder="请选择公司">
  9. <el-option v-for="item in allCompanies" :key="item.id" :label="item.companyName" :value="item.id">
  10. </el-option>
  11. </el-select>
  12. </el-form-item>
  13. </el-col>
  14. <el-col :span="3">
  15. <el-form-item>
  16. <el-select v-model="filters.flag" placeholder="请选择查询条件">
  17. <el-option label="姓名" value="0"></el-option>
  18. <el-option label="手机号" value="1"></el-option>
  19. </el-select>
  20. </el-form-item>
  21. </el-col>
  22. <el-form-item>
  23. <el-input v-model="filters.keyName" clearable placeholder="请输入姓名或手机号进行搜索" style="width:250px;"></el-input>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" @click="getUsers">查询</el-button>
  27. </el-form-item>
  28. <el-form-item style="float:right;" v-if="user.subordinateType == 0 || user.isManager == 1">
  29. <el-button type="primary" @click="handleAdd">新增</el-button>
  30. </el-form-item>
  31. </el-form>
  32. </el-col>
  33. <!--列表-->
  34. <el-table :data="list" highlight-current-row :height="tableHeight" v-loading="listLoading" style="width: 100%;">
  35. <el-table-column type="index" width="60"></el-table-column>
  36. <el-table-column prop="username" label="姓名" width="120" sortable></el-table-column>
  37. <el-table-column prop="account" label="手机号" width="180" sortable></el-table-column>
  38. <!-- <el-table-column prop="mobile" label="联系方式" width="150" sortable></el-table-column> -->
  39. <el-table-column prop="projects" label="参与项目" sortable>
  40. <template slot-scope="scope">
  41. <span class="info" v-for="(item, index) in scope.row.projects">
  42. {{item.projectName}}
  43. <span v-if="scope.row.projects != null && index != scope.row.projects.length-1">、</span>
  44. </span>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="roleName" label="备注" width="180" sortable></el-table-column>
  48. <el-table-column prop="teamName" label="类型" width="120" align="center" sortable></el-table-column>
  49. <el-table-column prop="companyName" label="所属公司" sortable></el-table-column>
  50. <el-table-column label="操作" align="left" width="230">
  51. <template slot-scope="scope" v-if="user.id == scope.row.parentId || user.isManager == 1 || (user.parentId == 1 && user.subordinateType == 0)">
  52. <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
  53. <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
  54. <el-button type="primary" size="small" @click="invite(scope.$index, scope.row)" v-if="user.id != 1 && scope.row.projects != null && scope.row.projects.length == 1">邀请</el-button>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <!--工具条-->
  59. <el-col :span="24" class="toolbar">
  60. <el-pagination
  61. @size-change="handleSizeChange"
  62. @current-change="handleCurrentChange"
  63. :page-sizes="[20 , 50 , 80 , 100]"
  64. :page-size="20"
  65. layout="total, sizes, prev, pager, next"
  66. :total="total"
  67. style="float:right;">
  68. </el-pagination>
  69. </el-col>
  70. <!--新增界面-->
  71. <el-dialog title="新增人员" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  72. <el-form :model="addForm" label-width="100px" :rules="formRules" ref="addForm" :inline="true" class="demo-form-inline">
  73. <el-form-item label="姓名" prop="username">
  74. <el-input v-model="addForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
  75. </el-form-item>
  76. <el-form-item label="手机号" prop="account">
  77. <el-input v-model="addForm.account" autocomplete="off" placeholder="请输入手机号(登录账号)"></el-input>
  78. </el-form-item>
  79. <el-form-item v-if="!(user.parentId == 1 && user.subordinateType == 0)" label="参与项目" prop="projectIds">
  80. <el-select v-model="addForm.projectIds" @change="choseProject" clearable filterable placeholder="请选择参与项目" style="width:202px">
  81. <el-option v-for="item in projects" :key="item.id" :label="item.projectName" :value="item.id">
  82. </el-option>
  83. </el-select>
  84. </el-form-item>
  85. <el-form-item label="公司" prop="companyId">
  86. <el-select v-model="addForm.companyId" clearable filterable placeholder="请选择所属公司" style="width:202px">
  87. <el-option v-for="item in company" :key="item.id" :label="item.companyName" :value="item.id">
  88. </el-option>
  89. </el-select>
  90. </el-form-item>
  91. <el-form-item label="备注">
  92. <el-input v-model="addForm.roleName" autocomplete="off" placeholder="请输入备注"></el-input>
  93. </el-form-item>
  94. </el-form>
  95. <div slot="footer" class="dialog-footer">
  96. <span style="color:#f00;float:left;margin-left:60px;">初始密码:000000</span>
  97. <el-button @click.native="addFormVisible = false">取消</el-button>
  98. <el-button type="primary" @click.native="addSubmit" :loading="addLoading">提交</el-button>
  99. </div>
  100. </el-dialog>
  101. <!--编辑界面-->
  102. <el-dialog title="编辑人员" v-if="editFormVisible" :visible.sync="editFormVisible" :close-on-click-modal="false" customClass='customWidth'>
  103. <el-form :model="editForm" label-width="80px" :rules="formRules" ref="editForm" :inline="true" class="demo-form-inline">
  104. <el-form-item label="姓名" prop="username">
  105. <el-input v-model="editForm.username" autocomplete="off" placeholder="请输入姓名"></el-input>
  106. </el-form-item>
  107. <el-form-item label="手机号" prop="account">
  108. <el-input v-model="editForm.account" disabled autocomplete="off" placeholder="请输入手机号(登录账号)"></el-input>
  109. </el-form-item>
  110. <el-form-item label="公司" prop="companyId">
  111. <el-input v-model="editForm.companyId" disabled autocomplete="off" placeholder="请选择所属公司"></el-input>
  112. </el-form-item>
  113. <el-form-item label="备注">
  114. <el-input v-model="editForm.roleName" autocomplete="off" placeholder="请输入备注"></el-input>
  115. </el-form-item>
  116. </el-form>
  117. <div slot="footer" class="dialog-footer">
  118. <span style="color:#f00;float:left;margin-left:60px;">初始密码:000000</span>
  119. <el-button @click.native="editFormVisible = false">取消</el-button>
  120. <el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
  121. </div>
  122. </el-dialog>
  123. <!--邀请界面-->
  124. <el-dialog title="邀请" v-if="inviteVisible" :visible.sync="inviteVisible" :close-on-click-modal="false" customClass='customWidth'>
  125. <el-input placeholder="请复制邀请链接" v-model="inviteLink" class="input-with-select">
  126. <el-button slot="append" v-clipboard:copy="inviteLink" v-clipboard:success="copyLink" v-clipboard:error="onError" type="primary" icon="el-icon-share">复制链接</el-button>
  127. </el-input>
  128. </el-dialog>
  129. </section>
  130. </template>
  131. <script>
  132. import util from '../../common/js/util'
  133. export default {
  134. data() {
  135. var checkPhone = (rule, value, callback) => {
  136. if (!value) {
  137. return callback(new Error('请输入联系方式'));
  138. } else {
  139. const reg = /^1[0-9]\d{9}$/
  140. if (reg.test(value)) {
  141. callback();
  142. } else {
  143. return callback(new Error('请输入正确的联系方式'));
  144. }
  145. }
  146. };
  147. return {
  148. filters: {
  149. keyName: '',
  150. roleName: '',
  151. flag: '姓名',
  152. companyId: ''
  153. },
  154. user: JSON.parse(sessionStorage.getItem('user')),
  155. company: [],
  156. projects: [],
  157. //搜索用 涉及到的所有公司
  158. allCompanies: [],
  159. list: [],
  160. total: 0,
  161. page: 1,
  162. size: 20,
  163. listLoading: false,
  164. tableHeight: 0,
  165. formRules: {
  166. username: [
  167. { required: true, message: '请输入姓名', trigger: 'blur' }
  168. ],
  169. account: [
  170. { required: true, validator: checkPhone, trigger: 'blur'}
  171. ],
  172. teamName: [
  173. { required: true, message: '请选择人员类型', trigger: ["blur",'change'] }
  174. ],
  175. projectIds: [
  176. { required: true, message: '请选择参与项目', trigger: ["blur",'change'] }
  177. ],
  178. companyId: [
  179. { required: true, message: '请选择所属公司', trigger: ["blur",'change'] }
  180. ]
  181. },
  182. //新增界面是否显示
  183. addFormVisible: false,
  184. addLoading: false,
  185. //新增界面数据
  186. addForm: {
  187. username: '',
  188. account: '',
  189. projectIds: '',
  190. companyId: '',
  191. roleName: '',
  192. flag: 0
  193. },
  194. //编辑界面是否显示
  195. editFormVisible: false,
  196. editLoading: false,
  197. //编辑界面数据
  198. editForm: {
  199. id: 0,
  200. username: '',
  201. account: '',
  202. companyId: '',
  203. roleName: '',
  204. flag: 1
  205. },
  206. //邀请
  207. inviteVisible: false,
  208. inviteLink: ''
  209. }
  210. },
  211. methods: {
  212. //获取基础数据
  213. getMsg(){
  214. if(this.user.parentId == 1 && this.user.subordinateType == 0) {
  215. this.company = [];
  216. this.allCompanies = [];
  217. this.http.post(this.port.base.getCompanyList, {
  218. id: this.user.id,
  219. parentId: this.user.parentId
  220. }, res => {
  221. if (res.code == "ok") {
  222. this.company = res.data;
  223. this.allCompanies = res.data;
  224. } else {
  225. this.$message({
  226. message: res.msg,
  227. type: 'error'
  228. });
  229. }
  230. }, error => {
  231. this.$message({
  232. message: error,
  233. type: 'error'
  234. });
  235. })
  236. } else if(this.user.parentId > 1 && this.user.isManager == 1) {
  237. this.http.post(this.port.project.projectByUser, {},
  238. res => {
  239. if (res.code == "ok") {
  240. this.projects = res.data;
  241. //再获取一下公司列表
  242. this.getAllCompanies();
  243. } else {
  244. this.$message({
  245. message: res.msg,
  246. type: 'error'
  247. });
  248. }
  249. }, error => {
  250. this.$message({
  251. message: error,
  252. type: 'error'
  253. });
  254. });
  255. }
  256. },
  257. //新版获取所有公司
  258. getAllCompanies(){
  259. this.allCompanies = [];
  260. this.http.post(this.port.base.getInfo, {}, res => {
  261. if (res.code == "ok") {
  262. this.allCompanies = res.data;
  263. } else {
  264. this.$message({
  265. message: res.msg,
  266. type: 'error'
  267. });
  268. }
  269. }, error => {
  270. this.$message({
  271. message: error,
  272. type: 'error'
  273. });
  274. });
  275. },
  276. //分页
  277. handleCurrentChange(val) {
  278. this.page = val;
  279. this.getUsers();
  280. },
  281. handleSizeChange(val) {
  282. this.size = val;
  283. this.getUsers();
  284. },
  285. //获取用户列表
  286. getUsers() {
  287. this.listLoading = true;
  288. this.http.post(this.port.project.userList, {
  289. keyName: this.filters.keyName,
  290. currentPage: this.page,
  291. pageSize: this.size,
  292. companyId: this.filters.companyId==''?-1:this.filters.companyId,
  293. flag: this.filters.flag=='姓名'?0:this.filters.flag
  294. }, res => {
  295. this.listLoading = false;
  296. if (res.code == "ok") {
  297. this.list = res.data.list;
  298. this.total = res.data.total;
  299. } else {
  300. this.$message({
  301. message: res.msg,
  302. type: 'error'
  303. });
  304. }
  305. }, error => {
  306. this.listLoading = false;
  307. this.$message({
  308. message: error,
  309. type: 'error'
  310. });
  311. })
  312. },
  313. //显示新增界面
  314. handleAdd() {
  315. this.addFormVisible = true;
  316. this.addForm = {
  317. parentId: this.user.id,
  318. username: '',
  319. account: '',
  320. mobile: '',
  321. projectIds: '',
  322. companyId: '',
  323. roleName: '',
  324. flag: 0
  325. };
  326. },
  327. //新增
  328. addSubmit() {
  329. this.$refs.addForm.validate((valid) => {
  330. if (valid) {
  331. this.addLoading = true;
  332. this.http.post(this.port.project.addUser, this.addForm , res => {
  333. this.addLoading = false;
  334. if (res.code == "ok") {
  335. this.addFormVisible = false;
  336. this.$message({
  337. message: '创建成功',
  338. type: 'success'
  339. });
  340. this.getUsers();
  341. } else {
  342. this.$message({
  343. message: res.msg,
  344. type: 'error'
  345. });
  346. }
  347. }, error => {
  348. this.addLoading = false;
  349. this.addFormVisible = false;
  350. this.$message({
  351. message: error,
  352. type: 'error'
  353. });
  354. })
  355. }
  356. });
  357. },
  358. //删除
  359. handleDel(index, row) {
  360. this.$confirm('确认删除该人员吗?', '提示', {
  361. type: 'warning'
  362. }).then(() => {
  363. this.http.post(this.port.project.delUser, {
  364. id: row.id
  365. }, res => {
  366. if (res.code == "ok") {
  367. this.$message({
  368. message: '删除成功',
  369. type: 'success'
  370. });
  371. this.getUsers();
  372. } else {
  373. this.$message({
  374. message: res.msg,
  375. type: 'error'
  376. });
  377. }
  378. }, error => {
  379. this.$message({
  380. message: error,
  381. type: 'error'
  382. });
  383. })
  384. });
  385. },
  386. //显示编辑界面
  387. handleEdit(index, row) {
  388. this.editFormVisible = true;
  389. this.editForm = {
  390. id: row.id,
  391. parentId: this.user.id,
  392. username: row.username,
  393. account: row.account,
  394. companyId: row.companyName,
  395. roleName: row.roleName,
  396. flag: 1
  397. };
  398. },
  399. //编辑
  400. editSubmit() {
  401. this.$refs.editForm.validate((valid) => {
  402. if (valid) {
  403. this.editLoading = true;
  404. this.http.post(this.port.project.addUser, {
  405. id: this.editForm.id,
  406. parentId: this.editForm.parentId,
  407. username: this.editForm.username,
  408. roleName: this.editForm.roleName,
  409. flag: 1
  410. } , res => {
  411. this.editLoading = false;
  412. if (res.code == "ok") {
  413. this.editFormVisible = false;
  414. this.$message({
  415. message: '修改成功',
  416. type: 'success'
  417. });
  418. this.getUsers();
  419. } else {
  420. this.$message({
  421. message: res.msg,
  422. type: 'error'
  423. });
  424. }
  425. }, error => {
  426. this.editLoading = false;
  427. this.editFormVisible = false;
  428. this.$message({
  429. message: error,
  430. type: 'error'
  431. });
  432. })
  433. }
  434. });
  435. },
  436. //修改
  437. choseProject() {
  438. if(this.addForm.projectIds == ""){
  439. this.company = [];
  440. this.addForm.companyId = null;
  441. }else{
  442. this.http.post(this.port.base.getProduceCompany, {
  443. projectId: this.addForm.projectIds
  444. }, res => {
  445. if (res.code == "ok") {
  446. this.company = res.data;
  447. } else {
  448. this.$message({
  449. message: res.msg,
  450. type: 'error'
  451. });
  452. }
  453. }, error => {
  454. this.$message({
  455. message: error,
  456. type: 'error'
  457. });
  458. })
  459. }
  460. },
  461. //邀请
  462. invite(index, row) {
  463. this.http.post(this.port.project.inviteUser, {
  464. inviteeId: row.id,
  465. projectId: row.projects[0].id,
  466. operatorId: this.user.id
  467. } , res => {
  468. if (res.code == "ok") {
  469. this.inviteVisible = true;
  470. this.inviteLink = res.data.addressUrl;
  471. } else {
  472. this.$message({
  473. message: res.msg,
  474. type: 'error'
  475. });
  476. }
  477. }, error => {
  478. this.$message({
  479. message: error,
  480. type: 'error'
  481. });
  482. })
  483. },
  484. //复制链接
  485. copyLink() {
  486. //this.inviteVisible = false;
  487. this.$message({
  488. message: "复制成功!",
  489. type: 'success'
  490. });
  491. },
  492. onError(e) {
  493. //this.inviteVisible = false;
  494. this.$message({
  495. message: "复制失败!",
  496. type: 'error'
  497. });
  498. }
  499. },
  500. created() {
  501. let height = window.innerHeight;
  502. this.tableHeight = height - 210;
  503. const that = this;
  504. window.onresize = function temp() {
  505. that.tableHeight = window.innerHeight - 210;
  506. };
  507. },
  508. mounted() {
  509. this.getMsg();
  510. this.getUsers();
  511. }
  512. }
  513. </script>
  514. <style scoped>
  515. .el-input-group__append button.el-button {
  516. background-color: #409EFF;
  517. border-color: #409EFF;
  518. color: #fff;
  519. }
  520. </style>