LocationBatchAddForm.vue 8.4 KB
<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="$t('config.encodingPrefix')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="prefix">
              <a-input v-model="model.prefix" :placeholder="$t('config.inputEncodingPrefix')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.startRow')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firstRow">
              <a-input v-model="model.firstRow" :placeholder="$t('config.inputStartRow')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.lastRow')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastRow">
              <a-input v-model="model.lastRow" :placeholder="$t('config.inputLastRow')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.startColumn')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firstColumn">
              <a-input v-model="model.firstColumn" :placeholder="$t('config.inputStartColumn')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.lastColumn')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastColumn">
              <a-input v-model="model.lastColumn" :placeholder="$t('config.inputLastColumn')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.startLayer')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="firstLayer">
              <a-input v-model="model.firstLayer" :placeholder="$t('config.inputStartLayer')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.lastLayer')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lastLayer">
              <a-input v-model="model.lastLayer" :placeholder="$t('config.inputLastLayer')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.roadway')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="roadWay">
              <a-input v-model="model.roadWay" :placeholder="$t('config.inputRoadway')"></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.highLow')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="high">
              <j-dict-select-tag type="list" v-model="model.high" dictCode="high_status" :placeholder="$t('config.selectHighLow')"/>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.zoneCode')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="zoneCode">
              <a-select
                show-search
                :placeholder="$t('config.selectZone')"
                option-filter-prop="children"

                v-model="model.zoneCode">
                <a-select-option v-for="item in zoneList" :key="item.name" :value="item.code">{{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item :label="$t('config.locationType')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="locationTypeCode">
              <a-select
                show-search
                :placeholder="$t('config.selectLocationType')"
                option-filter-prop="children"

                v-model="model.locationTypeCode">
                <a-select-option v-for="item in locationTypeList" :key="item.name" :value="item.code">{{
                    item.name
                  }}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">-->
          <!--              <j-dict-select-tag type="list" v-model="model.status" dictCode="location_status" placeholder="请选择状态" />-->
          <!--            </a-form-model-item>-->
          <!--          </a-col>-->
          <!--          <a-col :span="24">-->
          <!--            <a-form-model-item label="是否可用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="enable">-->
          <!--              <j-dict-select-tag type="list" v-model="model.enable" dictCode="enable_status" placeholder="请选择是否可用" />-->
          <!--            </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 {getZoneList} from '@/api/api'
import {getLocationTypeList} from '@/api/api'
import { translateResultMessage } from '@/api/api'

export default {
  name: 'LocationBatchAddForm',
  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,
      zoneList: [],
      locationTypeList: [],
      validatorRules: {
        prefix: [
          {required: true, message: this.$t('config.inputEncodingPrefix')},
        ],
        firstRow: [
          {required: true, message: this.$t('config.inputStartLine')},
        ],
        lastRow: [
          {required: true, message: this.$t('config.inputLastRow')},
        ],
        firstColumn: [
          {required: true, message: this.$t('config.inputStartColumn')},
        ],
        lastColumn: [
          {required: true, message: this.$t('config.inputLastColumn')},
        ],
        firstLayer: [
          {required: true, message: this.$t('config.inputStartLayer')},
        ],
        lastLayer: [
          {required: true, message: this.$t('config.inputLastLayer')},
        ],
        roadWay: [
          {required: true, message: this.$t('config.inputRoadway')},
        ],
        zoneCode: [
          {required: true, message: this.$t('config.inputZoneCode')},
        ],
        locationTypeCode: [
          {required: true, message: this.$t('config.inputLocationType')},
        ],
        high: [
          {required: true, message: this.$t('config.selectHighLow')},
        ],
      },
      url: {
        add: "/config/location/batchAdd",
        edit: "/config/location/edit",
        queryById: "/config/location/queryById"
      }
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    },
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model));
    this.loadFrom();
  },
  methods: {
    add() {
      this.edit(this.modelDefault);
    },
    edit(record) {
      this.model = Object.assign({}, record);
      this.visible = true;
    },
    loadFrom() {
      getZoneList().then((res) => {
        if (res.success) {
          this.zoneList = res.result
        }
      });
      getLocationTypeList().then((res) => {
        if (res.success) {
          this.locationTypeList = res.result
        }
      })
    },
    submitForm() {
      const that = this;
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          httpurl += this.url.add;
          method = 'post';
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(translateResultMessage(res, res.message))
              that.$emit('ok');
            } else {
              that.$message.warning(translateResultMessage(res, res.message))
            }
          }).finally(() => {
            that.confirmLoading = false;
          })
        }

      })
    },
  }
}
</script>