<template>
  <task-standard>
    <div slot="header-right">
      <header-button icon="arrow-left" type="no-line" @click="goBack">
        返回
      </header-button>
    </div>
    <el-form ref="queryForm" :model="queryParams" size="small" :inline="true">
      <template v-if="showSearch">
        <el-form-item prop="fileName" label="文件名称">
          <el-input
            v-model="queryParams.fileName"
            placeholder="请输入"
            clearable
            @keyup.enter.native="loadData"
          />
        </el-form-item>
        <el-form-item prop="status" label="文件状态">
          <el-select v-model="queryParams.status" placeholder="请选择">
            <el-option
              v-for="item in dict.type.file_status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="identifyNumber" label="文件识别号">
          <el-input
            v-model="queryParams.identifyNumber"
            placeholder="请输入"
            clearable
            @keyup.enter.native="loadData"
          />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >查询</el-button
          >
          <el-button
            type="default"
            icon="el-icon-refresh"
            size="mini"
            @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </template>
      <!-- <el-form-item>
        <right-toolbar
          :show-search.sync="showSearch"
          @queryTable="loadData"
        ></right-toolbar>
      </el-form-item> -->
    </el-form>
    <el-table
      v-loading="tableLoading"
      border
      :scroll-x="'1500px'"
      :default-sort="{ prop: 'createTime', order: 'descending' }"
      :data="tableData"
      @sort-change="sort_change"
    >
      <el-table-column type="index" width="55" label="序号" align="center">
        <template slot-scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="所属车企"
        sortable
        min-width="210"
        prop="enterpriseName"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        prop="fileName"
        label="文件名称"
        min-width="220"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        prop="version"
        label="文件版本"
        min-width="100"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        prop="publishDate"
        label="发布日期"
        min-width="100"
        show-overflow-tooltip
        align="left"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.publishDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="status"
        label="文件状态"
        min-width="100"
        align="left"
      >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == 0" size="medium" type="success"
            >{{ getDictData(dict.type.file_status, scope.row.status) }}
          </el-tag>
          <el-tag v-else size="medium" type="warning"
            >{{ getDictData(dict.type.file_status, scope.row.status) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="storage"
        label="存储位置"
        min-width="210"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        prop="identifyNumber"
        label="文件识别号"
        min-width="170"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        prop="createBy"
        label="创建人员"
        min-width="130"
        show-overflow-tooltip
        align="left"
      >
      </el-table-column>
      <el-table-column
        label="创建时间"
        min-width="170"
        align="left"
        sortable
        prop="createTime"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
    </el-table>
    <yan-dialog
      :dialog-manger="dialogManger"
      @refresh="refreshList = true"
      @close="dialogManger.dialogVisible = false"
    ></yan-dialog>
    <pagination
      :total="total"
      :background="false"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="loadData"
    >
    </pagination>
  </task-standard>
</template>

<script>
import page from '@/mixins/page'
import dialog from './components/dialog.vue'
import routerMixins from '@/mixins/router'
export default {
  components: {
    'yan-dialog': dialog
  },
  dicts: ['file_status'],
  mixins: [page, routerMixins],
  data() {
    return {
      // 弹窗管理器
      dialogManger: {
        dialogVisible: false,
        refreshList: false,
        dialogEditId: 0
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        taskId: this.$route.query.id,
        isAsc: 'desc',
        orderByColumn: 'createTime'
      },
      refreshList: false,
      baseUrl: process.env.VUE_APP_IMAGE_API,
      listUrl: '/review/enterprise/archive/findEnterpriseArchiveByTaskId',
      // 表格loading状态
      tableLoading: false,
      // 表格数据
      tableData: []
    }
  },
  watch: {
    refreshList(newVal) {
      if (newVal) {
        this.loadData()
        this.refreshList = false
      }
    }
  },
  created() {
    this.queryParams.taskId = this.$route.query.id
  },
  methods: {
    sort_change(column, prop, order) {
      this.queryParams.pageNum = 1 // 排序后返回第一页
      if (column.order) {
        this.queryParams.isAsc = column.order === 'ascending' ? 'asc' : 'desc'
        this.queryParams.orderByColumn = column.prop
        this.loadData()
      }
    },
    resetQuery() {
      // this.refs.queryForm.restForm()      this.resetForm("queryForm");
      this.queryParams = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        taskId: this.$route.query.id,
        isAsc: this.queryParams.isAsc,
        orderByColumn: this.queryParams.orderByColumn
      }
      this.handleQuery()
    },
    handleUpdate(id) {
      this.dialogManger.dialogVisible = true
      this.dialogManger.dialogEditId = id
    }
  }
}
</script>

<style lang="scss" scoped></style>
