staff.vue 24 KB

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