| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <template>
- <a-modal v-model:visible="visible" title="上传" @ok="handleOk">
- <a-form
- :model="formState"
- :rules="rules"
- ref="formRef"
- layout="horizontal"
- :label-col="{ span: 7 }"
- :wrapper-col="{ span: 12 }"
- >
- <a-form-item label="公告标题" name="title">
- <a-input v-model:value="formState.title" placeholder="输入公告标题"/>
- </a-form-item>
- <a-form-item label="公告内容" name="content">
- <a-textarea v-model:value="formState.content" placeholder="输入公告内容"
- :auto-size="{ minRows: 5, maxRows: 8 }"/>
- </a-form-item>
- </a-form>
- </a-modal>
- </template>
- <script setup>
- import {reactive, ref} from 'vue'
- import resourceAuditApi from '@/api/resourceAudit.js'
- const collegeMajorOptions = ref([]) //院系
- const majorIdName = ref([]) //院系回显
- const majorOptions = ref([]) //专业
- const formRef = ref() //专业
- const mode = ref('add') //专业
- import {addItem, detail, editItem} from '@/api/notice'
- const visible = ref(false)
- const emit = defineEmits([ "handleAddItem" ])
- const formState = reactive({
- noticeId : undefined,
- title: undefined,
- content: undefined,
- })
- const rules = {
- title: [{required: true, message: '请输入标题', trigger: 'blur'}],
- content: [{required: true, message: '请输入内容', trigger: 'blur'}],
- }
- watch(
- () => visible.value,
- (newVal, oldVal) => {
- if (newVal == false && formRef.value) {
- formRef.value.resetFields()
- }
- },
- {deep: true, immediate: true}
- )
- const open = () => {
- visible.value = true
- mode.value = 'add'
- }
- const edit = (item) => {
- visible.value = true
- mode.value = 'edit'
- console.log('编辑内容',item)
- detail({noticeId : item.noticeId}).then((res)=>{
- if(res.code ==200){
- formState.noticeId = item.noticeId
- formState.content = res.data.content
- formState.title = res.data.title
- }
- })
- }
- const handleOk = (e) => {
- formRef.value.validate().then(() => {
- let json = JSON.parse(JSON.stringify(formState))
- if (mode.value == 'add') {
- addItem(json).then((res) => {
- if(res.code == 200){
- emit("handleAddItem")
- visible.value = false
- }
- })
- }
- if (mode.value == 'edit') {
- editItem(json).then((res) => {
- if(res.code == 200){
- emit("handleAddItem")
- visible.value = false
- }
- })
- }
- })
- // console.logckPoint.value = false
- }
- const getOrgTreeSelector = () => {
- resourceAuditApi
- .orgList()
- .then((res) => {
- console.log(res.data, '获取学院')
- collegeMajorOptions.value = res.data
- })
- .catch((err) => {
- console.log(err)
- })
- }
- const changeCollegeMajor = (value, selectedOptions) => {
- console.log('Selected:', value, selectedOptions)
- if (!value) {
- formState.collegeTwoId = ''
- // majorIdName.value = ''
- return false
- }
- formState.majorId = undefined
- // majorIdName.value = selectedOptions.map((it) => it.name).join('/')
- // formState.collegeId = value[0] || null
- // formState.collegeTwoId = value[1] || null
- // formState.collegeThreeId = value[2] || null
- // if (selectedOptions.length) {
- // 获取选中的最后一级
- // const lastSelected = selectedOptions[selectedOptions.length - 1]
- // formState.selectedCollegeMajor = {
- // id: lastSelected.id,
- // name: lastSelected.name,
- // fullPath: selectedOptions.map((opt) => opt.name).join(' / ')
- // }
- console.log(formState.collegeTwoId, '最后一级id')
- getCollegeMajor(formState.collegeTwoId)
- // }
- }
- const getCollegeMajor = (id) => {
- resourceAuditApi
- .zyselect({collegeId: id})
- .then((res) => {
- console.log(res.data, '专业下拉数据')
- majorOptions.value = res.data
- })
- .catch((err) => {
- console.log(err)
- })
- }
- onMounted(() => {
- // getOrgTreeSelector()
- })
- defineExpose({open,edit})
- </script>
|