DialogView.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <a-modal v-model:visible="visible" title="上传" @ok="handleOk">
  3. <a-form
  4. :model="formState"
  5. :rules="rules"
  6. ref="formRef"
  7. layout="horizontal"
  8. :label-col="{ span: 7 }"
  9. :wrapper-col="{ span: 12 }"
  10. >
  11. <a-form-item label="公告标题" name="title">
  12. <a-input v-model:value="formState.title" placeholder="输入公告标题"/>
  13. </a-form-item>
  14. <a-form-item label="公告内容" name="content">
  15. <a-textarea v-model:value="formState.content" placeholder="输入公告内容"
  16. :auto-size="{ minRows: 5, maxRows: 8 }"/>
  17. </a-form-item>
  18. </a-form>
  19. </a-modal>
  20. </template>
  21. <script setup>
  22. import {reactive, ref} from 'vue'
  23. import resourceAuditApi from '@/api/resourceAudit.js'
  24. const collegeMajorOptions = ref([]) //院系
  25. const majorIdName = ref([]) //院系回显
  26. const majorOptions = ref([]) //专业
  27. const formRef = ref() //专业
  28. const mode = ref('add') //专业
  29. import {addItem, detail, editItem} from '@/api/notice'
  30. const visible = ref(false)
  31. const emit = defineEmits([ "handleAddItem" ])
  32. const formState = reactive({
  33. noticeId : undefined,
  34. title: undefined,
  35. content: undefined,
  36. })
  37. const rules = {
  38. title: [{required: true, message: '请输入标题', trigger: 'blur'}],
  39. content: [{required: true, message: '请输入内容', trigger: 'blur'}],
  40. }
  41. watch(
  42. () => visible.value,
  43. (newVal, oldVal) => {
  44. if (newVal == false && formRef.value) {
  45. formRef.value.resetFields()
  46. }
  47. },
  48. {deep: true, immediate: true}
  49. )
  50. const open = () => {
  51. visible.value = true
  52. mode.value = 'add'
  53. }
  54. const edit = (item) => {
  55. visible.value = true
  56. mode.value = 'edit'
  57. console.log('编辑内容',item)
  58. detail({noticeId : item.noticeId}).then((res)=>{
  59. if(res.code ==200){
  60. formState.noticeId = item.noticeId
  61. formState.content = res.data.content
  62. formState.title = res.data.title
  63. }
  64. })
  65. }
  66. const handleOk = (e) => {
  67. formRef.value.validate().then(() => {
  68. let json = JSON.parse(JSON.stringify(formState))
  69. if (mode.value == 'add') {
  70. addItem(json).then((res) => {
  71. if(res.code == 200){
  72. emit("handleAddItem")
  73. visible.value = false
  74. }
  75. })
  76. }
  77. if (mode.value == 'edit') {
  78. editItem(json).then((res) => {
  79. if(res.code == 200){
  80. emit("handleAddItem")
  81. visible.value = false
  82. }
  83. })
  84. }
  85. })
  86. // console.logckPoint.value = false
  87. }
  88. const getOrgTreeSelector = () => {
  89. resourceAuditApi
  90. .orgList()
  91. .then((res) => {
  92. console.log(res.data, '获取学院')
  93. collegeMajorOptions.value = res.data
  94. })
  95. .catch((err) => {
  96. console.log(err)
  97. })
  98. }
  99. const changeCollegeMajor = (value, selectedOptions) => {
  100. console.log('Selected:', value, selectedOptions)
  101. if (!value) {
  102. formState.collegeTwoId = ''
  103. // majorIdName.value = ''
  104. return false
  105. }
  106. formState.majorId = undefined
  107. // majorIdName.value = selectedOptions.map((it) => it.name).join('/')
  108. // formState.collegeId = value[0] || null
  109. // formState.collegeTwoId = value[1] || null
  110. // formState.collegeThreeId = value[2] || null
  111. // if (selectedOptions.length) {
  112. // 获取选中的最后一级
  113. // const lastSelected = selectedOptions[selectedOptions.length - 1]
  114. // formState.selectedCollegeMajor = {
  115. // id: lastSelected.id,
  116. // name: lastSelected.name,
  117. // fullPath: selectedOptions.map((opt) => opt.name).join(' / ')
  118. // }
  119. console.log(formState.collegeTwoId, '最后一级id')
  120. getCollegeMajor(formState.collegeTwoId)
  121. // }
  122. }
  123. const getCollegeMajor = (id) => {
  124. resourceAuditApi
  125. .zyselect({collegeId: id})
  126. .then((res) => {
  127. console.log(res.data, '专业下拉数据')
  128. majorOptions.value = res.data
  129. })
  130. .catch((err) => {
  131. console.log(err)
  132. })
  133. }
  134. onMounted(() => {
  135. // getOrgTreeSelector()
  136. })
  137. defineExpose({open,edit})
  138. </script>