血透系统PC前端

EditRole.vue 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <template>
  2. <el-dialog title="新增用户" width="660px" :visible.sync="visible" :before-close="_close">
  3. <!-- <el-form :model="form" :rules="rules" ref="form" label-width="90px">
  4. <el-form-item label="角色名称 : " prop="name">
  5. <el-input v-model="form.name" placeholder="" maxlength="30" ></el-input>
  6. </el-form-item>
  7. <el-form-item label="角色描述 : " prop="intro">
  8. <el-input type="textarea" v-model="form.intro" placeholder="" resize="none" rows="4" ></el-input>
  9. </el-form-item>
  10. </el-form>-->
  11. <div class="chooseuser">
  12. <span style="color:#303133">选择用户:</span>
  13. <el-radio v-model="checked" label="1">从已有员工中选择</el-radio>
  14. <el-radio v-model="checked" label="2">新增员工</el-radio>
  15. </div>
  16. <div v-if="checked == '1'" class="roleContent">
  17. <div class="roleContentLeft">
  18. <p style="color:#303133">选择:</p>
  19. <div class="chooseBox">
  20. <div>
  21. <el-checkbox
  22. :indeterminate="isIndeterminate"
  23. v-model="checkAll"
  24. @change="handleCheckAllChange"
  25. >全选</el-checkbox>
  26. </div>
  27. <el-checkbox-group v-model="checkedCities" @change="handleCheckedCitiesChange">
  28. <!-- <el-checkbox v-for="city in cities" :label="city" :key="city">{{city}}</el-checkbox> -->
  29. <div class="checkone" v-for="city in cities" :key="city">
  30. <el-checkbox :label="city">
  31. <img src="https://kuyi.shengws.com/S1.png" alt />
  32. <span>名字</span>
  33. </el-checkbox>
  34. </div>
  35. </el-checkbox-group>
  36. </div>
  37. </div>
  38. <div class="roleContentRight">
  39. <p style="color:#303133">已选:</p>
  40. <div class="chooseBox">
  41. <div class="hasChoosedOne">
  42. <img src="https://kuyi.shengws.com/S1.png" alt />
  43. <span>名字</span>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <div v-if="checked == '2'" class="newStaff">
  49. <el-form
  50. :model="ruleForm"
  51. :rules="newrules"
  52. label-position="right"
  53. label-width="80px"
  54. style="width:40%"
  55. >
  56. <el-form-item label="姓名" prop="name">
  57. <el-input v-model="ruleForm.name"></el-input>
  58. </el-form-item>
  59. <el-form-item label="手机号" prop="phone">
  60. <el-input v-model="ruleForm.phone"></el-input>
  61. </el-form-item>
  62. <el-form-item label="职位">
  63. <el-input></el-input>
  64. </el-form-item>
  65. </el-form>
  66. <div class="newItem">
  67. <p style="width:80px;text-align:right;padding-right:8px">
  68. <i class="el-icon-circle-plus" style="font-size:20px;color:#338AFB"></i>
  69. </p>
  70. <p style="color:#409FFF">继续新增员工</p>
  71. </div>
  72. </div>
  73. <div slot="footer" class="dialog-footer">
  74. <el-button @click="hide">取 消</el-button>
  75. <el-button type="primary" @click="submitAction()">保 存</el-button>
  76. </div>
  77. </el-dialog>
  78. </template>
  79. <script>
  80. import { addRole, modifyRole } from "@/api/role/role";
  81. export default {
  82. name: "EditRole",
  83. data() {
  84. return {
  85. form: {
  86. id: 0,
  87. name: "",
  88. intro: ""
  89. },
  90. visible: false,
  91. rules: {
  92. name: [
  93. { required: true, message: "请输入角色名称", trigger: "blur" },
  94. { max: 10, message: "10个字以内", trigger: "blur" }
  95. ],
  96. intro: [{ required: true, message: "请输入角色说明", trigger: "blur" }]
  97. },
  98. //
  99. checked: "1",
  100. checkAll: false,
  101. checkedCities: [],
  102. cities: ["上海", "北京", "广州", "深圳"],
  103. isIndeterminate: true,
  104. ruleForm: {
  105. name: "",
  106. phone: "",
  107. position: ""
  108. },
  109. newrules: {
  110. name: [
  111. { required: true, message: "请输入角色名称", trigger: "blur" },
  112. { max: 10, message: "10个字以内", trigger: "blur" }
  113. ],
  114. phone: [{ required: true, message: "请输入手机号", trigger: "blur" }]
  115. }
  116. };
  117. },
  118. methods: {
  119. _close: function(done) {
  120. this.clear();
  121. done();
  122. },
  123. clear: function() {
  124. this.form.id = 0;
  125. this.form.name = "";
  126. this.form.intro = "";
  127. },
  128. show() {
  129. this.clear();
  130. this.visible = true;
  131. },
  132. hide() {
  133. this.clear();
  134. this.visible = false;
  135. },
  136. modify(id, name, intro) {
  137. this.form.id = id;
  138. this.form.name = name;
  139. this.form.intro = intro;
  140. this.visible = true;
  141. },
  142. submitAction() {
  143. this.$refs.form.validate(valid => {
  144. if (valid) {
  145. // 验证通过
  146. if (this.form.id === 0) {
  147. // 新增 role
  148. addRole(this.form.name, this.form.intro)
  149. .then(rs => {
  150. var resp = rs.data;
  151. if (resp.state === 1) {
  152. var new_id = resp.data.id;
  153. var new_name = resp.data.name;
  154. var new_intro = resp.data.intro;
  155. var new_status = resp.data.status;
  156. this.$emit(
  157. "did-add-role",
  158. new_id,
  159. new_name,
  160. new_intro,
  161. new_status
  162. );
  163. this.hide();
  164. } else {
  165. this.$message.error(resp.msg);
  166. }
  167. })
  168. .catch(err => {
  169. this.$message.error(err);
  170. });
  171. } else {
  172. // 修改 role
  173. modifyRole(this.form.id, this.form.name, this.form.intro)
  174. .then(rs => {
  175. var resp = rs.data;
  176. if (resp.state === 1) {
  177. this.$emit(
  178. "did-edit-role",
  179. this.form.id,
  180. this.form.name,
  181. this.form.intro
  182. );
  183. this.hide();
  184. } else {
  185. this.$message.error(resp.msg);
  186. }
  187. })
  188. .catch(err => {
  189. this.$message.error(err);
  190. });
  191. }
  192. } else {
  193. // 验证失败
  194. return false;
  195. }
  196. });
  197. },
  198. handleCheckAllChange(val) {
  199. this.checkedCities = val ? this.cities : [];
  200. this.isIndeterminate = false;
  201. },
  202. handleCheckedCitiesChange(value) {
  203. let checkedCount = value.length;
  204. this.checkAll = checkedCount === this.cities.length;
  205. this.isIndeterminate =
  206. checkedCount > 0 && checkedCount < this.cities.length;
  207. }
  208. }
  209. };
  210. </script>
  211. <style lang="scss" scoped>
  212. .roleContent {
  213. margin-top: 20px;
  214. display: flex;
  215. justify-content: space-between;
  216. .roleContentLeft {
  217. .chooseBox {
  218. width: 280px;
  219. height: 320px;
  220. overflow-y: auto;
  221. border: 1px solid rgba(235, 238, 240, 1);
  222. margin-top: 26px;
  223. padding: 20px;
  224. .checkone {
  225. display: flex;
  226. align-items: center;
  227. height: 50px;
  228. }
  229. .el-checkbox__label {
  230. display: flex;
  231. align-items: center;
  232. img {
  233. width: 30px;
  234. height: 30px;
  235. margin-right: 10px;
  236. }
  237. }
  238. }
  239. }
  240. .roleContentRight {
  241. .chooseBox {
  242. width: 280px;
  243. height: 320px;
  244. overflow-y: auto;
  245. border: 1px solid rgba(235, 238, 240, 1);
  246. margin-top: 26px;
  247. padding: 20px;
  248. .hasChoosedOne {
  249. display: flex;
  250. align-items: center;
  251. height: 50px;
  252. img {
  253. width: 30px;
  254. height: 30px;
  255. margin-right: 10px;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. .newStaff {
  262. margin-top: 26px;
  263. .newItem {
  264. display: flex;
  265. align-items: center;
  266. }
  267. }
  268. </style>
  269. <style lang="scss">
  270. .roleContent {
  271. .roleContentLeft {
  272. .chooseBox {
  273. .el-checkbox {
  274. display: flex;
  275. align-items: center;
  276. }
  277. .el-checkbox__label {
  278. display: flex;
  279. align-items: center;
  280. }
  281. }
  282. }
  283. }
  284. </style>