<template>
  <div>
    <a-card :bordered="false" style="margin-bottom: 10px;">
      <!-- 条件搜索 -->
      <div class="table-page-search-wrapper">
        <a-form-model
          ref="form"
          :model="form"
          :rules="rules"
          slot="content"
          :label-col="{ span: 3 }"
          :wrapper-col="{ span: 21 }"
          layout="horizontal">
          <a-row :gutter="32">
            <a-col :span="24" style="font-size: 20px;padding-bottom: 20px">《难通过X光机辨识的货物清单》</a-col>
            <a-col :span="12">
              <a-form-model-item label="语义阈值" prop="xrayLimit">
                <a-input-number v-model="form.xrayLimit" :min="0" :max="100" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="24" style="font-size: 20px;padding-bottom: 20px">《含隐含性危险品货物清单》</a-col>
            <a-col :span="12">
              <a-form-model-item label="语义阈值" prop="riskLimit">
                <a-input-number v-model="form.riskLimit" :min="0" :max="100" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
            <a-col :span="12">
              <a-form-model-item label="匹配次数" prop="riskMatchTime">
                <a-input-number v-model="form.riskMatchTime" :min="0"  :max="100" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
             <a-col :span="24" style="font-size: 20px;padding-bottom: 20px">《疑似风险货物清单》</a-col>
            <a-col :span="12">
              <a-form-model-item label="风险程度阈值" prop="dangerousLimit">
                <a-input-number v-model="form.dangerousLimit" :min="0"  :max="100" style="width: 100%"/>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
        <a-button type="primary" @click="submitForm" style="margin: 20px">
          保存
        </a-button>
      </div>
    </a-card>
  </div>
</template>
<script>
import { addOptimizationSuggestionRule, getOptimizationSuggestionRule, updateOptimizationSuggestionRule } from '@/api/system/optimizationSuggestionRule'
export default {
  name: 'OptimizationSuggestionRule',
  data () {
    return {
      form: {
        id: undefined,
        xrayLimit: 0,
        riskLimit: 0,
        riskMatchTime: 0,
        dangerousLimit: 0
      },
      rules: {
        xrayLimit: [{ required: true, message: '难通过X光机清单语义阈值不能为空', trigger: 'blur' }],
        riskLimit: [{ required: true, message: '隐含危险品清单语义阈值不能为空', trigger: 'blur' }],
        riskMatchTime: [{ required: true, message: '隐含危险品清单匹配次数不能为空', trigger: 'blur' }],
        dangerousLimit: [{ required: true, message: '疑似风险品清单风险程度阈值不能为空', trigger: 'blur' }]
      }
    }
  },
  created () {
    this.getData()
  },
  methods: {
    /** 查询优化建议规则设置列表 */
    getData () {
      this.loading = true
      getOptimizationSuggestionRule().then(response => {
        if (response.data) this.form = response.data
        this.loading = false
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          const saveForm = JSON.parse(JSON.stringify(this.form))
          if (this.form.id !== undefined) {
            updateOptimizationSuggestionRule(saveForm).then(response => {
              this.$message.success('修改成功', 3)
            })
          } else {
            addOptimizationSuggestionRule(saveForm).then(response => {
              this.$message.success('新增成功', 3)
            })
          }
      } else {
          return false
        }
      })
    }
  }
}
</script>
