staff.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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">
  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 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. this.http.post(this.port.project.projectByUser, {},
  215. res => {
  216. if (res.code == "ok") {
  217. this.projects = res.data;
  218. //再获取一下公司列表
  219. this.getAllCompanies();
  220. } else {
  221. this.$message({
  222. message: res.msg,
  223. type: 'error'
  224. });
  225. }
  226. }, error => {
  227. this.$message({
  228. message: error,
  229. type: 'error'
  230. });
  231. });
  232. },
  233. //新版获取所有公司
  234. getAllCompanies(){
  235. this.allCompanies = [];
  236. this.http.post(this.port.base.getInfo, {}, res => {
  237. if (res.code == "ok") {
  238. this.allCompanies = res.data;
  239. } else {
  240. this.$message({
  241. message: res.msg,
  242. type: 'error'
  243. });
  244. }
  245. }, error => {
  246. this.$message({
  247. message: error,
  248. type: 'error'
  249. });
  250. });
  251. },
  252. //旧版获取所有公司
  253. // getAllCompanies2(){
  254. // this.allCompanies = [];
  255. // this.http.post(this.port.base.companys, {
  256. // id: this.user.id,
  257. // parentId: this.user.parentId
  258. // }, res => {
  259. // if (res.code == "ok") {
  260. // this.allCompanies = res.data;
  261. // } else {
  262. // this.$message({
  263. // message: res.msg,
  264. // type: 'error'
  265. // });
  266. // }
  267. // }, error => {
  268. // this.$message({
  269. // message: error,
  270. // type: 'error'
  271. // });
  272. // })
  273. // },
  274. //分页
  275. handleCurrentChange(val) {
  276. this.page = val;
  277. this.getUsers();
  278. },
  279. handleSizeChange(val) {
  280. this.size = val;
  281. this.getUsers();
  282. },
  283. //获取用户列表
  284. getUsers() {
  285. this.listLoading = true;
  286. this.http.post(this.port.project.userList, {
  287. keyName: this.filters.keyName,
  288. currentPage: this.page,
  289. pageSize: this.size,
  290. companyId: this.filters.companyId==''?-1:this.filters.companyId,
  291. flag: this.filters.flag=='姓名'?0:this.filters.flag
  292. }, res => {
  293. this.listLoading = false;
  294. if (res.code == "ok") {
  295. this.list = res.data.list;
  296. this.total = res.data.total;
  297. } else {
  298. this.$message({
  299. message: res.msg,
  300. type: 'error'
  301. });
  302. }
  303. }, error => {
  304. this.listLoading = false;
  305. this.$message({
  306. message: error,
  307. type: 'error'
  308. });
  309. })
  310. },
  311. //显示新增界面
  312. handleAdd() {
  313. this.addFormVisible = true;
  314. this.addForm = {
  315. parentId: this.user.id,
  316. username: '',
  317. account: '',
  318. mobile: '',
  319. projectIds: '',
  320. companyId: '',
  321. roleName: '',
  322. flag: 0
  323. };
  324. },
  325. //新增
  326. addSubmit() {
  327. this.$refs.addForm.validate((valid) => {
  328. if (valid) {
  329. this.addLoading = true;
  330. this.http.post(this.port.project.addUser, this.addForm , res => {
  331. this.addLoading = false;
  332. if (res.code == "ok") {
  333. this.addFormVisible = false;
  334. this.$message({
  335. message: '创建成功',
  336. type: 'success'
  337. });
  338. this.getUsers();
  339. } else {
  340. this.$message({
  341. message: res.msg,
  342. type: 'error'
  343. });
  344. }
  345. }, error => {
  346. this.addLoading = false;
  347. this.addFormVisible = false;
  348. this.$message({
  349. message: error,
  350. type: 'error'
  351. });
  352. })
  353. }
  354. });
  355. },
  356. //删除
  357. handleDel(index, row) {
  358. this.$confirm('确认删除该人员吗?', '提示', {
  359. type: 'warning'
  360. }).then(() => {
  361. this.http.post(this.port.project.delUser, {
  362. id: row.id
  363. }, res => {
  364. if (res.code == "ok") {
  365. this.$message({
  366. message: '删除成功',
  367. type: 'success'
  368. });
  369. this.getUsers();
  370. } else {
  371. this.$message({
  372. message: res.msg,
  373. type: 'error'
  374. });
  375. }
  376. }, error => {
  377. this.$message({
  378. message: error,
  379. type: 'error'
  380. });
  381. })
  382. });
  383. },
  384. //显示编辑界面
  385. handleEdit(index, row) {
  386. this.editFormVisible = true;
  387. this.editForm = {
  388. id: row.id,
  389. parentId: this.user.id,
  390. username: row.username,
  391. account: row.account,
  392. companyId: row.companyName,
  393. roleName: row.roleName,
  394. flag: 1
  395. };
  396. },
  397. //编辑
  398. editSubmit() {
  399. this.$refs.editForm.validate((valid) => {
  400. if (valid) {
  401. this.editLoading = true;
  402. this.http.post(this.port.project.addUser, {
  403. id: this.editForm.id,
  404. parentId: this.editForm.parentId,
  405. username: this.editForm.username,
  406. roleName: this.editForm.roleName,
  407. flag: 1
  408. } , res => {
  409. this.editLoading = false;
  410. if (res.code == "ok") {
  411. this.editFormVisible = false;
  412. this.$message({
  413. message: '修改成功',
  414. type: 'success'
  415. });
  416. this.getUsers();
  417. } else {
  418. this.$message({
  419. message: res.msg,
  420. type: 'error'
  421. });
  422. }
  423. }, error => {
  424. this.editLoading = false;
  425. this.editFormVisible = false;
  426. this.$message({
  427. message: error,
  428. type: 'error'
  429. });
  430. })
  431. }
  432. });
  433. },
  434. //修改
  435. choseProject() {
  436. if(this.addForm.projectIds == ""){
  437. this.company = [];
  438. this.addForm.companyId = null;
  439. }else{
  440. this.http.post(this.port.base.getCompanyByPro, {
  441. projectId: this.addForm.projectIds
  442. }, res => {
  443. if (res.code == "ok") {
  444. this.company = res.data;
  445. } else {
  446. this.$message({
  447. message: res.msg,
  448. type: 'error'
  449. });
  450. }
  451. }, error => {
  452. this.$message({
  453. message: error,
  454. type: 'error'
  455. });
  456. })
  457. }
  458. },
  459. //邀请
  460. invite(index, row) {
  461. this.http.post(this.port.project.inviteUser, {
  462. inviteeId: row.id,
  463. projectId: row.projects[0].id,
  464. operatorId: this.user.id
  465. } , res => {
  466. if (res.code == "ok") {
  467. this.inviteVisible = true;
  468. this.inviteLink = res.data.addressUrl;
  469. } else {
  470. this.$message({
  471. message: res.msg,
  472. type: 'error'
  473. });
  474. }
  475. }, error => {
  476. this.$message({
  477. message: error,
  478. type: 'error'
  479. });
  480. })
  481. },
  482. //复制链接
  483. copyLink() {
  484. //this.inviteVisible = false;
  485. this.$message({
  486. message: "复制成功!",
  487. type: 'success'
  488. });
  489. },
  490. onError(e) {
  491. //this.inviteVisible = false;
  492. this.$message({
  493. message: "复制失败!",
  494. type: 'error'
  495. });
  496. }
  497. },
  498. created() {
  499. let height = window.innerHeight;
  500. this.tableHeight = height - 210;
  501. const that = this;
  502. window.onresize = function temp() {
  503. that.tableHeight = window.innerHeight - 210;
  504. };
  505. },
  506. mounted() {
  507. this.getMsg();
  508. this.getUsers();
  509. }
  510. }
  511. </script>
  512. <style scoped>
  513. .el-input-group__append button.el-button {
  514. background-color: #409EFF;
  515. border-color: #409EFF;
  516. color: #fff;
  517. }
  518. </style>