<template>
  <div class="app-container">
    <el-card shadow="never">
      <div>
        <i class="el-icon-search"></i>
        <span>筛选搜索</span>
        <div style="float:right">
          <el-button type="primary" @click="handleSearchList" size="small">
            查询
          </el-button>
        </div>
      </div>
      <div style="margin-top: 15px">
        <el-form
          size="small"
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          @submit.native.prevent
        >
          <el-form-item label="手机号">
            <el-input v-model="queryParams.phone" placeholder="请输入" />
          </el-form-item>
        </el-form>
      </div>
    </el-card>
    <el-table style="width: 100%" class="table-container" :data="unscrambleList">
      <el-table-column
        label="序号"
        align="center"
        type="index"
      ></el-table-column>
      <el-table-column
        label="登录手机号"
        align="center"
        prop="username"
      ></el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
      ></el-table-column>
      <el-table-column
        label="最近登录"
        align="center"
        prop="loginTime"
      ></el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button @click="handlePage(scope.row.id)" type="text" size="small"
            >查看</el-button
          >
          <el-button
            @click="handleStatus(scope.row.id, 0)"
            type="text"
            size="small"
            v-if="scope.row.status != 0"
            >禁用</el-button
          >
          <el-button
            @click="handleStatus(scope.row.id, 3)"
            type="text"
            size="small"
            v-else
            >启用</el-button
          >
          <el-button
            @click="handleStatus(scope.row.id, 2)"
            type="text"
            size="small"
            >升级</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>
<script>
import {
  getUserList,
  handleUser,
  deleteCompanyUser,
  resetPw
} from '@/api/account';
export default {
  data() {
    return {
      unscrambleList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        phone:''
      },
      total:0,
      optionList1: [
        {
          value: '1',
          label: '地级市'
        },
        {
          value: '2',
          label: '合肥区县'
        }
      ]
    };
  },
  methods: {
    handleSearchList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    getList() {
      getUserList(this.queryParams).then(({ data }) => {
        this.unscrambleList = data.list;
        this.total = data.total
      });
    },
    handleStatus(userId, status) {
      handleUser({ userId, status }).then(({ message }) => {
        this.msgSuccess(message);
        this.getList();
      });
    },
    // 跳转页面
    handlePage(id) {
      this.$router.push({ path: '/addCustomer', query: { id, check: true } });
    },
    /** 删除按钮操作 */
    handleDelete(companyId) {
      this.$confirm('确认升级该数据?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(function() {
          return deleteCompanyUser({ companyId });
        })
        .then(() => {
          this.getList();
          this.msgSuccess('升级成功');
        });
    },
    // 重置密码
    resetPwd(userId) {
      // resetPw
      this.$prompt('请输入新密码', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消'
        // inputPattern: /[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?/,
        // inputErrorMessage: '邮箱格式不正确'
      })
        .then(({ value }) => {
          resetPw({ userId, password: value }).then(({ data }) => {
            this.msgSuccess(data);
          });
        })
        .catch(() => {});
    }
  },
  created() {
    this.getList();
  }
};
</script>
