<template>
  <div v-loading="loading">
    <div class="white-box">
      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;">
        <el-table-column label="Consignee" prop="CONSIGNEE" width="150"></el-table-column><!-- 收货人 -->
        <el-table-column label="Phone Number" prop="MOBILE" width="150"></el-table-column><!-- 手机号码 -->

        <el-table-column label="Address" prop="ADDRESS" ></el-table-column><!-- 详细地址 -->

        <el-table-column label="City" prop="CITY_NAME" width="150"></el-table-column>
        <el-table-column label="Local Government Area" prop="LGA_NAME" width="180"></el-table-column>
        <el-table-column label="State" prop="PROVINCE_NAME" width="150"></el-table-column>
        <el-table-column label="Default" width="100">
          <template slot-scope="scope">
            {{scope.row.IS_DEFAULT === '1' ? 'YES' : 'NO'}}<!-- 是：否 -->
          </template>
        </el-table-column>

        <el-table-column fixed="right" label="Action" width="180"><!-- 操作 -->
          <template slot-scope="scope">
            <el-dropdown size="small" trigger="click">
              <el-button type="primary" size="small" @click.stop="">
                Action<!-- 操作该数据 --><i class="el-icon-arrow-down el-icon--right"></i>

              </el-button>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item command="edit" @click.native="handleUpdate(scope.row)">Edit<!-- 编辑 --></el-dropdown-item>
                <el-dropdown-item command="edit" @click.native="handleDelete(scope.row)">Delete<!-- 删除 --></el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </template>
        </el-table-column>
      </el-table>
      <div class="white-box-footer">
        <el-button type="primary" size="small" @click="handleAdd">Add shipping address<!-- 添加收货地址 --></el-button>
        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
      </div>
    </div>
  </div>
</template>

<script>
  import network from '@/utils/network'
  import tool from '@/utils/tool'
  import Pagination from '@/components/Pagination'

  export default {
    name: 'config_receive-address-list',
    components: {Pagination},
    mounted() {
      this.loading = false
      this.getData()
    },
    data() {
      return {
        tableData: [],
        loading: true,
        multipleSelection: [],
        currentPage: 1,
        totalPages: 1,
        totalCount: 1,
        pageSize: 20,
        tool: tool,
        filterData: null,
        filterStatus: 'ALL',
        periodNum: null,
        periodNums: null,
        allType:{ORDER:'订货店补',TRANS:'转账店补',PROD:'产品补贴',TOOL:'工具流补贴'}
      }
    },
    methods: {
      handleCurrentChange(page) {
        this.getData(page, this.pageSize)
      },
      handleSizeChange(pageSize) {
        this.getData(this.currentPage, pageSize)
      },
      getData(page, pageSize) {
        let vueObj = this
        network.getPageData(this, 'config/receive-address-list', page, pageSize, null, function (response) {
          vueObj.tableData = response.list
        })
      },
      handleAdd() {
        this.$router.push({path: `/config/receive-address-add`})
      },
      handleUpdate (row) {
        this.$router.push({path: `/config/receive-address-edit/${row.ID}`})
      },
      handleDelete (row) {
        this.$confirm(`Are you sure you want to delete the selected data？`, 'Hint', {//`确定要删除所选数据吗？`, '提示'
          confirmButtonText: 'Confirm',//确定
          cancelButtonText: 'cancel',//取消
          type: 'warning'
        }).then(() => {
          let selectedIds = [row.ID]
          return network.postData(`config/receive-address-delete`, {selected: selectedIds})
        }).then(response => {
          this.$message({
            message: response,
            type: 'success'
          })
          this.getData(this.currentPage, this.pageSize)
        }).catch(response => {
          this.$message({
            message: response,
            type: 'error'
          })
        })
      },
    }
  }

</script>

<style scoped>
  .leo-filter {
    padding: 0 0 15px 0;
  }

  .leo-filter .filter-hidden {
    display: none;
  }

  .filter-item {
    margin-right: 10px;
  }

  @media (min-width: 768px) {
    .leo-filter {
    }

    .leo-filter .filter-item {
      display: inline-block;
      max-width: 200px;
    }

    .leo-filter .filter-item.filter-date-month-picker {
      display: inline-block;
      max-width: 220px;
    }

    .leo-filter .filter-item.filter-date-range-picker {
      display: inline-block;
      max-width: 380px;
    }

    .leo-filter .filter-item.filter-filter-btn {
      height: 38px;
      width: 80px;
    }

    .leo-filter .filter-hidden {
      display: none;
    }
  }

  .table-box .el-form-item__label {
    width: 100px;
    color: #99a9bf;
  }

  .table-box .el-form-item {
    width: 30%;
    margin-right: 0;
    margin-bottom: 0;
  }
</style>
