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

<script>
import { postRequest } from '@/api/api';
import newErrorCode from '@/components/plug/new-error-code';
export default {
  components: {
    newErrorCode
  },
  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);
        }
      });
    }
  }
};
</script>
<style lang="less" scoped></style>
