info.vue 11 KB
<template>
  <div style="margin: 40px" v-loading="loading">
    <el-form
      ref="form"
      :model="form"
      label-width="200px"
      size="small"
      :disabled="disable"
      :rules="rules"
    >
      <el-form-item label="航班号" prop="purposeOfFlightNo">
        <el-input
          v-model="form.purposeOfFlightNo"
          style="width: 30%"
        ></el-input>
      </el-form-item>

      <el-form-item style="width: 40%">
        <el-alert
          title="提示:站点之间用回车符分隔"
          type="warning"
          show-icon
          size="small"
          :closable="false"
          style="height: 30px"
        >
        </el-alert>
      </el-form-item>
      <el-row :gutter="20">
        <el-col :span="10">
          <el-form-item label="站点包含">
            <!-- <el-alert title="提示:站点之间用回车符分隔" type="info" show-icon size="small" :closable="false" style="height:30px; margin-buttom"> </el-alert> -->
            <el-input
              type="textarea"
              v-model="form.location"
              :rows="6"
              resize="none"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="站点不包含">
            <el-input
              type="textarea"
              v-model="form.notLocation"
              :rows="6"
              resize="none"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item style="width: 40%">
        <el-alert
          title="提示:URSA之间用分号分隔,例:F2;F3;P_"
          type="warning"
          show-icon
          size="small"
          :closable="false"
          style="height: 30px"
        >
        </el-alert>
      </el-form-item>
      <el-row :gutter="20">
        <el-col :span="10">
          <el-form-item label="URSA包含">
            <el-input
              type="textarea"
              v-model="form.includeUrsa"
              :rows="6"
              resize="none"
            ></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="URSA不包含">
            <el-input
              type="textarea"
              v-model="form.notIncludeUrsa"
              :rows="6"
              resize="none"
            ></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="件数">
        <el-col :span="3">
          <!-- <el-input v-model="form.minNumOfPieces"></el-input> -->
          <el-input-number
            v-model="
              form.minNumOfPieces == 0
                ? (form.minNumOfPieces = undefined)
                : form.minNumOfPieces
            "
            :precision="0"
            :controls="false"
            style="width: 100%"
          ></el-input-number>
        </el-col>
        <el-col style="text-align: center" :span="1">-</el-col>
        <el-col :span="3">
          <!-- <el-input v-model="form.maxNumOfPieces"></el-input> -->
          <el-input-number
            v-model="
              form.maxNumOfPieces == 0
                ? (form.maxNumOfPieces = undefined)
                : form.maxNumOfPieces
            "
            :precision="0"
            :controls="false"
            style="width: 100%"
            :min="form.minNumOfPieces + 1"
          ></el-input-number>
        </el-col>
      </el-form-item>

      <el-form-item label="重量">
        <el-col :span="3">
          <!-- <el-input v-model="form.minWeight"></el-input> -->
          <el-input-number
            v-model="
              form.minWeight == 0
                ? (form.minWeight = undefined)
                : form.minWeight
            "
            :precision="2"
            :controls="false"
            style="width: 100%"
          ></el-input-number>
        </el-col>
        <el-col :span="1" style="text-align: center"><span>Kg</span></el-col>
        <el-col style="text-align: center" :span="1">-</el-col>
        <el-col :span="3">
          <!-- <el-input v-model="form.maxWeight"></el-input> -->
          <el-input-number
            v-model="
              form.maxWeight == 0
                ? (form.maxWeight = undefined)
                : form.maxWeight
            "
            :precision="2"
            :controls="false"
            style="width: 100%"
            :min="form.minWeight + 0.01"
          ></el-input-number>
        </el-col>
        <el-col :span="1" style="text-align: center"><span>Kg</span></el-col>
      </el-form-item>

      <el-form-item label="申报类别">
        <el-card shadow="never" style="width: 70%">
          <el-checkbox-group v-model="form.typeOfGoods">
            <el-checkbox
              v-for="item in cargoType"
              :key="item.id"
              :label="item.chineseName"
              :name="item.chineseName"
            ></el-checkbox>
          </el-checkbox-group>
        </el-card>
      </el-form-item>

      <el-form-item label="货物类型">
        <el-card shadow="never" style="width: 70%">
          <el-checkbox-group v-model="form.declarationCategory">
            <el-checkbox
              v-for="item in cargoStatus"
              :key="item.id"
              :label="item.chineseName"
              :name="item.chineseName"
            ></el-checkbox>
          </el-checkbox-group>
        </el-card>
      </el-form-item>

      <el-form-item label="Service Code">
        <el-card shadow="never" style="width: 70%">
          <el-checkbox-group v-model="form.serviceCode">
            <el-checkbox
              v-for="item in serviceCode"
              :key="item.id"
              :label="item.englishName"
              :name="item.englishName"
            ></el-checkbox>
          </el-checkbox-group>
        </el-card>
      </el-form-item>

      <el-form-item label="Sub Category">
        <el-card shadow="never" style="width: 70%">
          <el-checkbox-group v-model="form.subCategory">
            <el-checkbox
              v-for="item in subCategory"
              :key="item.id"
              :label="item.englishName"
              :name="item.englishName"
            ></el-checkbox>
          </el-checkbox-group>
        </el-card>
      </el-form-item>
    </el-form>
    <el-row style="margin-left: 200px">
      <el-button
        type="primary"
        size="small"
        v-if="$route.params.handle != 'detail'"
        @click="submit('form')"
        :loading="btnLoading"
      >
        <span v-if="$route.params.handle === 'add'">添加</span>
        <span v-else>保存</span>
      </el-button>
      <el-button size="small" @click="close">取消</el-button>
    </el-row>
  </div>
</template>

<script>
import {
  findByFlightId,
  updateOrAddFlight,
  allDictData,
} from "@/api/destinationFlight";

export default {
  data() {
    return {
      form: {
        typeOfGoods: [],
        declarationCategory: [],
        serviceCode: [],
        subCategory: [],
      },
      rules: {
        purposeOfFlightNo: [
          { required: true, message: "请输入航班号", trigger: "blur" },
        ],
      },
      typeOfGoods: [],
      declarationCategory: [],
      formServiceCode: [],
      formSubCategory: [],
      cargoType: [],
      cargoStatus: [],
      serviceCode: [],
      subCategory: [],
      disable: false,
      btnLoading: false,
      loading: true,
    };
  },
  methods: {
    submit(form) {
      this.$refs[form].validate((valid) => {
        if (!valid) {
          return false;
        }
      });

      this.btnLoading = true;
      let handle = this.$route.params.handle;
      if (handle === "update") {
        //修改,获取id
        this.form.id = this.$route.params.id;
      }

      //调用接口
      this.typeOfGoods = this.form.typeOfGoods;
      this.declarationCategory = this.form.declarationCategory;
      this.formServiceCode = this.form.serviceCode;
      this.formSubCategory = this.form.subCategory;
      updateOrAddFlight(this.form).then((response) => {
        if (response.code === 200) {
          this.$message({
            showClose: true,
            message: "成功",
            type: "success",
          });
          this.close();
        } else {
          this.$message({
            showClose: true,
            message: response.msg,
            type: "error",
          });
          this.btnLoading = false;
        }
      });
      this.form.typeOfGoods = this.typeOfGoods;
      this.form.declarationCategory = this.declarationCategory;
      this.form.serviceCode = this.formServiceCode;
      this.form.subCategory = this.formSubCategory;
    },
    close() {
      this.$store.state.tagsView.visitedViews.splice(
        this.$store.state.tagsView.visitedViews.findIndex(
          (item) => item.path === this.$route.path
        ),
        1
      );
      this.$router.push(
        this.$store.state.tagsView.visitedViews[
          this.$store.state.tagsView.visitedViews.length - 1
        ].path
      );
    },
  },
  created() {
    let matched = this.$route.matched.filter(
      (item) => item.meta && item.meta.title
    );
    let routers = this.$router.options.routes;
    let handle = this.$route.params.handle;

    allDictData().then((response) => {
      if (response.code != 200) {
        this.$message({
          showClose: true,
          message: response.msg,
          type: "error",
        });
        reuturn;
      }
      let dict = response.data;
      this.cargoType = dict.cargoType;
      this.cargoStatus = dict.cargoStatus;
      this.serviceCode = dict.serviceCode;
      this.subCategory = dict.subCategory;
    });
    if (handle === "detail") {
      this.disable = true;
    }

    if (handle != "add") {
      let id = this.$route.params.id;

      //货物信息
      findByFlightId(id).then((response) => {
        if (response.code != 200) {
          this.$message({
            showClose: true,
            message: response.msg,
            type: "error",
          });
          reuturn;
        }
        let info = response.data.list;
        info.typeOfGoods = info.typeOfGoods ? info.typeOfGoods.split(";") : [];
        info.declarationCategory = info.declarationCategory
          ? info.declarationCategory.split(";")
          : [];
        info.serviceCode = info.serviceCode ? info.serviceCode.split(";") : [];
        info.subCategory = info.subCategory ? info.subCategory.split(";") : [];
        this.form = info;
        this.loading = false;
      });
    } else {
      this.loading = false;
    }
  },
};
</script>
<style rel="stylesheet/scss" lang="scss">
.el-textarea.is-disabled .el-textarea__inner {
  background-color: rgba(255, 255, 255, 0.5);
  color: #303133;
}
.el-input.is-disabled .el-input__inner {
  background-color: rgba(255, 255, 255, 0.5);
  color: #303133;
}
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  background-color: rgba(255, 255, 255, 0.5);
}
.el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #303133;
}
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #303133;
}
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner {
  border-color: #606266;
}
</style>