<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth="'blacklist.create'"
        ></el-button>
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="query.search"
            placeholder="名称/信用号码"
            clearable
            @keyup.enter="handleQuery"
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="handleQuery"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable ref="table" :apiObj="apiObj" row-key="id" stripe>
        <el-table-column label="#" type="index" width="50"></el-table-column>
        <el-table-column
          label="企业名称"
          prop="name"
          width="240"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column label="信用代码" prop="number" width="180">
        </el-table-column>
        <el-table-column
          label="原因"
          :show-overflow-tooltip="true"
          prop="reason"
        >
        </el-table-column>
        <el-table-column label="最后操作人" width="200">
          <template #default="scope">
            <span v-if="scope.row.update_by_"
              >{{ scope.row.update_by_.name }}-{{ scope.row.update_time }}</span
            >
          </template>
        </el-table-column>

        <el-table-column label="操作" fixed="right" align="left" width="200">
          <template #default="scope">
            <el-button
              link
              type="primary"
              size="small"
              @click="table_show(scope.row, scope.$index)"
              >查看</el-button
            >
            <el-button
              link
              type="warning"
              size="small"
              @click="table_edit(scope.row, scope.$index)"
              v-auth="'blacklist.update'"
              >编辑</el-button
            >
            <el-popconfirm
              title="确定删除吗？"
              @confirm="table_del(scope.row, scope.$index)"
            >
              <template #reference>
                <el-button
                  link
                  type="danger"
                  size="small"
                  v-auth="'blacklist.delete'"
                  >删除</el-button
                >
              </template>
            </el-popconfirm>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSaveSuccess"
    @closed="dialog.save = false"
  ></save-dialog>
</template>
      <script>
import saveDialog from "./blacklist_form.vue";
export default {
  name: "rparty",
  components: {
    saveDialog,
  },
  data() {
    return {
      dialog: {
        save: false,
      },
      apiObj: this.$API.rpm.blacklist.list,
      query: {},
      selection: [],
      search: {
        keyword: null,
      },
    };
  },
  methods: {
    //添加
    add() {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("add");
      });
    },
    //编辑
    table_edit(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(row);
      });
    },
    //查看
    table_show(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("show").setData(row);
      });
    },
    //删除
    async table_del(row) {
      this.$API.rpm.blacklist.delete
        .req(row.id)
        .then((res) => {
          this.$message.success("删除成功");

          return res;
        })
        .catch((err) => {
          return err;
        });
    },

    //本地更新数据
    handleSaveSuccess(data, mode) {
      if (mode == "add") {
        this.$refs.table.refresh();
      } else if (mode == "edit") {
        this.$refs.table.refresh();
      }
    },
    handleQuery() {
      this.$refs.table.queryData(this.query);
    },
    resetQuery() {
      this.query = {};
    },
  },
};
</script>