<template>
  <div class="app-container" style="margin-left: 20px;">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">


      <el-form-item label="数据类型" prop="dataType">

        <el-select
          v-model="queryParams.dataType"
          placeholder="请选择数据类型"
          clearable
        >
          <el-option label="有效" value="act"></el-option>
          <el-option label="授权" value="auth"></el-option>
          <el-option label="公开" value="pub"></el-option>
        </el-select>


      </el-form-item>

      <el-form-item label="文件名" prop="fileName">
        <el-input
          v-model="queryParams.fileName"
          placeholder="请输入文件名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="导出日期" prop="expDate">

        <el-date-picker
          v-model="queryParams.expDate"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="导出状态" prop="expStatus">

        <el-select
          v-model="queryParams.expStatus"
          placeholder="导出状态"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="dict in statusOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>


      </el-form-item>


      <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!--
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['adjust:asynchExpLog:add']"
        >新增</el-button>
      </el-col>
      -->
      <!--
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['adjust:asynchExpLog:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['adjust:asynchExpLog:remove']"
        >删除</el-button>
      </el-col>
      <!--
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['adjust:asynchExpLog:export']"
        >导出</el-button>
      </el-col>-->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="asynchExpLogList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="数据类型" align="center" prop="dataType">
      </el-table-column>


      <el-table-column label="文件地址" align="center" prop="fileUrl">

      </el-table-column>

      <el-table-column label="数据类型" align="center" prop="dataType">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_asynch_exp_type" :value="scope.row.dataType"/>
        </template>
      </el-table-column>
-->

      <el-table-column label="数据类型" align="center" prop="dataTypeName" />
      <el-table-column label="文件名" align="left" prop="fileName" width="250px;">
        <template slot-scope="scope">
          <a v-show="scope.row.expStatus==2" :href="scope.row.fileUrl" target="_blank" style="text-decoration:underline;">{{ scope.row.fileName }} </a>
          <span v-show="scope.row.expStatus!=2">{{ scope.row.fileName }} </span>
        </template>
      </el-table-column>

      <el-table-column label="导出日期" align="center" prop="expDate">

      </el-table-column>
      <el-table-column label="导出状态" align="center" prop="expStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_exp_status" :value="scope.row.expStatus"/>
        </template>
    </el-table-column>
      <el-table-column label="导出用时" align="center" prop="expUsedTime">
        <template slot-scope="scope">
          <span v-if="scope.row.expStatus=='2'">{{ scope.row.expUsedTime }}秒</span>
        </template>
      </el-table-column>

      <el-table-column label="总记录数" align="center" prop="totalCnt">
      </el-table-column>
      <el-table-column label="当前导出记录" align="center" prop="currCnt">
      </el-table-column>
      <el-table-column label="当前进度" align="center" prop="currRate">
      </el-table-column>


      <el-table-column label="导出时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="导出人" align="center" prop="createBy">

      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!--
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['adjust:asynchExpLog:edit']"
          >修改</el-button>-->

          <el-link v-show="scope.row.expStatus=='2'" :href="scope.row.fileUrl" type="success" style="margin-right: 20px;">点击下载</el-link>

          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['adjust:asynchExpLog:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改导步导出日志对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <!--
        <el-form-item label="数据类型" prop="dataType">

        </el-form-item>
        <el-form-item label="数据类型名" prop="dataTypeName">
          <el-input v-model="form.dataTypeName" placeholder="请输入数据类型名" />
        </el-form-item>
        -->
        <el-form-item label="文件地址" prop="fileUrl">
          <el-input v-model="form.fileUrl" placeholder="请输入文件地址" />
        </el-form-item>
        <el-form-item label="文件名" prop="fileName">
          <el-input v-model="form.fileName" placeholder="请输入文件名" />
        </el-form-item>
        <el-form-item label="导出状态">

        </el-form-item>
        <el-form-item label="失败原因" prop="errReason">
          <el-input v-model="form.errReason" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="导出日期" prop="expDate">
          <el-input v-model="form.expDate" placeholder="请输入导出日期" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listAsynchExpLog, getAsynchExpLog, delAsynchExpLog, addAsynchExpLog, updateAsynchExpLog } from "@/api/adjust/asynchExpLog";

export default {
  name: "AsynchExpLog",
  dicts: ['sys_exp_status'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 导步导出日志表格数据
      asynchExpLogList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        dataType: 'act',
        fileName: null,
        expStatus: null,
        expDate: null,
        createBy: null,

      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },statusOptions:[],sysAsynchExpTypeOptions:[]
    };
  },
  created() {

    this.sysAsynchExpTypeOptions=[];
    this.getDicts("sys_exp_status").then(response => {
      this.statusOptions = response.data;
    });
    // this.getDicts("sys_asynch_exp_type").then(response => {
    //   this.sysAsynchExpTypeOptions = response.data;
    // });

    let dataType = this.$route.query.dataType;
    if(dataType){
      this.queryParams.dataType=dataType;
    }
    this.getList();

  },
  methods: {
    /** 查询导步导出日志列表 */
    getList() {
      this.loading = true;
      listAsynchExpLog(this.queryParams).then(response => {
        this.asynchExpLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        dataType: null,
        dataTypeName: null,
        fileUrl: null,
        filePath: null,
        fileName: null,
        expStatus: "0",
        errReason: null,
        expDate: null,
        expUsedTime: null,
        createTime: null,
        createBy: null,
        updateTime: null,
        updateBy: null,
        tenantNo: null,

      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加导步导出日志";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getAsynchExpLog(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改导步导出日志";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAsynchExpLog(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAsynchExpLog(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除导步导出日志编号为"' + ids + '"的数据项？').then(function() {
        return delAsynchExpLog(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('adjust/asynchExpLog/export', {
        ...this.queryParams
      }, `asynchExpLog_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
