e6a9588565954743a4f15b38e06cfea67f7529bc.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <template>
  2. <a-modal
  3. :title="title"
  4. :width="800"
  5. :visible="visible"
  6. :maskClosable="false"
  7. :confirmLoading="confirmLoading"
  8. @ok="handleOk"
  9. @cancel="handleCancel"
  10. cancelText="关闭">
  11. <a-spin :spinning="confirmLoading">
  12. <a-form-model ref="form" :model="model" :rules="validatorRules">
  13. <a-form-model-item
  14. :labelCol="labelCol"
  15. :wrapperCol="wrapperCol"
  16. prop="code"
  17. required
  18. label="职务编码">
  19. <a-input placeholder="请输入职务编码" v-model="model.code" :read-only="readOnly"/>
  20. </a-form-model-item>
  21. <a-form-model-item
  22. :labelCol="labelCol"
  23. :wrapperCol="wrapperCol"
  24. prop="name"
  25. required
  26. label="职务名称">
  27. <a-input placeholder="请输入职务名称" v-model="model.name"/>
  28. </a-form-model-item>
  29. <a-form-model-item
  30. :labelCol="labelCol"
  31. :wrapperCol="wrapperCol"
  32. prop="postRank"
  33. required
  34. label="职级"
  35. >
  36. <j-dict-select-tag
  37. placeholder="请选择职级"
  38. dictCode="position_rank"
  39. v-model="model.postRank"
  40. />
  41. </a-form-model-item>
  42. </a-form-model>
  43. </a-spin>
  44. </a-modal>
  45. </template>
  46. <script>
  47. import pick from 'lodash.pick'
  48. import { httpAction } from '@/api/manage'
  49. import { duplicateCheck } from '@/api/api'
  50. import JDictSelectTag from '@/components/dict/JDictSelectTag'
  51. let validatorCodeTimer = null
  52. export default {
  53. name: 'SysPositionModal',
  54. components: { JDictSelectTag },
  55. data() {
  56. return {
  57. title: '操作',
  58. visible: false,
  59. model: {},
  60. labelCol: {
  61. xs: { span: 24 },
  62. sm: { span: 5 },
  63. },
  64. wrapperCol: {
  65. xs: { span: 24 },
  66. sm: { span: 16 },
  67. },
  68. confirmLoading: false,
  69. validatorRules: {
  70. code: [
  71. { required: true, message: '请输入职务编码' },
  72. {
  73. validator: (rule, value, callback) => {
  74. // 函数消抖的简单实现,防止一段时间内发送多次请求
  75. if (validatorCodeTimer) {
  76. // 停止上次开启的定时器
  77. clearTimeout(validatorCodeTimer)
  78. }
  79. validatorCodeTimer = setTimeout(() => {
  80. duplicateCheck({
  81. tableName: 'sys_position',
  82. fieldName: 'code',
  83. fieldVal: value,
  84. dataId: this.model.id
  85. }).then((res) => {
  86. if (res.success) {
  87. callback()
  88. } else {
  89. callback(res.message)
  90. }
  91. }).catch(console.error)
  92. }, 300)
  93. }
  94. }
  95. ],
  96. name: [{ required: true, message: '请输入职务名称' }] ,
  97. postRank: [{ required: true, message: '请选择职级' }] ,
  98. },
  99. url: {
  100. add: '/sys/position/add',
  101. edit: '/sys/position/edit',
  102. },
  103. readOnly:false
  104. }
  105. },
  106. created() {
  107. },
  108. methods: {
  109. add() {
  110. this.edit({})
  111. },
  112. edit(record) {
  113. this.model = Object.assign({}, record)
  114. this.visible = true
  115. if(record.id){
  116. this.readOnly=true
  117. }else{
  118. this.readOnly=false
  119. }
  120. },
  121. close() {
  122. this.$emit('close')
  123. this.visible = false
  124. this.$refs.form.resetFields();
  125. },
  126. handleOk() {
  127. const that = this
  128. // 触发表单验证
  129. this.$refs.form.validate(valid => {
  130. if (valid) {
  131. that.confirmLoading = true
  132. let httpurl = ''
  133. let method = ''
  134. if (!this.model.id) {
  135. httpurl += this.url.add
  136. method = 'post'
  137. } else {
  138. httpurl += this.url.edit
  139. //method = 'put'
  140. }
  141. httpAction(httpurl, this.model, method).then((res) => {
  142. if (res.success) {
  143. that.$message.success(res.message)
  144. that.$emit('ok')
  145. } else {
  146. that.$message.warning(res.message)
  147. }
  148. }).finally(() => {
  149. that.confirmLoading = false
  150. that.close()
  151. })
  152. }else{
  153. return false;
  154. }
  155. })
  156. },
  157. handleCancel() {
  158. this.close()
  159. },
  160. }
  161. }
  162. </script>
  163. <style lang="less" scoped>
  164. </style>