
<template>
  <div class="agentManage app-container">
    <div class="search">
      <div>
        <el-input
          v-model="query.userName"
          size="small"
          placeholder="请输入用户ID或手机号"
          class="item-width-200 "
        ></el-input>
        <el-select
          v-model="query.address"
          size="small"
          clearable
          class="item-width-200 ml10"
          placeholder="请选择套餐"
        >
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
         <el-select
          v-model="query.address"
          size="small"
          clearable
          class="item-width-200 ml10"
          placeholder="请选择状态"
        >
          <el-option
            v-for="item in options1"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
         <el-button
        class="ml10"
        type="primary"
        size="small"
        icon="el-icon-search"
        @click="handleSearch"
      >
        搜索
      </el-button>
      </div>
      <el-button class="add-btn" type="primary" size="small" @click="handleAdd"
        >添加</el-button
      >
    </div>

    <el-table
      :data="tableData"
      tooltip-effect="dark"
      border
      v-loading="loading"
      style="width: 100%"
    >
      <el-table-column
        align="center"
        label="一级分类"
        prop="channelType"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="channelObjectId"
        align="center"
        label="二级分类"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="channelName"
        align="center"
        label="渠道网点名称"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        prop="createTime"
        align="center"
        label="所在地区"
        show-overflow-tooltip
      >
      <template slot-scope="scope">
         {{scope.row.province + '-' + scope.row.city + '-' + scope.row.district}}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        prop="status"
        label="渠道人数"
        show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
        align="center"
        prop="inviteCode"
        label="渠道邀请码"
        show-overflow-tooltip
      >
       
      </el-table-column>
      <el-table-column prop="address" align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="handleEdit(scope.row)"
            >编辑</el-button>
            <el-button type="text" size="small" @click="handleDel(scope.row.id)"
            >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="page-box">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        background
        :current-page="query.currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="query.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>
  
  <script>
  import {debounce} from '@/utils/index'
  import {channelManager} from '@/api/user'
export default {
  name: "agentManage",
  data() {
    return {
      tableData: [],
      options: [
        {
          value: "0",
          label: "全部套餐",
        },
        {
          value: "1",
          label: "10元套餐",
        },
        {
          value: "2",
          label: "20元套餐",
        },
        {
          value: "3",
          label: "30元套餐",
        },
        {
          value: "4",
          label: "无套餐",
        },
      ],
      options1: [
        {
          value: "0",
          label: "全部状态",
        },
        {
          value: "1",
          label: "启用",
        },
        {
          value: "2",
          label: "禁用",
        },
      ],
      loading: false,
      query: {
        channelName: "",
        channelObjectId: "",
        channelType: "",
        province: "",
        city: "",
        district: "",
        currentPage: 1,
        pageSize: 10,
      },
      title: "",
      total: 0,
    };
  },
  // watch: {
  //   query: {
  //     handler: debounce(function(val) {
  //       this.channelManager()
  //     }),
  //     deep:true
  //   }
  // },
  methods: {
    handleSearch(){
      this.query.currentPage = 1
      this.channelManager();

    },
    handleAdd() {
      this.$router.push("/userManage/agentManage/addAgent");
    },
    handleEdit(row) {
      sessionStorage.setItem('agentItem',JSON.stringify(row))
      this.$router.push("/userManage/agentManage/editAgent");

    },
    // 删除
     handleDel(id) {
       this.$confirm(`此操作将删除该数据, 是否继续?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          // delBanner({bannerId:id}).then(res=>{
          //   if(res.state == 'Success'){
          //      this.$notify({
          //       title: '成功',
          //       message: '操作成功',
          //       type: 'success'
          //     });
          //     this.channelManager()
          //   }
          // })
        })
    },
    handleSizeChange(val) {
      this.query.currentPage = 1;
      this.query.pageSize = val;
    this.channelManager()
    },
    handleCurrentChange(val) {
      this.query.currentPage = val;
    this.channelManager()
    },

    channelManager(){
      this.loading = true;
      channelManager(this.query).then(res=>{
        this.loading = false;
          if(res.state == 'Success'){
            this.tableData = res.content.records
            this.total = res.content.total
          }
      })
    }
  },
  created() {
    this.channelManager()
  },
};
</script>
  
<style lang="scss" scoped>
.agentManage {
  .search {
    justify-content: space-between;
    .add-btn {
      // margin-right: 20px;
    }
  }
}
</style>
  