AddDeptInfo.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <!-- 添加机构信息 By_liucf -->
  2. <template>
  3. <div>
  4. <crumbs :title="topInfo" linkTo="/admin/LT-YXSJWH-KSWH">
  5. </crumbs>
  6. <div class="contents">
  7. <el-form ref="form" :model="form" :rules="rules" label-width="120" class="add-admin-form">
  8. <el-form-item label="科室名称:" prop="name">
  9. <el-input v-model="form.name" placeholder="请输入科室名称"></el-input>
  10. </el-form-item>
  11. <el-form-item label="描述:" prop="remark" class="desc">
  12. <el-input type="textarea" :rows="3" placeholder="请输入科室描述" v-model="form.remark" maxlength="1024"></el-input>
  13. </el-form-item>
  14. </el-form-item>
  15. <el-button size="small" type="primary" @click="addOrga">{{text}}</el-button>
  16. </el-form>
  17. </div>
  18. </div>
  19. </template>
  20. <script>
  21. import api from '@api/icss.js';
  22. export default {
  23. name: 'AddDeptInfo',
  24. data(){
  25. const deptNameVaild = (rule, value, callback) => {
  26. if (!value) {
  27. return callback(new Error('请输入科室名称'));
  28. }
  29. if (value.length > 120) {
  30. this.form.name = value.substr(0, 120);
  31. this.$message({
  32. showClose: true,
  33. type: 'warning',
  34. message: '科室名称最多可输入120个字'
  35. })
  36. }
  37. callback();
  38. };
  39. return {
  40. id:null,
  41. form: {
  42. name: '',
  43. remark: '' //描述
  44. },
  45. rules: {
  46. name:[
  47. { required: true, validator: deptNameVaild, trigger: ['blur', 'change'] },
  48. { required: true, message: '请输入科室名称', trigger: ['blur', 'change'] }
  49. ],
  50. },
  51. text:'确定添加',
  52. topInfo:'icss科室维护系统-添加科室',
  53. toast:'添加成功'
  54. }
  55. },
  56. created(){
  57. let deptInfo = this.$route.params;
  58. if(deptInfo.info){
  59. this.text = "确定修改";
  60. this.topInfo = "icss科室维护系统-修改科室";
  61. this.toast = "修改成功";
  62. this.form.name = deptInfo.info.name;
  63. this.form.remark = deptInfo.info.remark;
  64. this.id = deptInfo.info.id;
  65. }
  66. },
  67. methods: {
  68. addOrga() {
  69. this.$refs.form.validate((valid)=> {
  70. if (valid) {
  71. // 有id是修改,没有id是添加
  72. if(this.id){
  73. let param = {
  74. id:this.id,
  75. name:this.form.name,
  76. remark:this.form.remark
  77. }
  78. api.modifDeptInfo(param).then((res) => {
  79. if (res.data.code == '0') {
  80. this.$message({showClose: true,message: this.toast, type: 'success'});
  81. this.$router.push({path: 'LT-YXSJWH-KSWH'});
  82. } else {
  83. this.$message({
  84. showClose: true,
  85. message: res.data.msg,
  86. type: 'warning'
  87. });
  88. }
  89. }).catch((error) => {
  90. this.$message({
  91. showClose: true,
  92. message: "服务器正忙...",
  93. type: 'warning'
  94. });
  95. })
  96. }else{
  97. api.addDeptInfo(this.form).then((res) => {
  98. if (res.data.code == '0') {
  99. this.$message({showClose: true,message: this.toast, type: 'success'});
  100. this.$router.push({path: 'LT-YXSJWH-KSWH'});
  101. } else {
  102. this.$message({
  103. showClose: true,
  104. message: res.data.msg,
  105. type: 'warning'
  106. });
  107. }
  108. }).catch((error) => {
  109. this.$message({
  110. showClose: true,
  111. message: "服务器正忙...",
  112. type: 'warning'
  113. });
  114. })
  115. }
  116. }
  117. });
  118. },
  119. back(){
  120. this.$router.go(-1);
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="less" scoped>
  126. @import "../../less/admin.less";
  127. .add-admin-form {
  128. background: #fff;
  129. padding: 20px 10px 30px;
  130. &
  131. > div {
  132. margin-left: 9px;
  133. }
  134. }
  135. .el-button{
  136. margin: 30px 0 0 20px;
  137. }
  138. .contents{
  139. position: relative;
  140. .back{
  141. position: absolute;
  142. top: 10px;
  143. left: 5px;
  144. z-index: 7;
  145. cursor: pointer;
  146. }
  147. }
  148. .desc{
  149. padding-left: 39px;
  150. }
  151. .el-textarea{
  152. width: 90%;
  153. }
  154. </style>