index.vue 10.4 KB
<template>
  <div ref="barEcharts" class="route-info-container">
    <!-- 航线设置规则信息查询条件 -->
    <el-row style="padding: 0 50px">
      <el-col>
        <yl-form
          ref="ruleForm"
          :formConfig="formConfig"
          :queryForm="queryForm"
          :inline="false"
          formWidth="auto"
          @blur="blurEvent"
        >
          <route-draggable
            :routeList="routeList"
            :dragOptions="dragOptions"
          ></route-draggable>
        </yl-form>
      </el-col>
    </el-row>
    <!-- 航线设置规则信息 -->
    <el-row>
      <el-col :span="24">
        <el-divider content-position="left">航线维度设置</el-divider>
      </el-col>
      <el-col>
        <route-info
          ref="routeInfo"
          :routesInfo="routesInfo"
          :cargoType="cargoType"
          :cargoStatus="cargoStatus"
          :puporpux="puporpux"
          :serviceCode="serviceCode"
          :handlingCode="handlingCode"
          :subCategory="subCategory"
          :status="getRouter"
          :loading="loading"
          @location="changeLocation"
          @destinationSite="changeDestinationSite"
          @addRlue="addRlue"
          @save="saveSubmit"
          @onOff="onOffSubmit"
          @delete="deleteSubmit"
        >
        </route-info>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import YlForm from "@/components/YlForm";
import RouteInfo from "../components/RouteInfo";
import RouteDraggable from "../components/RouteDraggable";
import { formConfig, routeRuleForm, validateForm } from "./formConfig";
import {
  updateOrAddFlight, // 新增/修改航线规则设置
  delFlightId, // 删除航线规则设置
  enableOrDisable, // 开启/停用航线规则设置
  batchUpdateOrAddFlight, // 航班航线优先级更新
  queryRouteByFltNo, // 通过航班号查询航线
} from "@/api/destinationFlight";
import indexMixins from "../mixins";
export default {
  components: {
    YlForm,
    RouteInfo,
    RouteDraggable,
  },
  mixins: [indexMixins],
  data() {
    return {
      loading: false, // 折叠面板
      dragOptions: {
        // 航线优先级拖拽配置
        animation: 200,
        group: "description",
        disabled: true, // 是否禁止拖拽
        ghostClass: "ghost",
      },
      formConfig: formConfig, // 表单配置项
      queryForm: {
        // 表单参数
      },
      routeList: [], // 航线
      routesInfo: [], // 航线规则信息
      cargoType: [], // 申报类别
      cargoStatus: [], // 货物类型
      puporpux: [], // 取件扫描号
      serviceCode: [], // Service Code
      handlingCode: [], // Handling Code
      subCategory: [], // Sub Category
    };
  },
  /*
    判断有日期的找到了就走有日期的,如果日期级别的没有找到再去走一次普通级别的接口
  */
  created() {
    this.getAllDictData(); // 获取全部字典
    const parmas = {
      querySpecifyData: this.$route.query.querySpecifyData || "", // 查询特殊数据字段
      purposeOfFlightNo: this.$route.query.purposeOfFlightNo || "", // 航班号
      flightDate: this.$route.query.flightDate || "", // 飞行日期
      flightRouteListStr: this.$route.query.flightRouteListStr || "", // 飞行航线集合
      status: this.$route.query.status || "", // 状态
      dataStatus: this.$route.query.dataStatus || "", // add 、edit、view
      flightKindName: this.$route.query.flightKindName || "", // 航班种类White Tail 、Purple Tail
      pageName: this.$route.query.pageName || "", //
      id: this.$route.query.id || "",
    };
    // 指定隐藏或显示From表单域
    this.hiddenFormItem(parmas);
    // queryCondition只负责接收参数和接口调用
    this.queryCondition(parmas);
  },
  mounted() {},
  methods: {
    // 【通过航班号查询航线】
    getQueryRouteByFltNo(parmas) {
      queryRouteByFltNo(parmas)
        .then((res) => {
          const { code, data } = res;
          if (code == 200) {
            if (data.list.length) {
              let isEtesRoute = data.list.filter(
                (item) => item.isEtesRoute == "N"
              ); // 过滤ET86航线
              const routes = [];
              if (isEtesRoute.length) {
                isEtesRoute.map((item) => {
                  routes.push({ config: false, route: item.route });
                });
              } else {
                this.msgWarning("暂无航线");
              }
              this.routeList = isEtesRoute;
              this.routesInfo = routes;
            } else {
              this.routeList = [];
              this.msgWarning("暂无航线");
            }
          }
        })
        .catch(() => {});
    },
    // 航班号输入框失焦事件
    blurEvent({ purposeOfFlightNo }) {
      // 航班号转大写
      routeRuleForm.flightRoute = this.upCase(purposeOfFlightNo);
      // 通过航班号查询航线
      this.getQueryRouteByFltNo({ fltNo: this.upCase(purposeOfFlightNo) });
      this.queryForm.purposeOfFlightNo = this.upCase(purposeOfFlightNo);
    },
    // 新增规则
    addRlue(index) {
      // 如果当前航班号的航线下没有数据,新增规则给默认数据
      routeRuleForm.purposeOfFlightNo = this.$route.query.purposeOfFlightNo;
      this.setattrVal(routeRuleForm);
      const mergeObj = {
        ...this.routesInfo[index],
        ...routeRuleForm,
      };
      this.$set(this.routesInfo, index, mergeObj); // 给新增规则赋上默认数据
    },
    // 保存 【新增/修改航线规则设置】
    saveSubmit(item, index) {
      item.flightRoute = item.route || item.flightRoute;
      let parmas = JSON.parse(JSON.stringify(item));
      this.returnString(parmas, "cargoType");
      this.returnString(parmas, "typeOfGoods");
      this.returnString(parmas, "puporpuxCode");
      this.returnString(parmas, "serviceCode");
      this.returnString(parmas, "handlingCode");
      this.returnString(parmas, "subCategory");
      if (parmas.minWeight || parmas.maxWeight) {
        if (
          !/^(0|[1-9]\d*)(.\d{1,5})?$/.test(
            parmas.minWeight || parmas.maxWeight
          )
        ) {
          this.msgWarning("请输入有效重量,小数保留5位");
          return;
        }
      }
      if (parmas.minNumOfPieces || parmas.maxNumOfPieces) {
        if (!/^\d+$/.test(parmas.minNumOfPieces || parmas.maxNumOfPieces)) {
          this.msgWarning("请输入有效件数");
          return;
        }
      }
      if (parmas.minNumOfPieces && parmas.maxNumOfPieces) {
        if (Number(parmas.minNumOfPieces) > Number(parmas.maxNumOfPieces)) {
          this.msgWarning("最小件数不能大于最大件数");
          return;
        }
      }
      if (parmas.minWeight && parmas.maxWeight) {
        if (Number(parmas.minWeight) > Number(parmas.maxWeight)) {
          this.msgWarning("最小重量不能大于最大重量");
          return;
        }
      }
      // 校验表单域的选项
      let validate = validateForm.some((key) => parmas[key]);
      if (validate) {
        this.loading = true;
        parmas.ruleDate = item.ruleDate || this.queryForm.flightDate;
        updateOrAddFlight(parmas)
          .then((res) => {
            const { code, msg, data } = res;
            if (code == 200) {
              this.hasOwnProperty(data, "typeOfGoods");
              this.hasOwnProperty(data, "puporpuxCode");
              this.hasOwnProperty(data, "serviceCode");
              this.hasOwnProperty(data, "handlingCode");
              this.hasOwnProperty(data, "subCategory");
              this.setattrVal(data); // 设置属性值
              this.$set(this.routesInfo, index, {
                config: true,
                ...data,
              });
              this.msgSuccess("保存成功!");
            } else {
              this.msgWarning(msg);
            }
            this.loading = false;
          })
          .catch(() => {
            this.loading = false;
          });
      } else {
        this.msgWarning("未添加规则信息,请添加后再保存!");
      }
    },
    // 开启/停用【开启/停用航线规则设置】
    onOffSubmit(item, index) {
      this.loading = true;
      let tip = item.status == "1" ? "停用" : "启用";
      let parmas = {
        id: item.id,
        status: item.status == "1" ? "3" : "1",
      };
      this.$confirm("是否确认" + tip + "此航班规则?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          enableOrDisable(parmas)
            .then((res) => {
              const { code, msg, data } = res;
              if (code == 200) {
                this.hasOwnProperty(data, "typeOfGoods");
                this.hasOwnProperty(data, "puporpuxCode");
                this.hasOwnProperty(data, "serviceCode");
                this.hasOwnProperty(data, "handlingCode");
                this.hasOwnProperty(data, "subCategory");
                this.setattrVal(data); // 设置属性值
                this.$set(this.routesInfo, index, {
                  config: true,
                  ...data,
                });
                this.msgSuccess(tip + "成功");
              } else {
                this.msgWarning(msg);
              }
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
            });
        })
        .catch(() => {
          this.loading = false;
        });
    },
    // 删除航线规则设置
    deleteSubmit(item, index) {
      this.loading = true;
      let parmas = {
        id: item.id,
      };
      this.$confirm("是否确认删除此航班规则?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        showCancelButton: true,
        type: "warning",
      })
        .then(() => {
          delFlightId(parmas)
            .then((res) => {
              const { code, msg, data } = res;
              if (code == 200) {
                this.$set(this.routesInfo, index, {
                  route: item.flightRoute,
                  config: false,
                });
                this.msgSuccess(msg);
              } else {
                this.msgWarning(msg);
              }
              this.loading = false;
            })
            .catch(() => {
              this.loading = false;
            });
        })
        .catch(() => {
          this.loading = false;
        });
    },
  },
};
</script>
<style lang="scss" scoped>
.route-info-container {
  padding: 20px;
}
</style>