AddOrganization.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <!-- 添加机构信息 By_liucf -->
  2. <template>
  3. <div>
  4. <crumbs title="机构信息-添加机构" linkTo="organizationInfo">
  5. </crumbs>
  6. <div class="contents">
  7. <!--<img src="../../images/return.png" height="18" width="18" class="back" @click="back">-->
  8. <el-form ref="form" :model="form" :rules="rules" label-width="120" class="add-admin-form">
  9. <h4>基本信息</h4>
  10. <el-form-item label="机构名称:" prop="organizationName">
  11. <el-input v-model="form.organizationName" placeholder="请输入机构名称"></el-input>
  12. </el-form-item>
  13. <el-form-item label="机构负责人:" prop="principal" required>
  14. <el-input v-model="form.principal" placeholder="请输入机构负责人姓名"></el-input>
  15. </el-form-item>
  16. <el-form-item label="机构所在地:" prop="address" >
  17. <el-input v-model="form.address" placeholder="请输入机构所在地"></el-input>
  18. </el-form-item>
  19. <el-form-item label="机构属性:" prop="type">
  20. <el-select v-model="form.type" placeholder="请选择机构">
  21. <el-option v-for="item in orgList" :key="item.key" :label="item.name" :value="item.key">
  22. </el-option>
  23. </el-select>
  24. </el-form-item>
  25. <el-form-item label="下属机构数量:" prop="subNum">
  26. <el-input v-model="form.subNum" placeholder="请输入下属机构数量" @change="handleNumInput"></el-input>
  27. </el-form-item>
  28. <el-button size="small" type="primary" @click="addOrga">确定添加</el-button>
  29. </el-form>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. import adminApi from '@api/admin.js';
  35. import utils from '@api/utils.js';
  36. export default {
  37. name: 'AddOrganization',
  38. data(){
  39. const principalVaild = (rule, value, callback) => {
  40. if (!value) {
  41. return callback(new Error('请输入机构负责人'));
  42. }
  43. if (value.length > 10) {
  44. this.form.principal = value.substr(0, 10);
  45. this.$message({
  46. showClose: true,
  47. type: 'warning',
  48. message: '机构负责人最多可输入10个字'
  49. })
  50. }
  51. callback();
  52. };
  53. const addressVaild = (rule, value, callback) => {
  54. if (!value) {
  55. return callback(new Error('请输入机构所在地'));
  56. }
  57. if (value.length > 60) {
  58. this.form.address = value.substr(0, 60);
  59. this.$message({
  60. showClose: true,
  61. type: 'warning',
  62. message: '机构所在地最多可输入60个字'
  63. })
  64. }
  65. callback();
  66. };
  67. const organizationNameVaild = (rule, value, callback) => {
  68. if (!value) {
  69. return callback(new Error('请输入机构名称'));
  70. }
  71. if (value.length > 20) {
  72. this.form.organizationName = value.substr(0, 20);
  73. this.$message({
  74. showClose: true,
  75. type: 'warning',
  76. message: '机构名称最多可输入20个字'
  77. })
  78. }
  79. callback();
  80. };
  81. const subNumVaild = (rule, value, callback) => {
  82. const numReg = new RegExp(/[^\d]/g);
  83. if(numReg.test(value) || this.form.subNum < 0){
  84. this.form.subNum = null;
  85. }
  86. if (value && value.length > 5) {
  87. this.form.subNum = value.substr(0, 5);
  88. this.$message({
  89. showClose: true,
  90. type: 'warning',
  91. message: '下属机构数量超出最大限制'
  92. })
  93. }
  94. callback();
  95. };
  96. return {
  97. orgList:[],
  98. form: {
  99. principal: '',//负责人
  100. address: '',
  101. subNum: null,
  102. organizationName: '',
  103. type: ''
  104. },
  105. rules: {
  106. principal:[
  107. { validator: principalVaild, trigger: ['blur', 'change'] }
  108. ],
  109. address:[
  110. { required: true, validator: addressVaild, trigger: ['blur', 'change'] }
  111. ],
  112. organizationName:[
  113. { required: true, validator: organizationNameVaild, trigger: ['blur', 'change'] },
  114. { required: true, message: '请输入机构名称', trigger: ['blur', 'change'] }
  115. ],
  116. type:[
  117. { required: true, message: '请选择机构属性', trigger: ['blur', 'change'] }
  118. ],
  119. subNum: [
  120. { validator: subNumVaild, trigger: ['blur', 'change'] }
  121. ]
  122. }
  123. }
  124. },
  125. created() {
  126. const enumsList = JSON.parse(localStorage.getItem('enumsData'));
  127. this.orgList = enumsList.organizationTypeEnum;
  128. },
  129. methods: {
  130. handleNumInput(){//机构数量只能数字
  131. const numReg = new RegExp(/[^\d]/g);
  132. if(numReg.test(this.form.subNum) || this.form.subNum < 0){
  133. this.form.subNum = null;
  134. }
  135. },
  136. addOrga() {
  137. this.$refs.form.validate((valid)=> {
  138. if (valid) {
  139. adminApi.addOrganization(this.form).then((res) => {
  140. if (res.data.code == '0') {
  141. this.$message({showClose: true,message: "添加成功", type: 'success'});
  142. this.$router.push({path: 'LT-KHZX-JGXX'});
  143. } else {
  144. this.$message({
  145. showClose: true,
  146. message: res.data.msg,
  147. type: 'warning'
  148. });
  149. }
  150. }).catch((error) => {
  151. this.$message({
  152. showClose: true,
  153. message: "服务器正忙...",
  154. type: 'warning'
  155. });
  156. })
  157. }
  158. });
  159. },
  160. back(){
  161. this.$router.go(-1);
  162. },
  163. handleNumInput(){//机构数量只能数字
  164. const numReg = new RegExp(/[^\d]/g);
  165. if(numReg.test(this.form.subNum) || this.form.subNum < 0){
  166. this.form.subNum = null;
  167. }
  168. }
  169. }
  170. }
  171. </script>
  172. <style lang="less" scoped>
  173. @import "../../less/admin.less";
  174. .add-admin-form {
  175. background: #fff;
  176. padding: 20px 10px 30px;
  177. &
  178. > div {
  179. margin-left: 9px;
  180. }
  181. }
  182. h4 {
  183. text-indent: 20px;
  184. font-size: 15px;
  185. margin-bottom: 20px;
  186. }
  187. .el-button{
  188. margin: 30px 0 0 20px;
  189. }
  190. .el-dropdown{
  191. margin-bottom: 15px;
  192. }
  193. .contents{
  194. position: relative;
  195. .back{
  196. position: absolute;
  197. top: 10px;
  198. left: 5px;
  199. z-index: 7;
  200. cursor: pointer;
  201. }
  202. }
  203. </style>