<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="运营商id" prop="merchantId">
        <el-input
          v-model="queryParams.merchantId"
          placeholder="请输入运营商id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="站点id" prop="stationId">
        <el-input
          v-model="queryParams.stationId"
          placeholder="请输入站点id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用电度数" prop="useElectricity">
        <el-input
          v-model="queryParams.useElectricity"
          placeholder="请输入用电度数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充电次数" prop="chargeNum">
        <el-input
          v-model="queryParams.chargeNum"
          placeholder="请输入充电次数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="充电时长" prop="chargeTime">
        <el-input
          v-model="queryParams.chargeTime"
          placeholder="请输入充电时长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电费金额" prop="electricityAmount">
        <el-input
          v-model="queryParams.electricityAmount"
          placeholder="请输入电费金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="服务费金额" prop="serviceAmount">
        <el-input
          v-model="queryParams.serviceAmount"
          placeholder="请输入服务费金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收入金额" prop="totalAmount">
        <el-input
          v-model="queryParams.totalAmount"
          placeholder="请输入收入金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="虚拟金额" prop="virtualAmount">
        <el-input
          v-model="queryParams.virtualAmount"
          placeholder="请输入虚拟金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="交易日期" prop="tradeDate">
      <el-date-picker
          v-model="value"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :clearable=false
        ></el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="交易金额" prop="tradeAmount">
        <el-input
          v-model="queryParams.tradeAmount"
          placeholder="请输入交易金额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="交易手续费" prop="tradeFee">
        <el-input
          v-model="queryParams.tradeFee"
          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-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="['pile:report: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="['pile:report: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="['pile:report: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="['pile:report:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row> -->

    <el-table v-loading="loading" :data="reportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="主键" align="center" prop="id" /> -->
<!--      <el-table-column label="运营商id" align="center" prop="merchantId" />-->
      <!-- <el-table-column label="站点id" align="center" prop="stationId" /> -->
      <el-table-column label="交易日期" align="center" prop="tradeDate" />
      <el-table-column label="用电度数" align="center" prop="useElectricity" />
      <el-table-column label="充电次数" align="center" prop="chargeNum" />
      <el-table-column label="充电时长" align="center" prop="chargeTime" />
      <el-table-column label="电费金额" align="center" prop="electricityAmount" />
      <el-table-column label="服务费金额" align="center" prop="serviceAmount" />
      <el-table-column label="收入金额" align="center" prop="totalAmount" />
      <el-table-column label="虚拟金额" align="center" prop="virtualAmount" />
      <el-table-column label="交易金额" align="center" prop="tradeAmount" />
      <el-table-column label="交易手续费" align="center" prop="tradeFee" />
<!--      <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="['pile:report:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['pile:report: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="运营商id" prop="merchantId">
          <el-input v-model="form.merchantId" placeholder="请输入运营商id" />
        </el-form-item>
        <el-form-item label="站点id" prop="stationId">
          <el-input v-model="form.stationId" placeholder="请输入站点id" />
        </el-form-item>
        <el-form-item label="用电度数" prop="useElectricity">
          <el-input v-model="form.useElectricity" placeholder="请输入用电度数" />
        </el-form-item>
        <el-form-item label="充电次数" prop="chargeNum">
          <el-input v-model="form.chargeNum" placeholder="请输入充电次数" />
        </el-form-item>
        <el-form-item label="充电时长" prop="chargeTime">
          <el-input v-model="form.chargeTime" placeholder="请输入充电时长" />
        </el-form-item>
        <el-form-item label="电费金额" prop="electricityAmount">
          <el-input v-model="form.electricityAmount" placeholder="请输入电费金额" />
        </el-form-item>
        <el-form-item label="服务费金额" prop="serviceAmount">
          <el-input v-model="form.serviceAmount" placeholder="请输入服务费金额" />
        </el-form-item>
        <el-form-item label="收入金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入收入金额" />
        </el-form-item>
        <el-form-item label="虚拟金额" prop="virtualAmount">
          <el-input v-model="form.virtualAmount" placeholder="请输入虚拟金额" />
        </el-form-item>
        <el-form-item label="交易日期" prop="tradeDate">
          <el-input v-model="form.tradeDate" placeholder="请输入交易日期" />
        </el-form-item>
        <el-form-item label="交易金额" prop="tradeAmount">
          <el-input v-model="form.tradeAmount" placeholder="请输入交易金额" />
        </el-form-item>
        <el-form-item label="交易手续费" prop="tradeFee">
          <el-input v-model="form.tradeFee" placeholder="请输入交易手续费" />
        </el-form-item>
        <el-form-item label="删除标识" prop="delFlag">
          <el-input v-model="form.delFlag" 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 { listReport, getReport, delReport, addReport, updateReport } from "@/api/settle/orderReport";

export default {
  name: "Report",
  data() {
    return {
      value:'',
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 结算订单报表格数据
      reportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        merchantId: null,
        stationId: null,
        useElectricity: null,
        chargeNum: null,
        chargeTime: null,
        electricityAmount: null,
        serviceAmount: null,
        totalAmount: null,
        virtualAmount: null,
        tradeDate: null,
        tradeAmount: null,
        tradeFee: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    // this.getList();
  },
  methods: {
    /** 查询结算订单报列表 */
    getList() {
      this.loading = true;
      this.queryParams.stationId = this.$route.params.id
      listReport(this.queryParams).then(response => {
        console.log('查询订单日报',response)
        this.reportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        merchantId: null,
        stationId: null,
        useElectricity: null,
        chargeNum: null,
        chargeTime: null,
        electricityAmount: null,
        serviceAmount: null,
        totalAmount: null,
        virtualAmount: null,
        tradeDate: null,
        tradeAmount: null,
        tradeFee: null,
        createTime: null,
        delFlag: null
      };

      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      console.log('this.value 日期',this.value)
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.value = null
      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
      getReport(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) {
            updateReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addReport(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 delReport(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('pile/report/export', {
        ...this.queryParams
      }, `report_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
