123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- <template>
- <xn-form-container
- :title="formData.id ? '上传结款凭证' : '上传结款凭证'"
- :width="700"
- v-model:open="open"
- :destroy-on-close="true"
- @close="onClose"
- >
- <a-form ref="formRef" :model="formData" :rules="formRules" :wrapper-col="wrapperCol" :label-col="labelCol">
- <a-form-item label="发票信息:" >
- <p v-for="(item, index) in fileUploadInvoice" :key="index" style="margin-top:5px;">
- <a @click="downloadMaterial(item.url)" target="_blank">{{ item.name }}</a>
- </p>
- </a-form-item>
- <a-form-item label="上传结款凭证:" name="filePathList" :rules="[{ required: true, message: '请上传结款凭证' }]">
- <a-upload
- v-model:file-list="fileList"
- class="avatar-uploader"
- list-type="picture"
- :show-upload-list="true"
- :custom-request="customRequest"
- :remove="file => removeOtherFile(file,index)"
- :before-upload="beforeUpload"
- accept="image/png, image/jpeg, image/jpg"
- >
- <a-button>
- <upload-outlined></upload-outlined>
- upload
- </a-button>
- </a-upload>
- </a-form-item>
- <a-form-item label="驳回备注:" name="settleReason">
- <a-textarea
- v-model:value="formData.settleReason"
- placeholder="请输入驳回备注"
- :maxlength="200"
- show-count
- />
- </a-form-item>
- </a-form>
- <template #footer>
- <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
- <a-button style="margin-right: 8px" @click="reject" type="primary" danger>驳回</a-button>
- <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
- </template>
- </xn-form-container>
- </template>
- <script setup name="bizRecordForm">
- import { cloneDeep } from 'lodash-es'
- import { required } from '@/utils/formRules'
- import bizSettleApi from "@/api/biz/bizSettleApi";
- import fileApi from '@/api/dev/fileApi'
- import sysConfig from "@/config";
- import {message, Modal, Upload } from 'ant-design-vue';
- // 抽屉状态
- const open = ref(false)
- const emit = defineEmits({ successful: null })
- const formRef = ref()
- // 表单数据
- const formData = ref({filePathList:[],fileNameList:[]})
- const submitLoading = ref(false)
- //设置表单样式
- const labelCol = ref({ span: 5})
- const wrapperCol = ref({ span: 16})
- const fileList = ref([])
- const fileUploadInvoice = ref([])
- // 打开抽屉
- const onOpen = (record) => {
- open.value = true
- if (record) {
- let recordData = cloneDeep(record)
- formData.value = Object.assign({}, recordData)
- formData.value.filePathList = []
- formData.value.fileNameList = []
- fileList.value = []
- if (formData.value.fileInvoicePath) {
- for (var i = 0; i < formData.value.fileInvoicePath.split(',').length; i++) {
- fileUploadInvoice.value.push({
- url: sysConfig.PREVIEW_PATH + formData.value.fileInvoicePath.split(',')[i],
- name: formData.value.fileInvoiceName.split(',')[i]
- })
- }
- }
- }
- }
- // 关闭抽屉
- const onClose = () => {
- formRef.value.resetFields()
- formData.value = {}
- formData.value.fileNameList = []
- formData.value.filePathList = []
- fileList.value = []
- open.value = false
- fileUploadInvoice.value = []
- }
- const downloadMaterial = (url) => {
- window.open( url)
- }
- // 默认要校验的
- const formRules = {
- }
- // 验证并提交数据
- const onSubmit = () => {
- formRef.value
- .validate()
- .then(() => {
- if (
- formData.value.filePathList == [] ||
- formData.value.filePathList == '' ||
- formData.value.filePathList == null
- ) {
- message.warn('请上传发票')
- return
- }
- submitLoading.value = true
- const formDataParam = cloneDeep(formData.value)
- console.log("formData:"+formDataParam.filePahList)
- bizSettleApi
- .uploadVoucher(formDataParam)
- .then(() => {
- onClose()
- emit('successful')
- })
- .finally(() => {
- submitLoading.value = false
- })
- })
- .catch(() => {})
- }
- const reject = () => {
- if(formData.value.settleReason== '' || formData.value.settleReason==null){
- message.error('驳回时,备注信息不能为空')
- return
- }
- submitLoading.value = true
- const formDataParam = cloneDeep(formData.value)
- bizSettleApi.auditReject(formDataParam).then((res)=>{
- onClose()
- emit('successful')
- }).finally(() => {
- submitLoading.value = false
- })
- }
- const customRequest = (data) => {
- console.log("data:"+JSON.stringify(data.file.name))
- //保存图片
- const fileData = new FormData()
- fileData.append('file', data.file)
- fileApi
- .uploadImgMap(fileData)
- .then((result) => {
- formData.value.filePathList.push(result.imageFile)
- formData.value.fileNameList.push(data.file.name)
- }).finally(()=>{
- data.onSuccess()
- })
- }
- //文件删除
- const removeOtherFile = (file) => {
- fileList.value.forEach((item,index)=>{
- console.log(item.name+"======="+file.name)
- if(item.name === file.name){
- fileList.value.splice(index, 1);
- formData.value.filePathList.splice(index,1)
- formData.value.fileNameList.splice(index,1)
- }
- })
- }
- const beforeUpload = (file) => {
- const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
- if (!isJpgOrPng) {
- message.error('请上传JPG/PNG格式的图片!')
- }
- return isJpgOrPng || Upload.LIST_IGNORE
- }
- // 抛出函数
- defineExpose({
- onOpen
- })
- </script>
|