<template>
  <div class="location-list">
    <el-table :data="tableData" style="width: 100%">
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column prop="addressid" label="ID"> </el-table-column>
      <el-table-column prop="addressname" label="地址名称"> </el-table-column>
      <el-table-column prop="longitude" label="经度"> </el-table-column>
      <el-table-column prop="latitude" label="维度"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="120">
        <template slot-scope="scope">
          <el-button
            @click.native.prevent="deleteRow(scope.row)"
            type="text"
            size="small"
          >
            移除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getLocation, delLocation } from "@/api/location";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    //获取全部的地址信息
    getLocationList() {
      getLocation().then((res) => {
        this.tableData = res.data;
      });
    },
    //点击删除
    deleteRow(row) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delLocation({
            addressid: row.addressid,
          })
            .then((res) => {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getLocationList();
            })
            .catch((err) => {
              this.$message.error('删除失败');
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
  },
  created() {
    this.getLocationList();
  },
};
</script>

<style scoped>
.location-list {
  width: 70%;
  margin: 120px auto;
}
</style>