<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="订单号" prop="orderNo">
        <el-input
          v-model="queryParams.orderNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="标识" prop="flagName">
        <el-input
            v-model="queryParams.flagName"
            placeholder="请输入操作名称"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="success">
        <el-select clearable v-model="queryParams.success">
          <el-option key="0" label="失败" value="失败">失败</el-option>
          <el-option key="0" label="成功" value="成功">成功</el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="createTimeMin">
        <el-date-picker
            v-model="queryParams.createTimeMin"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间" prop="createTimeMax">
        <el-date-picker
            v-model="queryParams.createTimeMax"
            type="datetime"
            value-format="yyyy-MM-dd HH:mm:ss"
            placeholder="选择开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="操作名称" prop="stepName">
        <el-input
          v-model="queryParams.stepName"
          placeholder="请输入操作名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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-table v-loading="loading" :data="orderLogsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="订单号" align="center" prop="orderNo" />
      <el-table-column label="状态" align="center" prop="success" />
      <el-table-column label="标识" align="center" prop="flagName" />
      <el-table-column label="操作时间" align="center" prop="createTime" />
      <el-table-column label="备注" align="center" prop="remark" show-overflow-tooltip />
      <el-table-column label="操作名称" align="center" prop="stepName" />
      <el-table-column label="入参" align="center" prop="inParams" show-overflow-tooltip />
      <el-table-column label="出参" align="center" prop="outParams" show-overflow-tooltip />
    </el-table>

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

<script>
import {listOrderLogs} from "@/api/cai/orderLogs";

export default {
  name: "OrderLogs",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单日志表格数据
      orderLogsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTimeMax: undefined,
        createTimeMin: undefined,
        success: undefined,
        orderNo: undefined,
        flagName: undefined,
        stepName: undefined,
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单日志列表 */
    getList() {
      this.loading = true;
      listOrderLogs(this.queryParams).then(response => {
        this.orderLogsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    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
    },
  }
};
</script>
