zhouwx
昨天 5c907144472ab91d2f4c1d10b0651b60e832b239
src/views/build/conpanyFunctionConsult/companyInfo/overview/components/overviewDialog.vue
@@ -7,29 +7,19 @@
            :before-close="handleClose"
        >
            <el-form :model="state.noticeForm" size="default" ref="noticeRef" :rules="title === '新增' || title === '编辑' ? state.formRules : {}" label-width="110px" >
              <el-form-item label="企业名称:" prop="companyName" v-if="state.isAdmin">
                <el-select
                    v-model="state.noticeForm.companyName"
                    filterable
                    remote
                    :disabled="title == '查看' || title == '编辑' || !state.isAdmin"
                    @change="selectValue"
                    reserve-keyword
                    placeholder="请输入企业名称"
                    remote-show-suffix
                    :remote-method="getCompanyList"
                    style="width: 100%"
                >
              <el-form-item v-if="state.isAdmin" label="企业:" prop="companyId">
                <el-select v-model="state.noticeForm.companyId" placeholder="请选择" clearable filterable style="width: 100%" :disabled="title == '查看' || title == '编辑' || !state.isAdmin">
                  <el-option
                      v-for="item in state.companyList"
                      :key="item.id"
                      :label="item.name"
                      :value="item.name"
                  />
                      :value="item.id">
                  </el-option>
                </el-select>
              </el-form-item>
                <el-form-item label="企业概括:" v-if="showEditor"  required>
                    <t-editor style="width: 800px" ref="myEditor" :value="state.noticeForm.companySummary" ></t-editor>
                    <t-editor style="width: 800px" ref="myEditor" :toolbar="toolbar" :value="state.noticeForm.companySummary" ></t-editor>
                </el-form-item>
                <el-form-item label="企业概括:" v-else>
                    <div class="ql-container ql-snow" style="height: 500px;width: 100%;margin-top: 10px;" >
@@ -37,6 +27,14 @@
                            <div class="reviewTable" v-html="state.noticeForm.companySummary"  @click="showFile($event)"></div>
                        </div>
                    </div>
                </el-form-item>
                <el-form-item label="营业执照:" prop="filePath">
                  <el-upload accept=".jpg,.jpeg,.png,.pdf" :action="state.uploadUrl" :headers="state.header" method="post" :on-success="(res, uploadFile)=>handleAvatarSuccess(res, uploadFile)" :on-exceed="showTip" :limit='state.fileLimit' v-model:file-list="state.fileList" :before-upload="picSize" :on-remove="(file, uploadFiles)=>handleRemove(file, uploadFiles)" >
                    <el-button type="primary">点击上传</el-button>
                    <template #tip>
                      <div class="el-upload__tip">尺寸小于5M,最多可上传1张</div>
                    </template>
                  </el-upload>
                </el-form-item>
            </el-form>
            <template #footer v-if="!isReview">
@@ -61,12 +59,14 @@
import {addCom, editCom} from "@/api/companyInfo/overview";
import Cookies from "js-cookie";
import {getCompany} from "@/api/onlineEducation/company";
import {delPic} from "@/api/onlineEducation/banner";
const emit = defineEmits(["getList"]);
const dialogVisible = ref(false);
const title = ref("");
const toolbar = ref('fontsizeselect | undo redo')
const noticeRef = ref();
const fileList = ref([]);
const myEditor = ref();
@@ -77,35 +77,57 @@
        id: '',
        companySummary: '',
        companyId:null,
        companyName: ''
        companyName: '',
        filePath: '',
        fileName: ''
    },
    formRules:{
      companyName: [{ required: true, message: '请选择企业', trigger: 'blur' }],
      companyId: [{ required: true, message: '请选择企业', trigger: 'blur' }],
      companySummary: [{ required: true, message: '企业概况', trigger: 'blur' }],
      filePath: [{ required: true, message: '请上传营业执照', trigger: 'blur' }],
    },
  isAdmin: false,
  companyList: []
  companyList: [],
  uploadUrl: import.meta.env.VITE_APP_BASE_API + '/system/common/uploadFile',
  header: {
    Authorization: getToken()
  },
  fileLimit: 1,
  fileList: []
})
onMounted(() => {
});
const openDialog = async (type, value) => {
const openDialog = async (type, value,companyList) => {
    const userInfo = JSON.parse(Cookies.get('userInfo'))
    state.isAdmin = userInfo.userType === 0;
  if(state.isAdmin){
    await   getCompanyList()
    state.companyList = companyList
  }
    isReview.value = false;
    showEditor.value = false
    title.value = type === 'add' ? '新增' : type ==='edit' ? '编辑' : '查看' ;
    if(type === 'edit' || type === 'review') {
      Object.keys(state.noticeForm).forEach(key => {
        if (key in value) {
          state.noticeForm[key] = value[key]
        }
      })
      state.noticeForm.companySummary = value.companySummary
      state.noticeForm.id = value.id
      if(state.isAdmin){
        state.noticeForm.companyId = value.companyId
        state.noticeForm.companyName = value.companyName
      }
      if(value.filePath) {
        const obj = {
          url: value.filePath,
          name: value.fileName
        }
        state.fileList = [obj]
      }
    }
    if(type === 'review') {
@@ -158,31 +180,7 @@
        })
    }
}
const getCompanyList = async (val)=>{
  if(val){
    const queryParams = {
      name: val
    }
    const res = await getCompany(queryParams)
    if (res.code == 200) {
      state.companyList = res.data.list
    } else {
      ElMessage.warning(res.message)
    }
  }else {
    const queryParams = {
      pageSize: 10,
      pageNum: 1,
    }
    const res = await getCompany(queryParams)
    if (res.code == 200) {
      state.companyList = res.data.list
    } else {
      ElMessage.warning(res.message)
    }
  }
}
const onSubmit = async () => {
    state.noticeForm.companySummary = tinyMCE.activeEditor.getContent();
@@ -253,6 +251,7 @@
    }
    // reset()
  state.fileList = []
    state.companyList = []
    noticeRef.value.clearValidate();
    dialogVisible.value = false;
@@ -262,9 +261,62 @@
      id: '',
      companySummary: '',
      companyId:null,
      companyName: ''
      companyName: '',
      filePath: '',
      fileName: ''
    }
    state.fileList = []
}
const handleAvatarSuccess = (res, uploadFile) => {
  if(res.code == 200){
    state.noticeForm.fileName = res.data.originName
    state.noticeForm.filePath = res.data.path
  }else{
    state.fileList = []
    ElMessage({
      type: 'warning',
      message: '文件上传失败'
    })
  }
}
const showTip =()=>{
  ElMessage({
    type: 'warning',
    message: '超出文件上传数量'
  });
}
const picSize = async (rawFile) => {
  if(rawFile.size / 1024 / 1024 > 5){
    ElMessage({
      type: 'warning',
      message: '文件大小不能超过5M'
    });
    return false
  }
};
const handleRemove = async (file, uploadFiles) => {
  let path = state.noticeForm.filePath;
  await delPic({path: path}).then(res => {
    if(res.code == 200){
      // ElMessage({
      //   type: 'success',
      //   message: '文件已删除'
      // })
      state.noticeForm.filePath = ''
      state.noticeForm.fileName = ''
    }else{
      ElMessage({
        type: 'warning',
        message: res.message
      })
    }
  }).catch(() => {
    state.noticeForm.filePath = ''
  });
}
defineExpose({
    openDialog