<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="addPPLConcerned">新增相关人员</el-button>
        </div>
      </div>
      <div class="moreFilter"></div>
    </div>
    <div class="system-table-box">
      <el-table
        :data="currentList"
        stripe
        style="width: 100%">
        <el-table-column
          label="用户类型">
          <template slot-scope="scope">
            {{getUserType(scope.row)}}
          </template>
        </el-table-column>
        <el-table-column
          prop="UserName"
          label="用户名称">
        </el-table-column>
        <el-table-column
          prop="Tel"
          label="手机号">
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="warning"
              @click="editItem(scope.$index, scope.row)">编辑</el-button>
          </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>

export default {
  name: '',
  data () {
    return {
      total: 0,
      postData: { // 表格搜索条件
        caseid: this.$route.query.id, // 案场名称
        page: 1, // 当前页码
        pagesize: 10, // 请求数据量
      },
      currentList: [],
      typeList: [],
    }
  },
  created () {
    this.getUserTypeList().then(() => {
      this.getList()
    })
  },
  methods: {
    getUserType (row) {
      return (this.typeList.filter(x => x.TypeCode === row.UserType)[0] || {}).TypeName || ''
    },
    getUserTypeList () { // 获取用户类型
      return new Promise((resolve) => {
        this.$ajax(this.$api.caseManager.getCaseUserType.url, {
          method: this.$api.caseManager.getCaseUserType.method,
        }).then(res => {
          this.typeList = res
          resolve()
        })
      })
    },
    addPPLConcerned () { // 添加相关人员
      this.$router.push({ name: 'editPPLConcerned', query: { id: this.$route.query.id } })
    },
    getList () { // 获取列表
      this.$ajax(this.$api.caseManager.getCaseUserList.url, {
        method: this.$api.caseManager.getCaseUserList.method,
        queryData: this.postData
      }).then(res => {
        this.currentList = res.list
        this.postData.page = res.page
        this.total = res.pagenum
      })
    },
    handleCurrentChange (val) { // 跳转到分页
      this.getList()
    },
    editItem (index, row) { // 修改
      this.$router.push({ name: 'editPPLConcerned', query: { id: this.$route.query.id, userid: row.CaseUserId } })
    },
    searchList (key) { // 搜索列表
      this.postData.name = key
      this.currentList = []
      this.postData.page = 1
      this.getList()
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style lang="scss" scoped>
@import "page.scss";
</style>
