<template>
    <data-table :handleFlag.sync="handleFlag" :toolMenuFlag="false" :loadingFlag="loadingFlag" :showPage="false"
                :sourceData.sync="formTableData.sourceData" :menuFlag="true" operateBtnLayout="false"
                :columns="columns" :border="true" :stripe="true">
        <el-table-column align="center" :label="$t('common.operate')" >
            <template slot-scope="scope">
              <btn-upload :classType="true" :fileID="scope.row.fileId" :icon="(scope.row.fileId == '' || scope.row.fileId == 0) ? '' : 'iconfont iconzhongxinshangchuan'" size="small" :rowData="scope.row" :uploadApi="uploadApi"  @uploadFailed="uploadFailed" @uploadSuccess="uploadSuccess"></btn-upload>
              <btn-download v-if="(scope.row.fileId && scope.row.fileId !== 0)" :fileID="scope.row.fileId"></btn-download>
              <el-tooltip v-if="(scope.row.fileId && scope.row.fileId !== 0)" class="item" effect="dark" :content="$t('common.del')" placement="top">
                <el-button @click="deleteFile(scope.row)" circle size="medium" class="iconfont iconshanchu12"></el-button>
              </el-tooltip>
            </template>
        </el-table-column>
        <el-table-column align="center" :label="$t('traceMgr.commissionerFeedback')">
            <template slot-scope="scope">
                <el-input type="textarea" maxlength="253" v-model.trim="scope.row.factoringCommissionerFeedback"></el-input>
            </template>
        </el-table-column>
    </data-table>
</template>

<script>
import { DataTable, authButton, btnUpload, btnDownload, componentsApi } from 'newepoch-components'
import { UPLOAD_API, PLOAD_API, BATCH_UPLOAD_API, IMPORT_API } from '@/constant.js'
import tracemgrApi from '@/api/tracemgrApi'
export default {
  components: {
    btnDownload,
    DataTable,
    authButton,
    BATCH_UPLOAD_API,
    IMPORT_API,
    UPLOAD_API,
    btnUpload,
    PLOAD_API,
    componentsApi,
    tracemgrApi
  },
  data () {
    return {
      uploadApi: UPLOAD_API,
      handleFlag: true,
      sourceData: [
        {
          fileName: this.$i18n.messages[this.$i18n.locale].common.basicTransactionContract,
          opinions: this.$i18n.messages[this.$i18n.locale].common.noSignaturePageProvided
        },
        {
          fileName: this.$i18n.messages[this.$i18n.locale].common.basicTransactionContract,
          opinions: this.$i18n.messages[this.$i18n.locale].common.noSignaturePageProvided
        },
        {
          fileName: this.$i18n.messages[this.$i18n.locale].common.basicTransactionContract,
          opinions: this.$i18n.messages[this.$i18n.locale].common.noSignaturePageProvided
        }
      ],
      columns: [
        {
          prop: 'fileName',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].traceMgr.fileName,
          showOverflowTooltip: true
        },
        {
          prop: 'auditOpinion',
          align: 'left',
          label: this.$i18n.messages[this.$i18n.locale].approval.opinions,
          showOverflowTooltip: true
        }
      ],
      feedbackText: ''
    }
  },
  props: {
    loadingFlag: {
      type: Boolean
    },
    formTableData: {
      type: Object,
      default () {
        return this.sourceData
      }
    }
  },
  methods: {
    uploadSuccess: function (returnData, rowData) {
      rowData.fileId = returnData.fileID
      console.log(rowData)
      this.success(returnData.fileName + this.$i18n.messages[this.$i18n.locale].traceMgr.fileSuccess)
    },
    uploadFailed: function (a, b, c) {
      this.error(this.$i18n.messages[this.$i18n.locale].traceMgr.fileEorro)
    },
    deleteFile: function (row) {
      row.fileId = 0
      // tracemgrApi['fileList'].deleteFile({ 'fileId': fileId }).then(res => {
      //   if (res.data) {
      //     fileId = res.data.fileId
      //     this.success(this.$i18n.messages[this.$i18n.locale].common.delSuccess)
      //   } else {
      //     this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
      //   }
      // }).catch(res => {
      //   this.error(this.$i18n.messages[this.$i18n.locale].common.delFailure)
      // })
    }
  }
}
</script>
