<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    okText="保存"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form ref="form" :model="model" :rules="validatorRules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="燃油重量(吨)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fuel">
              <a-input-number v-model="model.fuel" placeholder="请输入燃油重量(吨)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="淡水重量(吨)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="water">
              <a-input-number v-model="model.water" placeholder="请输入淡水重量(吨)" style="width: 100%" />
            </a-form-model-item>
          </a-col>
           <a-col :span="24">
            <a-form-model-item label="HHQ-9B导弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hq10">
              <a-input-number v-model="model.hhq9b" placeholder="请输入HQ-10 导弹数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="HQ-10 导弹数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="hq10">
              <a-input-number v-model="model.hq10" placeholder="请输入HQ-10 导弹数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="YJ-18A导弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rm857">
              <a-input-number v-model="model.yj18" placeholder="请输入右中857余弹量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="副炮余弹量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="rr857">
              <a-input-number v-model="model.secGunAmmo" placeholder="请输入右后857余弹量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="主炮余弹量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lr857">
              <a-input-number v-model="model.mainGunAmmo" placeholder="请输入左后857余弹量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="厘米箔条弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chaffCm">
              <a-input-number v-model="model.chaffCm" placeholder="请输入厘米箔条弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="毫米箔条弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="chaffMm">
              <a-input-number v-model="model.chaffMm" placeholder="请输入毫米箔条弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="红外弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ir">
              <a-input-number v-model="model.ir" placeholder="请输入红外弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="烟幕弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smoke">
              <a-input-number v-model="model.smoke" placeholder="请输入烟幕弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="水声诱饵弹" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smoke">
              <a-input-number v-model="model.acousticDecoy" placeholder="请输入烟幕弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="水声干扰器" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="smoke">
              <a-input-number v-model="model.acousticJammer" placeholder="请输入烟幕弹" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import moment from "moment"
import { add052,edit052 } from '@/api/materialSupport'
import JCron from "@/components/jeecg/JCron";
import JSelectMultiple from '@/components/jeecg/JSelectMultiple'
import pick from 'lodash.pick'
  

  export default {
    name: "materialSupportModal",
    components: {
      JCron,
      JSelectMultiple
    },
    data () {
      return {
        title:"操作",
        visible:false,
        model:{
         },
        form: this.$form.createForm(this),
        confirmLoading: false,
        validatorRules: {
          fuel: {rules: [{required: true, message: '请输入燃油重量!'}]},
          water: {rules: [{required: true, message: '请输入淡水重量!'}]},
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
      }
    },
    created () {
       this.modelDefault = JSON.parse(JSON.stringify(this.model));
       this.modelDefault.status=0;
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      onChange(value, dateString) {
        this.model.startTime = dateString[0];
        this.model.endTime = dateString[1];
        console.log(this.model);
      },
      onOk(value) {
        
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          console.log('values',values)
          if (!err) {
            this.model.taskId = this.taskId
            that.confirmLoading = true;
            if(!this.model.id){
              add052(this.model).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.$emit('ok');
                  this.close()
                }else{
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              })
            }else{
              edit052(this.model).then((res)=>{
                if(res.success){
                  that.$message.success(res.message);
                  that.$emit('ok');
                  this.close()
                }else{
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.confirmLoading = false;
              })
            }
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>
.disabled{
  pointer-events: none;
}
</style>