/* 
等级列表
author: zsy
date: 2024-1-19
*/
<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" width="180">
      </el-table-column>
      <el-table-column prop="addressname" label="地址" width="180">
      </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) {
      console.log(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: 100px auto;
}
</style>