<!--
 * @Author: @liulin
 * @Date: 2022-05-23 09:58:27
 * @LastEditTime: 2022-06-15 17:52:51
 * @LastEditors: @liulin
 * @Description: 
 * @FilePath: \cqxy_pm_web\src\views\projectManagent\modules\component\economicsInfo.vue
-->
<template>
  <!-- 经济资料 -->
  <div
    class="items bgc"
    id="work8"
  >
    <!-- 标题 -->
    <div class="title">
      <span class="icon"></span>
      <span class="text">经济资料</span>
    </div>
    <!-- 详情 -->
    <div class="table-border">
      <el-table
        :data="data"
        height="230"
        border
        style="width: 100%;"
        :header-cell-style="{background:'#f2f2f2',color:'#000'}"
      >
        <el-table-column
          type="index"
          label="序号"
          width="60"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="文件名称"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="type"
          label="文件类型"
          align="center"
          :show-overflow-tooltip="true"
        >
          <template v-slot="{row}">
            {{getDictName('tyfj-fjlx',row.type)}}
          </template>
        </el-table-column>
        <el-table-column
          prop="fileSize"
          label="文件大小"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="createName"
          label="上传人"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="上传时间"
          align="center"
          :show-overflow-tooltip="true"
        >
        </el-table-column>
        <ht-table-column
          label="操作"
          width="200"
        >
          <template v-slot="{row}">
            <el-dropdown
              size="mini"
              split-button
              @command="handleCommand"
              @click="handleCommand({row, command: 'preview'})"
            >
              <span> <i class="el-icon-view"></i>查看</span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item
                  icon="el-icon-download"
                  :command="{row: row, command: 'download'}"
                >下载</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </ht-table-column>
      </el-table>
      <div class="page-footer">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageResult.page"
          :page-sizes="[5,10,20,30,50]"
          :page-size="pageResult.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageResult.total"
        >
        </el-pagination>
      </div>
      <el-dialog
        title="预览"
        class="dialog"
        append-to-body
        :close-on-click-modal="false"
        :visible.sync="dialogVisible"
        v-if="dialogVisible"
        destroy-on-close
        @close="closeDialog"
        width="100%"
      >
        <div>
          <iframe
            :src="url"
            frameborder="0"
            style="z-index: 1000; height: 800px; width: 100%"
          ></iframe>
        </div>
      </el-dialog>
      <!-- <dialog-accessory ref="accessory" /> -->
    </div>
  </div>
</template>
<script>
import dialogAccessory from '../dialog/dialogAccessory.vue'
export default {
  name: 'change',
  components: {
    // dialogAccessory
  },
  data() {
    return {
      data: [], //表格数据
      pageResult: {
        page: 1,
        pageSize: 10,
        total: 0
      },
      form: {},
      dialogVisible: false,
      dialogTitle: '添加'
    }
  },
  mounted() {
    this.loadData()
  },
  methods: {
    // //附件
    // handleLook(obj) {
    //   this.$refs.accessory.open(obj)
    // },
    handleSizeChange(val) {
      this.pageResult.pageSize = val
      this.loadData()
    },
    handleCurrentChange(val) {
      this.pageResult.page = val
      this.loadData()
    },
    loadData() {
      let param = {
        pageBean: {
          ...this.pageResult
        },
        querys: [
          {
            group: 'advance',
            opener: 'LIKE',
            property: 'project_id_',
            relation: 'AND',
            value: this.$route.params.id
          },
          {
            group: 'main',
            operation: 'EQUAL',
            parentGroup: '',
            property: 'SOURCE_ID_',
            relation: 'AND',
            value: 'economicData'
          }
        ],
        sorter: [{direction: 'DESC', property: 'CREATE_TIME_'}]
      }
      this.$http
        .post('${cqxy}/biz/universal/accessory/v1/getPageBySourceId', param)
        .then(
          resp => {
            let response=resp.data.value
            this.data = response.rows
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total
            }
          },
          error => {
            reject(error)
          }
        )
    },
    handleCommand(params) {
      console.log(params)
      if (params.command == 'preview') {
        let type = params.row.suffix
        if (
          type.indexOf('xsl') !== -1 ||
          type.indexOf('xslx') !== -1 ||
          type.indexOf('xls') !== -1 ||
          type.indexOf('docx') !== -1 ||
          type.indexOf('doc') !== -1 ||
          type.indexOf('pdf') !== -1 ||
          type.indexOf('jpg') !== -1 ||
          type.indexOf('png') !== -1 ||
          type.indexOf('jpeg') !== -1 ||
          type.indexOf('pptx') !== -1 ||
          type.indexOf('ppt') !== -1
        ) {
          this.dialogVisible = true
          // this.url = encodeURIComponent(row.url)
          this.url = params.row.url
        } else {
          this.$message('当前文件暂不支持预览，请下载查看')
        }
      } else {
        let ids = params.row.id
        let bizPath = 'default'
        let formData = new FormData()
        formData.append('bizPath', bizPath)
        formData.append('ids', ids)
        req
          .downloadPostCopy(
            '${cqxy}/biz/universal/accessory/v1/minIoAllDownFile',
            formData
          )
          .then(res => {
            console.log(res)
          })
      }
    },
    closeDialog() {
      this.dialogVisible = false
    }
  }
}
</script>
<style lang="scss" scoped>
@import '../css/projectCommon.scss';
/deep/ .el-main  .content{
  padding: 0 !important;
}
.page-footer{
  padding-top: 10px;
  float: right;
}
.table-border{
  height: 515px;
}
/deep/ .el-table{
  height: calc(100% - 32px) !important;
}
</style>