<template>
  <div class="container normal-panel">
    <!-- 表格搜索 -->
    <div class="flex-align-center search-panel" style="margin-bottom: 16px">
      <div class="flex-align-center">
        <p>搜索:</p>
        <el-input prefix-icon="el-icon-search" style="width:200px" placeholder="账号,系统名称,联系电话" v-model="param.content.where.condition" class="input-with-select" size="small" @clear="listData('search')" @keyup.native.enter="listData('search')" clearable></el-input>
      </div>
      <div class="flex-align-center" style="margin-left: 30px">
        <p>状态:</p>
        <el-select
          style="width: 120px"
          size="small"
          v-model="status"
          placeholder="请选择"
          @change="listData('search')"
        >
          <el-option
            v-for="item in select"
            :label="item.remarks"
            :value="item.value"
            :key="item.index"
          ></el-option>
        </el-select>
      </div>
      <div class="flex-align-center" style="margin-left: 30px">
        <p style="width:70px">用户类型:</p>
        <el-select
          style="width: 120px"
          size="small"
          v-model="userType"
          placeholder="请选择"
          @change="listData('search')"
          clearable
        >
          <el-option
            v-for="item in userTypeArr"
            :label="item.remarks"
            :value="item.value"
            :key="item.rowindex"
          ></el-option>
        </el-select>
      </div>
    </div>
    <!-- 表格主题 -->
    <tableLayout
      :layout="tablecols"
      :data="list"
      :opwidth="200"
      :custom="true"
      :height="tableHieght"
    >
      <template v-slot:customcol="scope">
        <p v-if="scope.column.columnname === 'status'">
          <span
            :style="
              scope.column.data.status === 'ACTIVE'
                ? 'color:#52C41A'
                : 'color:#FF3B30'
            "
            >{{
              scope.column.data.status === "ACTIVE"
                ? "启用"
                : scope.column.data.status === "INACTIVE"
                ? "停用"
                : "其他"
            }}</span
          >
        </p>
        <p v-else>{{ scope.column.data[scope.column.columnname] }}</p>
      </template>
      <template v-slot:opreation="scope">
        <slot name="detail" :data="scope.data"></slot>
        <slot name="edit" :data="scope.data"></slot>
        <slot name="use" :data="scope.data"></slot>
        <!-- <el-button size="mini" type="text"  @click="onDelete(scope)">删 除</el-button> -->
        <slot name="del" :data="scope.data"></slot>
      </template>
    </tableLayout>
    <div style="margin-top: 16px; text-align: right">
      <el-pagination
        background
        small
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="param.content.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import tableLayout from "../../../components/dynamic-table";
export default {
  components: {
    tableLayout,
  },
  data() {
    return {
      param: {
        classname: "webmanage.users.users",
        method: "query_userList",
        content: {
          pageNumber: 1,
          pageSize: 20,
          where: {
            condition: "",
            status: "",
          },
        },
      },
      status: "ALL",
      select: [],
      tablecols: [],
      list: [],
      total: 0,
      currentPage: 0,
      value: "",
      userType: '',
      userTypeArr: ''
    };
  },
  methods: {
    listData(issearch) {
      issearch === "search" ? (this.param.content.pageNumber = 1) : "";
      this.param.content.where.usertype = this.userType

      this.param.content.where.status =
        this.status === "ALL" ? "" : this.status;

      this.$api.requested(this.param).then((res) => {
        this.list = res.data;
        this.total = res.total;
        console.log(this.total);

        this.currentPage = res.pageNumber;
      });
    },
    //获取用户类型
    async getRoleData() {
      let param = {
          "accesstoken": "4a6559d45d2a4c6e0ebac2c803344106",
          "classname": "sysmanage.develop.optiontype.optiontype",
          "method": "optiontypeselect",
          "content": {
              "pageNumber": 1,
              "pageSize": 20,
              "typename": "usertype",
              "parameter": {
              }
          }
      }
      let res = await this.$api.requested(param)
      res.data.unshift({
        remarks:'全部',
        rowindex:100,
        value: ''
      })
      this.userTypeArr = res.data
    },
    async userstatus() {
      let param = {
        classname: "sysmanage.develop.optiontype.optiontype",
        method: "optiontypeselect",
        content: {
          pageNumber: 1,
          pageSize: 20,
          typename: "userstatus",
          parameter: {},
        },
      };
      const res = await this.$api.requested(param);
      this.select = res.data;
      console.log(this.select);
      
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.param.content.pageSize = val;
      this.listData();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.param.content.pageNumber = val;
      this.listData();
    },
    handleSelectionChange(selecttion) {
      this.$emit("handleSelectionChange", selecttion);
    },
  },
  created() {
    this.getRoleData()
  },
  mounted() {
    this.listData();
    this.userstatus();
    this.tablecols = this.tool.tabelCol(
      this.$route.name
    ).accountTable.tablecols;
  },
};
</script>
<style>
.el-input-group__append,
.el-input-group__prepend {
  background-color: #4f7bfd;
  color: #fff;
  border: 1px solid #4f7bfd;
  cursor: pointer;
}
</style>
<style scoped>
.search-panel p {
  flex: 1 0 auto;
  width: 40px;
  font-size: 14px;
}
</style>


