網站首頁 編程語言 正文
一.首先定義一個賦默認值的方法,然后初始化時調用,新增時調用
二.新增與更新,入參一致,所以可以共用一個接口,一個方法,根據是否有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
- 上一篇:沒有了
- 下一篇:沒有了
相關推薦
- 2022-03-14 npm 更改為淘寶鏡像的方法
- 2022-07-22 Qt鍵盤事件和鼠標事件、定時器小實例詳解
- 2022-07-06 C++實現中值濾波的示例代碼_C 語言
- 2022-10-16 Android原生定位服務LocationManager_Android
- 2023-02-03 C++中為何推薦要把基類析構函數設置成虛函數_C 語言
- 2023-04-02 linux?top命令基本實戰_linux shell
- 2022-06-21 C語言超全面講解函數的使用方法上_C 語言
- 2022-09-18 C++如何實現二叉樹鏈表_C 語言
- 欄目分類
-
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支