<template>
  <el-dialog v-loading="loading" v-if="visible" :visible.sync="visible" title="替换">
    <el-table :data="list">
      <el-table-column prop="CREATE_TIME" label="日期"/>
      <el-table-column prop="CREATOR_NAME" label="姓名"/>
      <el-table-column prop="PATH" label="替换前附件">
        <template slot-scope="{row,$index}">
          <a v-if="$index !== list.length-1" style="color: blue" @click="goViewTxt(list[$index+1].PATH)">[预览]</a>
        </template>
      </el-table-column>
      <el-table-column prop="PATH" label="替换后附件">
        <template slot-scope="{row}">
          <a style="color: blue" @click="goViewTxt(row.PATH)">[预览]</a>
        </template>
      </el-table-column>
    </el-table>
    <div slot="footer" class="dialog-footer">
      <el-button @click="goBack">取 消</el-button>
    </div>
    <el-dialog :visible.sync="dialogViewTxt" title="查看" width="1200px" height = "500px" append-to-body>
      <iframe :src="dialogViewUrl" width="100%" height="500px" frameborder="1" />
    </el-dialog>
  </el-dialog>
</template>
<script>
import Pagination from '@/components/Pagination'
import waves from '@/directive/waves'
import { requestFN } from '@/utils/request'

export default {
  components: { Pagination },
  directives: { waves },
  data() {
    return {
      visible: false,
      dialogViewTxt: false,
      dialogViewUrl: '',
      list: [],
      loading: false,
      id: ''
    }
  },
  methods: {
    init(e) {
      this.visible = true
      this.id = e.BUS_TEXT_LIBRARY_ID
      this.getList()
    },
    goViewTxt(filePath) {
      this.dialogViewTxt = true
      this.dialogViewUrl = config.fileUrl + filePath
    },
    goBack() {
      this.list = []
      this.visible = false
    },
    getList() {
      this.loading = true
      requestFN(
        '/textLibrary/getUpdateLog',
        {
          BUS_TEXT_LIBRARY_ID: this.id
        }
      ).then((data) => {
        this.loading = false
        this.list = data.list
      }).catch((e) => {
        this.loading = false
      })
    }
  }
}

</script>
