<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs="crumbs"></bread-crumb>

      <el-button type="primary" @click="returnTo">返回</el-button>
    </div>
    <div class="app-container">
      <div class="set-contanin">
        <div class="select-list">
          <div style="line-height: 36px; white-space: nowrap">
            请选择耗材自动入库仓库：
          </div>
          <el-select v-model="h1" filterable placeholder="请选择" @select="handleSelect1" @change="updateconfig1(h1)" >
            <el-option
              v-for="item in options"
              :key="item.storehouse_name"
              :label="item.storehouse_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="select-list">
          <div style="line-height: 36px; white-space: nowrap">
            请选择耗材自动出库仓库：
          </div>
          <el-select v-model="h2" filterable placeholder="请选择" @select="handleSelect2" @change="updateconfig2(h2)">
            <el-option
              v-for="item in options"
              :key="item.storehouse_name"
              :label="item.storehouse_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="select-list">
          <div style="line-height: 36px; white-space: nowrap">
            请选择药品自动入库仓库：
          </div>
          <el-select v-model="h3" filterable placeholder="请选择" @select="handleSelect3" @change="updateconfig3(h3)">
            <el-option
              v-for="item in options"
              :key="item.storehouse_name"
              :label="item.storehouse_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
        <div class="select-list">
          <div style="line-height: 36px; white-space: nowrap">
            请选择药品自动出库仓库：
          </div>
          <el-select v-model="h4" filterable placeholder="请选择" @select="handleSelect4" @change="updateconfig4(h4)">
            <el-option
              v-for="item in options"
              :key="item.storehouse_name"
              :label="item.storehouse_name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import BreadCrumb from "@/xt_pages/components/bread-crumb";
import { getallstorehousename,findstorehouseconfig,updateinfo,updateoutinfo,updatedruginfo,updatedrugout } from "@/api/warehouse";
export default {
  components: {
    BreadCrumb,
  },
  data() {
    return {
      crumbs: [
        { path: false, name: "库房管理" },
        { path: false, name: "仓库管理" },
        { path: false, name: "仓库设置" },
      ],
      options:[],
      h1:"",
      h2:"",
      h3:"",
      h4:"",
    };
  },

  created(){
    this.initData()
  },

  methods:{
      returnTo(){
          this.$router.back(-1)
      },
    initData() {
      let params = {};
      //获取当前机构的所有可用仓库名称接口
      getallstorehousename(params).then((response) => {
        if (response.data.state == 1) {
          this.options = response.data.data.list;
        }
      });
      let param ={}
      findstorehouseconfig(param).then((response) => {
        if (response.data.state == 1) {
          this.h1 = response.data.data.storehouse_info;
          this.h2 = response.data.data.storehouse_out_info;
          this.h3 = response.data.data.drug_storehouse_info;
          this.h4 = response.data.data.drug_storehouse_out;
        }
      });
    },

    handleSelect1(item) {
      this.h1 = item.storehouse_name;
    },
    handleSelect2(item) {
      this.h2 = item.storehouse_name;
    },
    handleSelect3(item) {
      this.h3 = item.storehouse_name;
    },
    handleSelect4(item) {
      this.h4 = item.storehouse_name;
    },
    updateconfig1(h1){
      let params = {
        id:h1
      };
      updateinfo(params).then((response) => {
        if (response.data.state == 1) {
          this.$message.success("修改成功");
        }
      });
    },
    updateconfig2(h2){
      let params = {
        id:h2
      };
      updateoutinfo(params).then((response) => {
        if (response.data.state == 1) {
          this.$message.success("修改成功");
        }
      });
    },
    updateconfig3(h3){
      let params = {
        id:h3
      };
      updatedruginfo(params).then((response) => {
        if (response.data.state == 1) {
          this.$message.success("修改成功");
        }
      });
    },
    updateconfig4(h4){
      let params = {
        id:h4
      };
      updatedrugout(params).then((response) => {
        if (response.data.state == 1) {
          this.$message.success("修改成功");
        }
      });
    },


  }
};
</script>

<style rel="stylesheet/css" lang="scss" scoped>
.set-contanin {
  width: 30%;
  height: 50%;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* 横竖都居中 */
  margin: auto;
  .select-list {
    display: flex;
    padding: 10px 0;
  }
}
/deep/ .el-input__inner {
  width: 202px;
}
</style>
