<template>
  <div>
    <!--条件-->
    <el-form :model="listQuery" ref="queryForm" :inline="true">
      <el-form-item label="机构编码">
        <el-input
          v-model="listQuery.orgId"
          placeholder="请输入机构编码"
        ></el-input>
      </el-form-item>
      <el-form-item label="机构名称">
        <el-input
          v-model="listQuery.orgName"
          placeholder="请输入机构名称"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="机构类型">
        <el-select
          v-model="listQuery.orgType"
          placeholder="请选择机构类型"
        >
        <el-option v-for="item in orgData"
              :key="item.id"
              :label="item.dicVal"
              :value="item.dicCode"
              clearable></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="getData(true)">查询 </el-button>
        <el-button @click="reset(true)">重置 </el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <div>
      <el-table
        ref="multipleTable"
        row-key="id"
        v-loading="listLoading"
        :data="list"
        element-loading-text="加载中"
        fit
        stripe
      >
        <template slot="empty">
          <img src="@/assets/nopage.png" alt />
          <p>暂无数据</p>
        </template>
        <el-table-column width="50">
          <template slot-scope="scope">
            <el-radio v-model="orgRadio" :label="scope.row.orgId"
              >&nbsp;</el-radio
            >
          </template>
        </el-table-column>
        <el-table-column type="index" label="序号" width="60"></el-table-column>
        <el-table-column label="机构编码" prop="orgId" />
        <el-table-column label="机构名称" prop="orgName" />
        <!-- <el-table-column label="机构类型" prop="orgType">
          <template #default="{ row }">
              <span v-if="row.orgType == '2'">医疗机构</span>
              <span v-if="row.orgType == '4'">供应商</span>
          </template>
        </el-table-column> -->
      </el-table>
    </div>

    <!--分页-->
    <yl-pagination
      v-show="total > 0"
      :total="total"
      :page.sync="listQuery.current"
      :limit.sync="listQuery.size"
      @pagination="getData(true)"
    />

    <div slot="footer" class="dialog-footer" style="text-align: right">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </div>
</template>

<script>
import { getOrganData } from "@/api/system/users";
import ylPagination from "@/components/yl-pagination";
import { getQueryDic } from "@/api/system/dic";

export default {
  components: {
    ylPagination
  },
  props: {
    checkOrg: {
      type: Array,
      default: []
    },
    orgRadio: {
      type: String,
      default: ""
    }
  },

  watch: {},

  data() {
    return {
      orgRadio: "",
      list: [], //列表
      total: 0, //分页
      listLoading: false,
      listQuery: {
        //条件查询
        orgName: "",
        current: 1,
        size: 10,
        orgId: "",
        orgType: ""
      },
      facType: {
        dicCode: "orgType"
      },
      orgData: []
    };
  },
  created() {
    this.getData();
    this.getQual();
  },
  methods: {
    // 关闭
    close() {
      this.$emit("orgClose", false);
    },
    // 重置页面
    reset() {
      this.listQuery.orgName = "";
      this.listQuery.orgId = "";
      this.listQuery.orgType = "";
      this.getData();
    },
    // 提交
    submit() {
      let chooseList = [];
      chooseList = this.list.find((item) => {
        return item.orgId == this.orgRadio;
      });
      this.$emit("orgSubmit", this.orgRadio, chooseList.orgName);
    },

    //获取列表数据
    getData(query) {
      this.listLoading = true;
      getOrganData(this.listQuery)
        .then((response) => {
          this.list = response.data.records;
          this.total = response.data.total;
          this.listLoading = false;
        })
        .catch((err) => {
          this.listLoading = false;
        });
    },
    // 字典查询
    getQual() {
      getQueryDic(this.facType).then((res) => {
        if (res.success == true) {
          this.orgData = res.data;
        }
      });
    }
  }
};
</script>

<style scoped>
</style>
