<template>
  <div class="charge-box">
    <div class="charge-tools">
      <el-form :inline="true" :model="queryParams">
        <el-form-item label="模型名称:">
          <el-input placeholder="请输入司机姓名" v-model="queryParams.modelName" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery" class="serch actve">查询</el-button>
          <el-button type="primary" @click="resetForm" class="serch">重置</el-button>
        </el-form-item>

      </el-form>
    </div>
    <div class="charge-table">

      <div class="charge-table-bottom">
        <el-table :data="datalist" :header-cell-style="{
          background: '#1d283e',
          borderColor: '#2f3c86',
          height: '36px',
          lineHeight: '36px',
          color: 'white',
          fontSize: '16px',
        }" stripe fit :height="tableheight" style="width: 100%" :default-sort="{ prop: 'date', order: 'descending' }">
          <el-table-column prop="modelId" label="费率模型版本">
          </el-table-column>
          <el-table-column prop="modelName" label="模型名称">
          </el-table-column>
          <el-table-column prop="createTime" label="下发时间">
          </el-table-column>
          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button type="primary" class="handle" size="small" @click="handlealarm(scope.row)">详情</el-button>
              <el-button type="primary" class="handle" size="small" v-if="scope.row.isCanDelete == 0"
                @click="del(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="pageblock">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page="queryParams.page" :page-sizes="[10, 20, 30, 40]" :page-size="queryParams.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="total">
        </el-pagination>
      </div>
    </div>

    <!--弹窗-->
    <div class="rolemanage alarmFrom">
      <el-dialog title="详情" :visible.sync="dialogAlarmVisible" :destroy-on-close="true">
        <el-form :model="alarmFrom" class="dislog">
          <el-form-item label="费率模型名称：" label-width="120px">
            <el-input v-model="alarmFrom.modelName" disabled></el-input>
          </el-form-item></el-form>

        <div class="charge-table-bottom">
          <el-table :data="alarmFrom.rateDetailList" :header-cell-style="{
            background: '#1d283e',
            borderColor: '#2f3c86',
            height: '36px',
            lineHeight: '36px',
            color: 'white',
            fontSize: '16px',
          }" stripe fit style="width: 100%" :default-sort="{ prop: 'date', order: 'descending' }">
            <el-table-column prop="startTime" label="费率起始时分">
            </el-table-column>
            <el-table-column prop="chargePower" label="电价费率(kW·h/元)">
            </el-table-column>
            <el-table-column prop="serPower" label="服务费率(kW·h/元)">
            </el-table-column>
          </el-table>
        </div>
        <div slot="footer" class="dialog-footer">

        </div>
      </el-dialog>
    </div>
    <!--处理告警弹窗结束-->
  </div>
</template>
  
<script>
import '../permission.scss';
import { getratelist, getdeletecode } from "@/api/records";
export default {
  name: "RecordAlarm",
  components: {},
  data() {
    return {
      // 表单校验
      rules: {
        remark: [
          { min: 0, max: 30, message: '长度最大30个字符', trigger: 'blur' }
        ],
      },
      //查询时间数组
      dateArr: {
        alarmDate: [],
      },
      datalist: [],
      //查询参数
      queryParams: {
        page: 1, //当前页
        pageSize: 10,//每页条数
        modelName: undefined, //充电机ID
        orderByField: undefined, //排序字段
        orderByWays: 'desc'//排序方式
      },
      total: 0,//总条数，
      tableheight: 0,//表格高度设置
      dialogAlarmVisible: false,//弹窗状态
      alarmFrom: {
      },
      formLabelWidth: '120px',
      loading: false,
    };
  },
  mounted() {
    this.alarmList()
    this.onLoadHeight()
    this.changeWindow()
  },
  methods: {
    //告警记录列表，
    alarmList() {
      const params = this.queryParams
      getratelist(params).then(res => {
        this.datalist = res.data.list
        this.total = res.data.total
      });
    },
    /**分页下一页 */
    handleSizeChange(val) {
      this.queryParams.pageSize = val
      this.alarmList()
    },
    /**分页选择页数 */
    handleCurrentChange(val) {
      this.queryParams.page = val
      this.alarmList()
    },
    //搜索
    handleQuery() {
      this.alarmList()
    },
    //搜索重置
    resetForm() {
      this.queryParams.modelName = undefined
      this.alarmList()
    },
    //弹窗
    handlealarm(row) {
      console.log(row, 'rp')
      this.alarmFrom = row
      this.dialogAlarmVisible = true;
    },
    //删除
    del(e) {
      this.$confirm("删除数据将丢失,请确认是否删除", "确认删除", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning",
      }).then(async () => {
        await getdeletecode(e.id).then(res => {
          if (res.code == 0) {
            this.$message({
              type: "success",
              message: "删除成功！",
            });
            this.alarmList()
          }
        })
      })
        .catch((err) => {
          console.error(err);
        });

    }
  },
};
</script>
<style lang="scss" scoped>
::v-deep .is-disabled {
  .el-input__inner {
    border: 1px solid #556179 !important;
  }

  margin-bottom: 20px;
}

::v-deep .el-dialog__body {
  padding: 0px;
  padding-top: 20px;
}

::v-deep .dislog {
  .el-form-item {
    margin-left: 0px;
  }
}

::v-deep .el-dialog__body {
  .el-table__body-wrapper {
    max-height: 280px;
    overflow-y: auto;
  }
}
</style>