puzhibing
6 天以前 0db8c9b94a9ac655549d5eba5c2a6c92ac386c06
culture/src/views/strain-library/strain-library-manage/add.vue
@@ -135,6 +135,7 @@
        count: ''
      },
      displayStrainSeq: '', // 显示用的序号(可能包含前导零)
      cacheForm: null,
      form: {
        projectId: '',
        strainCode: '',
@@ -185,7 +186,12 @@
      }
    }
  },
  async mounted() {
  deactivated() {
    this.cacheForm = JSON.parse(JSON.stringify(this.form));
    this.cacheForm.displayStrainSeq = this.displayStrainSeq
  },
  async activated() {
    console.log('mounted')
    await this.fetchTeamList();
    this.form = {
@@ -199,24 +205,35 @@
      preservationMethod: '',
      remark: ''
    }
    this.displayStrainSeq = 0
    if (this.$route.query.id) {
      getDetail({id: this.$route.query.id}).then(res => {
        this.form = {...res}
        console.log('projectId =', this.form.projectId, typeof this.form.projectId)
    console.log('this.cacheForm', this.cacheForm)
    if (this.cacheForm) {
      this.form = this.cacheForm;
      if (this.cacheForm.displayStrainSeq) {
        this.displayStrainSeq = this.cacheForm.displayStrainSeq;
      }
      return
    }
        if (res.strainCode) {
          const parts = res.strainCode.split('-');
          if (parts.length > 1) {
            const seq = parts.pop();
            this.displayStrainSeq = seq.replace(/^0+/, '');
            this.form.strainCode = parts.join('-');
          } else {
            this.form.strainCode = res.strainCode;
          }
    console.log('this.$route.query.id', this.$route.query.id)
    if (this.$route.query.id && !this.cacheForm) {
      const res = await getDetail({id: this.$route.query.id});
      this.form = {...res}
      console.log('projectId =', this.form.projectId, typeof this.form.projectId)
      if (res.strainCode) {
        const parts = res.strainCode.split('-');
        if (parts.length > 1) {
          const seq = parts.pop();
          this.displayStrainSeq = seq.replace(/^0+/, '');
          this.form.strainCode = parts.join('-');
        } else {
          this.form.strainCode = res.strainCode;
        }
      })
      }
      this.$forceUpdate();
    }
  },
  watch: {
@@ -277,12 +294,7 @@
          this.form.strainSeq = String(num);
          // 显示时补零到3位
          this.displayStrainSeq = String(num).padStart(3, '0');
        } else {
          this.form.strainSeq = '';
          this.displayStrainSeq = '';
        }
      } else {
        this.displayStrainSeq = '';
      }
      console.log('格式化后存储值:', this.form.strainSeq);
@@ -296,8 +308,6 @@
      if (this.form.strainSeq) {
        // 显示原始数字,去除前导零
        this.displayStrainSeq = this.form.strainSeq;
      } else {
        this.displayStrainSeq = '';
      }
    },
    getFullStrainCode() {
@@ -389,8 +399,10 @@
        } else {
          await add(requestData);
        }
        this.cacheForm = null
        this.displayStrainSeq = null
        this.signatureVisible = false;
        this.$router.push({ path: '/strain-library/strain-library-manage' });
        this.$closeCurrentView('/strain-library/strain-library-manage');
        this.$message.success('操作成功');
      } catch (error) {
        this.$message.error('操作失败');