AddDeptInfo.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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" :label-position="labelPosition" :model="form" :rules="rules" label-width="100px" class="add-admin-form">
  8. <el-form-item label="科室名称:" prop="name">
  9. <el-input v-model="form.name" placeholder="请输入科室名称" maxlength="30"></el-input>
  10. </el-form-item>
  11. <el-form-item label="描述:" prop="remark">
  12. <el-input type="textarea" :rows="3" placeholder="请输入科室描述" v-model="form.remark" maxlength="100"></el-input>
  13. </el-form-item>
  14. <el-button size="small" type="primary" @click="addOrga">{{text}}</el-button>
  15. </el-form>
  16. </div>
  17. </div>
  18. </template>
  19. <script>
  20. import api from '@api/icss.js';
  21. export default {
  22. name: 'AddDeptInfo',
  23. data(){
  24. const deptNameVaild = (rule, value, callback) => {
  25. if (!value) {
  26. return callback(new Error('请输入科室名称'));
  27. }
  28. if (value.length > 120) {
  29. this.form.name = value.substr(0, 120);
  30. this.$message({
  31. showClose: true,
  32. type: 'warning',
  33. message: '科室名称最多可输入120个字'
  34. })
  35. }
  36. callback();
  37. };
  38. return {
  39. id:null,
  40. labelPosition:'right',
  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. if(!this.form.name.trim()){
  72. this.$message({
  73. message: '科室名称不能为空',
  74. type: 'warning'
  75. });
  76. return
  77. }
  78. // 有id是修改,没有id是添加
  79. if(this.id){
  80. let param = {
  81. id:this.id,
  82. name:this.form.name.trim(),
  83. remark:this.form.remark
  84. }
  85. api.modifDeptInfo(param).then((res) => {
  86. if (res.data.code == '0') {
  87. this.$message({showClose: true,message: this.toast, type: 'success'});
  88. this.$router.push({path: 'LT-YXSJWH-KSWH'});
  89. } else {
  90. this.$message({
  91. showClose: true,
  92. message: res.data.msg,
  93. type: 'warning'
  94. });
  95. }
  96. }).catch((error) => {
  97. this.$message({
  98. showClose: true,
  99. message: "服务器正忙...",
  100. type: 'warning'
  101. });
  102. })
  103. }else{
  104. let params = {
  105. name:this.form.name.trim(),
  106. remark:this.form.remark
  107. }
  108. api.addDeptInfo(params).then((res) => {
  109. if (res.data.code == '0') {
  110. this.$message({showClose: true,message: this.toast, type: 'success'});
  111. this.$router.push({path: 'LT-YXSJWH-KSWH'});
  112. } else {
  113. this.$message({
  114. showClose: true,
  115. message: res.data.msg,
  116. type: 'warning'
  117. });
  118. }
  119. }).catch((error) => {
  120. this.$message({
  121. showClose: true,
  122. message: "服务器正忙...",
  123. type: 'warning'
  124. });
  125. })
  126. }
  127. }
  128. });
  129. },
  130. back(){
  131. this.$router.go(-1);
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="less" scoped>
  137. @import "../../less/admin.less";
  138. .add-admin-form {
  139. background: #fff;
  140. padding: 20px 10px 30px;
  141. &
  142. > div {
  143. margin-left: 9px;
  144. }
  145. }
  146. .el-button{
  147. margin: 30px 0 0 20px;
  148. }
  149. /* .contents{
  150. position: relative;
  151. .back{
  152. position: absolute;
  153. top: 10px;
  154. left: 5px;
  155. z-index: 7;
  156. cursor: pointer;
  157. }
  158. } */
  159. .el-textarea{
  160. width: 97%;
  161. }
  162. </style>