JyEiaUpLoadComponent.vue 25 KB

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