InvoiceReimbursementUpLoadComponent.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. <!--文件上传组件-->
  2. <template>
  3. <div :key="uploadKey">
  4. <el-divider v-if="showDivider" content-position="left"><i class="el-icon-document"></i> {{ dividerName }}
  5. </el-divider>
  6. <el-upload ref="upload" style="display: inline-block; :show-header='status'" action="" :limit="999"
  7. :http-request="httpRequest" multiple :on-exceed="(files, fileList) => {
  8. $message.warning(`当前限制选择 999 个文件,本次选择了 ${files.length} 个文件,共选择了 ${files.length + fileList.length} 个文件`)
  9. }" :show-file-list="false" :before-upload="beforeUpload" :on-change="changes" :on-progress="uploadVideoProcess"
  10. :file-list="fileList">
  11. <template v-if="auth === 'view' && uploadFlag === false" #tip>
  12. <el-button :loading="loading" type="primary" size="default" :disabled="true"> 点击上传 </el-button>
  13. </template>
  14. <template v-else #trigger>
  15. <el-button :loading="loading" type="primary" size="default"> 点击上传 </el-button> <span
  16. style="margin-left: 20px;font-size:14px;font-weight:normal;color:red;" type="primary">
  17. 上传报销的数电发票xml文件</span>
  18. </template>
  19. </el-upload>
  20. <div style="height: calc(100% - 80px);margin-top: 10px">
  21. <!-- 进度条 -->
  22. <el-progress style="margin-left: 5em" v-if="progressFlag" :percentage="loadProgress"></el-progress>
  23. <el-table ref="uploadTable" v-loading="loading" :key="tableKey" :data="dataListNew">
  24. <el-table-column type="seq" width="40"></el-table-column>
  25. <el-table-column label="文件名称" prop="name" align="center">
  26. <template #default="scope">
  27. <div v-if="ifName(scope.row) === true">
  28. <el-image style="width: 30px; height: 30px;padding-top: 4px;" :src="scope.row.lsUrl"
  29. :preview-src-list="[scope.row.lsUrl]" :preview-teleported="true"></el-image>
  30. </div>
  31. <div v-else>
  32. <el-link type="primary" :underline="false" @click="showFile(scope.row)">{{ scope.row.name
  33. }}</el-link>
  34. </div>
  35. </template>
  36. </el-table-column>
  37. <el-table-column label="创建人" prop="createBy.name" align="center"></el-table-column>
  38. <el-table-column label="创建时间" prop="createTime" align="center"></el-table-column>
  39. <el-table-column label="文件大小" prop="size" align="center">
  40. <template #default="scope">
  41. {{ getSize(scope.row.size) }}
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="操作" width="200px" fixed="right" align="center">
  45. <template #default="scope">
  46. <el-button text type="primary" key="01" icon="el-icon-download" size="small"
  47. @click="toHref(scope.row)">下载</el-button>
  48. <el-button text type="primary" key="02" icon="el-icon-delete" size="small"
  49. @click="deleteById(scope.row, scope.$index, fileList)"
  50. :disabled="auth === 'view' && delFlag === false && createBy !== scope.row.createBy.name">删除</el-button>
  51. <!-- <el-button v-if="createBy===scope.row.createBy.name" type="text" icon="el-icon-delete" size="small" @click="deleteById(scope.row, scope.$index)" :disabled="auth==='view'&&delFlag === false">删除2</el-button>-->
  52. </template>
  53. </el-table-column>
  54. </el-table>
  55. </div>
  56. <!-- <el-image-viewer v-if="showViewer" :on-close="closeViewer" :url-list="[url]" :zIndex=9999></el-image-viewer>-->
  57. </div>
  58. </template>
  59. <script>
  60. // eslint-disable-next-line no-unused-vars
  61. import OSSSerivce, {
  62. httpRequest,
  63. // eslint-disable-next-line no-unused-vars
  64. handleRemove,
  65. fileNameInvoice,
  66. // eslint-disable-next-line no-unused-vars
  67. beforeAvatarUpload,
  68. exnameFix,
  69. // eslint-disable-next-line no-unused-vars
  70. openWindowOnUrl,
  71. // eslint-disable-next-line no-unused-vars
  72. toHref
  73. } from '@/api/sys/OSSService'
  74. // import ElImageViewer from 'element-ui/packages/image/src/image-viewer'
  75. import moment from 'moment'
  76. export default {
  77. data() {
  78. return {
  79. uploadKey: '',
  80. progressFlag: false,
  81. loadProgress: 0,
  82. fileList: [],
  83. dataList: [],
  84. oldDataList: [],
  85. dataListNew: [],
  86. url: '',
  87. showViewer: false,
  88. ossService: null,
  89. auth: '',
  90. directory: 'public',
  91. maxValue: 300,
  92. tableKey: '',
  93. fileLoading: true,
  94. dividerName: '',
  95. uploadFlag: false,
  96. delFlag: false,
  97. createBy: '',
  98. showDivider: true,
  99. loading: false,
  100. dataListLength: '',
  101. uploadDelFlag: false
  102. }
  103. },
  104. watch: {
  105. },
  106. created() {
  107. this.ossService = new OSSSerivce()
  108. },
  109. components: {
  110. // ElImageViewer
  111. },
  112. mounted() {
  113. window.onPreview = this.onPreview
  114. },
  115. methods: {
  116. /**
  117. * dividerName: 组件中divider的名称赋值
  118. * showDivider: ‘附件‘Divider是否展示
  119. * 注:值为空时,默认值为true
  120. * showDivider=false时 ‘附件‘Divider隐藏
  121. **/
  122. setDividerName(dividerName, showDivider) {
  123. if (this.commonJS.isNotEmpty(dividerName)) {
  124. this.dividerName = dividerName
  125. }
  126. if (this.commonJS.isNotEmpty(showDivider)) {
  127. if (showDivider === false) {
  128. this.showDivider = false
  129. } else {
  130. this.showDivider = true
  131. }
  132. } else {
  133. this.showDivider = true
  134. }
  135. },
  136. /**
  137. * 文件上传组件初始化
  138. * @param auth
  139. * auth的值为"view"时,不可上传/编辑文件
  140. * auth为其他值时,可上传/编辑文件
  141. * @param fileList 要显示到文件上传列表中的文件。
  142. * 注:文件必须要有url属性并且文件的url属性值必须是在oss中的路径值
  143. * 例:'/attachment-file/xxx/xxx/2022/9/08/xxx.jpg'
  144. * @param directory 要存放到oss的哪个文件夹下。
  145. * 注:值为空时,默认存放到"public"文件夹
  146. * @param maxValue 上传文件允许的最大值,单位:MB
  147. * 注:值为空时,默认值为300MB
  148. * @param dividerName 组件中divider的名称
  149. * 注:值为空时,默认值为‘附件’
  150. * @param uploadFlag ‘上传文件’按钮是否禁用
  151. * 注:值为空时,默认值为false
  152. * auth=view&&uploadFlag=false时 ‘上传文件’按钮禁用
  153. * @param delFlag ‘删除’按钮是否禁用
  154. * 注:值为空时,默认值为false
  155. * auth=view&&delFlag=false时 ‘删除’按钮禁用
  156. * @param showDivider ‘附件‘Divider是否展示
  157. * 注:值为空时,默认值为true
  158. * showDivider=false时 ‘附件‘Divider隐藏
  159. */
  160. async newUpload(auth, fileList, directory, maxValue, dividerName, uploadFlag, delFlag, showDivider) {
  161. this.uploadKey = Math.random()
  162. await this.fileLoadingFalse()
  163. if (this.commonJS.isEmpty(fileList)) {
  164. fileList = []
  165. this.fileLoading = true
  166. } else {
  167. this.dataListLength = fileList.length
  168. }
  169. if (this.commonJS.isEmpty(dividerName)) {
  170. this.dividerName = '附件'
  171. } else {
  172. this.dividerName = dividerName
  173. }
  174. if (directory !== undefined && directory !== null && directory !== '' && directory !== {}) {
  175. this.directory = directory
  176. } else {
  177. this.directory = 'public'
  178. }
  179. if (maxValue !== undefined && maxValue !== null && maxValue !== '' && maxValue !== 0) {
  180. this.maxValue = maxValue
  181. } else {
  182. this.maxValue = 300
  183. }
  184. this.auth = auth
  185. if (this.commonJS.isEmpty(uploadFlag)) {
  186. this.uploadFlag = false
  187. } else {
  188. if (uploadFlag !== true && uploadFlag !== false) {
  189. this.uploadFlag = false
  190. } else {
  191. this.uploadFlag = uploadFlag
  192. }
  193. }
  194. if (this.commonJS.isEmpty(delFlag)) {
  195. this.delFlag = false
  196. } else {
  197. if (delFlag !== true && delFlag !== false) {
  198. this.delFlag = false
  199. this.createBy = delFlag
  200. } else {
  201. this.delFlag = delFlag
  202. }
  203. }
  204. this.oldDataList = []
  205. for await (let item of fileList) {
  206. await this.ossService.getFileSizeByUrl(item.url).then((data) => {
  207. item.lsUrl = data.url
  208. item.size = data.size
  209. this.dataList.push(item)
  210. this.oldDataList.push(item)
  211. this.dataListNew.push(item)
  212. if (this.dataListNew.length === fileList.length) {
  213. this.fileLoading = true
  214. }
  215. })
  216. }
  217. // this.dataList = JSON.parse(JSON.stringify(fileList))
  218. // this.dataListNew = JSON.parse(JSON.stringify(fileList))
  219. if (this.commonJS.isEmpty(showDivider)) {
  220. this.showDivider = true
  221. } else {
  222. if (showDivider === false) {
  223. this.showDivider = false
  224. } else {
  225. this.showDivider = true
  226. }
  227. }
  228. },
  229. async httpRequest(file) {
  230. await httpRequest(file, fileNameInvoice(file), this.directory, this.maxValue)
  231. },
  232. async beforeUpload(file) {
  233. if (this.uploadDelFlag) {
  234. this.$message.warning('该文件已上传,请勿重复上传');
  235. this.uploadKey = Math.random()
  236. return true; // 取消上传
  237. } else {
  238. // 对文件进行判定
  239. const isXml = file.type === 'text/xml'; // 假设只接受 XML 文件
  240. if (!isXml) {
  241. this.$message.error('只能上传 XML 文件');
  242. return false; // 取消上传
  243. } else {
  244. try {
  245. //对上传的xml文件信息进行处理并通过后端接口进行解析返回到父页面进行调整
  246. const formBody = new FormData()
  247. formBody.append('file', file)
  248. await this.ossService.disposeXmlFile(formBody).then((data) => {
  249. if (Object.keys(data).length === 0) {
  250. this.$message.warning('上传的数电发票格式错误');
  251. this.loading = false;
  252. // 在验证失败时删除已经添加的行
  253. const index = this.fileList.findIndex(item => item.name === file.name);
  254. if (index !== -1) {
  255. this.deleteFileById(this.fileList[index], index, this.fileList);
  256. }
  257. } else {
  258. let parent = this.$parent
  259. while (!parent.invoiceReimbursementDispose) {
  260. parent = parent['$parent']
  261. }
  262. var flag = parent.invoiceReimbursementDispose(data)
  263. //var flag = this.$parent.invoiceReimbursementDispose(data);
  264. if (!flag) {
  265. this.httpRequest(file);
  266. } else {
  267. this.$message.error('发票号:' + data.InvoiceNumber + "已上传,请勿重复上传")
  268. // 在验证失败时删除已经添加的行
  269. const index = this.dataListNew.findIndex(item => item.name === file.name);
  270. if (index !== -1) {
  271. this.deleteFileById(this.dataListNew[index], index, this.dataListNew);
  272. }
  273. this.loading = false;
  274. }
  275. }
  276. })
  277. } catch (error) {
  278. console.error(error);
  279. }
  280. }
  281. // 其他判定逻辑...
  282. return true; // 允许上传
  283. }
  284. },
  285. handleOnDownToOss(row, url) {
  286. this.ossService.getFileSizeByUrl(url).then((data) => {
  287. let file = {
  288. lsUrl: data.url,
  289. size: data.size,
  290. createBy: {
  291. id: this.$store.state.user.id,
  292. name: this.$store.state.user.name,
  293. },
  294. createTime: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
  295. name: row.fileName,
  296. percentage: 100,
  297. status: "success",
  298. url: url
  299. }
  300. this.dataList.push(file)
  301. this.dataListNew.push(file)
  302. this.fileList.push(file)
  303. })
  304. },
  305. uploadVideoProcess(event, file, fileList) {
  306. let parent = this.$parent
  307. while (!parent.inputForm) {
  308. parent = parent['$parent']
  309. }
  310. var reimbursementType = parent.inputForm.reimbursementType
  311. this.progressFlag = true // 显示进度条
  312. this.loadProgress = parseInt(event.percent) // 动态获取文件上传进度
  313. if (this.loadProgress >= 100) {
  314. this.loadProgress = 100
  315. if ("1" === reimbursementType) {
  316. var fileName = file.raw.name;
  317. const spliceLength2 = fileName.lastIndexOf(".");
  318. var fileNameSuffix = fileName.slice(spliceLength2 + 1);
  319. let lowerFileNameSuffix = fileNameSuffix.toLowerCase();
  320. if (lowerFileNameSuffix === "xml") {
  321. //对上传的xml文件信息进行处理并通过后端接口进行解析返回到父页面进行调整
  322. const formBody = new FormData()
  323. formBody.append('file', file.raw)
  324. this.ossService.disposeXmlFile(formBody).then((data) => {
  325. if (Object.keys(data).length > 0) {
  326. parent.invoiceReimbursementDisposeData(data, file)
  327. } else {
  328. this.$message.warning('上传的数电发票格式错误')
  329. this.loading = false;
  330. // 在验证失败时删除已经添加的行
  331. const index = this.fileList.findIndex(item => item.name === file.name);
  332. if (index !== -1) {
  333. this.deleteFileById(this.fileList[index], index, this.fileList);
  334. }
  335. }
  336. })
  337. }
  338. }
  339. setTimeout(() => {
  340. this.progressFlag = false
  341. }, 1000) // 一秒后关闭进度条
  342. }
  343. },
  344. getSize(value) {
  345. if (this.commonJS.isEmpty(value)) {
  346. return '0 B'
  347. } else {
  348. let val = parseInt(value)
  349. if (this.commonJS.isEmpty(val)) {
  350. return '0 B'
  351. }
  352. if (isNaN(val)) {
  353. return '0 B'
  354. }
  355. if (val === 0) {
  356. return '0 B'
  357. }
  358. let k = 1024
  359. let sizes = ['B', 'KB', 'MB', 'GB', 'PB', 'TB', 'EB', 'ZB', 'YB']
  360. let i = Math.floor(Math.log(val) / Math.log(k))
  361. let result = val / Math.pow(k, i);
  362. let kb = parseFloat(result.toPrecision(3));
  363. return kb + '' + sizes[i]
  364. }
  365. },
  366. async changes(file, fileList) {
  367. this.uploadKey = Math.random()
  368. console.log(fileList)
  369. for (let i = 0; i < fileList.length; i++) {
  370. var fileItem = fileList[i];
  371. if (fileList[i].raw !== undefined && fileList[i].raw !== null && fileList[i].raw !== {}) {
  372. fileItem = fileList[i].raw;
  373. }
  374. const isXml = fileItem.type === 'text/xml'; // 假设只接受 XML 文件
  375. if (!isXml) {
  376. console.log("删除该文件")
  377. //fileList[i].remove()
  378. fileList.splice(i, 1);
  379. // Since the element is removed, decrease the index by 1 to adjust for the removed element
  380. i--;
  381. }
  382. }
  383. this.uploadDelFlag = false;
  384. // if (file.status !== 'ready') {
  385. // return
  386. // }
  387. if (!beforeAvatarUpload(file, fileList, this.maxValue)) {
  388. this.$message.error('文件大小不能超过 ' + this.maxValue + ' MB!')
  389. return
  390. }
  391. var verificationFileList = []
  392. if (this.oldDataList) {
  393. for (let item of this.oldDataList) {
  394. verificationFileList.push(item)
  395. }
  396. }
  397. for (let item of fileList) {
  398. verificationFileList.push(item)
  399. }
  400. var fileCount = 0;
  401. for (let item of verificationFileList) {
  402. var fileItem = item;
  403. if (item.raw !== undefined && item.raw !== null && item.raw !== {}) {
  404. fileItem = item.raw;
  405. }
  406. if (file.raw.name === fileItem.name) {
  407. fileCount++
  408. }
  409. }
  410. if (fileCount > 1) {
  411. this.uploadDelFlag = true;
  412. return
  413. }
  414. this.dataListNew = []
  415. this.dataList.forEach((item) => {
  416. this.dataListNew.push(item)
  417. })
  418. var fileListNames = []
  419. for (let fileItem of this.fileList) {
  420. fileListNames.push(fileItem.name)
  421. }
  422. for (let item of fileList) {
  423. if (fileListNames.length === 0 || fileListNames.indexOf(item.name) === -1) {
  424. this.fileList.push(item)
  425. }
  426. item.createTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  427. item.createBy = {
  428. id: '',
  429. name: ''
  430. }
  431. item.createBy.id = this.$store.state.user.id
  432. item.createBy.name = this.$store.state.user.name
  433. this.dataListNew.push(item)
  434. }
  435. for (let item of this.dataListNew) {
  436. if (item.raw !== undefined && item.raw !== null && item.raw !== {}) {
  437. item.url = item.raw.url
  438. if (item.raw.url !== undefined && item.raw.url !== null && item.raw.url !== {}) {
  439. this.ossService.getTemporaryUrl(item.raw.url).then((data) => {
  440. item.lsUrl = data
  441. })
  442. }
  443. }
  444. }
  445. },
  446. showFile(row) {
  447. openWindowOnUrl(row)
  448. },
  449. onPreview(url) {
  450. this.url = url
  451. this.showViewer = true
  452. },
  453. // 关闭查看器
  454. closeViewer() {
  455. this.url = ''
  456. this.showViewer = false
  457. },
  458. toHref(row) {
  459. toHref(row)
  460. },
  461. async deleteById(row, index, fileList) {
  462. console.log("dasfgasdas")
  463. // this.$refs.upload.handleRemove(this.dataListNew[index])
  464. await this.dataListNew.splice(index, 1)
  465. await this.dataList.splice(index, 1)
  466. if (this.commonJS.isNotEmpty(row.id)) {
  467. this.ossService.deleteMsgById(row.id)
  468. }
  469. var newFileList = [];
  470. for (var i = 0; i < fileList.length; i++) {
  471. if (fileList[i].name !== row.name) {
  472. newFileList.push(fileList[i])
  473. }
  474. }
  475. this.fileList = newFileList;
  476. let parent = this.$parent
  477. while (!parent.inputForm) {
  478. parent = parent['$parent']
  479. }
  480. var reimbursementType = parent.inputForm.reimbursementType
  481. if ("1" === reimbursementType) {
  482. var fileName = ''
  483. if (null === row.raw || undefined === row.raw) {
  484. fileName = row.name;
  485. } else {
  486. fileName = row.raw.name;
  487. }
  488. const spliceLength2 = fileName.lastIndexOf(".");
  489. var fileNameSuffix = fileName.slice(spliceLength2 + 1);
  490. let lowerFileNameSuffix = fileNameSuffix.toLowerCase();
  491. if (lowerFileNameSuffix === "xml") {
  492. //对上传的xml文件信息进行处理并通过后端接口进行解析返回到父页面进行调整
  493. const formBody = new FormData()
  494. if (null === row.raw || undefined === row.raw) {
  495. this.ossService.downLoadFileDisposeXmlFile(row.url).then((data) => {
  496. parent.deleteInvoiceReimbursementDisposeData(data)
  497. })
  498. } else {
  499. formBody.append('file', row.raw)
  500. this.ossService.disposeXmlFile(formBody).then((data) => {
  501. if (data) {
  502. parent.deleteInvoiceReimbursementDisposeData(data)
  503. } else {
  504. this.$message.warning('上传的数电发票格式错误')
  505. this.loading = false;
  506. // 在验证失败时删除已经添加的行
  507. const index = this.fileList.findIndex(item => item.name === file.name);
  508. if (index !== -1) {
  509. this.deleteFileById(this.fileList[index], index, this.fileList);
  510. }
  511. }
  512. })
  513. }
  514. }
  515. }
  516. },
  517. async deleteFileById(row, index, fileList) {
  518. // this.$refs.upload.handleRemove(this.dataListNew[index])
  519. await this.dataListNew.splice(index, 1)
  520. await this.dataList.splice(index, 1)
  521. if (this.commonJS.isNotEmpty(row.id)) {
  522. this.ossService.deleteMsgById(row.id)
  523. }
  524. var newFileList = [];
  525. for (var i = 0; i < fileList.length; i++) {
  526. if (fileList[i].name !== row.name) {
  527. newFileList.push(fileList[i])
  528. }
  529. }
  530. this.fileList = newFileList;
  531. let parent = this.$parent
  532. while (!parent.inputForm) {
  533. parent = parent['$parent']
  534. }
  535. var reimbursementType = parent.inputForm.reimbursementType
  536. if ("1" === reimbursementType) {
  537. var fileName = ''
  538. if (null === row.raw || undefined === row.raw) {
  539. fileName = row.name;
  540. } else {
  541. fileName = row.raw.name;
  542. }
  543. const spliceLength2 = fileName.lastIndexOf(".");
  544. var fileNameSuffix = fileName.slice(spliceLength2 + 1);
  545. let lowerFileNameSuffix = fileNameSuffix.toLowerCase();
  546. if (lowerFileNameSuffix === "xml") {
  547. //对上传的xml文件信息进行处理并通过后端接口进行解析返回到父页面进行调整
  548. const formBody = new FormData()
  549. if (null === row.raw || undefined === row.raw) {
  550. this.ossService.downLoadFileDisposeXmlFile(row.url).then((data) => {
  551. //parent.deleteInvoiceReimbursementDisposeData(data)
  552. })
  553. } else {
  554. formBody.append('file', row.raw)
  555. this.ossService.disposeXmlFile(formBody).then((data) => {
  556. if (data) {
  557. //parent.deleteInvoiceReimbursementDisposeData(data)
  558. } else {
  559. this.$message.warning('上传的数电发票格式错误')
  560. this.loading = false;
  561. // 在验证失败时删除已经添加的行
  562. const index = this.fileList.findIndex(item => item.name === file.name);
  563. if (index !== -1) {
  564. this.deleteFileById(this.fileList[index], index, this.fileList);
  565. }
  566. }
  567. })
  568. }
  569. }
  570. }
  571. },
  572. async parentDeleteById(row) {
  573. console.log('this.dataListNew', this.dataListNew)
  574. var index = null;
  575. for (var j = 0; j < this.dataListNew.length; j++) {
  576. if (this.dataListNew[j].name === row.name) {
  577. index = j;
  578. }
  579. }
  580. await this.dataListNew.splice(index, 1)
  581. await this.dataList.splice(index, 1)
  582. if (this.commonJS.isNotEmpty(row.id)) {
  583. this.ossService.deleteMsgById(row.id)
  584. }
  585. var newFileList = [];
  586. for (var i = 0; i < this.fileList.length; i++) {
  587. if (this.fileList[i].name !== row.name) {
  588. newFileList.push(this.fileList[i])
  589. }
  590. }
  591. this.fileList = newFileList;
  592. let parent = this.$parent
  593. while (!parent.inputForm) {
  594. parent = parent['$parent']
  595. }
  596. var reimbursementType = parent.inputForm.reimbursementType
  597. if ("1" === reimbursementType) {
  598. var fileName = ''
  599. if (null === row.raw || undefined === row.raw) {
  600. fileName = row.name;
  601. } else {
  602. fileName = row.raw.name;
  603. }
  604. const spliceLength2 = fileName.lastIndexOf(".");
  605. var fileNameSuffix = fileName.slice(spliceLength2 + 1);
  606. let lowerFileNameSuffix = fileNameSuffix.toLowerCase();
  607. if (lowerFileNameSuffix === "xml") {
  608. //对上传的xml文件信息进行处理并通过后端接口进行解析返回到父页面进行调整
  609. const formBody = new FormData()
  610. if (null === row.raw || undefined === row.raw) {
  611. this.ossService.downLoadFileDisposeXmlFile(row.url).then((data) => {
  612. parent.deleteInvoiceReimbursementDisposeData(data)
  613. })
  614. } else {
  615. formBody.append('file', row.raw)
  616. this.ossService.disposeXmlFile(formBody).then((data) => {
  617. parent.deleteInvoiceReimbursementDisposeData(data)
  618. })
  619. }
  620. }
  621. }
  622. },
  623. async deleteFileinfo(row) {
  624. var index = null;
  625. for (var j = 0; j < this.dataListNew.length; j++) {
  626. if (this.dataListNew[j].name === row.name) {
  627. index = j;
  628. }
  629. }
  630. await this.dataListNew.splice(index, 1)
  631. await this.dataList.splice(index, 1)
  632. var newFileList = [];
  633. for (var i = 0; i < this.fileList.length; i++) {
  634. if (this.fileList[i].name !== row.name) {
  635. newFileList.push(this.fileList[i])
  636. }
  637. }
  638. this.fileList = newFileList;
  639. },
  640. /**
  641. * 关闭dialog时使用 清除el-upload中上传的文件
  642. */
  643. clearUpload() {
  644. this.fileList = []//用于清除上传文件的缓存
  645. this.$refs.upload.clearFiles()
  646. this.dataList = []
  647. this.dataListNew = []
  648. this.createBy = ''
  649. },
  650. /**
  651. * 获取当前文件列表中的文件数据
  652. */
  653. getDataList() {
  654. return this.dataListNew
  655. },
  656. /**
  657. * 判断进度条是否结束,附件是否加载完成
  658. * @returns {boolean}
  659. */
  660. checkProgress() {
  661. if (this.progressFlag === true) {
  662. this.$message.warning('请等待附件上传完成再进行操作')
  663. return true
  664. }
  665. if (this.fileLoading === false) {
  666. this.$message.warning('请等待附件加载完成再进行操作')
  667. if (this.dataListLength === this.dataListNew.length) {
  668. this.fileLoading = true
  669. }
  670. return true
  671. }
  672. return false
  673. },
  674. ifName(row) {
  675. if (this.commonJS.isEmpty(row.name)) {
  676. row.name = '---'
  677. return false
  678. }
  679. let suffix = row.name.substring(row.name.lastIndexOf('.') + 1)
  680. if (suffix === 'jpg' || suffix === 'png' || suffix === 'gif' || suffix === 'bmp' || suffix === 'jpeg') {
  681. return true
  682. } else {
  683. return false
  684. }
  685. },
  686. fileLoadingFalse() {
  687. this.fileLoading = false
  688. },
  689. // 开启/关闭页面的加载中状态
  690. changeLoading(loading) {
  691. if (this.commonJS.isNotEmpty(loading)) {
  692. this.loading = loading
  693. } else {
  694. this.loading = false
  695. }
  696. }
  697. }
  698. }
  699. </script>
  700. <style>
  701. .el-divider__text {
  702. font-size: 16px;
  703. font-weight: bold;
  704. }
  705. </style>