<template>
  <div class="search-box">
    <el-form :model="form" :inline="true" ref="create">
      <el-form-item
        label="医院名称"
        prop="hospName"
        v-if="orgType == 'SUP' || orgType == 'MSUP'"
      >
        <el-input
          v-model="form.hospName"
          style="width: 170px; margin-right: 2px"
          placeholder=""
          clearable
        />
      </el-form-item>
      <el-form-item
        label="配送商名称"
        prop="supplierName"
        v-else-if="orgType == 'HOS' || orgType == 'MHOS'"
      >
        <el-input
          v-model="form.supplierName"
          style="width: 170px; margin-right: 2px"
          placeholder=""
          clearable
        />
      </el-form-item>
      <el-form-item label="医院名称" prop="hospName" v-else>
        <el-input
          v-model="form.hospName"
          style="width: 170px; margin-right: 2px"
          placeholder=""
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">查询</el-button>
        <el-button @click="resetForm('create')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { searchInputData } from "./searchData";
import { sup, hos } from "../const";
export default {
  name: "searchView",
  data() {
    return {
      form: {},
      searchData: searchInputData,
      orgType: "",
    };
  },
  created() {
    let { user } = this.$store.state;
    if (user && user.orgType) {
      if (user.orgType == "SUP" || user.orgType == "MSUP")
        this.$set(this.form, "hospName", "");
      else if (user.orgType == "HOS" || user.orgType == "MHOS")
        this.$set(this.form, "supplierName", "");
      else this.$set(this.form, "hospName", "");
      this.orgType = user.orgType;
    }
  },
  methods: {
    onSubmit() {
      this.$refs["create"].validate((valid) => {
        if (valid) {
          this.$emit("searchSuses", this.form);
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.$emit("searchSuses", this.form);
    },
  },
};
</script>
<style scoped lang="scss">
.search-box {
  padding: 0;
}
</style>
