<template>
  <div class="content-container">
    <el-row class="tool-bar">
      <el-col :span="12" class="left">
        <div class="content-title">微信客户</div>
      </el-col>

      <el-col :span="12" class="right">
        <el-input v-model="conditions.keywords" style="width: 200px;" class="filter-item" prefix-icon="el-icon-search" size="mini" placeholder="请输入内容" @keyup.enter.native="getData" />
        <el-button class="filter-item" style="margin-left: 10px;" type="primary" size="mini" icon="el-icon-search" @click="getData">查询</el-button>
      </el-col>
    </el-row>

    <el-row class="content-body">
      <el-table v-loading="listLoading" class="page-table" border :data="dataList" size="mini" height="calc(100vh - 280px)">
        <el-table-column type="index" label="序号" header-align="center" align="center" width="80" />

        <el-table-column label="客户名称" width="200" align="center" header-align="center">
          <template v-slot="{row}">
            <span>{{ row.wxName }}</span>
          </template>
        </el-table-column>

        <el-table-column label="卡号" width="200" align="center" header-align="center">
          <template v-slot="{row}">
            <span>{{ row.cardNo }}</span>
          </template>
        </el-table-column>

        <el-table-column label="电话号码" width="200" align="center" header-align="center">
          <template v-slot="{row}">
            <span>{{ row.wxPhone }}</span>
          </template>
        </el-table-column>

        <el-table-column label="备注">
          <template v-slot="{row}">
            <span>{{ row.remark }}</span>
          </template>
        </el-table-column>

        <el-table-column label="操作" class-name="small-padding fixed-width" align="center" header-align="center" width="120">
          <template v-slot="{row}">
            <el-button size="mini" icon="el-icon-delete" type="danger" @click="handleDelete(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>

    <div class="pagination-container">
      <pagination v-show="total>0" :total="total" :page.sync="conditions.page" :limit.sync="conditions.limit" @pagination="getData" />
    </div>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { getWxUserByPage, deleteWxUserById } from '@/api/system/wxUserApi'

export default {
  name: 'WxUserIndex',
  components: {
    Pagination
  },

  data() {
    return {
      dataList: undefined,
      listLoading: false,
      total: 0,
      conditions: {
        page: 1,
        limit: 10,
        keywords: ''
      }
    }
  },
  mounted() {
    this.getData()
  },
  methods: {

    // 初始化
    getData() {
      this.listLoading = true
      getWxUserByPage(this.conditions).then((resp) => {
        const { data, total } = resp
        this.listLoading = false
        this.total = total
        this.dataList = data
      }).catch((error) => {
        console.log(error)
      })
    },

    // 删除
    handleDelete(data) {
      const { wxId } = data
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteWxUserById(wxId).then((resp) => {
          const { msg } = resp
          this.getData()
          this.$message.success(msg)
        }).catch((error) => {
          console.log(error)
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    }
  }
}
</script>
<style lang="scss">
</style>
<style lang="scss" scoped>
.content-container{
}
</style>
