<template>
  <div class="edit-dialog">
    <el-form :inline="true" :model="formInline" label-width="100px" :disabled="disabled" class="edit-dialog-formInline">
      <el-form-item label="方案名称:" required>
        <el-input v-model="formInline.schemeName" placeholder="请输入方案名称"></el-input>
      </el-form-item>
      <el-form-item label="压力模式:" required>
        <el-select v-model="formInline.pressurePattern" placeholder="请选择">
          <el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in patternOptions" :key="item.dictCode"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="剂型:" required>
        <el-select v-model="formInline.dosageForm" placeholder="请选择">
          <el-option :label="item.dictLabel" :value="item.dictValue" v-for="item in typeOptions" :key="item.dictCode"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="煎煮时间:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.decoctTime" placeholder="煎煮时间"></el-input>
          <span class="inline-flex-suffer">min</span>
        </div>
      </el-form-item>
      <el-form-item label="先煎时间:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.preDecoctTime" placeholder="先煎时间"></el-input>
          <span class="inline-flex-suffer">min</span>
        </div>
      </el-form-item>
      <el-form-item label="一煎时间:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.firstDecoctTime" placeholder="一煎时间"></el-input>
          <span class="inline-flex-suffer">min</span>
        </div>
      </el-form-item>
      <el-form-item label="二煎时间:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.secondDecoctTime" placeholder="二煎时间"></el-input>
          <span class="inline-flex-suffer">min</span>
        </div>
      </el-form-item>
      <el-form-item label="后下时间:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.backDownTime" placeholder="后下时间"></el-input>
          <span class="inline-flex-suffer">min</span>
        </div>
      </el-form-item>
      <el-form-item label="启用状态:" required>
        <el-radio-group v-model="formInline.status">
          <el-radio :label="0">开启</el-radio>
          <el-radio :label="1">关闭</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="排序:">
        <div class="inline-flex">
          <el-input type="number" v-model="formInline.sort"></el-input>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getSchemeDetail, addScheme, updateScheme } from "@/api/decoct/scheme";
export default {
  props: {
    disabled: {
      type: Boolean,
      default: false
    },
    id: [Number, String]
  },
  data() {
    return {
      formInline: {
        schemeName: '',
        pressurePattern: '',
        pressurePattern: '',
        dosageForm: '',
        decoctTime: '',
        firstDecoctTime: '',
        secondDecoctTime: '',
        preDecoctTime: '',
        backDownTime: '',
        status: 0,
        sort: ''
      },
      loading: false,
      typeOptions: [],
      patternOptions: []
    }
  },
  mounted() {
    this.getDicts("dosage_form").then((response) => {
      this.typeOptions = response.data;
    });
    this.getDicts("pressure_pattern").then((response) => {
      this.patternOptions = response.data;
    });
  },
  methods: {
    openDialog() {
      this.formInline = {
        schemeName: '',
        pressurePattern: '',
        pressurePattern: '',
        dosageForm: '',
        decoctTime: '',
        firstDecoctTime: '',
        secondDecoctTime: '',
        preDecoctTime: '',
        backDownTime: '',
        status: 0,
        sort: ''
      }

    },
    // 详情
    getDetail() {
      this.loading = true;
      getSchemeDetail(this.id).then((response) => {
        this.formInline = response.data
        this.loading = false;
      });
    },
    // 修改
    toUpdate() {
      this.loading = true;
      updateScheme(this.formInline).then((response) => {
        this.msgSuccess('修改成功')
        this.$emit('success')
      }).finally(res => {
        this.loading = false;
      })
    },
    // 新增
    toAdd() {
      this.loading = true;
      addScheme(this.formInline).then((response) => {
        this.msgSuccess('新增成功')
        this.$emit('success')
      }).finally(res => {
        this.loading = false;
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.edit-dialog {
  height: 580px;
  overflow: auto;
  &-formInline{
    width: 360px;
    margin: auto;
  }
  ::v-deep .el-form-item{
    display: flex;
    .inline-flex{
      display: flex;
      &-suffer{
        word-break: keep-all;
      }
    }
    &__content{
      flex: 1;
    }
    .el-select{
      width: 100%;
    }
  }
}
</style>
