<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="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入订单编号/交易流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="桩编码" prop="pileSn">
        <el-input
          v-model="queryParams.pileSn"
          placeholder="请输入桩编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="startTime">
        <el-input
          v-model="queryParams.startTime"
          placeholder="请输入开始时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-input
          v-model="queryParams.endTime"
          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="['order:abnormalRecord: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="['order:abnormalRecord: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="['order:abnormalRecord: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="['order:abnormalRecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>-->

    <el-table v-loading="loading" :data="abnormalRecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!--<el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="订单编号" align="center" prop="orderCode" />
      <el-table-column label="桩编码" align="center" prop="pileSn" />
      <el-table-column label="枪口号" align="center" prop="connectorCode" />
      <el-table-column label="开始时间" align="center" prop="startTime" />
      <el-table-column label="结束时间" align="center" prop="endTime" />
<!--      <el-table-column label="尖单价" align="center" prop="sharpPrice" />-->
<!--      <el-table-column label="尖电量" align="center" prop="sharpUsedElectricity" />-->
<!--      <el-table-column label="计损尖电量" align="center" prop="sharpPlanLossElectricity" />-->
<!--      <el-table-column label="尖金额" align="center" prop="sharpAmount" />-->
<!--      <el-table-column label="峰单价" align="center" prop="peakPrice" />-->
<!--      <el-table-column label="峰电量" align="center" prop="peakUsedElectricity" />-->
<!--      <el-table-column label="计损峰电量" align="center" prop="peakPlanLossElectricity" />-->
<!--      <el-table-column label="峰金额" align="center" prop="peakAmount" />-->
<!--      <el-table-column label="平单价" align="center" prop="flatPrice" />-->
<!--      <el-table-column label="平电量" align="center" prop="flatUsedElectricity" />-->
<!--      <el-table-column label="计损平电量" align="center" prop="flatPlanLossElectricity" />-->
<!--      <el-table-column label="平金额" align="center" prop="flatAmount" />-->
<!--      <el-table-column label="谷单价" align="center" prop="valleyPrice" />-->
<!--      <el-table-column label="谷电量" align="center" prop="valleyUsedElectricity" />-->
<!--      <el-table-column label="计损谷电量" align="center" prop="valleyPlanLossElectricity" />-->
<!--      <el-table-column label="谷金额" align="center" prop="valleyAmount" />-->
<!--      <el-table-column label="电表总起值" align="center" prop="ammeterTotalStart" />-->
<!--      <el-table-column label="电表总止值" align="center" prop="ammeterTotalEnd" />-->
      <el-table-column label="总电量" align="center" prop="totalElectricity" />
<!--      <el-table-column label="计损总电量" align="center" prop="planLossTotalElectricity" />-->
      <el-table-column label="消费金额" align="center" prop="consumptionAmount" />
<!--      <el-table-column label="VIN码" align="center" prop="vinCode" />-->
<!--      <el-table-column label="交易标识" align="center" prop="transactionIdentifier" />-->
<!--      <el-table-column label="交易时间" align="center" prop="transactionTime" />-->
      <el-table-column label="停止原因" align="center" prop="stopReasonMsg" />
<!--      <el-table-column label="物理卡号" align="center" prop="logicCard" />-->
      <!--<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="['order:abnormalRecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['order:abnormalRecord: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="orderCode">
          <el-input v-model="form.orderCode" placeholder="请输入订单编号/交易流水号" />
        </el-form-item>
        <el-form-item label="桩编码" prop="pileSn">
          <el-input v-model="form.pileSn" placeholder="请输入桩编码" />
        </el-form-item>
        <el-form-item label="枪号" prop="connectorCode">
          <el-input v-model="form.connectorCode" placeholder="请输入枪号" />
        </el-form-item>
        <el-form-item label="开始时间" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入开始时间" />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="尖单价   精确到小数点后五位" prop="sharpPrice">
          <el-input v-model="form.sharpPrice" placeholder="请输入尖单价   精确到小数点后五位" />
        </el-form-item>
        <el-form-item label="尖电量   精确到小数点后四位" prop="sharpUsedElectricity">
          <el-input v-model="form.sharpUsedElectricity" placeholder="请输入尖电量   精确到小数点后四位" />
        </el-form-item>
        <el-form-item label="计损尖电量" prop="sharpPlanLossElectricity">
          <el-input v-model="form.sharpPlanLossElectricity" placeholder="请输入计损尖电量" />
        </el-form-item>
        <el-form-item label="尖金额" prop="sharpAmount">
          <el-input v-model="form.sharpAmount" placeholder="请输入尖金额" />
        </el-form-item>
        <el-form-item label="峰单价   精确到小数点后五位" prop="peakPrice">
          <el-input v-model="form.peakPrice" placeholder="请输入峰单价   精确到小数点后五位" />
        </el-form-item>
        <el-form-item label="峰电量" prop="peakUsedElectricity">
          <el-input v-model="form.peakUsedElectricity" placeholder="请输入峰电量" />
        </el-form-item>
        <el-form-item label="计损峰电量" prop="peakPlanLossElectricity">
          <el-input v-model="form.peakPlanLossElectricity" placeholder="请输入计损峰电量" />
        </el-form-item>
        <el-form-item label="峰金额" prop="peakAmount">
          <el-input v-model="form.peakAmount" placeholder="请输入峰金额" />
        </el-form-item>
        <el-form-item label="平单价   精确到小数点后五位" prop="flatPrice">
          <el-input v-model="form.flatPrice" placeholder="请输入平单价   精确到小数点后五位" />
        </el-form-item>
        <el-form-item label="平电量" prop="flatUsedElectricity">
          <el-input v-model="form.flatUsedElectricity" placeholder="请输入平电量" />
        </el-form-item>
        <el-form-item label="计损平电量" prop="flatPlanLossElectricity">
          <el-input v-model="form.flatPlanLossElectricity" placeholder="请输入计损平电量" />
        </el-form-item>
        <el-form-item label="平金额" prop="flatAmount">
          <el-input v-model="form.flatAmount" placeholder="请输入平金额" />
        </el-form-item>
        <el-form-item label="谷单价   精确到小数点后五位" prop="valleyPrice">
          <el-input v-model="form.valleyPrice" placeholder="请输入谷单价   精确到小数点后五位" />
        </el-form-item>
        <el-form-item label="谷电量" prop="valleyUsedElectricity">
          <el-input v-model="form.valleyUsedElectricity" placeholder="请输入谷电量" />
        </el-form-item>
        <el-form-item label="计损谷电量" prop="valleyPlanLossElectricity">
          <el-input v-model="form.valleyPlanLossElectricity" placeholder="请输入计损谷电量" />
        </el-form-item>
        <el-form-item label="谷金额" prop="valleyAmount">
          <el-input v-model="form.valleyAmount" placeholder="请输入谷金额" />
        </el-form-item>
        <el-form-item label="电表总起值" prop="ammeterTotalStart">
          <el-input v-model="form.ammeterTotalStart" placeholder="请输入电表总起值" />
        </el-form-item>
        <el-form-item label="电表总止值" prop="ammeterTotalEnd">
          <el-input v-model="form.ammeterTotalEnd" placeholder="请输入电表总止值" />
        </el-form-item>
        <el-form-item label="总电量" prop="totalElectricity">
          <el-input v-model="form.totalElectricity" placeholder="请输入总电量" />
        </el-form-item>
        <el-form-item label="计损总电量" prop="planLossTotalElectricity">
          <el-input v-model="form.planLossTotalElectricity" placeholder="请输入计损总电量" />
        </el-form-item>
        <el-form-item label="消费金额   精确到小数点后四位，包含电费、 服务费" prop="consumptionAmount">
          <el-input v-model="form.consumptionAmount" placeholder="请输入消费金额   精确到小数点后四位，包含电费、 服务费" />
        </el-form-item>
        <el-form-item label="VIN 码   VIN 码，此处 VIN 码和充电时 VIN 码不同， 正序直接上传， 无需补 0 和反序" prop="vinCode">
          <el-input v-model="form.vinCode" placeholder="请输入VIN 码   VIN 码，此处 VIN 码和充电时 VIN 码不同， 正序直接上传， 无需补 0 和反序" />
        </el-form-item>
        <el-form-item label="交易标识(0x01app启动; 0x02卡启动; 0x04离线卡启动; 0x05vin码启动充电)" prop="transactionIdentifier">
          <el-input v-model="form.transactionIdentifier" placeholder="请输入交易标识(0x01app启动; 0x02卡启动; 0x04离线卡启动; 0x05vin码启动充电)" />
        </el-form-item>
        <el-form-item label="交易时间  CP56Time2a 格式" prop="transactionTime">
          <el-input v-model="form.transactionTime" placeholder="请输入交易时间  CP56Time2a 格式" />
        </el-form-item>
        <el-form-item label="停止原因" prop="stopReasonMsg">
          <el-input v-model="form.stopReasonMsg" placeholder="请输入停止原因" />
        </el-form-item>
        <el-form-item label="物理卡号  不足 8 位补 0" prop="logicCard">
          <el-input v-model="form.logicCard" placeholder="请输入物理卡号  不足 8 位补 0" />
        </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 { listAbnormalRecord, getAbnormalRecord, delAbnormalRecord, addAbnormalRecord, updateAbnormalRecord } from "@/api/order/abnormalRecord";

export default {
  name: "AbnormalRecord",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单异常记录表格数据
      abnormalRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: null,
        pileSn: null,
        startTime: null,
        endTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询订单异常记录列表 */
    getList() {
      this.loading = true;
      listAbnormalRecord(this.queryParams).then(response => {
        this.abnormalRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderCode: null,
        pileSn: null,
        connectorCode: null,
        startTime: null,
        endTime: null,
        sharpPrice: null,
        sharpUsedElectricity: null,
        sharpPlanLossElectricity: null,
        sharpAmount: null,
        peakPrice: null,
        peakUsedElectricity: null,
        peakPlanLossElectricity: null,
        peakAmount: null,
        flatPrice: null,
        flatUsedElectricity: null,
        flatPlanLossElectricity: null,
        flatAmount: null,
        valleyPrice: null,
        valleyUsedElectricity: null,
        valleyPlanLossElectricity: null,
        valleyAmount: null,
        ammeterTotalStart: null,
        ammeterTotalEnd: null,
        totalElectricity: null,
        planLossTotalElectricity: null,
        consumptionAmount: null,
        vinCode: null,
        transactionIdentifier: null,
        transactionTime: null,
        stopReasonMsg: null,
        logicCard: null,
        createTime: 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
      getAbnormalRecord(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) {
            updateAbnormalRecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAbnormalRecord(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 delAbnormalRecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('order/abnormalRecord/export', {
        ...this.queryParams
      }, `abnormalRecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
