<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="设备ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceId">-->
<!--              <a-input v-model="model.deviceId" placeholder="请输入设备ID"  ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="设备名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceName">
              <a-input v-model="model.deviceName" placeholder="请输入设备名称" style="border:0px" size="large" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item  label="设备编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="deviceName">
              <a-input v-model="model.deviceCode" placeholder="请输入设备编号" style="border:0px" size="large" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="风险名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="testItem">
              <a-input v-model="model.testItem" placeholder="请输入风险名称" style="border:0px" size="large" ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="风险发生时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="time">
              <a-input placeholder="风险发生时间" v-model="model.time" dateFormat="YYYY-MM-DD HH:mm:ss" style="border:0px" size="large"/>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="故障类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remindType">-->
<!--              <j-dict-select-tag v-model="model.remindType" placeholder="请输入故障类型" dict-code="remind_type" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="风险说明" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="remind">
              <a-input v-model="model.remind" placeholder="风险说明" style="border:0px" size="large"></a-input>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="查看状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">-->
<!--              <a-input-number v-model="model.status" placeholder="请输入查看状态" style="width: 100%" />-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
          <a-col :span="24">
            <a-form-model-item label="风险危害" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="riskHarm">
              <a-textarea v-model="model.riskHarm" placeholder="请输入风险危害" style="font-size:16px;border:0px"  size="large"  :auto-size="{ minRows: 3, maxRows: 10 }"></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="suggest">
              <span slot="label">
                <span style="color: #034117;font-size: 20px;font-weight: bold">专家建议</span>
              </span>
              <a-textarea style="font-size: 20px;color:#034117;font-weight: bold;border:0px" v-model="model.suggest"
                          placeholder="请输入处理建议" size="large" :auto-size="{ minRows: 2, maxRows: 10 }"></a-textarea>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="处理措施" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="content">
              <a-textarea v-model="model.content" placeholder="请输入处理措施" :rows="3" show-count:maxlength="100"></a-textarea>
            </a-form-model-item>
          </a-col>
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="处理人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="user">-->
<!--              <a-input v-model="model.user" placeholder="请输入处理人" :rows="3" disabled ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
<!--          <a-col :span="24">-->
<!--            <a-form-model-item label="处理时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="processingTime">-->
<!--              <a-input v-model="model.processingTime" placeholder="请输入处理时间" :rows="3" disabled ></a-input>-->
<!--            </a-form-model-item>-->
<!--          </a-col>-->
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction, getAction } from '@/api/manage'
import { validateDuplicateValue } from '@/utils/util'
import JFormContainer from "@comp/jeecg/JFormContainer";
import JDictSelectTag from "@comp/dict/JDictSelectTag";
import JSelectDevice from "@comp/jeecgbiz/JSelectDevice";
import JDate from "@comp/jeecg/JDate";

export default {
  name: 'BuDeviceOnlineForm',
  components: {
    JFormContainer,
    JDate,
    JDictSelectTag,
    JSelectDevice,
  },
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data () {
    return {
      model:{
      },
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
      },
      url: {
        add: "/device/buDeviceOnline/add",
        edit: "/device/buDeviceOnline/edit",
        queryById: "/device/buDeviceOnline/queryById"
      }
    }
  },
  computed: {
    formDisabled(){
      return this.disabled
    },
  },
  created () {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
  },
  methods: {
    add () {
      this.edit(this.modelDefault);
    },
    edit (record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    submitForm () {
      const that = this;
      if (this.model.content === "" || this.model.content === undefined || this.model.content === null){
        that.$message.warning("请填写处理结果！");
        return
      }
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if(!this.model.id){
            httpurl+=this.url.add;
            method = 'post';
          }else{
            httpurl+=this.url.edit;
            method = 'put';
          }
          httpAction(httpurl,this.model,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>
<style lang="scss" >
.ant-row {
  .ant-form-item {
    margin: 0;
    padding: 0;
    color: rgba(0,0,0,0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    vertical-align: top;
  }
}
</style>