<template>
  <div class="list">
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column type="index" width="50"> </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 label="操作">
        <template slot-scope="scope">
          <el-button size="mini" type="danger" @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { showAddresses, delOneAddress } from "@/api/address.js";
export default {
  data() {
    return {
      tableData: [],
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      showAddresses()
        .then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.records;
          }
        })
        .catch((err) => {
          console.log(err, "失败");
        });
    },
    handleDelete(row) {
      let _id = row.addressid;
      console.log(_id);
      delOneAddress([_id])
        .then((res) => {
          if (res.code == 200) {
            this.$message({
              message: res.message,
              type: "success",
            });
            this.init();
          }
        })
        .catch((err) => {
          console.log(err, "失败");
        });
    },
  },
};
</script>

<style scoped>
.list {
  width: 70%;
  margin: 200px auto 0;
}
</style>
