<template>
  <div style="margin-top:20px">
    <div class="table-content">
      <el-table :data="tableData" style="width: 100%" tooltip-effect="dark" v-loading="loading" :height="tableHeight">
        <el-table-column label="错误码" prop="errorCode"> </el-table-column>
        <el-table-column label="错误信息" prop="errorInfo"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="edit(scope.row)">编辑</el-button>
            <dm-delete @confirm="deleteList(scope.row)" tips="确定要删除吗?">
              <el-button type="text">删除</el-button>
            </dm-delete>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <newErrorCode v-if="showNewCode" :errorSettingId="errorSettingId" :errorCode="errorCode" :errorInfo="errorInfo" @getList="getList" @cancelNewCoce="cancelNewCoce"></newErrorCode>
  </div>
</template>

<script>
import { postRequest } from '@/api/api';
import newErrorCode from '@/components/plug/new-error-code';
export default {
  props: {
    tableData: {
      type: Array,
      default() {
        return [];
      }
    }
  },
  data() {
    return {
      showNewCode: false,
      errorSettingId: '',
      errorInfo: '',
      errorCode: ''
    };
  },
  methods: {
    getList() {
      this.$emit('getList');
    },
    edit(item) {
      this.showNewCode = true;
      this.errorSettingId = item.errorSettingId;
      this.errorCode = item.errorCode;
      this.errorInfo = item.errorInfo;
    },
    cancelNewCoce() {
      this.showNewCode = false;
    },
    deleteList(item) {
      let params = {
        errorSettingId: item.errorSettingId
      };
      postRequest('/gateway-manage/delete-error-setting', params).then(res => {
        if (res.data.code == '0000') {
          this.$emit('getList');
        } else {
          this.$message.error(res.data.message);
        }
      });
    }
  },
  components: {
    newErrorCode
  }
};
</script>
<style lang="less" scoped></style>
