wuHanReimbursementBusinessForm.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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/treeUserDataAllOffice?type=2`"
  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="年份" prop="year" :rules="[{required: true, message: '年份不能为空', trigger: 'blur'}]">
  29. <el-select v-model="inputForm.year" @change="selectYear(inputForm.year)" style="width:100%" placeholder="请选择">
  30. <el-option
  31. v-for="year in yearList"
  32. :key="year.id"
  33. :label="year.year"
  34. :value="year.year">
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="12" v-if="method !== 'read'">
  40. <el-form-item label="报销类型" prop="reimbursementType"
  41. :rules="[
  42. {required: true, message:'报销类型不能为空', trigger:'blur'}
  43. ]">
  44. <el-radio-group v-model="inputForm.reimbursementType">
  45. <el-radio v-for="item in $dictUtils.getDictList('reimbursement_type')" @change="selectReimbursementType(inputForm.reimbursementType)" :label="item.value" :key="item.id">{{item.label}}</el-radio>
  46. </el-radio-group>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="12" v-if="this.show">
  50. <el-form-item label="报销天数" prop="reimbursementDay" :rules="[{required: true, max: 10, message:'报销天数不能为空且只可为整数', trigger:'blur'}]">
  51. <el-input v-model="inputForm.reimbursementDay" class="bg-grey" size="small" placeholder="报销天数" style="width: 100%;" @keyup.native="inputForm.reimbursementDay = checkInputs(inputForm.reimbursementDay)"></el-input>
  52. </el-form-item>
  53. </el-col>
  54. <el-col :span="12" v-if="this.show">
  55. <el-form-item label="剩余报销天数" prop="surplusReimbursementDay" :rules="[{ max: 10, trigger:'blur'}]">
  56. <el-input v-model="inputForm.surplusReimbursementDay" class="bg-grey" size="small" placeholder="剩余报销天数" style="width: 100%;" :disabled="true"></el-input>
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="12">
  60. <el-form-item label="报销金额" prop="reimbursementAmount":rules="[{required: true, max: 10, message:'报销金额不可为空', max: 10,trigger:'blur'}]">
  61. <el-input id="reimbursementAmount" v-model="inputForm.reimbursementAmount" class="bg-grey" size="small" placeholder="报销金额" style="width: 100%;" v-bind:disabled="this.show" @keyup.native="inputForm.reimbursementAmount = checkReimbursementAmount(inputForm.reimbursementAmount)">
  62.   </el-input>
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="12" v-if="this.show">
  66. <el-form-item label="日报销额度" prop="reimbursementQuotaDay":rules="[{max: 10,trigger:'blur'}]">
  67. <el-input v-model="inputForm.reimbursementQuotaDay" class="bg-grey" size="small" placeholder="日报销额度" style="width: 100%;" :disabled="true">
  68.   </el-input>
  69. </el-form-item>
  70. </el-col>
  71. <el-col :span="12">
  72. <el-form-item label="年报销额度" prop="reimbursementQuota":rules="[{max: 10,trigger:'blur'}]">
  73. <el-input v-model="inputForm.reimbursementQuota" class="bg-grey" size="small" placeholder="年报销额度" style="width: 100%;" :disabled="true">
  74.   </el-input>
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="12">
  78. <el-form-item label="剩余可报额度" prop="remainReimbursementAmount" :rules="[{max: 10, trigger:'blur'}]">
  79. <el-input v-model="inputForm.remainReimbursementAmount" class="bg-grey" size="small" placeholder="剩余可报额度" style="width: 100%;" :disabled="true">
  80.   </el-input>
  81. </el-form-item>
  82. </el-col>
  83. <el-col :span="12">
  84. <el-form-item label="业务可报额度" prop="canReimbursementAmount" :rules="[{max: 10, trigger:'blur'}]">
  85. <el-input v-model="inputForm.canReimbursementAmount" class="bg-grey" size="small" placeholder="业务可报额度" style="width: 100%;" :disabled="true">
  86.   </el-input>
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="12">
  90. <el-form-item label="业务剩余可报额度" prop="surplusReimbursementAmount" :rules="[{max: 10, trigger:'blur'}]">
  91. <el-input v-model="inputForm.surplusReimbursementAmount" class="bg-grey" size="small" placeholder="业务剩余可报额度" style="width: 100%;" :disabled="true">
  92.   </el-input>
  93. </el-form-item>
  94. </el-col>
  95. <el-col :span="24">
  96. <el-form-item label="备注" prop="remarks" :rules="[{max: 255, trigger:'blur'}]">
  97. <el-input type="textarea" v-model="inputForm.remarks" oninput="if(value.length>255)value=value.slice(0,254)" placeholder="备注" > </el-input>
  98. </el-form-item>
  99. </el-col>
  100. </el-row>
  101. </el-form>
  102. <span slot="footer" class="dialog-footer">
  103. <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
  104. <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
  105. </span>
  106. </el-dialog>
  107. </template>
  108. <script>
  109. import SelectUserTree from './treeReimbursementBuinessUserSelect'
  110. import ReimbursementBusiness from '@/api/reimbursementSys/wuHanReimbursementBusinessService'
  111. export default {
  112. data () {
  113. return {
  114. show: false,
  115. visible: false,
  116. loading: false,
  117. title: '',
  118. method: '',
  119. yearList: [],
  120. inputForm: {
  121. id: '',
  122. userId: '', // 人员id
  123. year: '', // 年份
  124. reimbursementType: '', // 报销类型
  125. reimbursementQuota: '', // 年报销额度
  126. reimbursementAmount: '', // 报销金额
  127. reimbursementQuotaDay: '', // 日报销额度
  128. canReimbursementAmount: '', // 业务可报销额度
  129. surplusReimbursementAmount: '', // 业务剩余可报销额度
  130. reimbursementDay: '', // 报销天数
  131. surplusReimbursementDay: '', // 剩余报销天数
  132. oldSurplusReimbursementDay: '', // 剩余报销天数(比较数据)
  133. remarks: '' // 备注
  134. }
  135. }
  136. },
  137. ReimbursementBusiness: null,
  138. created () {
  139. this.reimbursementBusiness = new ReimbursementBusiness()
  140. },
  141. mounted () {
  142. },
  143. components: {
  144. SelectUserTree
  145. },
  146. provide () {
  147. return {
  148. say: this.say
  149. }
  150. },
  151. methods: {
  152. checkInputs: function (num) {
  153. let str = num.toString()
  154. var len1 = str.substr(0, 1)
  155. var len2 = str.substr(1, 1)
  156. // eslint-disable-next-line eqeqeq
  157. if (str.length > 1 && len1 == 0 && len2 != '.') {
  158. str = str.substr(1, 1)
  159. }
  160. // eslint-disable-next-line eqeqeq
  161. if (len1 == '.') {
  162. str = ''
  163. }
  164. // eslint-disable-next-line no-useless-escape
  165. str = str.replace(/[^\d^]+/g, '') // 保留数字
  166. // 获取日报销额度
  167. let reimbursementQuotaDayNumber = this.inputForm.reimbursementQuotaDay
  168. if (reimbursementQuotaDayNumber) {
  169. var oldSurplusReimbursementDay = this.inputForm.oldSurplusReimbursementDay
  170. this.inputForm.reimbursementAmount = (str * reimbursementQuotaDayNumber).toString()
  171. this.inputForm.surplusReimbursementDay = (oldSurplusReimbursementDay - str).toString()
  172. }
  173. return str
  174. },
  175. checkReimbursementAmount: function (num) {
  176. let str = num.toString()
  177. var len1 = str.substr(0, 1)
  178. var len2 = str.substr(1, 1)
  179. // eslint-disable-next-line eqeqeq
  180. if (str.length > 1 && len1 == 0 && len2 != '.') {
  181. str = str.substr(1, 1)
  182. }
  183. // eslint-disable-next-line eqeqeq
  184. if (len1 == '.') {
  185. str = ''
  186. }
  187. // eslint-disable-next-line eqeqeq
  188. if (str.indexOf('.') != -1) {
  189. var str_ = str.substr(str.indexOf('.') + 1)
  190. // eslint-disable-next-line eqeqeq
  191. if (str_.indexOf('.') != -1) {
  192. str = str.substr(0, str.indexOf('.') + str_.indexOf('.') + 1)
  193. }
  194. if (str_.length > 2) {
  195. this.$message.warning(`金额小数点后只能输入两位,请正确输入!`)
  196. return (str = '')
  197. }
  198. }
  199. // eslint-disable-next-line no-useless-escape
  200. str = str.replace(/[^\d^\.]+/g, '') // 保留数字和小数点
  201. return str
  202. },
  203. say (userId) {
  204. // 根据用户id查询年份信息
  205. this.reimbursementBusiness.yearList({userId: userId, current: 1, size: -1}).then(({data}) => {
  206. this.yearList = data.records
  207. if (this.yearList.length > 0) {
  208. this.inputForm.year = this.yearList[0].year
  209. this.inputForm.reimbursementQuotaDay = this.yearList[0].reimbursementQuotaDay
  210. this.inputForm.reimbursementQuota = this.yearList[0].reimbursementQuota
  211. this.inputForm.remainReimbursementAmount = this.yearList[0].remainReimbursementAmount
  212. this.inputForm.surplusReimbursementDay = this.yearList[0].surplusReimbursementDay
  213. this.inputForm.oldSurplusReimbursementDay = this.yearList[0].surplusReimbursementDay
  214. // 获取日报销额度
  215. let reimbursementQuotaDayNumber = this.inputForm.reimbursementQuotaDay
  216. let reimbursementDayNumber = this.inputForm.reimbursementDay
  217. if (reimbursementQuotaDayNumber && reimbursementDayNumber) {
  218. var oldSurplusReimbursementDay = this.inputForm.oldSurplusReimbursementDay
  219. this.inputForm.reimbursementAmount = (reimbursementDayNumber * reimbursementQuotaDayNumber).toString()
  220. this.inputForm.surplusReimbursementDay = (oldSurplusReimbursementDay - reimbursementDayNumber).toString()
  221. }
  222. } else {
  223. this.inputForm.year = ''
  224. this.inputForm.reimbursementQuotaDay = ''
  225. this.inputForm.reimbursementQuota = ''
  226. this.inputForm.remainReimbursementAmount = ''
  227. this.inputForm.surplusReimbursementDay = ''
  228. this.inputForm.oldSurplusReimbursementDay = ''
  229. }
  230. })
  231. },
  232. selectReimbursementType (reimbursementType) {
  233. if (reimbursementType === '1') {
  234. // reimbursementAmount.isdisabled = true
  235. this.show = true
  236. } else {
  237. this.show = false
  238. }
  239. },
  240. selectYear (year) {
  241. for (var yearKey in this.yearList) {
  242. if (this.yearList[yearKey].year === year) {
  243. this.inputForm.reimbursementQuotaDay = this.yearList[yearKey].reimbursementQuotaDay
  244. this.inputForm.reimbursementQuota = this.yearList[yearKey].reimbursementQuota
  245. this.inputForm.remainReimbursementAmount = this.yearList[yearKey].remainReimbursementAmount
  246. // 获取日报销额度
  247. let reimbursementQuotaDayNumber = this.inputForm.reimbursementQuotaDay
  248. let reimbursementDayNumber = this.inputForm.reimbursementDay
  249. if (reimbursementQuotaDayNumber && reimbursementDayNumber) {
  250. this.inputForm.reimbursementAmount = (reimbursementDayNumber * reimbursementQuotaDayNumber).toString()
  251. }
  252. }
  253. }
  254. },
  255. init (method, obj) {
  256. this.method = method
  257. this.inputForm.businessCodeId = obj.businessCodeId
  258. this.inputForm.businessCode = obj.businessCode
  259. if (method === 'addBusinessInfo') {
  260. this.title = `新建报销信息`
  261. } else if (method === 'edit') {
  262. this.title = '修改人员信息'
  263. } else if (method === 'view') {
  264. this.title = '查看人员信息'
  265. }
  266. this.visible = true
  267. this.$nextTick(() => {
  268. this.inputForm.id = obj.id
  269. this.$refs['inputForm'].resetFields()
  270. if (method === 'edit' || method === 'view') { // 修改或者查看
  271. this.inputForm.id = obj
  272. this.loading = true
  273. this.reimbursementBusiness.queryById(this.inputForm.id).then(({data}) => {
  274. this.inputForm = this.recover(this.inputForm, data)
  275. this.selectReimbursementType(this.inputForm.reimbursementType)
  276. this.loading = false
  277. })
  278. }
  279. if (method === 'addBusinessInfo') { // 修改或者查看
  280. this.inputForm.businessCodeId = obj.businessCodeId
  281. this.loading = true
  282. this.reimbursementBusiness.getBusinessById(this.inputForm.businessCodeId).then(({data}) => {
  283. this.inputForm = this.recover(this.inputForm, data)
  284. this.selectReimbursementType(this.inputForm.reimbursementType)
  285. this.loading = false
  286. })
  287. }
  288. })
  289. },
  290. // 表单提交
  291. doSubmit () {
  292. this.$refs['inputForm'].validate((valid) => {
  293. if (valid) {
  294. this.loading = true
  295. this.inputForm.officeType = 1
  296. this.reimbursementBusiness.save(this.inputForm).then(({data}) => {
  297. this.loading = false
  298. this.visible = false
  299. this.$message.success(data)
  300. this.$emit('refreshDataList')
  301. }).catch(() => {
  302. this.loading = false
  303. })
  304. }
  305. })
  306. }
  307. }
  308. }
  309. </script>