department-add-or-update.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 :model="dataForm"
  8. :rules="dataRule"
  9. ref="dataForm"
  10. @keyup.enter.native="dataFormSubmit()"
  11. label-width="80px"
  12. size="mini"
  13. style="margin-left: 20px;width: 500px">
  14. <el-form-item label="部门名称" prop="departmentName">
  15. <el-input v-model="dataForm.departmentName"></el-input>
  16. </el-form-item>
  17. <el-form-item label="部门代码" prop="departmentCode">
  18. <el-input v-model="dataForm.departmentCode"></el-input>
  19. </el-form-item>
  20. <el-form-item label="负责人" prop="leader">
  21. <el-input v-model="dataForm.leader"></el-input>
  22. </el-form-item>
  23. </el-form>
  24. <span slot="footer" class="dialog-footer">
  25. <el-button size="mini" @click="visible = false">关闭</el-button>
  26. <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
  27. </span>
  28. </el-dialog>
  29. </template>
  30. <script>
  31. // import { treeDataTranslate } from '@/utils'
  32. export default {
  33. data () {
  34. return {
  35. visible: false,
  36. dataForm: {
  37. id: undefined,
  38. departmentCode: '',
  39. departmentName: '',
  40. leader: ''
  41. },
  42. dataRule: {
  43. departmentName: [
  44. { required: true, message: '部门名称不能为空', trigger: 'blur' },
  45. { min: 1, max: 10, message: '长度在 1 到 10 个字符之间', trigger: ['blur', 'change'] }
  46. ],
  47. departmentCode: [
  48. { required: true, message: '部门代码不能为空', trigger: 'blur' },
  49. { type: 'string' , message: '以BM开头,后接三位数字', pattern: /^BM[0-9]{3}$/ }
  50. ],
  51. leader: [
  52. { required: true, message: '部门负责人不能为空', trigger: 'blur' },
  53. { min: 1, max: 10, message: '长度在 1 到 10 个字符之间', trigger: ['blur', 'change'] }
  54. ]
  55. },
  56. tempKey: -666666, // 临时key, 用于解决tree半选中状态项不能传给后台接口问题. # 待优化
  57. gender: [
  58. {
  59. value: 1,
  60. label: '男'
  61. },
  62. {
  63. value: 2,
  64. label: '女'
  65. }
  66. ],
  67. // pastures: [], // 牧场select
  68. departments: [], // 部门select
  69. jobs: [], // 岗位select
  70. roleList: []
  71. }
  72. },
  73. methods: {
  74. // resetForm () {
  75. // this.dataForm.id = undefined
  76. // this.dataForm.departmentCode = ''
  77. // this.dataForm.departmentName = ''
  78. // this.dataForm.leader = ''
  79. // },
  80. init (id) {
  81. this.visible = true
  82. this.$nextTick(() => {
  83. this.$refs['dataForm'].resetFields()
  84. })
  85. // 在role.vue调用该方法
  86. this.dataForm.id = id || 0
  87. if (!this.dataForm.id) {
  88. return;
  89. }
  90. this.$http({
  91. url: this.$http.adornUrl(`/sys/department/info/${this.dataForm.id}`),
  92. method: 'get',
  93. params: this.$http.adornParams()
  94. }).then(({data}) => {
  95. this.dataForm.id = data.department.id
  96. this.dataForm.departmentCode = data.department.departmentCode
  97. this.dataForm.departmentName = data.department.departmentName
  98. this.dataForm.leader = data.department.leader
  99. })
  100. // this.$http({
  101. // url: this.$http.adornUrl("/management/pasture/findAll"),
  102. // method: "post"
  103. // }).then(async({ data }) => {
  104. // // 牧场select
  105. // data.all.forEach(pasture => {
  106. // let item = {
  107. // value: pasture.id,
  108. // label: pasture.name
  109. // }
  110. // this.pastures.push(item)
  111. // })
  112. // // 部门select
  113. // let departments = []
  114. // let departmentR = await this.$http({
  115. // url: this.$http.adornUrl("/sys/department/findAll"),
  116. // method: "get"
  117. // })
  118. // departmentR.data.departmentList && (departments = departmentR.data.departmentList)
  119. // departments.forEach(department => {
  120. // let item = {
  121. // value: department.departmentCode,
  122. // label: department.departmentName
  123. // }
  124. // this.departments.push(item)
  125. // })
  126. // // 岗位select
  127. // let jobs = []
  128. // let jobR = await this.$http({
  129. // url: this.$http.adornUrl("/sys/job/findAll"),
  130. // method: "get"
  131. // })
  132. // jobR.data.jobList && (jobs = jobR.data.jobList)
  133. // jobs.forEach(job => {
  134. // let item = {
  135. // value: job.jobCode,
  136. // label: job.jobName
  137. // }
  138. // this.jobs.push(item)
  139. // })
  140. // // 获取status
  141. // let roleR = await this.$http({
  142. // url: this.$http.adornUrl('/sys/role/select'),
  143. // method: 'get',
  144. // params: this.$http.adornParams()
  145. // })
  146. // this.roleList = roleR.data && roleR.data.code === 0 ? roleR.data.list : []
  147. // // 获取form的修改的东西
  148. // if (!this.dataForm.userId) {
  149. // return;
  150. // }
  151. // let formR = await this.$http({
  152. // url: this.$http.adornUrl(`/sys/user/info/${this.dataForm.userId}`),
  153. // method: 'get',
  154. // params: this.$http.adornParams()
  155. // })
  156. // // 修改操作:form表单完整
  157. // console.log(formR.data.user);
  158. // this.dataForm.username = formR.data.user.username
  159. // this.dataForm.sex = formR.data.user.sex
  160. // this.dataForm.birthday = formR.data.user.birthday
  161. // this.dataForm.mobile = formR.data.user.mobile
  162. // this.dataForm.email = formR.data.user.email
  163. // this.dataForm.farmId = formR.data.user.farmId
  164. // this.dataForm.departmentCode = formR.data.user.departmentCode
  165. // this.dataForm.jobCode = formR.data.user.jobCode
  166. // this.dataForm.address = formR.data.user.address
  167. // this.dataForm.remarks = formR.data.user.remarks
  168. // this.dataForm.roleIdList = formR.data.user.roleIdList
  169. // this.dataForm.status = formR.data.user.status
  170. // })
  171. },
  172. // 表单提交
  173. dataFormSubmit () {
  174. this.$refs['dataForm'].validate((valid) => {
  175. if (valid) {
  176. this.$http({
  177. url: this.$http.adornUrl(`/sys/department/${!this.dataForm.id ? 'save' : 'update'}`),
  178. method: 'post',
  179. data: this.$http.adornData({
  180. 'id': this.dataForm.id || undefined,
  181. 'departmentCode': this.dataForm.departmentCode,
  182. 'departmentName': this.dataForm.departmentName,
  183. 'leader': this.dataForm.leader
  184. })
  185. }).then(({data}) => {
  186. if (data && data.code === 0) {
  187. this.visible = false
  188. this.$emit('refreshDataList')
  189. this.$message({
  190. message: '操作成功',
  191. type: 'success',
  192. duration: 1500,
  193. // onClose: () => {
  194. // this.visible = false
  195. // this.$emit('refreshDataList')
  196. // }
  197. })
  198. this.visible = false
  199. } else {
  200. this.$message.error(data.msg)
  201. }
  202. })
  203. }
  204. })
  205. }
  206. }
  207. }
  208. </script>