G<template>
  <div>
    <!-- 新增试验间弹窗 -->
    <el-dialog :title="$t('page.business.study.studyRoom.qysyj')" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <!-- 试验区域 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.study.studyRoom.syqy')" prop="syqy">
              <SelectTestArea v-model="form.syqy" />
            </el-form-item>
          </el-col>
          <!-- 饲养间号 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.study.studyRoom.syjh')" prop="syjh">
              <SelectRoom v-model="form.syjh" :testArea="form.syqy"/>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <!-- 动物种属 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.study.studyRoom.dwzs')" prop="dwzs">
              <SelectAnimalSpecies v-model="form.dwzs" />
            </el-form-item>
          </el-col>
          <!-- 笼具 -->
          <el-col :span="12">
            <el-form-item :label="$t('page.business.study.studyRoom.longju')" prop="lj">
              <SelectCage v-model="form.lj" :animalSpecies="form.dwzs"/>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 开始使用原因 -->
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('page.business.study.studyRoom.kssyyl')" prop="kssyyl">
              <el-input type="text" v-model="form.kssyyl" maxlength="50"
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.qmyy')" prop="qmyy">
              <el-input type="text" :value="form.qmyy" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.signer')">
              <el-input type="text" v-model="nickName" maxlength="50" disabled
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item :label="$t('form.password')" prop="qmrmm">
              <el-input type="password" v-model="form.qmrmm" maxlength="20"
                :placeholder="$t('form.placeholderInput')" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="save">{{ $t('form.confirm') }}</el-button>
        <el-button @click="cancel">{{ $t('form.cancel') }}</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { studyRoom_save } from "@/api/business/study/studyRoom"
import { mapGetters } from 'vuex'
import BusinessSelect from '@/views/business/comps/select/BusinessSelect';
import SelectTestArea from '@/views/business/comps/select/SelectTestArea';
import SelectRoom from '@/views/business/comps/select/SelectRoom';
import SelectAnimalSpecies from '@/views/business/comps/select/SelectAnimalSpecies';
import SelectCage from '@/views/business/comps/select/SelectCage';
export default {
  name: "XzSyj",
  components: { BusinessSelect, SelectTestArea, SelectRoom, SelectCage, SelectAnimalSpecies },
  data() {
    return {
      open: false,
      form: {},
      rules: {
        syqy: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        syjh: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        dwzs: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        lj: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        kssyyl: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
        qmrmm: [{
          required: true,
          message: ' ',
          trigger: 'blur'
        }],
      }
    }
  },
  computed: {
    ...mapGetters([
      'nickName'
    ]),
  },
  created() {
  },
  methods: {
    cancel() {
      this.open = false
    },
    reset() {
      this.form = {
        id: null,
        syqy: null,
        syjh: null,
        dwzs: null,
        lj: null,
        qmrmm: null,
        kssyyl:'',
        qmyy: '启用饲养间',
        bjbz: ''
      }
      this.resetForm("form")
    },
    show(studyId) {
      this.reset()
      this.form.studyId = studyId
      this.open = true
    },
    save() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          studyRoom_save(this.form).then(response => {
            this.open = false
            this.$emit('callback')
          })
        }
      })
    }
  }
}
</script>
