reimbursementRatioForm.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <el-dialog
  3. :title="title"
  4. :close-on-click-modal="false"
  5. v-dialogDrag
  6. :visible.sync="visible">
  7. <el-form size="small" :model="inputForm" ref="inputForm" @keyup.enter.native="doSubmit()"
  8. label-width="80px" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'" @submit.native.prevent>
  9. <el-row :gutter="15">
  10. <el-col :span="12">
  11. <el-form-item label="业务编码" prop="businessCode" :rules=" [{required: true,max: 50, message: '业务编号不能为空', trigger: 'blur'}]">
  12. <el-input v-model="inputForm.businessCode" placeholder="业务编码" :disabled="true"></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="12">
  16. <el-form-item label="报销比例(%)" prop="reimbursementRatio":rules="[{required: true, max: 10, message:'报销比例不能为空', trigger:'blur'}]">
  17. <el-input v-model="inputForm.reimbursementRatio" class="bg-grey" size="small" placeholder="报销比例(%)" style="width: 100%;" @keyup.native="inputForm.reimbursementRatio = checkInputs(inputForm.reimbursementRatio)">
  18.   </el-input>
  19. </el-form-item>
  20. </el-col>
  21. </el-row>
  22. </el-form>
  23. <span slot="footer" class="dialog-footer">
  24. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  25. <el-button size="small" v-if="method != 'view'" type="primary" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
  26. </span>
  27. </el-dialog>
  28. </template>
  29. <script>
  30. import ReimbursementSys from '@/api/reimbursementSys/accountant/reimbursementSysService'
  31. export default {
  32. data () {
  33. return {
  34. title: '',
  35. method: '',
  36. visible: false,
  37. loading: false,
  38. inputForm: {
  39. id: '',
  40. name: '',
  41. parent: {
  42. id: ''
  43. },
  44. businessCode: '', // 业务编码
  45. reimbursementRatio: '' // 报销比例
  46. }
  47. }
  48. },
  49. reimbursementSys: null,
  50. created () {
  51. this.reimbursementSys = new ReimbursementSys()
  52. },
  53. methods: {
  54. checkInputs (num) {
  55. let str = num.toString()
  56. var len1 = str.substr(0, 1)
  57. var len2 = str.substr(1, 1)
  58. // eslint-disable-next-line eqeqeq
  59. if (str.length > 1 && len1 == 0 && len2 != '.') {
  60. str = str.substr(1, 1)
  61. }
  62. // eslint-disable-next-line eqeqeq
  63. if (len1 == '.') {
  64. str = ''
  65. }
  66. // eslint-disable-next-line eqeqeq
  67. if (str.indexOf('.') != -1) {
  68. var str_ = str.substr(str.indexOf('.') + 1)
  69. // eslint-disable-next-line eqeqeq
  70. if (str_.indexOf('.') != -1) {
  71. str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
  72. }
  73. if (str_.length > 2) {
  74. this.$message.warning(`金额小数点后只能输入两位,请正确输入!`)
  75. return (str = '')
  76. }
  77. }
  78. // eslint-disable-next-line no-useless-escape
  79. str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
  80. return str
  81. },
  82. init (method, obj) {
  83. this.method = method
  84. if (method === 'editBusinessRatio') {
  85. this.title = '修改报销比例'
  86. } else if (method === 'view') {
  87. this.title = '查看业务编码'
  88. }
  89. this.visible = true
  90. this.$nextTick(() => {
  91. this.$refs['inputForm'].resetFields()
  92. this.inputForm.id = obj.id
  93. this.inputForm.parent.id = obj.parent.id
  94. this.inputForm.parent.name = obj.parent.name
  95. if (method === 'editBusinessRatio' || method === 'view') { // 修改或者查看
  96. this.loading = true
  97. this.reimbursementSys.queryBusinessById(this.inputForm.id).then(({data}) => {
  98. this.inputForm = this.recover(this.inputForm, data)
  99. this.loading = false
  100. })
  101. }
  102. })
  103. },
  104. // 表单提交
  105. doSubmit () {
  106. this.$refs['inputForm'].validate((valid) => {
  107. if (valid) {
  108. this.loading = true
  109. this.reimbursementSys.updateReimbursementRatio(this.inputForm).then(({data}) => {
  110. this.loading = false
  111. this.$message({
  112. message: '操作成功',
  113. type: 'success',
  114. duration: 1500
  115. })
  116. this.visible = false
  117. this.$emit('refreshDataList')
  118. }).catch(() => {
  119. this.loading = false
  120. })
  121. }
  122. })
  123. }
  124. }
  125. }
  126. </script>