EditRole.vue 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <el-dialog
  3. title="新增用户"
  4. width="660px"
  5. :visible.sync="visible"
  6. :before-close="_close"
  7. >
  8. <!-- <el-form :model="form" :rules="rules" ref="form" label-width="90px">
  9. <el-form-item label="角色名称 : " prop="name">
  10. <el-input v-model="form.name" placeholder="" maxlength="30" ></el-input>
  11. </el-form-item>
  12. <el-form-item label="角色描述 : " prop="intro">
  13. <el-input type="textarea" v-model="form.intro" placeholder="" resize="none" rows="4" ></el-input>
  14. </el-form-item>
  15. </el-form>-->
  16. <div class="chooseuser">
  17. <span style="color:#303133">选择用户:</span>
  18. <el-radio v-model="checked" label="1">从已有员工中选择</el-radio>
  19. <el-radio v-model="checked" label="2">新增员工</el-radio>
  20. </div>
  21. <div v-if="checked == '1'" v-loading="loading" class="roleContent">
  22. <div class="roleContentLeft">
  23. <p style="color:#303133">选择:</p>
  24. <div class="chooseBox">
  25. <div>
  26. <el-checkbox
  27. :indeterminate="isIndeterminate"
  28. v-model="checkAll"
  29. @change="handleCheckAllChange"
  30. >全选
  31. </el-checkbox
  32. >
  33. </div>
  34. <el-checkbox-group
  35. v-model="checkedCities"
  36. >
  37. <div class="checkone" v-for="(item,index) in admin_user" :key="index">
  38. <el-checkbox :label="item.id" :value="item.id" @change="change">
  39. <img v-if="item.avatar.length > 0" :src="item.avatar" alt=""/>
  40. <img
  41. v-if="item.avatar.length == 0"
  42. src="https://kuyi.shengws.com/S1.png"
  43. alt=""
  44. />
  45. <span>{{item.user_name}}</span>
  46. </el-checkbox>
  47. </div>
  48. </el-checkbox-group>
  49. </div>
  50. </div>
  51. <div class="roleContentRight" v-loading="loading">
  52. <p style="color:#303133">已选:</p>
  53. <div class="chooseBox">
  54. <div class="hasChoosedOne" v-for="(item,index) in is_check_admin_user" :key="index">
  55. <img v-if="item.avatar.length > 0" :src="item.avatar" alt=""/>
  56. <img
  57. v-if="item.avatar.length == 0"
  58. src="https://kuyi.shengws.com/S1.png"
  59. alt=""
  60. />
  61. <span>{{item.user_name}}</span>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. <div v-if="checked == '2'" class="newStaff">
  67. <el-form
  68. :model="ruleForm"
  69. :rules="newrules"
  70. ref="form"
  71. label-position="left"
  72. >
  73. <el-form-item label="姓名" prop="name" label-width="50px">
  74. <el-input v-model="ruleForm.name"></el-input>
  75. </el-form-item>
  76. <el-form-item label="手机号" prop="phone" label-width="70px">
  77. <el-input v-model="ruleForm.phone" maxlength="11"></el-input>
  78. </el-form-item>
  79. <el-form-item label="职称 : " label-width="50px">
  80. <el-select v-model="ruleForm.user_type" placeholder="用户类型">
  81. <el-option
  82. v-for="item in user_types"
  83. :label="item.name"
  84. :value="item.index"
  85. :key="item.index"
  86. ></el-option>
  87. </el-select>
  88. <el-select v-model="ruleForm.user_title" placeholder="用户职称">
  89. <el-option
  90. v-for="item in user_titles"
  91. :label="item.name"
  92. :value="item.index"
  93. :key="item.index"
  94. ></el-option>
  95. </el-select>
  96. </el-form-item>
  97. <el-form-item label="职位" label-width="50px">
  98. <el-input v-model="ruleForm.position"></el-input>
  99. </el-form-item>
  100. </el-form>
  101. <div class="newItem">
  102. <p style="width:80px;text-align:right;padding-right:8px">
  103. <i
  104. class="el-icon-circle-plus"
  105. style="font-size:20px;color:#338AFB"
  106. ></i>
  107. </p>
  108. <p style="color:#409FFF" @click="continueAddStaff()">继续新增员工</p>
  109. </div>
  110. </div>
  111. <div slot="footer" class="dialog-footer">
  112. <el-button @click="hide">取 消</el-button>
  113. <el-button type="primary" :loading="submitLoading" @click="submitAction()">保 存</el-button>
  114. </div>
  115. </el-dialog>
  116. </template>
  117. <script>
  118. import { addRole, AddUserRole, getStaffsList, modifyRole } from '@/api/role/role'
  119. import { addAdmin, getAddAdminInitData, getModifyAdminInitData, modifyAdmin } from '@/api/role/admin'
  120. export default {
  121. name: 'EditRole',
  122. data() {
  123. var checkMobile = (rule, value, callback) => {
  124. if (!value || value.length == 0) {
  125. return callback(new Error('手机号不能为空'))
  126. }
  127. if (/^1\d{10}$/.test(value) == false) {
  128. return callback(new Error('手机号格式错误'))
  129. } else {
  130. callback()
  131. }
  132. }
  133. var checkName = (rule, value, callback) => {
  134. if (!value || value.length == 0) {
  135. return callback(new Error('姓名不能为空'))
  136. } else {
  137. callback()
  138. }
  139. }
  140. return {
  141. submitLoading:false,
  142. loading:true,
  143. form: {
  144. id: 0,
  145. name: '',
  146. intro: ''
  147. },
  148. role_id: 0,
  149. visible: false,
  150. rules: {
  151. phone: [{ required: true, validator: checkMobile, trigger: 'blur' }],
  152. name: [{ required: true, validator: checkName, trigger: 'blur' }],
  153. intro: [{ required: true, message: '请输入角色说明', trigger: 'blur' }]
  154. },
  155. admin_user: [],
  156. is_check_admin_user: [],
  157. user_types: [
  158. { index: 2, name: '医生' },
  159. { index: 3, name: '护士' }
  160. ],
  161. user_titles: [
  162. { index: 1, name: '医士' },
  163. { index: 2, name: '医师' },
  164. { index: 3, name: '住院医师' },
  165. { index: 4, name: '主治医师' },
  166. { index: 5, name: '副主任医师' },
  167. { index: 6, name: '主任医师' },
  168. { index: 7, name: '护士' },
  169. { index: 8, name: '护师' },
  170. { index: 9, name: '主管护师' },
  171. { index: 10, name: '副主任护师' },
  172. { index: 11, name: '主任护师' },
  173. { index: 12, name: '运营专员' },
  174. { index: 13, name: '运营主管' }
  175. ],
  176. //
  177. checked: '1',
  178. checkAll: false,
  179. checkedCities: [],
  180. isIndeterminate: true,
  181. ruleForm: {
  182. name: '',
  183. phone: '',
  184. position: '',
  185. user_type: 2,
  186. user_title: 1,
  187. role: ''
  188. },
  189. newrules: {
  190. phone: [{ required: true, validator: checkMobile, trigger: 'blur' }],
  191. name: [
  192. { required: true, message: '请输入用户名字', trigger: 'blur' },
  193. { max: 10, message: '10个字以内', trigger: 'blur' }
  194. ]
  195. }
  196. }
  197. },
  198. methods: {
  199. continueAddStaff(){
  200. this.$refs.form.validate(valid => {
  201. if (valid) {
  202. if (this.form.id === 0) {
  203. this.ruleForm.role = this.role_id
  204. addAdmin(
  205. this.ruleForm.phone,
  206. this.ruleForm.name,
  207. this.ruleForm.user_type,
  208. this.ruleForm.user_title,
  209. this.ruleForm.role,
  210. '',
  211. this.ruleForm.position
  212. )
  213. .then(rs => {
  214. var resp = rs.data
  215. if (resp.state === 1) {
  216. this.$store.dispatch('DidChangeAdmins')
  217. var _this = this
  218. setTimeout(() => {
  219. _this.$store.dispatch('RecoverAdminsChangeState')
  220. }, 500)
  221. this.$emit('did-edit-role')
  222. this.ruleForm.phone = ''
  223. this.ruleForm.name = ''
  224. this.ruleForm.user_type = 2
  225. this.ruleForm.user_title = 1
  226. this.ruleForm.role = ''
  227. this.ruleForm.position = ''
  228. } else {
  229. this.$message.error(resp.msg)
  230. }
  231. })
  232. .catch(err => {
  233. this.loading = false
  234. this.$message.error(err)
  235. })
  236. }
  237. } else {
  238. return false
  239. }
  240. })
  241. },
  242. change(val) {
  243. if (this.checkedCities.length == this.admin_user.length) {
  244. this.checkAll = true
  245. } else {
  246. this.checkAll = false
  247. }
  248. }
  249. ,
  250. GetAllStaff: function() {
  251. getStaffsList()
  252. .then(rs => {
  253. var resp = rs.data
  254. if (resp.state === 1) {
  255. this.admin_user = resp.data.admins
  256. for (let i = 0; i < this.admin_user.length; i++) {
  257. if (this.admin_user[i].role_ids.length > 0) {
  258. let isExist = -1
  259. let ids = this.admin_user[i].role_ids.split(',')
  260. isExist = ids.indexOf(this.role_id.toString())
  261. if (isExist >= 0) {
  262. this.is_check_admin_user.push(this.admin_user[i])
  263. this.admin_user.splice(i, 1)
  264. i = i - 1
  265. }
  266. }
  267. }
  268. for (let i = 0; i < this.admin_user.length; i++) {
  269. if (this.admin_user[i].user_id == resp.data.org.creator) {
  270. this.admin_user.splice(i, 1)
  271. i = i - 1
  272. }
  273. }
  274. this.loading = false
  275. } else {
  276. this.$message.error(resp.msg)
  277. this.loading = false
  278. }
  279. })
  280. .catch(err => {
  281. this.$message.error(err)
  282. })
  283. },
  284. _close: function(done) {
  285. this.clear()
  286. done()
  287. },
  288. clear: function() {
  289. this.form.id = 0
  290. this.form.name = ''
  291. this.form.intro = ''
  292. },
  293. show(role_id) {
  294. this.clear()
  295. this.loading = true
  296. this.checked = '1'
  297. this.visible = true
  298. this.role_id = role_id
  299. this.admin_user = []
  300. this.is_check_admin_user = []
  301. this.checkedCities = []
  302. this.GetAllStaff()
  303. },
  304. hide() {
  305. this.clear()
  306. this.visible = false
  307. },
  308. modify(id, name, intro) {
  309. this.form.id = id
  310. this.form.name = name
  311. this.form.intro = intro
  312. this.visible = true
  313. },
  314. submitAction() {
  315. if (this.checked == '1') {
  316. if (this.checkedCities.length == 0) {
  317. this.$message.error('至少选择一个用户')
  318. return
  319. }
  320. let params = {
  321. id: this.role_id,
  322. ids: this.checkedCities.join(',')
  323. }
  324. this.submitLoading = true
  325. AddUserRole(params).then(response => {
  326. if (response.data.state === 1) {
  327. this.$message.success('添加成功')
  328. this.$emit('did-edit-role')
  329. this.hide()
  330. this.submitLoading = false
  331. } else {
  332. this.submitLoading = false
  333. this.$message.error(response.data.msg)
  334. }
  335. }).catch(e => {
  336. this.submitLoading = false
  337. });
  338. } else {
  339. this.$refs.form.validate(valid => {
  340. if (valid) {
  341. this.submitLoading = true
  342. if (this.form.id === 0) {
  343. this.ruleForm.role = this.role_id
  344. addAdmin(
  345. this.ruleForm.phone,
  346. this.ruleForm.name,
  347. this.ruleForm.user_type,
  348. this.ruleForm.user_title,
  349. this.ruleForm.role,
  350. '',
  351. this.ruleForm.position
  352. )
  353. .then(rs => {
  354. this.submitLoading = false
  355. var resp = rs.data
  356. if (resp.state === 1) {
  357. this.$store.dispatch('DidChangeAdmins')
  358. var _this = this
  359. setTimeout(() => {
  360. _this.$store.dispatch('RecoverAdminsChangeState')
  361. }, 500)
  362. this.$emit('did-edit-role')
  363. this.hide()
  364. this.ruleForm.phone = ''
  365. this.ruleForm.name = ''
  366. this.ruleForm.user_type = 2
  367. this.ruleForm.user_title = 1
  368. this.ruleForm.role = ''
  369. this.ruleForm.position = ''
  370. } else {
  371. this.$message.error(resp.msg)
  372. }
  373. })
  374. .catch(err => {
  375. this.submitLoading = false
  376. this.loading = false
  377. this.$message.error(err)
  378. })
  379. }
  380. } else {
  381. this.submitLoading = false
  382. return false
  383. }
  384. })
  385. }
  386. // this.$refs.form.validate(valid => {
  387. // if (valid) {
  388. // // 验证通过
  389. // if (this.form.id === 0) {
  390. // // 新增 role
  391. // addRole(this.form.name, this.form.intro)
  392. // .then(rs => {
  393. // var resp = rs.data;
  394. // if (resp.state === 1) {
  395. // var new_id = resp.data.id;
  396. // var new_name = resp.data.name;
  397. // var new_intro = resp.data.intro;
  398. // var new_status = resp.data.status;
  399. // this.$emit(
  400. // "did-add-role",
  401. // new_id,
  402. // new_name,
  403. // new_intro,
  404. // new_status
  405. // );
  406. //
  407. // this.hide();
  408. // } else {
  409. // this.$message.error(resp.msg);
  410. // }
  411. // })
  412. // .catch(err => {
  413. // this.$message.error(err);
  414. // });
  415. // } else {
  416. // // 修改 role
  417. // modifyRole(this.form.id, this.form.name, this.form.intro)
  418. // .then(rs => {
  419. // var resp = rs.data;
  420. // if (resp.state === 1) {
  421. // this.$emit(
  422. // "did-edit-role",
  423. // this.form.id,
  424. // this.form.name,
  425. // this.form.intro
  426. // );
  427. // this.hide();
  428. // } else {
  429. // this.$message.error(resp.msg);
  430. // }
  431. // })
  432. // .catch(err => {
  433. // this.$message.error(err);
  434. // });
  435. // }
  436. // } else {
  437. // // 验证失败
  438. // return false;
  439. // }
  440. // });
  441. },
  442. handleCheckAllChange(val) {
  443. this.checkedCities = []
  444. if (val) {
  445. for (let i = 0; i < this.admin_user.length; i++) {
  446. this.checkedCities.push(this.admin_user[i].id)
  447. }
  448. } else {
  449. this.checkedCities = []
  450. }
  451. this.isIndeterminate = false
  452. },
  453. handleCheckedCitiesChange(value) {
  454. let checkedCount = value.length
  455. this.checkAll = checkedCount === this.cities.length
  456. this.isIndeterminate =
  457. checkedCount > 0 && checkedCount < this.cities.length
  458. }
  459. }
  460. }
  461. </script>
  462. <style lang="scss" scoped>
  463. .roleContent {
  464. margin-top: 20px;
  465. display: flex;
  466. justify-content: space-between;
  467. .roleContentLeft {
  468. .chooseBox {
  469. width: 280px;
  470. height: 320px;
  471. overflow-y: auto;
  472. border: 1px solid rgba(235, 238, 240, 1);
  473. margin-top: 26px;
  474. padding: 20px;
  475. .checkone {
  476. display: flex;
  477. align-items: center;
  478. height: 50px;
  479. }
  480. .el-checkbox__label {
  481. display: flex;
  482. align-items: center;
  483. img {
  484. width: 30px;
  485. height: 30px;
  486. margin-right: 10px;
  487. }
  488. }
  489. }
  490. }
  491. .roleContentRight {
  492. .chooseBox {
  493. width: 280px;
  494. height: 320px;
  495. overflow-y: auto;
  496. border: 1px solid rgba(235, 238, 240, 1);
  497. margin-top: 26px;
  498. padding: 20px;
  499. .hasChoosedOne {
  500. display: flex;
  501. align-items: center;
  502. height: 50px;
  503. img {
  504. width: 30px;
  505. height: 30px;
  506. margin-right: 10px;
  507. }
  508. }
  509. }
  510. }
  511. }
  512. .newStaff {
  513. margin-top: 26px;
  514. .newItem {
  515. display: flex;
  516. align-items: center;
  517. }
  518. }
  519. </style>
  520. <style lang="scss">
  521. .roleContent {
  522. .roleContentLeft {
  523. .chooseBox {
  524. .el-checkbox {
  525. display: flex;
  526. align-items: center;
  527. }
  528. .el-checkbox__label {
  529. display: flex;
  530. align-items: center;
  531. }
  532. }
  533. }
  534. }
  535. </style>