<!-- 小程序用户管理列表 -->
<template>
  <div class="app-container">
    <!--筛选条件-->
    <div class="search-div">
      <el-form ref="selectForm" :inline="true" :model="listQuery" class="form-container">
        <el-row>
          <el-form-item class="selectForm-container-item">
            <el-input v-model.trim="listQuery.phone" placeholder="手机号" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item">
            <el-input v-model.trim="listQuery.name" placeholder="姓名" clearable/>
          </el-form-item>
          <el-form-item class="selectForm-container-item">
            <el-select v-model="listQuery.status" filterable placeholder="用户状态" clearable value="" >
              <el-option
                v-for="item in statusList"
                :key="item.value"
                :label="item.name"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-form-item class="selectForm-container-item">
            <el-select v-model="listQuery.project" filterable placeholder="所在项目" clearable value="" >
              <el-option
                v-for="item in projectList"
                :key="item.value"
                :label="item.name"
                :value="item.value"/>
            </el-select>
          </el-form-item>
          <el-button class="filter-item" type="primary" icon="el-icon-search" @click="search">查询</el-button>
        </el-row>
      </el-form>
    </div>
    <!--查询结果Table显示-->
    <div>
      <el-row class="table-title">
        <el-col :span="15"><div class="title-header"><i class="el-icon-menu"/>数据列表</div></el-col>
        <el-button style=" float:right;margin:7px 3px;" size="small" @click="add">批量导入用户</el-button>
        <el-button style=" float:right;margin:7px 3px;" size="small" @click="add">新增用户</el-button>
      </el-row>
      <el-table v-loading="listLoading" :data="list" class="table" border @selection-change="handleSelectionChange">
        <el-table-column :index="indexMethod" align="center" type="index" label="序号" width="55"/>
        <el-table-column v-for="column in columns" :key="column.value" :label="column.text" :width="column.width" :align="column.align" show-overflow-tooltip>
          <template slot-scope="scope">
            <span :class="column.class">{{ scope.row[column.value] }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template slot-scope="scope">
            <el-button type="text" @click="detail(scope.row)">详情</el-button>
            <el-button v-if="scope.row.userStatusName !== '已删除'" type="text" @click="edit(scope.row)">编辑</el-button>
            <el-button v-if="scope.row.userStatusName !== '未绑定' & scope.row.userStatusName !== '已删除'" type="text" @click="unbind(scope.row)">解绑</el-button>
            <el-button v-if="scope.row.userStatusName !== '已删除'" type="text" @click="del(scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页-->
    <div class="pagination-container">
      <el-pagination
        :current-page="listQuery.offset"
        :page-sizes="[10,20,30]"
        :page-size="listQuery.limit"
        :total="total"
        align="center"
        layout="total, sizes, prev, pager, next"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"/>
    </div>
    <AddUserDialog v-show="dialogFormVisible" ref="addUserDialogRef" @watchChild="fetchData"/>
  </div>
</template>

<script>
import DownloadTemplate from '@/components/DownloadTemplate/index'
import AddUserDialog from '../components/addUserDialog.vue'
export default {
  name: 'ListQuality',
  components: { DownloadTemplate, AddUserDialog },
  data() {
    return {
      fileList: [], // 批量导入
      qualityfilename: 'repairsImp.xlsx',
      statusList: [
        {
          name: '已绑定',
          value: '1'
        },
        {
          name: '未绑定',
          value: '2'
        },
        {
          name: '已删除',
          value: '3'
        }
      ],
      projectList: [
        {
          id: '1',
          name: '项目1'
        },
        {
          id: '2',
          name: '项目2'
        },
        {
          id: '3',
          name: '项目3'
        }
      ],
      listQuery: {
        name: '', // 项目名称
        phone: '', // 手机号
        status: '', // 项目状态
        project: '', // 所在项目
        offset: 1,
        limit: 10
      }, // 筛选条件
      columns: [
        {
          text: '手机号',
          value: 'phone',
          align: 'center'
        },
        {
          text: '姓名',
          value: 'name',
          align: 'center'
        },
        {
          text: '所在项目',
          value: 'project',
          align: 'center'
        },
        {
          text: '微信用户',
          value: 'wxAccount',
          align: 'center'
        },
        {
          text: '绑定时间',
          value: 'time',
          align: 'center'
        },
        {
          text: '用户状态',
          value: 'userStatusName',
          align: 'center'
        }
      ], // 显示列
      list: [], // 列表数据
      total: 0, // 数据总数
      multipleSelection: [], // 多选
      listLoading: true, // 加载动画
      fullscreenLoading: false, // 全屏加载动画
      editShow: false, // 是否显示编辑框
      dialogFormVisible: false, // 是否显示编辑框
      exportDialogVisible: false // 导出弹窗显隐
    }
  },
  created() {
    this.fetchData()// 获取数据
  },
  activated() {
    this.fetchData()// 获取数据
  },
  methods: {
    closeDialog() {
      this.exportDialogVisible = false
    },
    // 查询数据
    search() {
      console.log(this.listQuery)
      this.fetchData(false)
    },
    // 获取字典数据
    fetchData(isNowPage = true) {
      // this.listLoading = true
      if (!isNowPage) { // 是否显示当前页，否则跳转第一页
        this.listQuery.offset = 1
      }
      this.list = [
        {
          id: '1',
          name: 'test',
          phone: '123456',
          project: '项目1',
          projectIds: ['1', '2'],
          wxAccount: 'wx123646',
          time: '2102-12-12 12::06:05',
          userStatusName: '已绑定'
        },
        {
          id: '1',
          name: 'test',
          phone: '123456',
          project: '项目1',
          projectIds: ['2', '3'],
          wxAccount: 'wx123646',
          time: '2102-12-12 12::06:05',
          userStatusName: '未绑定'
        },
        {
          id: '1',
          name: 'test',
          phone: '123456',
          project: '项目2',
          projectIds: ['1', '2', '3'],
          wxAccount: 'wx123646',
          time: '2102-12-12 12::06:05',
          userStatusName: '已删除'
        },
        {
          id: '1',
          name: 'test',
          phone: '123456',
          project: '项目1',
          wxAccount: 'wx123646',
          time: '2102-12-12 12::06:05',
          userStatusName: '未绑定'
        }
      ]
      // getLogList(this.listQuery).then(response => {
      //   this.list = response.data.rows
      //   this.total = parseInt(response.data.total)
      this.listLoading = false
      // })
    },
    // 制作表格序号
    indexMethod(index) {
      return this.listQuery.limit * (this.listQuery.offset - 1) + index + 1
    },
    // 改变页容量
    handleSizeChange(val) {
      this.listQuery.limit = val
      this.fetchData()
    },
    // 改变当前页
    handleCurrentChange(val) {
      this.listQuery.offset = val
      this.fetchData()
    },
    // 多选触发方法
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    // 点击新增
    add() {
      this.dialogFormVisible = true
      this.$refs.addUserDialogRef.initDialog('create', this.dialogFormVisible)
    },
    // 点击编辑
    edit(row) {
      this.dialogFormVisible = true
      this.$refs.addUserDialogRef.initDialog('update', this.dialogFormVisible, row)
    },
    // 点击详情
    detail(row) {
      this.dialogFormVisible = true
      this.$refs.addUserDialogRef.initDialog('detail', this.dialogFormVisible, row)
    },
    // 点击解绑
    unbind(row) {

    },
    // 点击删除
    del(row) {

    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  $tableTitleHeight:46px;
  .table{
    margin-bottom: 20px;
  }
  .pagination-container{
    margin-bottom: 50px;
  }
  .table-title{
    background-color:rgba(243, 243, 243, 1);
    height: $tableTitleHeight;
    .title-header{
      line-height:$tableTitleHeight;
      color: #606266;
      font-size: 15px;
      i{
        margin-left: 5px;
        margin-right: 5px;
      }
    }
  }
  .edit_btns{
    .edit_btn{
      float:right;
      margin:7px 3px;//为了需要居中显示margin-top和bottom要用$tableTitleHeight减去按钮原高度除以2
    }
  }
  .upload-btn{
    display: inline;
  }
</style>
