<template>
  <el-dialog title="选择人员" :modal-append-to-body="true" :visible.sync="dialogVisible" width="60%" :before-close="handleClose">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="用户手机号" prop="mobile">
        <el-input v-model="queryParams.mobile" maxlength="11" placeholder="请输入用户手机号" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="注册时间">
        <el-date-picker v-model="daterangeCreateTime" size="small" style="width: 240px" value-format="yyyy-MM-dd" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
      <el-row :gutter="10" class="mb8">
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="list">
        <el-table-column type="index" width="55" label="序号" align="center">
          <template slot-scope="scope">
            <div>
              {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="会员ID" align="center" prop="id" width="80" />
        <el-table-column label="头像" align="center" prop="headPhoto">
          <template slot-scope="scope">
            <el-image v-if="scope.row.headPhoto" style="width: 50px; height: 50px" :src="scope.row.headPhoto" :preview-src-list="scope.row.headPhoto ? [scope.row.headPhoto] : []"></el-image>
            <div v-else>--</div>
          </template>
        </el-table-column>
        <el-table-column label="昵称" align="center" prop="nickname" />
        <el-table-column label="手机号" prop="mobile" align="center" />
        <el-table-column label="注册时间" align="center" prop="createTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="select(scope.row)">选择</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" />
    </el-form>
  </el-dialog>
</template>

<script>
import { userPage } from "@/api/user.js";
export default {
  data () {
    return {
      dialogVisible: false,
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: undefined,
        locationCode: undefined
      },
    }
  },
  methods: {
    open () {
      this.dialogVisible = true;
      this.getList()
    },
    handleClose (done) {
      this.dialogVisible = false;
    },
    select (row) {
      this.$emit("result", row);
      this.handleClose()
    },
    /** 查询测试单表列表 */
    getList () {
      this.loading = true;
      this.queryParams["createDayStart"] = undefined;
      this.queryParams["createDayEnd"] = undefined;
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams["createDayStart"] = this.daterangeCreateTime[0];
        this.queryParams["createDayEnd"] = this.daterangeCreateTime[1];
      }
      userPage(this.queryParams).then(response => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

<style lang='scss' scoped>
</style>