<template>
  <div class="main-page">
    <div class="main-page-header">
      <p class="title">用户管理</p>
      <el-form
        :inline="true"
        :model="searchForm"
        ref="searchForm"
        size="small"
      >
        <el-form-item
          prop="hospitalCode"
          label="单位名称"
        >
          <el-select
            v-model="searchForm.hospitalCode"
            placeholder="请选择医院"
            style="width: 100%"
            :clearable="true"
          >
            <el-option
              v-for="item in hospitalList"
              :label="item.hospitalName"
              :key="item.id"
              :value="item.hospitalCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="hospitalCode"
          label="角色类型"
        >
          <el-select
            v-model="searchForm.hospitalCode"
            placeholder="请选择医院"
            style="width: 100%"
            :clearable="true"
          >
            <el-option
              v-for="item in hospitalList"
              :label="item.hospitalName"
              :key="item.id"
              :value="item.hospitalCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="materialType"
          label="用户名"
        >
          <el-input
            placeholder="请输入用户名"
            v-model="searchForm.vehicleManager"
          />
        </el-form-item>
        <div class="btns">
          <el-button
            type="primary"
            size="small"
            @click="search"
          >查询</el-button>
          <el-button
            size="small"
            @click="resetForm('searchForm')"
          >重置</el-button>
          <!-- <el-button
            type="primary"
            size="small"
            @click="search"
          >同步用户信息</el-button> -->
        </div>
      </el-form>
    </div>
    <div class="main-page-body">
      <div class="mainContent">
        <table-mixin
          :pageSize="pageSize"
          :pageNum="pageNum"
          :total="total"
          :pagination="pagination"
          :handleSizeChange="handleSizeChange"
          :handleCurrentChange="handleCurrentChange"
        >
          <el-table
            v-loading="tableData.loading"
            :data="tableData.body"
            @sort-change="handleSortChange"
          >
            <div
              slot="empty"
              class="noData"
            ></div>
            <el-table-column
              label="序号"
              type="index"
              min-width="50"
            >
            </el-table-column>
            <el-table-column
              v-for="(item,index) in tableData.head"
              :prop="item.key"
              :label="item.name"
              align="left"
              :formatter="item.formatter"
              :sortable="item.sortable"
              :fixed="item.fixed"
              :key="index"
              :min-width="item.width"
              :show-overflow-tooltip="true"
            >
            </el-table-column>
            <el-table-column
              label="操作"
              align="left"
              width="auto"
              min-width="200px"
            >
              <template slot-scope="scope">
                <el-link
                  type="primary"
                  @click="auditHandler(scope.row.id)"
                >权限配置</el-link>
              </template>
            </el-table-column>
          </el-table>
        </table-mixin>
      </div>
    </div>
  </div>
</template>
<script>
import { tableDataMixin } from '../../common/js/mixin'
import { queryEmergencyHospitalList } from '@/api/common'
import { updateInsideRole, queryTeamUserPageList } from '@/api/user'
export default {
  name: 'expertPage',
  mixins: [tableDataMixin],
  data() {
    return {
      searchForm: {
        hospitalCode: '',
        materialType: ''
      },
      hospitalList: [],
      tableData: {
        loading: false,
        head: [
          {
            name: '用户名',
            key: 'loginName',
            sortable: false,
            width: '200',
            fixed: false
          },
          {
            name: '真实姓名',
            key: 'userName',
            sortable: false,
            width: '100',
            fixed: false
          },
          {
            name: '手机号',
            key: 'cellphone',
            sortable: false,
            width: '200',
            fixed: false
          },
          {
            name: '单位名称',
            key: 'storeCount',
            sortable: false,
            width: '150',
            fixed: false
          },
          {
            name: '辖区',
            key: 'storePlaceStr',
            sortable: false,
            width: '300',
            fixed: false
          },
          {
            name: '状态',
            key: 'auditStatusStr',
            sortable: false,
            width: '100',
            fixed: false
          },
          {
            name: '注册时间',
            key: 'auditStatusStr',
            sortable: false,
            width: '100',
            fixed: false
          }
        ],
        body: [],
        option: [],
        condition: []
      }
    }
  },
  mounted() {
    //获取可选择的医院
    queryEmergencyHospitalList().then(res => {
      this.hospitalList = res.respData
    })
    this.search()
  },
  methods: {
    getTableData() {
      this.tableData.loading = true
      const params = {
        ...this.searchForm,
        pageNo: this.pageNum,
        pageSize: this.pageSize
      }
      queryTeamUserPageList(params).then((res) => {
        if (res.msg == 201) {
          this.dealTableResponse(res)
        } else {
          this.$message.error(res.content)
        }
      })
    },
    showSaveDialog(type = 'add', id = '') {
      this.$refs.saveDialog.init(type, id)
    },
    auditHandler(id) {
      this.$confirm('是否审批通过？', '提示', {
        confirmButtonText: '通过',
        cancelButtonText: '拒绝',
        distinguishCancelAndClose: true,
        type: 'warning'
      }).then(() => {
        this.auditData(id, 2)
      }).catch(action => {
        if (action === 'cancel') {
          this.auditData(id, 3)
        }
      })
    },
    auditData(id, auditStatus) {
      addOrUpdateEmergencyMedical({ id: id, auditStatus: auditStatus }).then(res => {
        if (res.msg === 201) {
          this.$message.success('操作成功！')
        } else {
          this.$message.error(res.content)
        }
        this.search()
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.mainContent {
  padding: 20px;
  .bt {
    text-align: right;
    margin-bottom: 16px;
  }
}
</style>
