<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="收货人" prop="CONSIGNEE" width="150"></el-table-column>
        <el-table-column label="手机号码" prop="MOBILE" width="150"></el-table-column>
        <el-table-column label="省/市" prop="PROVINCE_NAME" width="150"></el-table-column>
        <el-table-column label="市/区" prop="CITY_NAME" width="150"></el-table-column>
        <el-table-column label="区/县" prop="COUNTY_NAME" width="150"></el-table-column>
        <el-table-column label="详细地址" prop="ADDRESS" ></el-table-column>
        <el-table-column label="是否默认" width="100">
          <template slot-scope="scope">
            {{scope.row.IS_DEFAULT === '1' ? '是' : '否'}}
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="180">
          <template slot-scope="scope">
            <el-dropdown size="small" trigger="click">
              <el-button type="primary" size="small" @click.stop="">
                操作该数据<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)">编辑</el-dropdown-item>
                <el-dropdown-item command="edit" @click.native="handleDelete(scope.row)">删除</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">添加收货地址</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(`确定要删除所选数据吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          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>
