uploadVoucher.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <xn-form-container
  3. :title="formData.id ? '上传结款凭证' : '上传结款凭证'"
  4. :width="700"
  5. v-model:open="open"
  6. :destroy-on-close="true"
  7. @close="onClose"
  8. >
  9. <a-form ref="formRef" :model="formData" :rules="formRules" :wrapper-col="wrapperCol" :label-col="labelCol">
  10. <a-form-item label="发票信息:" >
  11. <p v-for="(item, index) in fileUploadInvoice" :key="index" style="margin-top:5px;">
  12. <a @click="downloadMaterial(item.url)" target="_blank">{{ item.name }}</a>
  13. </p>
  14. </a-form-item>
  15. <a-form-item label="上传结款凭证:" name="filePathList" :rules="[{ required: true, message: '请上传结款凭证' }]">
  16. <a-upload
  17. v-model:file-list="fileList"
  18. class="avatar-uploader"
  19. list-type="picture"
  20. :show-upload-list="true"
  21. :custom-request="customRequest"
  22. :remove="file => removeOtherFile(file,index)"
  23. :before-upload="beforeUpload"
  24. accept="image/png, image/jpeg, image/jpg"
  25. >
  26. <a-button>
  27. <upload-outlined></upload-outlined>
  28. upload
  29. </a-button>
  30. </a-upload>
  31. </a-form-item>
  32. <a-form-item label="驳回备注:" name="settleReason">
  33. <a-textarea
  34. v-model:value="formData.settleReason"
  35. placeholder="请输入驳回备注"
  36. :maxlength="200"
  37. show-count
  38. />
  39. </a-form-item>
  40. </a-form>
  41. <template #footer>
  42. <a-button style="margin-right: 8px" @click="onClose">关闭</a-button>
  43. <a-button style="margin-right: 8px" @click="reject" type="primary" danger>驳回</a-button>
  44. <a-button type="primary" @click="onSubmit" :loading="submitLoading">保存</a-button>
  45. </template>
  46. </xn-form-container>
  47. </template>
  48. <script setup name="bizRecordForm">
  49. import { cloneDeep } from 'lodash-es'
  50. import { required } from '@/utils/formRules'
  51. import bizSettleApi from "@/api/biz/bizSettleApi";
  52. import fileApi from '@/api/dev/fileApi'
  53. import sysConfig from "@/config";
  54. import {message, Modal, Upload } from 'ant-design-vue';
  55. // 抽屉状态
  56. const open = ref(false)
  57. const emit = defineEmits({ successful: null })
  58. const formRef = ref()
  59. // 表单数据
  60. const formData = ref({filePathList:[],fileNameList:[]})
  61. const submitLoading = ref(false)
  62. //设置表单样式
  63. const labelCol = ref({ span: 5})
  64. const wrapperCol = ref({ span: 16})
  65. const fileList = ref([])
  66. const fileUploadInvoice = ref([])
  67. // 打开抽屉
  68. const onOpen = (record) => {
  69. open.value = true
  70. if (record) {
  71. let recordData = cloneDeep(record)
  72. formData.value = Object.assign({}, recordData)
  73. formData.value.filePathList = []
  74. formData.value.fileNameList = []
  75. fileList.value = []
  76. if (formData.value.fileInvoicePath) {
  77. for (var i = 0; i < formData.value.fileInvoicePath.split(',').length; i++) {
  78. fileUploadInvoice.value.push({
  79. url: sysConfig.PREVIEW_PATH + formData.value.fileInvoicePath.split(',')[i],
  80. name: formData.value.fileInvoiceName.split(',')[i]
  81. })
  82. }
  83. }
  84. }
  85. }
  86. // 关闭抽屉
  87. const onClose = () => {
  88. formRef.value.resetFields()
  89. formData.value = {}
  90. formData.value.fileNameList = []
  91. formData.value.filePathList = []
  92. fileList.value = []
  93. open.value = false
  94. fileUploadInvoice.value = []
  95. }
  96. const downloadMaterial = (url) => {
  97. window.open( url)
  98. }
  99. // 默认要校验的
  100. const formRules = {
  101. }
  102. // 验证并提交数据
  103. const onSubmit = () => {
  104. formRef.value
  105. .validate()
  106. .then(() => {
  107. if (
  108. formData.value.filePathList == [] ||
  109. formData.value.filePathList == '' ||
  110. formData.value.filePathList == null
  111. ) {
  112. message.warn('请上传发票')
  113. return
  114. }
  115. submitLoading.value = true
  116. const formDataParam = cloneDeep(formData.value)
  117. console.log("formData:"+formDataParam.filePahList)
  118. bizSettleApi
  119. .uploadVoucher(formDataParam)
  120. .then(() => {
  121. onClose()
  122. emit('successful')
  123. })
  124. .finally(() => {
  125. submitLoading.value = false
  126. })
  127. })
  128. .catch(() => {})
  129. }
  130. const reject = () => {
  131. if(formData.value.settleReason== '' || formData.value.settleReason==null){
  132. message.error('驳回时,备注信息不能为空')
  133. return
  134. }
  135. submitLoading.value = true
  136. const formDataParam = cloneDeep(formData.value)
  137. bizSettleApi.auditReject(formDataParam).then((res)=>{
  138. onClose()
  139. emit('successful')
  140. }).finally(() => {
  141. submitLoading.value = false
  142. })
  143. }
  144. const customRequest = (data) => {
  145. console.log("data:"+JSON.stringify(data.file.name))
  146. //保存图片
  147. const fileData = new FormData()
  148. fileData.append('file', data.file)
  149. fileApi
  150. .uploadImgMap(fileData)
  151. .then((result) => {
  152. formData.value.filePathList.push(result.imageFile)
  153. formData.value.fileNameList.push(data.file.name)
  154. }).finally(()=>{
  155. data.onSuccess()
  156. })
  157. }
  158. //文件删除
  159. const removeOtherFile = (file) => {
  160. fileList.value.forEach((item,index)=>{
  161. console.log(item.name+"======="+file.name)
  162. if(item.name === file.name){
  163. fileList.value.splice(index, 1);
  164. formData.value.filePathList.splice(index,1)
  165. formData.value.fileNameList.splice(index,1)
  166. }
  167. })
  168. }
  169. const beforeUpload = (file) => {
  170. const isJpgOrPng = file.type === 'image/jpeg' || file.type === 'image/png'
  171. if (!isJpgOrPng) {
  172. message.error('请上传JPG/PNG格式的图片!')
  173. }
  174. return isJpgOrPng || Upload.LIST_IGNORE
  175. }
  176. // 抛出函数
  177. defineExpose({
  178. onOpen
  179. })
  180. </script>