<template>
  <div class="subPage">
    <div class="system-table-search">
      <div class="flex-h">
        <div class="flex-item flex-h">
          <!-- <el-button size="mini" type="success" @click="addGoodsType">新增商品类型</el-button> -->
        </div>
        <ul>
          <li>
            <!-- <span>选择案场：</span> -->
            <el-select v-model="CaseId" placeholder="请选择">
              <el-option
                key=""
                label="所有案场"
                value="">
              </el-option>
              <el-option
                v-for="item in cases"
                :key="item.CaseId"
                :label="item.CaseName"
                :value="item.CaseId">
              </el-option>
            </el-select>
          </li>
          <li>
            <el-input
              placeholder="请输入用户名"
              v-model="userName"
            >
            </el-input>
          </li>
          <li>
            <el-input
              placeholder="请输入手机号"
              v-model="mobile"
            >
            </el-input>
          </li>
        </ul>
        <el-button
          size="mini"
          type="primary" @click="search">搜索</el-button>
      </div>
      <div class="moreFilter"></div>
    </div>
    <div class="system-table-box">
      <el-table
        :data="currentList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="CaseName"
          label="案场">
        </el-table-column>
        <el-table-column
          prop="CustomerName"
          label="用户名">
        </el-table-column>
        <el-table-column
          prop="Phone"
          label="手机号">
        </el-table-column>
        <el-table-column
          prop="Sex"
          label="性别">
        </el-table-column>
        <el-table-column
          label="检测时间">
          <template slot-scope="scope">
            <label>{{toolClass.dateFormat(scope.row.CreateDate)}}</label>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      @current-change="handleCurrentChange"
      :current-page.sync="postData.page"
      :page-size="postData.pagesize"
      layout="prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex'
const { mapState: mapHealthState, mapActions: mapHealthActions } = createNamespacedHelpers('health')

export default {
  name: '',
  data () {
    return {
      total: 0,
      userName: '',
      mobile: '',
      postData: { // 表格搜索条件
        caseid: '',
        page: 1, // 当前页码
        pagesize: 10, // 请求数据量
      },
      currentList: []
    }
  },
  mounted () {
    this.$nextTick(function () {
      this.getList()
    })
  },
  computed: {
    ...mapState({
      cases: x => x.app.cases.list,
      defaultCaseId: x => x.app.cases.default
    }),
    ...mapHealthState({
      list: x => x.healthList
    }),
    CaseId: {
      get () {
        return this.postData.caseid || this.defaultCaseId
      },
      set (val) {
        this.postData.caseid = val
      }
    }
  },
  methods: {
    ...mapHealthActions(['getHealthList']),
    search () { // 搜索
      this.postData.page = 1
      this.currentList = []
      this.getList()
    },
    getCaseName (caseid) {
      return (this.cases.filter(x => x.CaseId === caseid)[0] || {}).CaseName
    },
    getList () { // 获取列表
      this.getHealthList({ ...this.postData, caseid: this.CaseId, phone: this.mobile, customerName: this.userName }).then((res) => {
        this.currentList = this.list.list
        this.postData.page = this.list.page
        this.total = this.list.pagenum
      })
    },
    handleCurrentChange (val) { // 跳转到分页
      this.getList()
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
</style>
