import Utils from "~/utils";

export default {
  methods: {
		// 表单提交
    async handleSubmit() {
      let result = await this.save();
      if (result.respCode == SUCCESS) {
        this.$notify({
          title: "成功",
          message: "保存成功",
          type: "success",
        });
        this.$router.history.push("/business/trnrel");
      } else {
        this.$notify({
          title: "失败",
          message: "保存失败",
          type: "error",
        });
      }
    },
		// 表单暂存
    async handleStash() {
      let result = await this.pedding();
      if (result.respCode == SUCCESS) {
        this.$notify({
          title: "成功",
          message: "暂存成功",
          type: "success",
        });
        this.$router.history.push("/business/sptsel");
      } else {
        this.$notify({
          title: "失败",
          message: "暂存失败",
          type: "error",
        });
      }
    },
		// 表单校验
    async handleCheck() {
      let result = await this.checkAll();
      if (result.respCode != SUCCESS) {
        this.$notify.error({ title: "错误", message: result.respMsg });
      } else {
        // 清除之前的校验状态
        this.$refs.modelForm.clearValidate();
        const fields = this.$refs.modelForm.fields;
        const fieldErrors = result.fieldErrors;
        this.updateModel(result.data);
        Utils.positioningErrorMsg(fieldErrors, fields);
        const tab = Utils.positioningErrorMsg(fieldErrors, fields);
        if (tab) {
          // tab切换之后，需出发tab-click的事件
          this.tabClick(tab);
        }
      }
    },
  },
};
