<template>
  <div class="app-container">
    <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 label="上级用户" prop="parentUserId">
        <el-select v-model="queryParams.parentUserId" placeholder="请选择" filterable clearable size="small" style="width: 240px">
          <el-option v-for="(v,i) in partnerList" :key="i" :label="v.username" :value="v.partnerId" />
        </el-select>
      </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-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
      <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" />
      <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="订单数" prop="orderNum" align="center" />
      <el-table-column label="注册时间" align="center" prop="createDay" 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" prop="lastLoginTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.lastLoginTime, '{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="goDetails(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" />
  </div>
</template>

<script>
import { userPage } from "@/api/user.js";
import { partnerRelationList } from "@/api/partner"
export default {
  dicts: [],
  data () {
    return {
      //按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 测试单表表格数据
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 创建时间时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: undefined,
        status: undefined,
        locationCode: undefined,
        parentUserId: undefined
      },
      partnerList: []
    }
  },
  created () {
    if (this.$route.query.parentId) {
      this.queryParams.parentUserId = this.$route.query.parentId * 1
    }
    this.getList();
    // this.getPartnerList()
  },
  methods: {
    /** 查询测试单表列表 */
    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;
      });
    },
    getPartnerList () {
      partnerRelationList().then(res => {
        this.partnerList = res.data
      })
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map(item => item.adId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    goDetails (row) {
      this.$router.push({
        path: "/user/details",
        query: {
          id: row.id
        }
      })
    },
  }
}
</script>

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