reimbursementUserForm.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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="120px" 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 prop="userId" :rules=" [{required: true, message: '人员不能为空', trigger: 'blur'}]" label="人员">
  12. <SelectUserTree
  13. ref="companyTree"
  14. :props="{
  15. value: 'id', // ID字段名
  16. label: 'name', // 显示名称
  17. children: 'children' // 子级字段名
  18. }"
  19. :url="`/sys/user/treeUserDataByOfficeName?type=2&officeName=兴光评估`"
  20. :value="inputForm.userId"
  21. :clearable="true"
  22. :accordion="true"
  23. :disabled="method==='edit'"
  24. @getValue="(value) => {inputForm.userId=value}"/>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="12">
  28. <el-form-item label="年份" id="year" prop="year"
  29. :rules="[
  30. {required: true, message:'年份不能为空', trigger:'blur'}
  31. ]">
  32. <el-date-picker
  33. v-model="inputForm.year"
  34. type="year"
  35. value-format="yyyy"
  36. style="width: 100%;"
  37. placeholder="选择年份">
  38. </el-date-picker>
  39. </el-form-item>
  40. </el-col>
  41. <el-col :span="12">
  42. <el-form-item label="日报销额度" id="reimbursementQuotaDay" prop="reimbursementQuotaDay":rules="[{required: true, max: 10, message:'日报销额度不能为空', trigger:'blur'}]">
  43. <el-input v-model="inputForm.reimbursementQuotaDay" @input="calculateReimbursementQuota(inputForm.reimbursementQuotaDay,inputForm.reimbursementAllDay)" class="bg-grey" size="small" placeholder="日报销额度" style="width: 100%;" @keyup.native="inputForm.reimbursementQuotaDay = checkInputs(inputForm.reimbursementQuotaDay)">
  44.   </el-input>
  45. </el-form-item>
  46. </el-col>
  47. <el-col :span="12">
  48. <el-form-item label="可报销天数" prop="reimbursementAllDay" :rules="[
  49. {required: true, message:'可报销天数不能为空', trigger:'blur'},
  50. {validator: validator.isNumber, trigger:'blur'}
  51. ]">
  52. <el-input-number v-model="inputForm.reimbursementAllDay" placeholder="可报销天数" @input="calculateReimbursementQuota(inputForm.reimbursementQuotaDay,inputForm.reimbursementAllDay)" :step="1" :min="1" :max="366" style="width: 100%;" ></el-input-number>
  53. </el-form-item>
  54. </el-col>
  55. <el-col :span="12">
  56. <el-form-item label="年报销额度" prop="reimbursementQuota":rules="[{required: true, max: 10, message:'年报销额度不能为空', trigger:'blur'}]">
  57. <el-input v-model="inputForm.reimbursementQuota" class="bg-grey" size="small" placeholder="年报销额度" style="width: 100%;" disabled>
  58.   </el-input>
  59. </el-form-item>
  60. </el-col>
  61. </el-row>
  62. </el-form>
  63. <span slot="footer" class="dialog-footer">
  64. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  65. <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
  66. </span>
  67. </el-dialog>
  68. </template>
  69. <script>
  70. import SelectUserTree from '@/views/modules/reimbursementSys/utils/treeReimbursementBuinessUserSelect.vue'
  71. import ReimbursementUser from '@/api/reimbursementSys/assess/user/reimbursementUserService'
  72. export default {
  73. data () {
  74. return {
  75. visible: false,
  76. loading: false,
  77. title: '',
  78. method: '',
  79. roleList: [],
  80. postList: [],
  81. inputForm: {
  82. id: '',
  83. userId: '', // 人员id
  84. year: '', // 年份
  85. reimbursementQuota: '', // 年报销额度
  86. reimbursementQuotaDay: '', // 日报销额度
  87. reimbursementAllDay: '' // 报销总天数
  88. }
  89. }
  90. },
  91. reimbursementUser: null,
  92. created () {
  93. this.reimbursementUser = new ReimbursementUser()
  94. },
  95. mounted () {
  96. },
  97. components: {
  98. SelectUserTree
  99. },
  100. methods: {
  101. checkInputs: function (num) {
  102. let str = num.toString()
  103. var len1 = str.substr(0, 1)
  104. var len2 = str.substr(1, 1)
  105. // eslint-disable-next-line eqeqeq
  106. if (str.length > 1 && len1 == 0 && len2 != '.') {
  107. str = str.substr(1, 1)
  108. }
  109. // eslint-disable-next-line eqeqeq
  110. if (len1 == '.') {
  111. str = ''
  112. }
  113. // eslint-disable-next-line eqeqeq
  114. if (str.indexOf('.') != -1) {
  115. var str_ = str.substr(str.indexOf('.') + 1)
  116. // eslint-disable-next-line eqeqeq
  117. if (str_.indexOf('.') != -1) {
  118. str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
  119. }
  120. if (str_.length > 2) {
  121. this.$message.warning(`金额小数点后只能输入两位,请正确输入!`)
  122. return (str = '')
  123. }
  124. }
  125. // eslint-disable-next-line no-useless-escape
  126. str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
  127. return str
  128. },
  129. calculateReimbursementQuota (reimbursementQuotaDay, reimbursementAllDay) {
  130. if (reimbursementQuotaDay && reimbursementAllDay) {
  131. if (!isNaN(reimbursementQuotaDay) && !isNaN(reimbursementAllDay)) {
  132. this.inputForm.reimbursementQuota = (reimbursementQuotaDay * reimbursementAllDay).toString()
  133. } else {
  134. this.inputForm.reimbursementQuota = ''
  135. }
  136. } else {
  137. this.inputForm.reimbursementQuota = ''
  138. }
  139. },
  140. init (method, obj) {
  141. this.method = method
  142. this.inputForm.id = obj
  143. if (method === 'add') {
  144. this.inputForm.id = obj.id
  145. this.title = `新建人员信息`
  146. } else if (method === 'edit') {
  147. this.title = '修改人员信息'
  148. } else if (method === 'view') {
  149. this.title = '查看人员信息'
  150. }
  151. this.visible = true
  152. this.$nextTick(() => {
  153. this.inputForm.id = obj.id
  154. this.$refs['inputForm'].resetFields()
  155. if (method === 'edit' || method === 'view') { // 修改或者查看
  156. this.inputForm.id = obj
  157. this.loading = true
  158. this.reimbursementUser.queryById(this.inputForm.id).then(({data}) => {
  159. this.inputForm = this.recover(this.inputForm, data)
  160. this.loading = false
  161. })
  162. } else if (method === 'add') {
  163. // 获取字典表中每日报销额度
  164. this.reimbursementUser.getReimbursementQuotaDay().then(({data}) => {
  165. this.inputForm = this.recover(this.inputForm, data)
  166. this.loading = false
  167. })
  168. }
  169. })
  170. },
  171. // 表单提交
  172. doSubmit () {
  173. this.$refs['inputForm'].validate((valid) => {
  174. if (valid) {
  175. this.loading = true
  176. this.reimbursementUser.save(this.inputForm).then(({data}) => {
  177. this.loading = false
  178. this.visible = false
  179. this.$message.success(data)
  180. this.$emit('refreshDataList')
  181. }).catch(() => {
  182. this.loading = false
  183. })
  184. }
  185. })
  186. }
  187. }
  188. }
  189. </script>