<template>
  <el-container style="flex-grow:1">
    <el-main class="containMain">
      <div class="contentTitle">消毒登记</div>
      <el-form ref="form" :model="formData" label-width="80px" style="margin-top:20px;max-width:300px">
        <el-form-item label="所在牧场">
          <el-select v-model="formData.currFarm" placeholder="请选择所在牧场">
            <el-option v-for="item in farmList" :key="item['牧场编号']" :label="item['牧场名称']" :value="item['牧场编号']"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="消毒区域">
          <el-input v-model="formData.area"></el-input>
        </el-form-item>

        <el-form-item label="消毒药品">
          <el-input v-model="formData.drug"></el-input>
        </el-form-item>

        <el-form-item label="消毒方式">
          <el-input v-model="formData.type"></el-input>
        </el-form-item>

        <el-form-item label="消毒用途">
          <el-input v-model="formData.way"></el-input>
        </el-form-item>

        <el-form-item label="发放量">
          <el-input-number v-model="formData.distribution" :min="0"></el-input-number>
          <span style="margin-left:10px">L</span>
        </el-form-item>

        <el-form-item label="浓度">
          <el-input-number v-model="formData.thickness" :min="0"></el-input-number>
          <span style="margin-left:10px">%</span>
        </el-form-item>

        <el-form-item label="原液量">
          <el-input-number v-model="formData.stoste" :min="0"></el-input-number>
          <span style="margin-left:10px">L</span>
        </el-form-item>

        <el-form-item label="备注">
          <el-input v-model="formData.note"></el-input>
        </el-form-item>

        <div style="margin-top:80px">
          <el-button @click="onSave" type="primary" style="width:98px;" size="mediu">确认消毒</el-button>
        </div>
      </el-form>
    </el-main>
  </el-container>
</template>
<script>
import formValidator from '../formValidator'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  created() {

    this.getHaleInfo('wsCow', 'getAllFarm', [], 'list').then((data) => {
      this.farmList = data
    })


  },
  data() {
    return {
      saving: false,
      formData: {
        currFarm: this.$store.state.farmNO.toString(),
        area: '',
        drug: '',
        type: '',
        way: '',
        distribution: '',
        thickness: '',
        stoste: '',
        opeator: this.$store.state.userInfo.username,
        note: ''
      },
      farmList: []
    }
  },
  computed: {
    ...mapState(['userInfo', 'allHeight']),

  },
  methods: {
    onSave() {
      if (!this.formData.currFarm) {
        this.$message({
          message: '请选择所在牧场',
          type: 'warning'
        });
        return
      }
      if (!this.formData.area) {
        this.$message({
          message: '请输入消毒区域',
          type: 'warning'
        });
        return
      }

      if (!this.formData.drug) {
        this.$message({
          message: '请输入消毒药品',
          type: 'warning'
        });
        return
      }

      if (!this.formData.type) {
        this.$message({
          message: '请输入消毒方式',
          type: 'warning'
        });
        return
      }

      if (!this.formData.way) {
        this.$message({
          message: '请输入消毒用途',
          type: 'warning'
        });
        return
      }

      if (!this.formData.distribution) {
        this.$message({
          message: '请输入发放量',
          type: 'warning'
        });
        return
      }

      if (!this.formData.thickness) {
        this.$message({
          message: '请输入浓度',
          type: 'warning'
        });
        return
      }

      if (!this.formData.stoste) {
        this.$message({
          message: '请输入原液量',
          type: 'warning'
        });
        return
      }
      if (!this.formData.note) {
        this.$message({
          message: '请输入备注',
          type: 'warning'
        });
        return
      }
      var data={
        "所在牧场":this.formData.currFarm,
        "消毒区域":this.formData.area,
        "消毒药品":this.formData.drug,
        "消毒方式":this.formData.type,
        "消毒用途":this.formData.way,
        "发放量":this.formData.distribution,
        "浓度":this.formData.thickness,
        "原液量":this.formData.stoste,
        "操作人":this.formData.opeator,
        "备注":this.formData.note
      }
      var form=new FormData()
      form.append('json',JSON.stringify(data))
      axios.post('http://172.16.84.41:82/xdxx/ProviderActionHandler.ashx?action=add',form, {
        withCredentials: false
      }).then(res => {
        
        if (res.data.status == 0) {
          this.$message({
            message:res.data.msg,
            type: 'warning'
          });
        }
        else {
          this.$message({
            message: '消毒信息录入成功',
            type: 'success'
          });
        }

      })

    },
    submit() {
      var data = JSON.parse(JSON.stringify(this.formData));
      this.$http.post({
        url: this.formData.id ? '/userInfo/update' : '/userInfo/save',
        data: data
      }).then(res => {
        if (res.success) {
          this.$message.success('成功');
          this.$router.go(-1);
        } else {
          this.$message.warning('失败')
        }
      });
    },
    getNowCow() {

      this.getCowInfo(this.formData.cowID).then((data) => {
        // console.log(data)
        if (data['是否在场'] == '否') {
          this.$message({
            message: '当前牛只并不在场',
            type: 'warning'
          });
          this.formData.cowID = ''
          return
        }

        if (data['当前牧场'] != this.$store.state.farmName) {
          this.$message({
            message: '牛只不属于你所在的牧场，无权转牛',
            type: 'warning'
          });
          this.formData.cowID = ''
          return
        }
        var list = []
        Object.keys(data).forEach(item => {
          list.push({
            key: item,
            value: data[item]
          })
        })

        // console.log(list)

        this.tableData = list
      }).catch(() => {
        this.formData.cowID = ''
      })
    }
  }
}
</script>
<style lang="less" scoped>
.containMain {
  background: rgba(255, 255, 255, 1);
  border-radius: 4px;
  padding: 15px;
  // margin-right: 10px;
  .contentTitle {
    border-bottom: 1px solid #f2f4f5;
  }
  // min-width: 450px;

  .sub {
    font-size: 14px;
    font-weight: 600;
    color: rgba(102, 102, 102, 1);
    line-height: 20px;
    margin-bottom: 40px;
    padding-left: 20px;
  }
}

.contentTitle {
  font-size: 16px;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
  line-height: 22px;
  letter-spacing: 1px;
  padding-bottom: 14px;
}

.containAside {
  padding: 0;
  margin-left: 10px;
  display: flex;
  flex-direction: column;
  .asideInfo {
    flex-grow: 1;
    background: rgba(255, 255, 255, 1);
    border-radius: 4px;
    padding: 15px;
  }
}
</style>
