<template>
  <div class="app-container">
    <div class="box">
      <h1>上班校区管理</h1>
      <span>当前选择的上班校区</span>
      <!--  -->
      <el-input class="select" placeholder="请输入内容" v-model="userWarehouseInfo.storeroomName" :disabled="true"> </el-input>
    </div>
    <!-- 选择库房 -->
    <el-table v-loading="loading" :data="warehouseList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="下上班校区" align="center" prop="storeroomName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope"> 
          <el-button @click="selectWarehouse(scope.row)">选 择</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script setup name="warehouse">
import { listWarehouse, getWarehouse, updateWarehouse } from "@/api/healthcare/warehouse";

const { proxy } = getCurrentInstance();

const warehouseList = ref([]);
const userWarehouseInfo = ref([]);

const open = ref(true);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const userInfo = ref({});

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    userId: null,
    userName: null,
    storeroomId: null,
    storeroomName: null,
  },
});

const { queryParams, form } = toRefs(data);

// 获取 仓库 列表
function getList() {
  loading.value = true;
  listWarehouse().then((response) => {
    //
    warehouseList.value = response.rows;
    //
    total.value = response.total;
    //
    loading.value = false;
  });
}

// 选择 库房的 方法 
function selectWarehouse(row) {
  console.log(row)
  userWarehouseInfo.value.storeroomId = row.id
  userWarehouseInfo.value.storeroomName = row.storeroomName
  //
  updateWarehouse(userWarehouseInfo.value).then((response) => {
    //
    proxy.$modal.msgSuccess("选择成功");
  })
}


import { getUserProfile } from "@/api/system/user.js";
// 获取 用户 的 库房信息
function obtainWarehouseInformation() {
  // 获取 用户 信息
  getUserProfile().then((response) => {
    console.log(response);
    console.log("时间", response.data.userId);
    if (response != null) {
      getWarehouse(response.data.userId).then((response) => {
        console.log(response);
        userWarehouseInfo.value = response.data;
      });
    }
  });
}
obtainWarehouseInformation();
getList();
</script>

<style scoped>
.app-container {
  margin: 0 auto;
}
.box {
  width: 50%;
  text-align: center;
  margin: 0 auto;
  margin-top: 50px;
}
.box > span {
  display: block;
  margin-top: 10px;
  font-size: 20px;
}
/* select =>  */
.box > .select {
  width: 300px;
  margin-top: 20px;
  margin-bottom: 20px;
  height: 40px;
}
</style>
