job-add-or-update.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible"
  6. width="600px">
  7. <el-form
  8. :rules="dataRule"
  9. :model="dataForm"
  10. ref="dataForm"
  11. @keyup.enter.native="dataFormSubmit()"
  12. label-width="80px"
  13. size="mini"
  14. style="margin-left: 20px;width: 500px">
  15. <el-form-item label="岗位名称" prop="jobName">
  16. <el-input v-model="dataForm.jobName"></el-input>
  17. </el-form-item>
  18. <el-form-item label="岗位代码" prop="jobCode">
  19. <el-input v-model="dataForm.jobCode"></el-input>
  20. </el-form-item>
  21. </el-form>
  22. <span slot="footer" class="dialog-footer">
  23. <el-button size="mini" @click="visible = false">关闭</el-button>
  24. <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
  25. </span>
  26. </el-dialog>
  27. </template>
  28. <script>
  29. export default {
  30. data () {
  31. return {
  32. visible: false,
  33. dataForm: {
  34. id: undefined,
  35. jobName: '',
  36. jobCode: ''
  37. },
  38. dataRule: {
  39. jobName: [
  40. { required: true, message: '岗位名称不能为空', trigger: 'blur' },
  41. { min: 1, max: 10, message: '长度在 1 到 10 个字符之间', trigger: ['blur', 'change'] }
  42. ],
  43. jobCode: [
  44. { required: true, message: '岗位代码不能为空', trigger: 'blur' },
  45. { type: 'string' , message: '以GW开头,后接三位数字', pattern: /^GW[0-9]{3}$/ }
  46. ]
  47. }
  48. }
  49. },
  50. methods: {
  51. init (id) {
  52. this.visible = true
  53. this.$nextTick(() => {
  54. this.$refs['dataForm'].resetFields()
  55. })
  56. this.dataForm.id = id || undefined
  57. if (this.dataForm.id) {
  58. this.$http({
  59. url: this.$http.adornUrl(`/sys/job/info/${this.dataForm.id}`),
  60. method: 'get',
  61. params: this.$http.adornParams()
  62. }).then(({data}) => {
  63. console.log(data);
  64. if (data && data.code === 0) {
  65. this.dataForm.jobName = data.job.jobName
  66. this.dataForm.jobCode = data.job.jobCode
  67. }
  68. })
  69. }
  70. // this.$http({
  71. // url: this.$http.adornUrl('/sys/job/select'),
  72. // method: 'get',
  73. // params: this.$http.adornParams()
  74. // }).then(({data}) => {
  75. // this.roleList = data && data.code === 0 ? data.list : []
  76. // }).then(() => {
  77. // this.visible = true
  78. // this.$nextTick(() => {
  79. // this.$refs['dataForm'].resetFields()
  80. // })
  81. // }).then(() => {
  82. // if (this.dataForm.id) {
  83. // this.$http({
  84. // url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.id}`),
  85. // method: 'get',
  86. // params: this.$http.adornParams()
  87. // }).then(({data}) => {
  88. // if (data && data.code === 0) {
  89. // this.dataForm.userName = data.user.username
  90. // this.dataForm.salt = data.user.salt
  91. // this.dataForm.email = data.user.email
  92. // this.dataForm.mobile = data.user.mobile
  93. // this.dataForm.roleIdList = data.user.roleIdList
  94. // this.dataForm.status = data.user.status
  95. // }
  96. // })
  97. // }
  98. // })
  99. },
  100. // 表单提交
  101. dataFormSubmit () {
  102. this.$refs['dataForm'].validate((valid) => {
  103. if (valid) {
  104. this.$http({
  105. url: this.$http.adornUrl(`/sys/job/${!this.dataForm.id ? 'save' : 'update'}`),
  106. method: 'post',
  107. data: this.$http.adornData({
  108. 'id': this.dataForm.id || undefined,
  109. 'jobCode': this.dataForm.jobCode,
  110. 'jobName': this.dataForm.jobName
  111. })
  112. }).then(({data}) => {
  113. if (data && data.code === 0) {
  114. this.visible = false
  115. this.$emit('refreshDataList')
  116. this.$message({
  117. message: '操作成功',
  118. type: 'success',
  119. duration: 1500,
  120. // onClose: () => {
  121. // this.visible = false
  122. // this.$emit('refreshDataList')
  123. // }
  124. })
  125. } else {
  126. this.$message.error(data.msg)
  127. }
  128. })
  129. }
  130. })
  131. }
  132. }
  133. }
  134. </script>