<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <w-form
        ref="form"
        slot="detail"
        :model="model"
        :rules="validatorRules"
        v-next
      >
        <w-row>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Seq. NO"
              prop="seqNo"
            >
              <w-input
                v-model="model.seqNo"
                v-required-color="true"
                placeholder="请输入Seq. NO"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="From-Company"
              prop="fromCompany"
            >
              <w-input
                v-model="model.fromCompany"
                placeholder="请输入From-Company"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="From-Customs-ID"
              prop="fromCustomsId"
            >
              <w-input
                v-model="model.fromCustomsId"
                placeholder="请输入From-Customs-ID"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="To-Company"
              prop="toCompany"
            >
              <w-input
                v-model="model.toCompany"
                placeholder="请输入To-Company"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="To-关务属性"
              prop="toCustomsId"
            >
              <w-input
                v-model="model.toCustomsId"
                placeholder="请输入To-关务属性"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Ship-to-Country"
              prop="shipToCountry"
            >
              <w-input
                v-model="model.shipToCountry"
                v-required-color="true"
                placeholder="请输入Ship-to-Country"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Customs-Clearance-Required"
              prop="customsClearanceRequired"
            >
              <w-input
                v-model="model.customsClearanceRequired"
                v-required-color="true"
                placeholder="请输入Customs-Clearance-Required"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Access-FT-Zone"
              prop="accessFtZone"
            >
              <w-input
                v-model="model.accessFtZone"
                v-required-color="true"
                placeholder="请输入Access-FT-Zone"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Scenario category"
              prop="scenarioCategory"
            >
              <w-input
                v-model="model.scenarioCategory"
                v-required-color="true"
                placeholder="请输入Scenario category"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Scenarios Description"
              prop="scenarioDescription"
            >
              <w-input
                v-model="model.scenarioDescription"
                v-required-color="true"
                placeholder="请输入Scenarios Description"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Comments"
              prop="comments"
            >
              <w-input
                v-model="model.comments"
                placeholder="请输入Comments"
              />
            </w-form-item>
          </w-col>
          <w-col :span="24">
            <w-form-item
              :label-col="labelCol"
              :wrapper-col="wrapperCol"
              label="Active"
              prop="active"
            >
              <w-input
                v-model="model.active"
                placeholder="请输入Active"
              />
            </w-form-item>
          </w-col>
        </w-row>
      </w-form>
    </j-form-container>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: 'BaseBdMatrixConfigForm',
  components: {
  },
  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: {
        seqNo: [
          { required: true, message: '请输入Seq. NO!' }
        ],
        shipToCountry: [
          { required: true, message: '请输入Ship-to-Country!' }
        ],
        customsClearanceRequired: [
          { required: true, message: '请输入Customs-Clearance-Required!' }
        ],
        accessFtZone: [
          { required: true, message: '请输入Access-FT-Zone!' }
        ],
        scenarioCategory: [
          { required: true, message: '请输入Scenario category!' }
        ],
        scenarioDescription: [
          { required: true, message: '请输入Scenarios Description!' }
        ]
      },
      url: {
        add: '/baseinfo/baseBdMatrixConfig/add',
        edit: '/baseinfo/baseBdMatrixConfig/edit',
        queryById: '/baseinfo/baseBdMatrixConfig/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
      // 触发表单验证
      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>
