日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

表單默認空白,無數據時賦默認值,新增時賦默認值

作者:Ybittersweet 更新時間: 2023-07-24 編程語言

一.首先定義一個賦默認值的方法,然后初始化時調用,新增時調用

二.新增與更新,入參一致,所以可以共用一個接口,一個方法,根據是否有id判斷

三.生成表單盡量用map不用push,因為push可能會出現重復添加的情況,但map每次會生成新的數組不用考慮這種情況

  <el-button type="primary" @click="switcSave()">保存</el-button>
    <el-button type="primary" @click="doPdf">生成報表</el-button>
    <el-button type="primary" @click="switcSave('add')">新增</el-button>
    <el-button type="danger" :disabled="this.flag" plain @click="doDelete">刪除</el-button>
    data(){
    flag:false
    }
// 新增保存
export function switchFormData(data) {
  if(data.id){
    return request({
      url: "/api/TaskFormData/Update",
      method: "put",
      data
    });
  }else{
    return request({
      url: "/api/TaskFormData/Insert",
      method: "post",
      data
    });
  }
}
 getFrom() {
      this.form = {
        id: "",
        remark01:"",
        remark02: "",
        remark03:"",
        remark07: "",
        remark08: "",
        remark09: "",
        remark10: "",
        remark11: "",
        remark12: "",
        remark13: "",
        remark14: "",
        remark16: moment(new Date()).format('YYYY-MM-DD'),
        user_remark10: ""
      }
    },
    async init() {
      const { data } = await GetFormData({ taskId: this.conditions.remark01, formName: this.formTableName })
      // 如果沒有數據就清空form,重新加載
      if (data.data.length == 0) {
        this.getFrom()
        this.formList = []
        this.flag = true
        this.formList.push(this.form)
        return false
      }
      if (data.statusCode == 200) {
        this.flag = false
        // 獲取到當前的表單
        data.data.forEach((el, index) => {
          if (this.currentIndex == index) {
            this.form = el.value
            this.form.id = el.id
          }
        })
           // 生成新的列表
          const values = data.data.map(item => item.value)
          this.formList = values
          console.log(  this.form ,"  this.form ");
          console.log("formList",this.formList);
      }

    },
    async switcSave(val) {
     
      if(val=='add'){
        this.getFrom()
      }
      this.form.remark01 = this.conditions.remark01;
      this.form.remark03 = this.conditions.remark03;
      let isFullBoxRemark = this.isFullBox == 0 ? "空箱" : "滿箱"
      let formData = {
        id: this.form.id,
        taskId: this.taskId,
        formName: this.formTableName,
        formNameRemark: `${this.conditions.remark03}_${isFullBoxRemark}_` + `測量_關鍵參數設置表`,
        key: {
          isFullBox: this.isFullBox,
          XYZDirection: this.conditions.remark03,
          step: 'X'
        },
        value: this.form,
      };
      this.form.id?formData['updatedUserId']=this.loginUserId:formData['createdUserId']=this.loginUserId
      const{data}= await switchFormData(formData)
      if (data.statusCode == 200) {
          this.$message.success(this.form.id?'保存成功':' 新增成功');
          this.init()
        } else {
          this.$message.error(this.form.id?'保存失敗':' 新增失敗');
        }
    },

原文鏈接:https://blog.csdn.net/Ybittersweet/article/details/129704148

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新