welfareEdit.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <template>
  2. <m-dialog ref="dialog" :title="itemData.subsidy ? '编辑' : '新增'" @sure="onSure">
  3. <m-form ref="form" v-model="formQuery" :items="items" v-loading="loading"></m-form>
  4. </m-dialog>
  5. </template>
  6. <script>
  7. import {
  8. saveWelfare,
  9. getWelfareDetail
  10. } from '@/api/welfare'
  11. export default {
  12. name: 'welfare-edit',
  13. data () {
  14. return {
  15. loading: false,
  16. formQuery: {
  17. subsidyName: null,
  18. subsidyTag: null
  19. },
  20. items: [
  21. {
  22. label: '福利名称',
  23. prop: 'subsidyName',
  24. type: 'input',
  25. rules: [
  26. { required: true, message: '请输入福利名称', trigger: 'blur' }
  27. ],
  28. options: {
  29. placeholder: '请输入福利名称'
  30. }
  31. },
  32. {
  33. label: '福利描述',
  34. prop: 'subsidyTag',
  35. type: 'input',
  36. options: {
  37. placeholder: '请输入福利名称'
  38. }
  39. }
  40. ],
  41. itemData: {}
  42. }
  43. },
  44. methods: {
  45. async open (item) {
  46. this.$refs.dialog.open()
  47. if (item) {
  48. this.formQuery.subsidyName = item.subsidyName
  49. this.formQuery.subsidyTag = item.subsidyTag
  50. this.loading = true
  51. try {
  52. const { data } = await getWelfareDetail({
  53. subsidyId: item.subsidyId
  54. })
  55. this.itemData = data
  56. } catch (error) {
  57. this.$message.error(error)
  58. } finally {
  59. this.loading = false
  60. }
  61. } else {
  62. this.formQuery.subsidyName = null
  63. this.formQuery.subsidyTag = null
  64. this.itemData = {}
  65. }
  66. },
  67. onSure () {
  68. this.$refs.form.validate(async valid => {
  69. if (valid) {
  70. const query = {
  71. subsidy: {
  72. subsidyId: this.itemData.subsidy?.subsidyId,
  73. ...this.formQuery
  74. },
  75. subsidyItems: this.itemData.subsidyItems ?? []
  76. }
  77. try {
  78. await saveWelfare(query)
  79. this.$refs.dialog.close()
  80. this.$emit('refresh')
  81. this.$message.success('保存成功')
  82. } catch (error) {
  83. this.$message.error(error)
  84. }
  85. }
  86. })
  87. }
  88. }
  89. }
  90. </script>
  91. <style lang="scss" scoped>
  92. </style>